Current section
Files
Jump to
Current section
Files
src/glyph@network@rest.erl
-module(glyph@network@rest).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([set_bot_user_agent/3, set_authorization/3, set_content_type/2, new/0, get/2, post/3]).
-export_type([token_type/0]).
-type token_type() :: bearer | bot.
-spec token_type_to_string(token_type()) -> binary().
token_type_to_string(Token_type) ->
case Token_type of
bearer ->
<<"Bearer"/utf8>>;
bot ->
<<"Bot"/utf8>>
end.
-spec set_bot_user_agent(gleam@http@request:request(LKI), binary(), binary()) -> gleam@http@request:request(LKI).
set_bot_user_agent(R, Url, Version) ->
_pipe = R,
gleam@http@request:set_header(
_pipe,
<<"User-Agent"/utf8>>,
<<<<<<<<"DiscordBot("/utf8, Url/binary>>/binary, ", "/utf8>>/binary,
Version/binary>>/binary,
")"/utf8>>
).
-spec set_authorization(
gleam@http@request:request(binary()),
token_type(),
binary()
) -> gleam@http@request:request(binary()).
set_authorization(R, Token_type, Token) ->
_pipe = R,
gleam@http@request:set_header(
_pipe,
<<"Authorization"/utf8>>,
<<<<(token_type_to_string(Token_type))/binary, " "/utf8>>/binary,
Token/binary>>
).
-spec set_content_type(gleam@http@request:request(binary()), binary()) -> gleam@http@request:request(binary()).
set_content_type(R, Content_type) ->
_pipe = R,
gleam@http@request:set_header(_pipe, <<"content-type"/utf8>>, Content_type).
-spec new() -> gleam@http@request:request(binary()).
new() ->
_pipe = gleam@http@request:new(),
_pipe@1 = gleam@http@request:set_scheme(_pipe, https),
gleam@http@request:set_host(_pipe@1, <<"discord.com"/utf8>>).
-spec get(gleam@http@request:request(binary()), binary()) -> {ok,
gleam@http@response:response(binary())} |
{error, gleam@hackney:error()}.
get(R, Endpoint) ->
_pipe = R,
_pipe@1 = gleam@http@request:set_method(_pipe, get),
_pipe@2 = gleam@http@request:set_path(
_pipe@1,
<<<<"/api/v"/utf8, "10"/utf8>>/binary, Endpoint/binary>>
),
gleam@hackney:send(_pipe@2).
-spec post(gleam@http@request:request(binary()), binary(), binary()) -> {ok,
gleam@http@response:response(binary())} |
{error, gleam@hackney:error()}.
post(R, Endpoint, Body) ->
_pipe = R,
_pipe@1 = gleam@http@request:set_method(_pipe, post),
_pipe@2 = gleam@http@request:set_path(
_pipe@1,
<<<<"/api/v"/utf8, "10"/utf8>>/binary, Endpoint/binary>>
),
_pipe@3 = gleam@http@request:set_body(_pipe@2, Body),
gleam@hackney:send(_pipe@3).