Skip to content

Commit

Permalink
resource_api: use the found "module" context var also for POST.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjan Scherpenisse committed Jul 19, 2011
1 parent affce7e commit e8ecd56
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions modules/mod_base/resources/resource_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -68,7 +68,7 @@ allowed_methods(ReqData, Context) ->
%% Not exists
{['GET', 'HEAD', 'POST'], ReqData, Context1}
end.


is_authorized(ReqData, Context) ->
%% Check if we are authorized via a regular session.
Expand Down Expand Up @@ -126,7 +126,7 @@ api_error(HttpCode, ErrCode, Message, ReqData, Context) ->


api_result(ReqData, Context, Result) ->
case Result of
case Result of
{error, Err=missing_arg, Arg} ->
api_error(400, Err, "Missing argument: " ++ Arg, ReqData, Context);

Expand Down Expand Up @@ -155,20 +155,18 @@ api_result(ReqData, Context, Result) ->
{{halt, 500}, ReqData1, Context}
end
end.


to_json(ReqData, Context) ->
Module = z_context:get("module", Context),
api_result(ReqData, Context, Module:process_get(ReqData, Context)).


process_post(ReqData, Context) ->
Method = list_to_atom(z_context:get_q("method", Context)),
{ok, Module} = z_module_indexer:find(service, Method, Context),
Module = z_context:get("module", Context),
case Module:process_post(ReqData, Context) of
ok ->
{true, ReqData, Context};
Result ->
api_result(ReqData, Context, Result)
end.

0 comments on commit e8ecd56

Please sign in to comment.