Mercury.Client (mercury_client v1.0.0)

Copy Markdown View Source

Holds configuration for talking to the Mercury Banking API and is passed as the first argument to every function in Mercury.Accounts, Mercury.Transactions, and the other resource modules.

Build one with new/2:

client = Mercury.Client.new("secret-token:mercury_production_...")

Mercury.Client is an immutable struct — it is cheap to build and safe to share across processes.

Summary

Types

request_hook()

@type request_hook() :: (method :: atom(),
                   url :: String.t(),
                   request_id :: String.t() ->
                     any())

response_hook()

@type response_hook() :: (method :: atom(),
                    url :: String.t(),
                    request_id :: String.t(),
                    status :: pos_integer(),
                    duration_ms :: non_neg_integer() ->
                      any())

t()

@type t() :: %Mercury.Client{
  api_key: String.t(),
  base_url: String.t(),
  on_request: request_hook() | nil,
  on_response: response_hook() | nil,
  req: Req.Request.t(),
  retry: Mercury.Retry.t(),
  timeout: pos_integer()
}

Functions

new(api_key, opts \\ [])

@spec new(api_key :: String.t(), opts :: keyword()) :: t()

Builds a new Mercury.Client.

api_key must include the "secret-token:" prefix, e.g. "secret-token:mercury_production_...".

Options

  • :base_url — override the API base URL. Default: "https://api.mercury.com/api/v1".
  • :timeout — per-request timeout in milliseconds. Default: 30000.
  • :retry — a Mercury.Retry struct. Default: Mercury.Retry.default/0.
  • :on_request — request hook, see request_hook/0.
  • :on_response — response hook, see response_hook/0.
  • :req_options — extra options merged into the underlying Req.new/1 call (e.g. :plug for tests, :connect_options for proxies).

Examples

Mercury.Client.new("secret-token:mercury_production_...")

Mercury.Client.new("secret-token:mercury_sandbox_...",
  base_url: "https://api-sandbox.mercury.com/api/v1",
  timeout: 10_000
)