Current section

Files

Jump to
glitch src glitch@event_sub@subscription@user.erl
Raw

src/glitch@event_sub@subscription@user.erl

-module(glitch@event_sub@subscription@user).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([authorization_to_string/1, to_string/1, authorization_from_string/1, from_string/1]).
-export_type([user/0, invalid_user_subscription/0, authorization/0]).
-type user() :: update | {authorization, authorization()}.
-type invalid_user_subscription() :: invalid_user_subscription.
-type authorization() :: grant | revoke.
-spec authorization_to_string(authorization()) -> binary().
authorization_to_string(Authorization) ->
case Authorization of
grant ->
<<"user.authorization.grant"/utf8>>;
revoke ->
<<"user.authorization.revoke"/utf8>>
end.
-spec to_string(user()) -> binary().
to_string(User) ->
case User of
update ->
<<"user.update"/utf8>>;
{authorization, Authorization} ->
authorization_to_string(Authorization)
end.
-spec authorization_from_string(binary()) -> {ok, authorization()} |
{error, invalid_user_subscription()}.
authorization_from_string(Str) ->
case Str of
<<"user.authorization.grant"/utf8>> ->
{ok, grant};
<<"user.authorization.revoke"/utf8>> ->
{ok, revoke};
_ ->
{error, invalid_user_subscription}
end.
-spec from_string(binary()) -> {ok, user()} |
{error, invalid_user_subscription()}.
from_string(Str) ->
case Str of
<<"user.update"/utf8>> ->
{ok, update};
_ ->
_pipe = Str,
_pipe@1 = authorization_from_string(_pipe),
gleam@result:map(
_pipe@1,
fun(Field@0) -> {authorization, Field@0} end
)
end.