Current section
Files
Jump to
Current section
Files
src/howdy@context@body.erl
-module(howdy@context@body).
-compile(no_auto_import).
-export([get_json/2, get_form/1]).
-spec get_json(
howdy@context:context(any()),
fun((gleam@dynamic:dynamic()) -> {ok, IAN} |
{error, list(gleam@dynamic:decode_error())})
) -> {ok, IAN} | {error, gleam@json:decode_error()}.
get_json(In, Decoder) ->
Result = gleam@bit_string:to_string(
erlang:element(4, erlang:element(3, In))
),
case Result of
{ok, Str} ->
gleam@json:decode(Str, Decoder);
{error, _@1} ->
{error, unexpected_end_of_input}
end.
-spec get_form(howdy@context:context(any())) -> {ok,
gleam@map:map_(binary(), binary())} |
{error, nil}.
get_form(In) ->
case gleam@bit_string:to_string(erlang:element(4, erlang:element(3, In))) of
{error, _try} -> {error, _try};
{ok, Body} ->
_pipe = Body,
_pipe@1 = gleam@string:split(_pipe, <<"&"/utf8>>),
_pipe@4 = gleam@list:map(
_pipe@1,
fun(X) ->
_pipe@2 = X,
_pipe@3 = gleam@string:split(_pipe@2, <<"="/utf8>>),
to_tuple(_pipe@3)
end
),
_pipe@5 = gleam@list:filter(
_pipe@4,
fun(X@1) -> X@1 /= {error, nil} end
),
_pipe@6 = gleam@list:map(
_pipe@5,
fun(X@2) ->
gleam@result:unwrap(X@2, {<<""/utf8>>, <<""/utf8>>})
end
),
_pipe@7 = gleam@map:from_list(_pipe@6),
{ok, _pipe@7}
end.
-spec to_tuple(list(binary())) -> {ok, {binary(), binary()}} | {error, nil}.
to_tuple(Lst) ->
case gleam@list:length(Lst) of
2 ->
case gleam@list:first(Lst) of
{error, _try} -> {error, _try};
{ok, First} ->
case gleam@list:last(Lst) of
{error, _try@1} -> {error, _try@1};
{ok, Last} ->
{ok, {First, Last}}
end
end;
_@1 ->
{error, nil}
end.