crux_rest v0.1.7 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

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

Used when sending files via Rest.create_message/2

All available types that can be resolved into a role id

All available types that can be resolved into a user id

Functions

Resolves and encodes a file resolvable under a key in a map.
If the key is not in the map nothing is done

Resolves a:

  • path to a file
  • tuple of path to a file or binary of one, and a file name
    to a resolved_file/0 automatically used by Rest.create_message/2

Resolves a channel_id_resolvable/0 into a channel id

Resolves a emoji_id_resolvable/0 into an emoji id

Resolves a string or a binary to a binary/0.

  • http / https url
  • local file path
  • a binary itself

Resolves a guild_id_resolvable/0 into a guild id

Resolves a message_id_resolvable/0 into a message id

Resolves a t:overwrite_target_resolvabe/0 into an overwrite target

Resolves a user_id_resolvable/0 into a user id

Link to this section Types

Link to this type channel_id_resolvable() View Source (since 0.1.1)

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

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()} :: %{
    id: Crux.Rest.snowflake(),
    position: integer()
  }

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

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.

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.

Link to this type guild_id_resolvable() View Source (since 0.1.1)

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

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.

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.

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.

Link to this type resolved_file() View Source (since 0.1.0)
resolved_file() ::
  {String.t() | :file, binary() | String.t(),
   {String.t(), [{String.t(), binary()}]}, [{String.t(), String.t()}]}
  | {:error, term()}

Used when sending files via Rest.create_message/2.

The elements are:

  1. Name of the file or :file for a local file
  2. Binary of the file or the file path
  3. Disposition (for form-data)
  4. Headers (content-type)
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.

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.

Link to this section Functions

Link to this function encode_map_key(map, key) View Source (since 0.1.7)
encode_map_key(map(), atom()) :: map()

Resolves and encodes a file resolvable under a key in a map.
If the key is not in the map nothing is done.

Link to this function map_file(path) View Source (since 0.1.0)
map_file(
  path ::
    Crux.Rest.file_list_entry()
    | {String.t() | :file, String.t() | binary(), String.t()}
) :: resolved_file() | {:error, term()}

Resolves a:

  • path to a file
  • tuple of path to a file or binary of one, and a file name
    to a resolved_file/0 automatically used by Rest.create_message/2
Link to this function resolve_channel_id(id) View Source (since 0.1.1)
resolve_channel_id(channel :: channel_id_resolvable()) :: Crux.Rest.snowflake()

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()
}

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()

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_file(file) View Source (since 0.1.0)
resolve_file(file :: String.t() | binary()) ::
  {:ok, binary()} | {:error, term()}

Resolves a string or a binary to a binary/0.

  • http / https url
  • local file path
  • a binary itself
Link to this function resolve_guild_id(id) View Source (since 0.1.1)
resolve_guild_id(guild :: guild_id_resolvable()) :: Crux.Rest.snowflake()

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()
}

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_message_id(id) View Source (since 0.1.0)
resolve_message_id(message :: message_id_resolvable()) :: Crux.Rest.snowflake()

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_overwrite_target(id) View Source (since 0.1.1)
resolve_overwrite_target(overwrite :: overwrite_target_resolvable()) ::
  {String.t() | :unknown, Crux.Rest.snowflake()}

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()

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()

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