Current section
Files
Jump to
Current section
Files
src/shimmer@http@endpoints.erl
-module(shimmer@http@endpoints).
-compile(no_auto_import).
-export([me/1, bot_gateway/1, send_message/3]).
-spec me(binary()) -> {ok, shimmer@types@user:user()} |
{error, shimmer@internal@error:shimmer_error()}.
me(Token) ->
Req = shimmer@http@request:new_with_auth(get, <<"/users/@me"/utf8>>, Token),
case begin
_pipe = gleam@hackney:send(Req),
gleam@result:map_error(_pipe, fun(Field@0) -> {http_error, Field@0} end)
end of
{error, _try} -> {error, _try};
{ok, Resp} ->
_pipe@1 = Resp,
_pipe@2 = gleam@http@response:get_header(
_pipe@1,
<<"content-type"/utf8>>
),
gleeunit_ffi:should_equal(
_pipe@2,
{ok, <<"application/json"/utf8>>}
),
shimmer@types@user:from_json_string(erlang:element(4, Resp))
end.
-spec bot_gateway(binary()) -> {ok,
shimmer@internal@types@responses@bot_gateway:bot_gateway_response()} |
{error, shimmer@internal@error:shimmer_error()}.
bot_gateway(Token) ->
Req = shimmer@http@request:new_with_auth(
get,
<<"/gateway/bot"/utf8>>,
Token
),
case begin
_pipe = gleam@hackney:send(Req),
gleam@result:map_error(_pipe, fun(Field@0) -> {http_error, Field@0} end)
end of
{error, _try} -> {error, _try};
{ok, Resp} ->
_pipe@1 = Resp,
_pipe@2 = gleam@http@response:get_header(
_pipe@1,
<<"content-type"/utf8>>
),
gleeunit_ffi:should_equal(
_pipe@2,
{ok, <<"application/json"/utf8>>}
),
shimmer@internal@types@responses@bot_gateway:from_json_string(
erlang:element(4, Resp)
)
end.
-spec send_message(binary(), binary(), binary()) -> {ok, boolean()} |
{error, shimmer@internal@error:shimmer_error()}.
send_message(Token, Channel_id, Content) ->
Json_body = <<<<"
{
\"content\": "/utf8, Content/binary>>/binary,
"\"
}
"/utf8>>,
Req = begin
_pipe = shimmer@http@request:new_with_auth(
post,
<<<<"/channels/"/utf8, Channel_id/binary>>/binary,
"/messages"/utf8>>,
Token
),
shimmer@http@request:set_body(_pipe, Json_body)
end,
case begin
_pipe@1 = gleam@hackney:send(Req),
gleam@result:map_error(
_pipe@1,
fun(Field@0) -> {http_error, Field@0} end
)
end of
{error, _try} -> {error, _try};
{ok, _@1} ->
{ok, true}
end.