Created
October 10, 2009 12:03
-
-
Save sinkovsky/206808 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tick_list_from_json(Series_id, Json) -> | |
case probix_series:series(Series_id) of | |
not_found -> | |
{error, not_found}; | |
_Series -> | |
case decode_tick_json(Series_id, Json) of | |
bad_json -> {error, bad_json}; | |
List -> List | |
end | |
end. | |
json_struct_to_tick(Series_id, {struct, Struct}) -> | |
#tick{ | |
id = {Series_id, proplists:get_value(<<"timestamp">>, Struct)}, | |
value = proplists:get_value(<<"value">>, Struct) | |
}. | |
decode_tick_json(Series_Id, Json) -> | |
try mochijson2:decode(Json) of | |
List when is_list(List) -> | |
[ json_struct_to_tick(Series_Id, P) || P <- List ]; | |
Struct when is_tuple(Struct) -> | |
[ json_struct_to_tick(Series_Id, Struct) ] | |
catch | |
_Any -> | |
bad_json | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment