Started craeting API dispatch and implementation. Updated api doc.
This commit is contained in:
parent
c04b73d9cc
commit
0d96c26174
@ -87,4 +87,11 @@ DELETE
|
||||
|
||||
Delete a timeline.
|
||||
|
||||
Events: ``/<user-id>/<timeline-id>/events``
|
||||
-------------------------------------------
|
||||
|
||||
GET
|
||||
~~~
|
||||
|
||||
PUT
|
||||
~~~
|
||||
|
51
src/ts_api.erl
Normal file
51
src/ts_api.erl
Normal file
@ -0,0 +1,51 @@
|
||||
-module(ts_api).
|
||||
-compile(export_all).
|
||||
|
||||
-include("ts_db_records/hrl").
|
||||
-include("yaws_api.hrl").
|
||||
|
||||
out(YArg) ->
|
||||
%get the app mod data
|
||||
PathString = YArg#arg.apmoddata,
|
||||
% split the path
|
||||
PathElements = cast PathString of
|
||||
undefined -> []; %handle no end slash: /ts_api
|
||||
_Any -> re:split(PathString, "/", [{return, list}])
|
||||
end,
|
||||
% process request
|
||||
dispatch_request(YArg, PathElements).
|
||||
|
||||
% ================================== %
|
||||
% ======== DISPATCH METHODS ======== %
|
||||
% ================================== %
|
||||
|
||||
%% Entry point to the TimeStamper API dispatch system
|
||||
dispatch_request(_YArg, []) ->
|
||||
% no arguments: URL is /ts_api or /ts_api/, shoe API docs
|
||||
{page, "/ts_api_doc/index.html"};
|
||||
|
||||
dispatch_request(YArg, [H|T]) ->
|
||||
Username = path_element_to_atom(H),
|
||||
case T of
|
||||
% no additional parameters, show user info
|
||||
[] -> get_user_info(YArg, Username);
|
||||
[Param|Params] ->
|
||||
Timeline = path_element_to_atom(Param)
|
||||
dispatch_timeline(YArg, Username, Timeline, Params)
|
||||
end.
|
||||
|
||||
% no events, show timeline pages
|
||||
%dispatch_timeline(_YArg, Username, Timeline, []) ->
|
||||
%Req = YArg#arg.arg,
|
||||
%HTTPMethod = Req#http_request.method,
|
||||
%
|
||||
%case HTTPMethod of
|
||||
%'GET' -> list_timelines(Yarg
|
||||
|
||||
% ============================== %
|
||||
% ======== UTIL METHODS ======== %
|
||||
% ============================== %
|
||||
|
||||
%% Convert one path element to an atom.
|
||||
path_element_to_atom(PE) ->
|
||||
list_to_atom(re:replace(PE, "\\s", "_", [{return, list}])).
|
Loading…
x
Reference in New Issue
Block a user