Synctera.Client (Synctera v1.0.0)

Copy Markdown View Source

Holds configuration for talking to the Synctera API. Construct one with new/1 and pass it as the first argument to every Synctera.* resource function, per Elixir convention (cf. Ecto.Repo, Req.Request).

Summary

Functions

Builds a new client.

Types

environment()

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

t()

@type t() :: %Synctera.Client{
  api_key: String.t(),
  auto_generate_ledger_idempotency_keys: boolean(),
  base_url: String.t(),
  default_device_info: Synctera.DeviceInfo.t() | nil,
  default_headers: [{String.t(), String.t()}],
  environment: environment(),
  on_response: (map() -> any()) | nil,
  receive_timeout_ms: pos_integer(),
  retry: Synctera.Retry.t()
}

Functions

new(opts \\ [])

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

Builds a new client.

Options

  • :api_key — required unless the SYNCTERA_API_KEY environment variable is set.
  • :environment:sandbox (default), :t_minus_10, or :production.
  • :base_url — overrides the environment-derived base URL entirely (e.g. for a mock server in tests).
  • :receive_timeout_ms — default 30_000.
  • :retry — a %Synctera.Retry{} struct, or a keyword list of its fields.
  • :auto_generate_ledger_idempotency_keys — default false. See Synctera.Idempotency for why this is opt-in.
  • :default_device_info — a %Synctera.DeviceInfo{} attached to every request unless overridden per-call.
  • :default_headers — extra headers merged into every request.
  • :on_response — a 1-arity function called after every response with a map of %{method:, url:, status:, request_id:, duration_ms:}, useful for logging/metrics.

Raises Synctera.UsageError if no API key is available.