diff --git a/doc/api.rst b/doc/api.rst index 1907a3a..82ab8f0 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -87,4 +87,11 @@ DELETE Delete a timeline. +Events: ``///events`` +------------------------------------------- +GET +~~~ + +PUT +~~~ diff --git a/src/ts_api.erl b/src/ts_api.erl new file mode 100644 index 0000000..df32884 --- /dev/null +++ b/src/ts_api.erl @@ -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}])).