ExNtfy.Config (ex_ntfy v0.1.1)

Copy Markdown View Source

Resolves client configuration with a fixed precedence: per-call options override application config (config :ex_ntfy, ...), which overrides library defaults.

Summary

Types

Client credentials.

A single client configuration option.

Functions

The client option keys, for splitting client options out of mixed keyword lists (as ExNtfy.Publisher does).

Merges opts over app_env over defaults and validates the result.

Types

auth()

@type auth() :: {:basic, String.t(), String.t()} | {:token, String.t()} | nil

Client credentials.

option()

@type option() ::
  {:base_url, String.t()}
  | {:auth, auth()}
  | {:auth_via, :header | :query}
  | {:receive_timeout, timeout()}
  | {:retry, term()}
  | {:req_options, keyword()}

A single client configuration option.

Functions

keys()

@spec keys() :: [atom()]

The client option keys, for splitting client options out of mixed keyword lists (as ExNtfy.Publisher does).

resolve(opts \\ [], app_env \\ Application.get_all_env(:ex_ntfy))

@spec resolve(
  [option()],
  keyword()
) :: [option()]

Merges opts over app_env over defaults and validates the result.

app_env defaults to Application.get_all_env(:ex_ntfy); unknown keys in it are ignored (the app env may hold unrelated entries), while unknown keys in opts raise NimbleOptions.ValidationError.

Examples

iex> ExNtfy.Config.resolve()[:base_url]
"https://ntfy.sh"

iex> ExNtfy.Config.resolve([], base_url: "https://cfg.example")[:base_url]
"https://cfg.example"

iex> ExNtfy.Config.resolve([base_url: "http://localhost:8080"],
...>   base_url: "https://cfg.example"
...> )[:base_url]
"http://localhost:8080"