Started craeting API dispatch and implementation. Updated api doc.

This commit is contained in:
Jonathan Bernard 2011-01-29 10:46:45 -06:00
parent c04b73d9cc
commit 0d96c26174
2 changed files with 58 additions and 0 deletions

View File

@ -87,4 +87,11 @@ DELETE
Delete a timeline.
Events: ``/<user-id>/<timeline-id>/events``
-------------------------------------------
GET
~~~
PUT
~~~

51
src/ts_api.erl Normal file
View 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}])).