Packages

A small, focused OAuth 2.0 library for Gleam, built on top of Gleams HTTP requests and responses.

Current section

Files

Jump to
flwr_oauth2 src flwr_oauth2@helpers.erl
Raw

src/flwr_oauth2@helpers.erl

-module(flwr_oauth2@helpers).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/flwr_oauth2/helpers.gleam").
-export([add_if_present/2, unwrap_both/1, generate_random_string/2]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(" Helper functions\n").
-file("src/flwr_oauth2/helpers.gleam", 9).
?DOC(" Appends the value if present a given list\n").
-spec add_if_present(list(FNW), gleam@option:option(FNW)) -> list(FNW).
add_if_present(D, Value) ->
_pipe = [Value],
_pipe@1 = gleam@option:values(_pipe),
lists:append(_pipe@1, D).
-file("src/flwr_oauth2/helpers.gleam", 15).
-spec unwrap_both({ok, FOA} | {error, FOA}) -> FOA.
unwrap_both(Res) ->
case Res of
{ok, Res@1} ->
Res@1;
{error, Res@2} ->
Res@2
end.
-file("src/flwr_oauth2/helpers.gleam", 46).
-spec concat_strings(binary(), binary()) -> binary().
concat_strings(Left, Right) ->
<<Left/binary, Right/binary>>.
-file("src/flwr_oauth2/helpers.gleam", 27).
-spec generate_random_string_rec(binary(), integer(), integer(), binary()) -> binary().
generate_random_string_rec(Generated, Index, Length, Chars) ->
case Index =:= Length of
true ->
Generated;
false ->
_pipe = Chars,
_pipe@1 = string:length(_pipe),
_pipe@2 = gleam@int:random(_pipe@1),
_pipe@3 = gleam@string:slice(Chars, _pipe@2, 1),
_pipe@4 = concat_strings(Generated, _pipe@3),
generate_random_string_rec(_pipe@4, Index + 1, Length, Chars)
end.
-file("src/flwr_oauth2/helpers.gleam", 23).
?DOC(" Generates a random string from a given list of characters with a given length\n").
-spec generate_random_string(binary(), integer()) -> binary().
generate_random_string(Chars, Length) ->
generate_random_string_rec(<<""/utf8>>, 0, Length, Chars).