Unit.Config (Unit v1.0.0)

Copy Markdown View Source

Configuration for the Unit client.

Configuration

Configure via config.exs:

config :unit,
  api_token: System.get_env("UNIT_API_TOKEN"),
  environment: :sandbox,    # :sandbox | :production
  timeout: 30_000,
  max_retries: 3,
  retry_delay: 500,
  telemetry_prefix: [:unit, :request]

Or pass options directly to any API call:

Unit.API.Customers.list(api_token: "token_...", timeout: 10_000)

Runtime config

Supports runtime config via {:system, "ENV_VAR"} tuples and MFA tuples:

config :unit, api_token: {:system, "UNIT_API_TOKEN"}
config :unit, api_token: {MyApp.Vault, :fetch_secret, [:unit_token]}

Summary

Functions

Returns the base URL for the configured environment.

Builds a Config struct from application env, merging in any runtime overrides.

Types

environment()

@type environment() :: :sandbox | :production

t()

@type t() :: %Unit.Config{
  api_token: String.t() | nil,
  base_url: String.t(),
  environment: environment(),
  extra_headers: [{String.t(), String.t()}],
  max_retries: non_neg_integer(),
  recv_timeout: pos_integer(),
  retry_delay: pos_integer(),
  telemetry_prefix: [atom()],
  timeout: pos_integer()
}

Functions

base_url(config)

@spec base_url(t()) :: String.t()

Returns the base URL for the configured environment.

new(overrides \\ [])

@spec new(keyword()) :: t()

Builds a Config struct from application env, merging in any runtime overrides.