Continuing work on the API.

The id_counter module now includes the record directly in the source.
Fixed many typos and small syntax errors.
Added ts_api:dispatch_user/2 to handle different HTTP methods.
Added method placeholder stubs to ts_api.
Implemented ts_api:list_entries/3.
Added ts_user record and ts_user module.
Implemented ts_entry:list/4, the more generic guts of the other list functions.
Created ts_entry:list_asc/3 and ts_entry:list_desc/3.
Fixed ts_json:encode_datetime/1.
This commit is contained in:
Jonathan Bernard
2011-02-02 16:57:58 -06:00
parent 098cd4cbb9
commit 6fe9184c8e
15 changed files with 263 additions and 64 deletions

View File

@ -13,7 +13,7 @@ record_to_ejson(Record=#ts_timeline{}) ->
{struct, [
{id, atom_to_list(TimelineId)},
{created, encode_datetime(Record#ts_timeline.created)},
{description, Record#ts_timeline.desc}]}.
{description, Record#ts_timeline.desc}]};
record_to_ejson(Record=#ts_entry{}) ->
% pull out the entry id
@ -30,28 +30,28 @@ record_to_ejson(Record=#ts_entry{}) ->
{notes, Record#ts_entry.notes}]}.
encode_datetime({{Year, Month, Day}, {Hour, Minute, Second}}) ->
io_lib:format("~2B-~2B-~2BT~2.10.0B:~2.10.0B:~2.10.0BZ",
[Year, Month, Day, Hour, Minute, Second]).
lists:flatten(io_lib:format("~4.10.0B-~2.10.0B-~2.10.0BT~2.10.0B:~2.10.0B:~2.10.0BZ",
[Year, Month, Day, Hour, Minute, Second])).
ejson_to_record(Empty=#ts_timeline{}, EJSON) ->
{struct, Fields} = EJSON,
{Username, _} = Empty#ts_timeline.ref,
#ts_timeline{
ref = {Username, element(2, lists:keyfind(id, 1, EJSON))},
created = decode_datetime(element(2, lists:keyfind(created, 1, EJSON))),
desc = element(2, lists:keyfind(description, 1, EJSON))}.
ref = {Username, element(2, lists:keyfind(id, 1, Fields))},
created = decode_datetime(element(2, lists:keyfind(created, 1, Fields))),
desc = element(2, lists:keyfind(description, 1, Fields))};
ejson_to_record(Empty=#ts_entry{}, EJSON) ->
{struct, Fields} = EJSON,
{Username, TimelineId, _} = Empty#ts_entry.ref,
#ts_entry{
ref = {Username, TimelineId, element(2, lists:keyfind(id, 1, EJSON))},
ref = {Username, TimelineId, element(2, lists:keyfind(id, 1, Fields))},
timestamp = calendar:datetime_to_gregorian_seconds(decode_datetime(
element(2, lists:keyfind(timestamp, 1, EJSON)))),
mark = element(2, lists:keyfind(mark, 1, EJSON)),
notes = element(2, lists:keyfind(notes, 1, EJSON))}.
element(2, lists:keyfind(timestamp, 1, Fields)))),
mark = element(2, lists:keyfind(mark, 1, Fields)),
notes = element(2, lists:keyfind(notes, 1, Fields))}.
decode_datetime(DateTimeString) ->
% TODO: catch badmatch and badarg on whole function
@ -66,9 +66,9 @@ decode_datetime(DateTimeString) ->
re:split(TimeString, ":", [{return, list}]),
Date = {list_to_integer(YearString), list_to_integer(MonthString),
list_to_integer(DayString)}
list_to_integer(DayString)},
Time = {list_to_integer(HourString), list_to_integer(MinuteString),
list_to_integer(SecondString)}
list_to_integer(SecondString)},
{Date, Time}.