aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Chmielowski <pchmielowski@process-one.net>2016-08-04 16:04:43 +0200
committerPaweł Chmielowski <pchmielowski@process-one.net>2016-09-13 11:27:59 +0200
commit2f596b0e1042607ef9b66b6ecbb5b18b87b073ea (patch)
treefe4a9d7b58caf7c7054b8da4683e9a3923180ab3
parentAdd X-Admin and basic auth header to CORS allowed headers in http_api (diff)
Expand parsing of json input to be able to handle update_roster command
-rw-r--r--src/mod_http_api.erl19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/mod_http_api.erl b/src/mod_http_api.erl
index e2f6cc240..dbca82375 100644
--- a/src/mod_http_api.erl
+++ b/src/mod_http_api.erl
@@ -387,6 +387,20 @@ format_args(Args, ArgsFormat) ->
L when is_list(L) -> exit({additional_unused_args, L})
end.
+format_arg({Elements},
+ {list, {_ElementDefName, {tuple, [{_Tuple1N, Tuple1S}, {_Tuple2N, Tuple2S}]} = Tuple}})
+ when is_list(Elements) andalso
+ (Tuple1S == binary orelse Tuple1S == string) ->
+ lists:map(fun({F1, F2}) ->
+ {format_arg(F1, Tuple1S), format_arg(F2, Tuple2S)};
+ ({Val}) when is_list(Val) ->
+ format_arg({Val}, Tuple)
+ end, Elements);
+format_arg(Elements,
+ {list, {_ElementDefName, {list, _} = ElementDefFormat}})
+ when is_list(Elements) ->
+ [{format_arg(Element, ElementDefFormat)}
+ || Element <- Elements];
format_arg(Elements,
{list, {_ElementDefName, ElementDefFormat}})
when is_list(Elements) ->
@@ -494,6 +508,11 @@ format_result({Code, Text}, {Name, restuple}) ->
{[{<<"res">>, Code == true orelse Code == ok},
{<<"text">>, iolist_to_binary(Text)}]}};
+format_result(Code, {Name, restuple}) ->
+ {jlib:atom_to_binary(Name),
+ {[{<<"res">>, Code == true orelse Code == ok},
+ {<<"text">>, <<"">>}]}};
+
format_result(Els, {Name, {list, {_, {tuple, [{_, atom}, _]}} = Fmt}}) ->
{jlib:atom_to_binary(Name), {[format_result(El, Fmt) || El <- Els]}};