Current section
Files
Jump to
Current section
Files
src/glitch@types@subscription.erl
-module(glitch@types@subscription).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([subscription_type_to_string/1, subscription_type_from_string/1, subscription_type_decoder/0, subscription_type_to_json/1, subscription_type_from_json/1, subscription_status_from_string/1, subscription_status_to_string/1, subscription_status_decoder/0, decoder/0, subscription_status_to_json/1, subscription_status_from_json/1]).
-export_type([subscription/0, subscription_type/0, subscription_status/0]).
-type subscription() :: {subscription,
binary(),
subscription_status(),
subscription_type(),
binary(),
integer(),
glitch@types@condition:condition(),
glitch@types@transport:transport()}.
-type subscription_type() :: automod_message_hold |
automod_message_update |
automod_settings_update |
automod_terms_update |
channel_update |
channel_follow |
channel_ad_break_begin |
channel_chat_clear |
channel_chat_clear_user_messages |
channel_chat_message |
channel_chat_message_delete |
channel_chat_notification |
channel_chat_settings_update |
channel_chat_user_message_hold |
channel_chat_user_message_update |
channel_subscribe |
channel_subscription_end |
channel_subscription_gift |
channel_subscription_message |
channel_cheer |
channel_raid |
channel_ban |
channel_unban |
channel_unban_request_create |
channel_unban_request_resolve |
channel_moderate |
channel_moderator_add |
channel_moderator_remove |
channel_guest_star_session_begin |
channel_guest_star_session_end |
channel_guest_star_guest_update |
channel_guest_star_settings_update |
channel_points_automatic_reward_redemption |
channel_points_custom_reward_add |
channel_points_custom_reward_update |
channel_points_custom_reward_remove |
channel_points_custom_reward_redemption_add |
channel_points_custom_reward_redemption_update |
channel_poll_begin |
channel_poll_progress |
channel_poll_end |
channel_prediction_begin |
channel_prediction_progress |
channel_prediction_lock |
channel_prediction_end |
channel_suspicious_user_message |
channel_suspicious_user_update |
channel_vip_add |
channel_vip_remove |
charity_donation |
charity_campaign_start |
charity_campaign_progress |
charity_campaign_stop |
conduit_shard_disabled |
drop_entitlement_grant |
extension_bits_transaction_create |
goal_begin |
goal_progress |
goal_end |
hype_train_begin |
hype_train_progress |
hype_train_end |
shield_mode_begin |
shield_mode_end |
shoutout_create |
shoutout_received |
stream_online |
stream_offline |
user_authorization_grant |
user_authorization_revoke |
user_update |
whisper_received.
-type subscription_status() :: enabled | web_hook_callback_verification_pending.
-spec subscription_type_to_string(subscription_type()) -> binary().
subscription_type_to_string(Subscription_type) ->
case Subscription_type of
automod_message_hold ->
<<"automod.message.hold"/utf8>>;
automod_message_update ->
<<"automod.message.update"/utf8>>;
automod_settings_update ->
<<"automod.settings.update"/utf8>>;
automod_terms_update ->
<<"automod.terms.update"/utf8>>;
channel_update ->
<<"channel.update"/utf8>>;
channel_follow ->
<<"channel.follow"/utf8>>;
channel_ad_break_begin ->
<<"channel.ad_break.begin"/utf8>>;
channel_chat_clear ->
<<"channel.chat.clear"/utf8>>;
channel_chat_clear_user_messages ->
<<"channel.chat.clear_user_messages"/utf8>>;
channel_chat_message ->
<<"channel.chat.message"/utf8>>;
channel_chat_message_delete ->
<<"channel.chat.message_delete"/utf8>>;
channel_chat_notification ->
<<"channel.chat.notification"/utf8>>;
channel_chat_settings_update ->
<<"channel.chat_settings.update"/utf8>>;
channel_chat_user_message_hold ->
<<"channel.chat.user_message_hold"/utf8>>;
channel_chat_user_message_update ->
<<"channel.chat.user_message_update"/utf8>>;
channel_subscribe ->
<<"channel.subscribe"/utf8>>;
channel_subscription_end ->
<<"channel.subscription.end"/utf8>>;
channel_subscription_gift ->
<<"channel.subscription.gift"/utf8>>;
channel_subscription_message ->
<<"channel.subscription.message"/utf8>>;
channel_cheer ->
<<"channel.cheer"/utf8>>;
channel_raid ->
<<"channel.raid"/utf8>>;
channel_ban ->
<<"channel.ban"/utf8>>;
channel_unban ->
<<"channel.unban"/utf8>>;
channel_unban_request_create ->
<<"channel.unban_request.create"/utf8>>;
channel_unban_request_resolve ->
<<"channel.unban_request.resolve"/utf8>>;
channel_moderate ->
<<"channel.moderate"/utf8>>;
channel_moderator_add ->
<<"channel.moderator.add"/utf8>>;
channel_moderator_remove ->
<<"channel.moderator.remove"/utf8>>;
channel_guest_star_session_begin ->
<<"channel.guest_star_session.begin"/utf8>>;
channel_guest_star_session_end ->
<<"channel.guest_star_session.end"/utf8>>;
channel_guest_star_guest_update ->
<<"channel.guest_star_guest.update"/utf8>>;
channel_guest_star_settings_update ->
<<"channel.guest_star_settings.update"/utf8>>;
channel_points_automatic_reward_redemption ->
<<"channel.channel_points_automatic_reward_redemption.add"/utf8>>;
channel_points_custom_reward_add ->
<<"channel.channel_points_custom_reward.add"/utf8>>;
channel_points_custom_reward_update ->
<<"channel.channel_points_custom_reward.update"/utf8>>;
channel_points_custom_reward_remove ->
<<"channel.channel_points_custom_reward.remove"/utf8>>;
channel_points_custom_reward_redemption_add ->
<<"channel.channel_points_custom_reward_redemption.add"/utf8>>;
channel_points_custom_reward_redemption_update ->
<<"channel.channel_points_custom_reward_redemption.update"/utf8>>;
channel_poll_begin ->
<<"channel.poll.begin"/utf8>>;
channel_poll_progress ->
<<"channel.poll.progress"/utf8>>;
channel_poll_end ->
<<"channel.poll.end"/utf8>>;
channel_prediction_begin ->
<<"channel.prediction.begin"/utf8>>;
channel_prediction_progress ->
<<"channel.prediction.progress"/utf8>>;
channel_prediction_lock ->
<<"channel.prediction.lock"/utf8>>;
channel_prediction_end ->
<<"channel.prediction.end"/utf8>>;
channel_suspicious_user_message ->
<<"channel.suspicious_user.message"/utf8>>;
channel_suspicious_user_update ->
<<"channel.suspicious_user.update"/utf8>>;
channel_vip_add ->
<<"channel.vip.add"/utf8>>;
channel_vip_remove ->
<<"channel.vip.remove"/utf8>>;
charity_donation ->
<<"channel.charity_campaign.donate"/utf8>>;
charity_campaign_start ->
<<"channel.charity_campaign.start"/utf8>>;
charity_campaign_progress ->
<<"channel.charity_campaign.progress"/utf8>>;
charity_campaign_stop ->
<<"channel.charity_campaign.stop"/utf8>>;
conduit_shard_disabled ->
<<"conduit.shard.disabled"/utf8>>;
drop_entitlement_grant ->
<<"drop.entitlement.grant"/utf8>>;
extension_bits_transaction_create ->
<<"extension.bits_transaction.create"/utf8>>;
goal_begin ->
<<"channel.goal.begin"/utf8>>;
goal_progress ->
<<"channel.goal.progress"/utf8>>;
goal_end ->
<<"channel.goal.end"/utf8>>;
hype_train_begin ->
<<"channel.hype_train.begin"/utf8>>;
hype_train_progress ->
<<"channel.hype_train.progress"/utf8>>;
hype_train_end ->
<<"channel.hype_train.end"/utf8>>;
shield_mode_begin ->
<<"channel.shield_mode.begin"/utf8>>;
shield_mode_end ->
<<"channel.shield_mode.end"/utf8>>;
shoutout_create ->
<<"channel.shoutout.create"/utf8>>;
shoutout_received ->
<<"channel.shoutout.receive"/utf8>>;
stream_online ->
<<"stream.online"/utf8>>;
stream_offline ->
<<"stream.offline"/utf8>>;
user_authorization_grant ->
<<"user.authorization.grant"/utf8>>;
user_authorization_revoke ->
<<"user.authorization.revoke"/utf8>>;
user_update ->
<<"user.update"/utf8>>;
whisper_received ->
<<"user.whisper.message"/utf8>>
end.
-spec subscription_type_from_string(binary()) -> {ok, subscription_type()} |
{error, nil}.
subscription_type_from_string(Str) ->
case Str of
<<"automod.message.hold"/utf8>> ->
{ok, automod_message_hold};
<<"automod.message.update"/utf8>> ->
{ok, automod_message_update};
<<"automod.settings.update"/utf8>> ->
{ok, automod_settings_update};
<<"automod.terms.update"/utf8>> ->
{ok, automod_terms_update};
<<"channel.update"/utf8>> ->
{ok, channel_update};
<<"channel.follow"/utf8>> ->
{ok, channel_follow};
<<"channel.ad_break.begin"/utf8>> ->
{ok, channel_ad_break_begin};
<<"channel.chat.clear"/utf8>> ->
{ok, channel_chat_clear};
<<"channel.chat.clear_user_messages"/utf8>> ->
{ok, channel_chat_clear_user_messages};
<<"channel.chat.message"/utf8>> ->
{ok, channel_chat_message};
<<"channel.chat.message_delete"/utf8>> ->
{ok, channel_chat_message_delete};
<<"channel.chat.notification"/utf8>> ->
{ok, channel_chat_notification};
<<"channel.chat_settings.update"/utf8>> ->
{ok, channel_chat_settings_update};
<<"channel.chat.user_message_hold"/utf8>> ->
{ok, channel_chat_user_message_hold};
<<"channel.chat.user_message_update"/utf8>> ->
{ok, channel_chat_user_message_update};
<<"channel.subscribe"/utf8>> ->
{ok, channel_subscribe};
<<"channel.subscription.end"/utf8>> ->
{ok, channel_subscription_end};
<<"channel.subscription.gift"/utf8>> ->
{ok, channel_subscription_gift};
<<"channel.subscription.message"/utf8>> ->
{ok, channel_subscription_message};
<<"channel.cheer"/utf8>> ->
{ok, channel_cheer};
<<"channel.raid"/utf8>> ->
{ok, channel_raid};
<<"channel.ban"/utf8>> ->
{ok, channel_ban};
<<"channel.unban"/utf8>> ->
{ok, channel_unban};
<<"channel.unban_request.create"/utf8>> ->
{ok, channel_unban_request_create};
<<"channel.unban_request.resolve"/utf8>> ->
{ok, channel_unban_request_resolve};
<<"channel.moderate"/utf8>> ->
{ok, channel_moderate};
<<"channel.moderator.add"/utf8>> ->
{ok, channel_moderator_add};
<<"channel.moderator.remove"/utf8>> ->
{ok, channel_moderator_remove};
<<"channel.guest_star_session.begin"/utf8>> ->
{ok, channel_guest_star_session_begin};
<<"channel.guest_star_session.end"/utf8>> ->
{ok, channel_guest_star_session_end};
<<"channel.guest_star_guest.update"/utf8>> ->
{ok, channel_guest_star_guest_update};
<<"channel.guest_star_settings.update"/utf8>> ->
{ok, channel_guest_star_settings_update};
<<"channel.channel_points_automatic_reward_redemption.add"/utf8>> ->
{ok, channel_points_automatic_reward_redemption};
<<"channel.channel_points_custom_reward.add"/utf8>> ->
{ok, channel_points_custom_reward_add};
<<"channel.channel_points_custom_reward.update"/utf8>> ->
{ok, channel_points_custom_reward_update};
<<"channel.channel_points_custom_reward.remove"/utf8>> ->
{ok, channel_points_custom_reward_remove};
<<"channel.channel_points_custom_reward_redemption.add"/utf8>> ->
{ok, channel_points_custom_reward_redemption_add};
<<"channel.channel_points_custom_reward_redemption.update"/utf8>> ->
{ok, channel_points_custom_reward_redemption_update};
<<"channel.poll.begin"/utf8>> ->
{ok, channel_poll_begin};
<<"channel.poll.progress"/utf8>> ->
{ok, channel_poll_progress};
<<"channel.poll.end"/utf8>> ->
{ok, channel_poll_end};
<<"channel.prediction.begin"/utf8>> ->
{ok, channel_prediction_begin};
<<"channel.prediction.progress"/utf8>> ->
{ok, channel_prediction_progress};
<<"channel.prediction.lock"/utf8>> ->
{ok, channel_prediction_lock};
<<"channel.prediction.end"/utf8>> ->
{ok, channel_prediction_end};
<<"channel.suspicious_user.message"/utf8>> ->
{ok, channel_suspicious_user_message};
<<"channel.suspicious_user.update"/utf8>> ->
{ok, channel_suspicious_user_update};
<<"channel.vip.add"/utf8>> ->
{ok, channel_vip_add};
<<"channel.vip.remove"/utf8>> ->
{ok, channel_vip_remove};
<<"channel.charity_campaign.donate"/utf8>> ->
{ok, charity_donation};
<<"channel.charity_campaign.start"/utf8>> ->
{ok, charity_campaign_start};
<<"channel.charity_campaign.progress"/utf8>> ->
{ok, charity_campaign_progress};
<<"channel.charity_campaign.stop"/utf8>> ->
{ok, charity_campaign_stop};
<<"conduit.shard.disabled"/utf8>> ->
{ok, conduit_shard_disabled};
<<"drop.entitlement.grant"/utf8>> ->
{ok, drop_entitlement_grant};
<<"extension.bits_transaction.create"/utf8>> ->
{ok, extension_bits_transaction_create};
<<"channel.goal.begin"/utf8>> ->
{ok, goal_begin};
<<"channel.goal.progress"/utf8>> ->
{ok, goal_progress};
<<"channel.goal.end"/utf8>> ->
{ok, goal_end};
<<"channel.hype_train.begin"/utf8>> ->
{ok, hype_train_begin};
<<"channel.hype_train.progress"/utf8>> ->
{ok, hype_train_progress};
<<"channel.hype_train.end"/utf8>> ->
{ok, hype_train_end};
<<"channel.shield_mode.begin"/utf8>> ->
{ok, shield_mode_begin};
<<"channel.shield_mode.end"/utf8>> ->
{ok, shield_mode_end};
<<"channel.shoutout.create"/utf8>> ->
{ok, shoutout_create};
<<"channel.shoutout.receive"/utf8>> ->
{ok, shoutout_received};
<<"stream.online"/utf8>> ->
{ok, stream_online};
<<"stream.offline"/utf8>> ->
{ok, stream_offline};
<<"user.authorization.grant"/utf8>> ->
{ok, user_authorization_grant};
<<"user.authorization.revoke"/utf8>> ->
{ok, user_authorization_revoke};
<<"user.update"/utf8>> ->
{ok, user_update};
<<"user.whisper.message"/utf8>> ->
{ok, whisper_received};
_ ->
{error, nil}
end.
-spec subscription_type_decoder() -> fun((gleam@dynamic:dynamic_()) -> {ok,
subscription_type()} |
{error, list(gleam@dynamic:decode_error())}).
subscription_type_decoder() ->
fun(Data) ->
gleam@result:'try'(
gleam@dynamic:string(Data),
fun(String) -> _pipe = String,
_pipe@1 = subscription_type_from_string(_pipe),
gleam@result:replace_error(
_pipe@1,
[{decode_error,
<<"SubscriptionType"/utf8>>,
<<<<"String("/utf8, String/binary>>/binary,
")"/utf8>>,
[]}]
) end
)
end.
-spec subscription_type_to_json(subscription_type()) -> gleam@json:json().
subscription_type_to_json(Subscription_type) ->
_pipe = Subscription_type,
_pipe@1 = subscription_type_to_string(_pipe),
gleam@json:string(_pipe@1).
-spec subscription_type_from_json(binary()) -> {ok, subscription_type()} |
{error, gleam@json:decode_error()}.
subscription_type_from_json(Json_string) ->
gleam@result:'try'(
gleam@json:decode(Json_string, fun gleam@dynamic:string/1),
fun(String) -> _pipe = String,
_pipe@1 = subscription_type_from_string(_pipe),
gleam@result:replace_error(
_pipe@1,
{unexpected_format,
[{decode_error,
<<"SubscriptionType"/utf8>>,
<<<<"String("/utf8, Json_string/binary>>/binary,
")"/utf8>>,
[]}]}
) end
).
-spec subscription_status_from_string(binary()) -> {ok, subscription_status()} |
{error, nil}.
subscription_status_from_string(Str) ->
case Str of
<<"enabled"/utf8>> ->
{ok, enabled};
<<"webhook_callback_verification_pending"/utf8>> ->
{ok, enabled};
_ ->
{error, nil}
end.
-spec subscription_status_to_string(subscription_status()) -> binary().
subscription_status_to_string(Status) ->
case Status of
enabled ->
<<"enabled"/utf8>>;
web_hook_callback_verification_pending ->
<<"webhook_callback_verification_pending"/utf8>>
end.
-spec subscription_status_decoder() -> fun((gleam@dynamic:dynamic_()) -> {ok,
subscription_status()} |
{error, list(gleam@dynamic:decode_error())}).
subscription_status_decoder() ->
fun(Data) ->
gleam@result:'try'(
gleam@dynamic:string(Data),
fun(String) -> _pipe = String,
_pipe@1 = subscription_status_from_string(_pipe),
gleam@result:replace_error(
_pipe@1,
[{decode_error,
<<"SubscriptionStatus"/utf8>>,
<<<<"String("/utf8, String/binary>>/binary,
")"/utf8>>,
[]}]
) end
)
end.
-spec decoder() -> fun((gleam@dynamic:dynamic_()) -> {ok, subscription()} |
{error, list(gleam@dynamic:decode_error())}).
decoder() ->
gleam@dynamic:decode7(
fun(Field@0, Field@1, Field@2, Field@3, Field@4, Field@5, Field@6) -> {subscription, Field@0, Field@1, Field@2, Field@3, Field@4, Field@5, Field@6} end,
gleam@dynamic:field(<<"id"/utf8>>, fun gleam@dynamic:string/1),
gleam@dynamic:field(<<"status"/utf8>>, subscription_status_decoder()),
gleam@dynamic:field(<<"type"/utf8>>, subscription_type_decoder()),
gleam@dynamic:field(<<"version"/utf8>>, fun gleam@dynamic:string/1),
gleam@dynamic:field(<<"cost"/utf8>>, fun gleam@dynamic:int/1),
gleam@dynamic:field(
<<"condition"/utf8>>,
glitch@types@condition:decoder()
),
gleam@dynamic:field(
<<"transport"/utf8>>,
glitch@types@transport:decoder()
)
).
-spec subscription_status_to_json(subscription_status()) -> gleam@json:json().
subscription_status_to_json(Subscription_status) ->
_pipe = Subscription_status,
_pipe@1 = subscription_status_to_string(_pipe),
gleam@json:string(_pipe@1).
-spec subscription_status_from_json(binary()) -> {ok, subscription_status()} |
{error, gleam@json:decode_error()}.
subscription_status_from_json(Json_string) ->
gleam@result:'try'(
gleam@json:decode(Json_string, fun gleam@dynamic:string/1),
fun(String) -> _pipe = String,
_pipe@1 = subscription_status_from_string(_pipe),
gleam@result:replace_error(
_pipe@1,
{unexpected_format,
[{decode_error,
<<"SubscriptionStatus"/utf8>>,
<<<<"String("/utf8, Json_string/binary>>/binary,
")"/utf8>>,
[]}]}
) end
).