View Source FLHook.Params (FLHook Client v1.0.0)

A module that provides helpers to decode command response and event params.

Link to this section Summary

Functions

Fetches a param as boolean from the params collection. Raises when the param is missing or could not be coerced.

Fetches a param as duration from the params collection. Raises when the param is missing or could not be coerced.

Fetches the param with the specified key from the params collection. Optionally allows specification of a type to coerce the param to.

Fetches the param with the specified key from the params collection. Optionally allows specification of a type to coerce the param to. Raises when the param is missing or could not be coerced to the given type.

Fetches a param as float from the params collection. Raises when the param is missing or could not be coerced.

Fetches a param as integer from the params collection. Raises when the param is missing or could not be coerced.

Fetches multiple params with the specified keys from the params collection. Optionally allows specification of a type to coerce the param to.

Puts multiple params with the specified keys from the params collection in the given struct. Optionally allows specification of a type to coerce the param to.

Fetches a param as string from the params collection. Raises when the param is missing or could not be coerced.

Converts the params to a plain map.

Link to this section Types

Specs

data() :: %{optional(String.t()) => String.t()}

Specs

key() :: atom() | String.t()

Specs

param_type() :: :boolean | :duration | :integer | :float | :string | module()

Specs

t() :: %FLHook.Params{data: data()}

Link to this section Functions

Specs

boolean!(t(), key()) :: boolean() | no_return()

Fetches a param as boolean from the params collection. Raises when the param is missing or could not be coerced.

Specs

duration!(t(), key()) :: FLHook.Duration.t() | no_return()

Fetches a param as duration from the params collection. Raises when the param is missing or could not be coerced.

Link to this function

fetch(params, key, type \\ :string)

View Source

Specs

fetch(t(), key(), param_type()) ::
  {:ok, any()} | {:error, FLHook.ParamError.t()}

Fetches the param with the specified key from the params collection. Optionally allows specification of a type to coerce the param to.

Link to this function

fetch!(params, key, type \\ :string)

View Source

Specs

fetch!(t(), key(), param_type()) :: any() | no_return()

Fetches the param with the specified key from the params collection. Optionally allows specification of a type to coerce the param to. Raises when the param is missing or could not be coerced to the given type.

Specs

float!(t(), key()) :: float() | no_return()

Fetches a param as float from the params collection. Raises when the param is missing or could not be coerced.

Specs

integer!(t(), key()) :: integer() | no_return()

Fetches a param as integer from the params collection. Raises when the param is missing or could not be coerced.

Link to this function

pick(params, keys_and_types)

View Source (since 0.3.0)

Specs

pick(t(), [key()] | [{key(), param_type()}]) ::
  {:ok, %{optional(key()) => any()}} | {:error, FLHook.ParamError.t()}

Fetches multiple params with the specified keys from the params collection. Optionally allows specification of a type to coerce the param to.

Link to this function

pick_into(params, target, keys_and_types)

View Source (since 0.3.0)

Specs

pick_into(t(), module() | struct(), [key()] | [{key(), param_type()}]) ::
  {:ok, struct()} | {:error, FLHook.ParamError.t()}

Puts multiple params with the specified keys from the params collection in the given struct. Optionally allows specification of a type to coerce the param to.

Specs

string!(t(), key()) :: String.t() | no_return()

Fetches a param as string from the params collection. Raises when the param is missing or could not be coerced.

Link to this function

to_map(params, key_style \\ :string)

View Source (since 0.3.0)

Specs

to_map(t(), key_style :: :string | :atom) :: map()

Converts the params to a plain map.