Bugfix and documentation.

- Fixed a bug in ts_api:list_timelines/2 and ts_api:list_entries/3, which
  respond only to GET requests but were looking for POST data.
- Added documentation for ts.js.
This commit is contained in:
Jonathan Bernard
2011-03-01 18:00:51 -06:00
parent efab46f167
commit 348c73a36f
4 changed files with 81 additions and 23 deletions

View File

@ -240,16 +240,16 @@ get_user(YArg, Username) ->
list_timelines(YArg, Username) ->
% pull out the POST data
PostData = yaws_api:parse_post(YArg),
QueryData = yaws_api:parse_query(YArg),
% read or default the Start
Start = case lists:keyfind(start, 1, PostData) of
Start = case lists:keyfind(start, 1, QueryData) of
{start, StartVal} -> list_to_integer(StartVal);
false -> 0
end,
% read or default the Length
Length = case lists:keyfind(length, 1, PostData) of
Length = case lists:keyfind(length, 1, QueryData) of
{length, LengthVal} ->
erlang:min(list_to_integer(LengthVal), 50);
false -> 50
@ -340,35 +340,35 @@ delete_timeline(_YArg, _Username, _TimelineId) -> {status, 405}.
list_entries(YArg, Username, TimelineId) ->
% pull out the POST data
PostData = yaws_api:parse_post(YArg),
QueryData = yaws_api:parse_query(YArg),
% first determine if we are listing by date
case {ts_timeline:lookup(Username, TimelineId),
lists:keyfind(byDate, 1, PostData)} of
lists:keyfind("byDate", 1, QueryData)} of
{no_record, _ByDateField} -> make_json_404(
[{status, "no such timeline"},
{see_docs, "/ts_api_doc/entries.html#LIST"}]);
% listing by date range
{Timeline, {byDate, "true"}} ->
{Timeline, {"byDate", "true"}} ->
% look for the start date; default to the beginning of the timeline
StartDate = case lists:keyfind(startDate, 1, PostData) of
StartDate = case lists:keyfind("startDate", 1, QueryData) of
% TODO: error handling if the date is badly formatted
{startDate, StartDateVal} -> ts_json:decode_date(StartDateVal);
false -> Timeline#ts_timeline.created
end,
% look for end date; default to right now
EndDate = case lists:keyfind(endDate, 1, PostData) of
EndDate = case lists:keyfind("endDate", 1, QueryData) of
% TODO: error handling if the date is badly formatted
{endDate, EndDateVal} -> ts_json:decode_date(EndDateVal);
false -> calendar:now_to_universal_time(erlang:now())
end,
% read sort order and list entries
Entries = case lists:keyfind(order, 1, PostData) of
Entries = case lists:keyfind("order", 1, QueryData) of
% descending sort order
{order, "desc"} -> ts_entry:list_desc(
{Username, TimelineId}, StartDate, EndDate);
@ -391,24 +391,24 @@ list_entries(YArg, Username, TimelineId) ->
_Other ->
% read or default the Start
Start = case lists:keyfind(start, 1, PostData) of
Start = case lists:keyfind("start", 1, QueryData) of
{start, StartVal} -> list_to_integer(StartVal);
false -> 0
end,
% read or default the Length
Length = case lists:keyfind(length, 1, PostData) of
Length = case lists:keyfind("length", 1, QueryData) of
{length, LengthVal} ->
erlang:min(list_to_integer(LengthVal), 500);
false -> 50
end,
% read sort order and list entries
Entries = case lists:keyfind(order, 1, PostData) of
{order, "desc"} -> ts_entry:list_desc(
Entries = case lists:keyfind("order", 1, QueryData) of
{"order", "desc"} -> ts_entry:list_desc(
{Username, TimelineId}, Start, Length);
_Other -> ts_entry:list_asc(
_UnknownOrder -> ts_entry:list_asc(
{Username, TimelineId}, Start, Length)
end,