Crux v2020-03-17 17:55:51Z Crux.Rest.Util View Source

Collection of util functions.

Link to this section Summary

Types

All available types that can be resolved into a channel id.

All available types that can be resolved into a channel position.

All available types that can be resolved into an emoji id.

All available types that can be resolved into an emoji identifier.

All available types that can be resolved into a guild id.

All available types which can be resolved into a role position.

Used for functions setting an icon / image / etc.
Can be either a binary() of an image or a data url.

All available types that can be resolved into a message id.

All available types that can be resolved into a target for a permission overwrite.

All available types that can be resolved into a role id.

All available types that can be resolved into a user id.

Functions

Updates a value in map with the given fun.
Is a noop if key is not in map.

Resolves a channel_id_resolvable/0 into a channel id.

Resolves a channel_position_resolvable/0 into a channel position.

Resolves a emoji_id_resolvable/0 into an emoji id.

Resolves a guild_id_resolvable/0 into a guild id.

Resolves a guild_role_position_resolvable/0 into a role position.

Used for functions resolving a image/0 into base64 image data urls.

Internally used to transform a image/0 within a map to a base64 image data urls.

Resolves a message_id_resolvable/0 into a message id.

Internally used to transform Crux.Rest.execute_webhook_options/0 and Crux.Rest.create_message_data/0 to a tuple of {body, extra_headers}

Resolves a t:overwrite_target_resolvabe/0 into an overwrite target.

Resolves a role_id_resolvable/0 into a role id.

resolve_user_id(id) deprecated

Resolves a user_id_resolvable/0 into a user id.

Link to this section Types

Link to this type

attachment() View Source (since 0.2.0)
attachment() :: binary() | {binary(), String.t()}

Used to attach files via Crux.Rest.create_message/2 or Crux.Rest.execute_webhook/3.

This can be one of:

Example
binary<<0, 0, 0, 0>> (will be named "file.jpg")
{binary, name}{<<104, 101, 108, 108, 111>>, "hello.txt"}
Link to this type

channel_id_resolvable() View Source (since 0.1.1)

All available types that can be resolved into a channel id.

Deprecated: Use Crux.Structs.CHannel.id_resolvable() instead

Link to this type

channel_position_resolvable() View Source (since 0.1.1)
channel_position_resolvable() ::
  Crux.Structs.Channel.t()
  | %{channel: Crux.Structs.Channel.t(), position: integer()}
  | {Crux.Rest.snowflake(), integer()}
  | %{id: Crux.Rest.snowflake(), position: integer()}

All available types that can be resolved into a channel position.

Deprecated: Use Crux.Structs.Channel.position_resolvable() instead

Link to this type

emoji_id_resolvable() View Source (since 0.1.1)
emoji_id_resolvable() ::
  Crux.Structs.Reaction.t() | Crux.Structs.Emoji.t() | String.t()

All available types that can be resolved into an emoji id.

Deprecated: Use Crux.Structs.Emoji.id_resolvable() instead

Link to this type

emoji_identifier_resolvable() View Source (since 0.1.1)
emoji_identifier_resolvable() ::
  Crux.Structs.Reaction.t() | Crux.Structs.Emoji.t() | String.t()

All available types that can be resolved into an emoji identifier.

Deprecated: Use Crux.Structs.Emoji.identifier_resolvable() instead

Link to this type

guild_id_resolvable() View Source (since 0.1.1)

All available types that can be resolved into a guild id.

Deprecated: Use Crux.Structs.Guild.id_resolvable() instead

Link to this type

guild_role_position_resolvable() View Source (since 0.1.2)
guild_role_position_resolvable() ::
  {Crux.Structs.Role.t(), integer()}
  | %{id: Crux.Rest.snowflake(), position: integer()}
  | {Crux.Rest.snowflake(), integer()}
  | %{role: Crux.Structs.Role.t(), position: integer()}

All available types which can be resolved into a role position.

Deprecated: Use Crux.Structs.Role.position_resolvable() instead.

Link to this type

image() View Source (since 0.2.0)
image() :: binary() | String.t() | nil

Used for functions setting an icon / image / etc.
Can be either a binary() of an image or a data url.

Link to this type

message_id_resolvable() View Source (since 0.1.1)
message_id_resolvable() :: Crux.Structs.Message.t() | Crux.Rest.snowflake()

All available types that can be resolved into a message id.

Deprecated: Use Crux.Structs.Message.id_resolvable() instead

Link to this type

overwrite_target_resolvable() View Source (since 0.1.1)

All available types that can be resolved into a target for a permission overwrite.

Deprecated: Use Crux.Structs.Overwrite.target_resolvable() instead

Link to this type

role_id_resolvable() View Source (since 0.1.1)
role_id_resolvable() :: Crux.Structs.Role.t() | Crux.Rest.snowflake()

All available types that can be resolved into a role id.

Deprecated: Use Crux.Structs.Role.id_resolvable() instead

Link to this type

user_id_resolvable() View Source (since 0.1.1)
user_id_resolvable() ::
  Crux.Structs.Member.t() | Crux.Structs.User.t() | integer()

All available types that can be resolved into a user id.

Deprecated: Use Crux.Structs.User.id_resolvable() instead

Link to this section Functions

Link to this function

optional_update_in_map(map, key, fun) View Source (since 0.2.1)
optional_update_in_map(map(), atom(), (term() -> term())) :: map()

Updates a value in map with the given fun.
Is a noop if key is not in map.

Link to this function

resolve_channel_id(id) View Source (since 0.1.1)
resolve_channel_id(channel :: channel_id_resolvable()) :: Crux.Rest.snowflake()

This function is deprecated. Use `Crux.Structs.resolve_id(&1, Crux.Structs.Channel)` instead.

Resolves a channel_id_resolvable/0 into a channel id.

Examples

iex> %Crux.Structs.Channel{id: 222079895583457280}
...> |> Crux.Rest.Util.resolve_channel_id()
222079895583457280

iex> %Crux.Structs.Message{channel_id: 222079895583457280}
...> |> Crux.Rest.Util.resolve_channel_id()
222079895583457280

iex> 222079895583457280
...> |> Crux.Rest.Util.resolve_channel_id()
222079895583457280
Link to this function

resolve_channel_position(arg1) View Source (since 0.1.0)
resolve_channel_position(channel :: channel_position_resolvable()) :: %{
  id: Crux.Rest.snowflake(),
  position: integer()
}

This function is deprecated. Use `Crux.Structs.Channel.resolve_position/1` instead.

Resolves a channel_position_resolvable/0 into a channel position.

Examples

iex> %Crux.Structs.Channel{id: 222079895583457280, position: 5}
...> |> Crux.Rest.Util.resolve_channel_position()
%{id: 222079895583457280, position: 5}

iex> {%Crux.Structs.Channel{id: 222079895583457280}, 5}
...> |> Crux.Rest.Util.resolve_channel_position()
%{id: 222079895583457280, position: 5}

iex> {222079895583457280, 5}
...> |> Crux.Rest.Util.resolve_channel_position()
%{id: 222079895583457280, position: 5}

iex> %{id: 222079895583457280, position: 5}
...> |> Crux.Rest.Util.resolve_channel_position()
%{id: 222079895583457280, position: 5}
Link to this function

resolve_emoji_id(emoji) View Source (since 0.1.1)
resolve_emoji_id(emoji :: emoji_id_resolvable()) :: String.t()

This function is deprecated. Use `Crux.Structs.resolve_id(&1, Crux.Structs.Emoji)` instead.

Resolves a emoji_id_resolvable/0 into an emoji id.

Examples

iex> %Crux.Structs.Emoji{id: 396521773216301056}
...> |> Crux.Rest.Util.resolve_emoji_id()
396521773216301056

iex> %Crux.Structs.Reaction{emoji: %Crux.Structs.Emoji{id: 396521773216301056}}
...> |> Crux.Rest.Util.resolve_emoji_id()
396521773216301056

iex> 396521773216301056
...> |> Crux.Rest.Util.resolve_emoji_id()
396521773216301056
Link to this function

resolve_guild_id(id) View Source (since 0.1.1)
resolve_guild_id(guild :: guild_id_resolvable()) :: Crux.Rest.snowflake()

This function is deprecated. Use `Crux.Structs.resolve_id(&1, Crux.Structs.Guild)` instead.

Resolves a guild_id_resolvable/0 into a guild id.

Examples

iex> %Crux.Structs.Guild{id: 222078108977594368}
...> |> Crux.Rest.Util.resolve_guild_id()
222078108977594368

iex> %Crux.Structs.Channel{guild_id: 222078108977594368}
...> |> Crux.Rest.Util.resolve_guild_id()
222078108977594368

iex> %Crux.Structs.Message{guild_id: 222078108977594368}
...> |> Crux.Rest.Util.resolve_guild_id()
222078108977594368

iex> 222078108977594368
...> |> Crux.Rest.Util.resolve_guild_id()
222078108977594368
Link to this function

resolve_guild_role_position(arg1) View Source
resolve_guild_role_position(role :: guild_role_position_resolvable()) :: %{
  id: Crux.Rest.snowflake(),
  position: integer()
}

This function is deprecated. Use `Crux.Structs.Role.resolve_position/1` instead.

Resolves a guild_role_position_resolvable/0 into a role position.

Examples

iex> {%Crux.Structs.Role{id: 373405430589816834}, 5}
...> |> Crux.Rest.Util.resolve_guild_role_position()
%{id: 373405430589816834, position: 5}

iex> %{id: 373405430589816834, position: 5}
...> |> Crux.Rest.Util.resolve_guild_role_position()
%{id: 373405430589816834, position: 5}

iex> %{role: %Crux.Structs.Role{id: 373405430589816834}, position: 5}
...> |> Crux.Rest.Util.resolve_guild_role_position()
%{id: 373405430589816834, position: 5}

iex> {373405430589816834, 5}
...> |> Crux.Rest.Util.resolve_guild_role_position()
%{id: 373405430589816834, position: 5}
Link to this function

resolve_image(data, extension \\ "jpg") View Source (since 0.2.0)
resolve_image(image(), extension :: String.t()) :: String.t() | nil

Used for functions resolving a image/0 into base64 image data urls.

Link to this function

resolve_image_in_map(map, key) View Source (since 0.2.0)
resolve_image_in_map(map(), atom()) :: map()

Internally used to transform a image/0 within a map to a base64 image data urls.

Link to this function

resolve_message_id(id) View Source (since 0.1.0)
resolve_message_id(message :: message_id_resolvable()) :: Crux.Rest.snowflake()

This function is deprecated. Use `Crux.Structs.resolve_id(&1, Crux.Structs.Message)` instead.

Resolves a message_id_resolvable/0 into a message id.

Examples

iex> %Crux.Structs.Message{id: 441568727302012928}
...> |> Crux.Rest.Util.resolve_message_id()
441568727302012928

iex> 441568727302012928
...> |> Crux.Rest.Util.resolve_message_id()
441568727302012928
Link to this function

resolve_multipart(data) View Source (since 0.2.0)
resolve_multipart(map()) :: {{:multipart, list()} | map(), list()}

Internally used to transform Crux.Rest.execute_webhook_options/0 and Crux.Rest.create_message_data/0 to a tuple of {body, extra_headers}

Link to this function

resolve_overwrite_target(id) View Source (since 0.1.1)
resolve_overwrite_target(overwrite :: overwrite_target_resolvable()) ::
  {String.t() | :unknown, Crux.Rest.snowflake()}

This function is deprecated. Use `Crux.Structs.Overwrite.resolve_target/1` instead.

Resolves a t:overwrite_target_resolvabe/0 into an overwrite target.

Examples

iex> %Crux.Structs.Overwrite{type: "member", id: 218348062828003328}
...> |> Crux.Rest.Util.resolve_overwrite_target()
{"member", 218348062828003328}

iex> %Crux.Structs.Role{id: 376146940762783746}
...> |> Crux.Rest.Util.resolve_overwrite_target()
{"role", 376146940762783746}

iex> %Crux.Structs.User{id: 218348062828003328}
...> |> Crux.Rest.Util.resolve_overwrite_target()
{"member", 218348062828003328}

iex> %Crux.Structs.Member{user: 218348062828003328}
...> |> Crux.Rest.Util.resolve_overwrite_target()
{"member", 218348062828003328}

iex> 218348062828003328
...> |> Crux.Rest.Util.resolve_overwrite_target()
{:unknown, 218348062828003328}
Link to this function

resolve_role_id(role_id) View Source (since 0.1.0)
resolve_role_id(role :: role_id_resolvable()) :: integer()

This function is deprecated. Use `Crux.Structs.resolve_id(&1, Crux.Structs.Role)` instead.

Resolves a role_id_resolvable/0 into a role id.

Examples

# A role struct
iex> %Crux.Structs.Role{id: 376146940762783746}
...> |> Crux.Rest.Util.resolve_role_id()
376146940762783746

# A role id
iex> 376146940762783746
...> |> Crux.Rest.Util.resolve_role_id()
376146940762783746
Link to this function

resolve_user_id(id) View Source (since 0.1.0)
resolve_user_id(user :: user_id_resolvable()) :: Crux.Rest.snowflake()

This function is deprecated. Use `Crux.Structs.resolve_id(&1, Crux.Structs.User)` instead.

Resolves a user_id_resolvable/0 into a user id.

Examples

iex> %Crux.Structs.User{id: 218348062828003328}
...> |> Crux.Rest.Util.resolve_user_id()
218348062828003328

iex> %Crux.Structs.Member{user: 218348062828003328}
...> |> Crux.Rest.Util.resolve_user_id()
218348062828003328

iex> 218348062828003328
...> |> Crux.Rest.Util.resolve_user_id()
218348062828003328