Started working on the client-side code.
This commit is contained in:
@ -62,20 +62,20 @@ dispatch_user(YArg, Session, [H]) ->
|
||||
{'GET', Username} -> get_user(YArg, Username);
|
||||
|
||||
{_BadMethod, Username} ->
|
||||
make_json_405(YArg, [{see_docs, "/ts_api_doc/users"}]);
|
||||
make_json_405(YArg, [{see_docs, "/ts_api_doc/users.html"}]);
|
||||
|
||||
_Other -> make_json_401(YArg, [{see_docs, "/ts_api_doc/users"}])
|
||||
_Other -> make_json_401(YArg, [{see_docs, "/ts_api_doc/users.html"}])
|
||||
end.
|
||||
|
||||
dispatch_timeline(YArg, _Session, []) ->
|
||||
make_json_404(YArg, [{see_docs, "/ts_api_doc/timelines"}]);
|
||||
make_json_404(YArg, [{see_docs, "/ts_api_doc/timelines.html"}]);
|
||||
|
||||
dispatch_timeline(YArg, Session, [UrlUsername|_T] = PathElements) ->
|
||||
Username = path_element_to_atom(UrlUsername),
|
||||
|
||||
case Session#ts_api_session.username of
|
||||
Username -> dispatch_timeline(YArg, PathElements);
|
||||
_Other -> make_json_404(YArg, [{see_docs, "/ts_api_doc/users"}])
|
||||
_Other -> make_json_404(YArg, [{see_docs, "/ts_api_doc/users.html"}])
|
||||
end.
|
||||
|
||||
% just username, list timelines
|
||||
@ -85,7 +85,7 @@ dispatch_timeline(YArg, [UrlUsername]) ->
|
||||
|
||||
case HTTPMethod of
|
||||
'GET' -> list_timelines(YArg, Username);
|
||||
_Other -> make_json_405(YArg, [{see_docs, "/ts_api_doc/timelines"}])
|
||||
_Other -> make_json_405(YArg, [{see_docs, "/ts_api_doc/timelines.html"}])
|
||||
end;
|
||||
|
||||
dispatch_timeline(YArg, [UrlUsername, UrlTimelineId]) ->
|
||||
@ -98,21 +98,21 @@ dispatch_timeline(YArg, [UrlUsername, UrlTimelineId]) ->
|
||||
'POST' -> post_timeline(YArg, Username, TimelineId);
|
||||
'PUT' -> put_timeline(YArg, Username, TimelineId);
|
||||
'DELETE' -> delete_timeline(YArg, Username, TimelineId);
|
||||
_Other -> make_json_405(YArg, [{see_docs, "/ts_api_doc/timelines"}])
|
||||
_Other -> make_json_405(YArg, [{see_docs, "/ts_api_doc/timelines.html"}])
|
||||
end;
|
||||
|
||||
dispatch_timeline(YArg, _Other) ->
|
||||
make_json_404(YArg, [{see_docs, "/ts_api_doc/timelines"}]).
|
||||
make_json_404(YArg, [{see_docs, "/ts_api_doc/timelines.html"}]).
|
||||
|
||||
dispatch_entry(YArg, _Session, []) ->
|
||||
make_json_404(YArg, [{see_docs, "/ts_aip_doc/entries"}]);
|
||||
make_json_404(YArg, [{see_docs, "/ts_aip_doc/entries.html"}]);
|
||||
|
||||
dispatch_entry(YArg, Session, [UrlUsername|_T] = PathElements) ->
|
||||
Username = path_element_to_atom(UrlUsername),
|
||||
|
||||
case Session#ts_api_session.username of
|
||||
Username -> dispatch_entry(YArg, PathElements);
|
||||
_Other -> make_json_404(YArg, [{see_docs, "/ts_api_doc/entries"}])
|
||||
_Other -> make_json_404(YArg, [{see_docs, "/ts_api_doc/entries.html"}])
|
||||
end.
|
||||
|
||||
dispatch_entry(YArg, [UrlUsername, UrlTimelineId]) ->
|
||||
@ -123,7 +123,7 @@ dispatch_entry(YArg, [UrlUsername, UrlTimelineId]) ->
|
||||
case HTTPMethod of
|
||||
'GET' -> list_entries(YArg, Username, TimelineId);
|
||||
'PUT' -> put_entry(YArg, Username, TimelineId);
|
||||
_Other -> make_json_405(YArg, [{see_docs, "/ts_api_doc/entries"}])
|
||||
_Other -> make_json_405(YArg, [{see_docs, "/ts_api_doc/entries.html"}])
|
||||
end;
|
||||
|
||||
dispatch_entry(YArg, [UrlUsername, UrlTimelineId, UrlEntryId]) ->
|
||||
@ -136,11 +136,11 @@ dispatch_entry(YArg, [UrlUsername, UrlTimelineId, UrlEntryId]) ->
|
||||
'GET' -> get_entry(YArg, Username, TimelineId, EntryId);
|
||||
'POST' -> post_entry(YArg, Username, TimelineId, EntryId);
|
||||
'DELETE' -> delete_entry(YArg, Username, TimelineId, EntryId);
|
||||
_Other -> make_json_405(YArg, [{see_docs, "/ts_api_doc/entries"}])
|
||||
_Other -> make_json_405(YArg, [{see_docs, "/ts_api_doc/entries.html"}])
|
||||
end;
|
||||
|
||||
dispatch_entry(YArg, _Other) ->
|
||||
make_json_404(YArg, [{see_docs, "/ts_api_doc/entries"}]).
|
||||
make_json_404(YArg, [{see_docs, "/ts_api_doc/entries.html"}]).
|
||||
|
||||
% ============================== %
|
||||
% ======== IMPLEMENTATION ====== %
|
||||
@ -175,7 +175,7 @@ do_login(YArg) ->
|
||||
"bad username/password combination"}])
|
||||
end;
|
||||
|
||||
_Other -> make_json_400(YArg, [{see_docs, "/ts_api_doc/login"}])
|
||||
_Other -> make_json_400(YArg, [{see_docs, "/ts_api_doc/login.html"}])
|
||||
end.
|
||||
|
||||
do_logout(YArg) ->
|
||||
@ -252,7 +252,7 @@ put_timeline(YArg, Username, TimelineId) ->
|
||||
JSONResponse = json:encode({struct, [
|
||||
{status, "ignored"},
|
||||
{timeline, EJSONRec},
|
||||
{see_docs, "/ts_api_doc/timelines#PUT"}
|
||||
{see_docs, "/ts_api_doc/timelines.html#PUT"}
|
||||
]}),
|
||||
|
||||
{content, "application/json", JSONResponse};
|
||||
@ -282,7 +282,7 @@ post_timeline(YArg, Username, TimelineId) ->
|
||||
|
||||
no_record -> make_json_404(YArg,
|
||||
[{status, "no such timeline"},
|
||||
{see_docs, "/ts_api_doc/timelines#POST"}]);
|
||||
{see_docs, "/ts_api_doc/timelines.html#POST"}]);
|
||||
|
||||
_Error -> make_json_500(YArg)
|
||||
end.
|
||||
@ -299,7 +299,7 @@ list_entries(YArg, Username, TimelineId) ->
|
||||
|
||||
{no_record, _ByDateField} -> make_json_404(
|
||||
[{status, "no such timeline"},
|
||||
{see_docs, "/ts_api_doc/entries#LIST"}]);
|
||||
{see_docs, "/ts_api_doc/entries.html#LIST"}]);
|
||||
|
||||
% listing by date range
|
||||
{Timeline, {byDate, "true"}} ->
|
||||
@ -402,7 +402,7 @@ put_entry(YArg, Username, TimelineId) ->
|
||||
JSONResponse = json:encode({struct, [
|
||||
{status, "ignored"},
|
||||
{entry, EJSONRec},
|
||||
{see_docs, "/ts_api_doc/entries#PUT"}
|
||||
{see_docs, "/ts_api_doc/entries.html#PUT"}
|
||||
]}),
|
||||
|
||||
{content, "application/json", JSONResponse};
|
||||
@ -425,7 +425,7 @@ post_entry(YArg, Username, TimelineId, EntryId) ->
|
||||
ok -> make_json_200(YArg, NewRecord);
|
||||
|
||||
no_record -> make_json_404(YArg,
|
||||
[{status, "no such entry"}, {see_docs, "/ts_api_doc/entries#POST"}]);
|
||||
[{status, "no such entry"}, {see_docs, "/ts_api_doc/entries.html#POST"}]);
|
||||
|
||||
_Error -> make_json_500(YArg)
|
||||
end.
|
||||
|
Reference in New Issue
Block a user