Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
add 'load' API resource
Browse files Browse the repository at this point in the history
  • Loading branch information
jkvor committed Jan 24, 2012
1 parent ff6bf26 commit 7444e3b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/logplex_api.erl
Expand Up @@ -87,6 +87,24 @@ handlers() ->
{200, <<"OK">>}
end},

{['POST', "/load$"], fun(Req, _Match) ->
authorize(Req),
Body = Req:recv_body(),
{struct, Modules} = mochijson2:decode(Body),
not is_list(Modules) andalso exit({expected_list}),

{RespCode, Json} = lists:foldl(fun(Module, {Code, Acc}) ->
Module1 = binary_to_atom(Module, latin1),
case c:l(Module1) of
{module, _} when Code == 200 -> {200, Acc};
{module, _} -> {Code, Acc};
{error, Reason} -> {400, [{Module, atom_to_binary(Reason, latin1)}|Acc]}
end
end, {200, []}, Modules),

{RespCode, iolist_to_binary(mochijson2:encode(Json))}
end},

{['POST', "/channels$"], fun(Req, _Match) ->
authorize(Req),
Body = Req:recv_body(),
Expand Down

0 comments on commit 7444e3b

Please sign in to comment.