Tink.Client (Tink v1.0.0)

Copy Markdown View Source

Represents an authenticated Tink API client.

Fields

  • :access_token — Bearer token (required)
  • :refresh_token — refresh token for obtaining new access tokens (if provided)
  • :token_type — "bearer" (default)
  • :expires_atDateTime expiry; nil means never checked
  • :scope — space-separated token scopes
  • :id_hint — user hint returned by Tink in token responses
  • :auto_refresh — re-fetch a client credentials token on 401
  • :cache — set false to bypass caching for all calls on this client
  • :rate_limit_key — Hammer bucket key; defaults to Tink.Config.client_id()
  • :adapter — HTTP adapter module (default: Tink.Config.http_adapter())

Creating clients

{:ok, client} = Tink.Auth.client_credentials(scope: "authorization:grant user:create")
{:ok, client} = Tink.Auth.user_client(auth_code)
client        = Tink.Client.new(access_token: "bearer_abc123")

Bypassing cache per-client

no_cache_client = %{user_client | cache: false}
{:ok, accounts} = Tink.Accounts.list(no_cache_client)

Tracing requests

Pass :client_trace_id to tag requests for tracing. Tink echoes it back in the X-Client-Trace-ID response header:

Tink.Accounts.list(client, client_trace_id: "my-trace-abc-123")

Idempotency

For POST requests that must not be duplicated (e.g. payments), pass an :idempotency_key. Tink de-duplicates requests with the same key for 24h:

Tink.Payments.create(client, params, idempotency_key: idempotency_uuid)

Per-call retry override

Tink.Transactions.list(client, max_retries: 0)   # disable retry
Tink.Accounts.get(client, "id", max_retries: 5)  # increase retries

Summary

Types

t()

@type t() :: %Tink.Client{
  access_token: String.t(),
  adapter: module() | nil,
  auto_refresh: boolean(),
  cache: boolean(),
  expires_at: DateTime.t() | nil,
  id_hint: String.t() | nil,
  rate_limit_key: String.t() | nil,
  refresh_token: String.t() | nil,
  scope: String.t() | nil,
  token_type: String.t()
}

Functions

add_query(path, params)

@spec add_query(String.t(), keyword() | map()) :: String.t()

Append query params to a path, omitting nil values.

Client.add_query("/data/v2/accounts", %{"pageSize" => 50, "pageToken" => nil})
# => "/data/v2/accounts?pageSize=50"

cache_enabled?(client)

@spec cache_enabled?(t()) :: boolean()

Whether caching is enabled for this client.

delete(client, path, opts \\ [])

@spec delete(t(), String.t(), keyword()) :: {:ok, map()} | {:error, Tink.Error.t()}

expired?(client)

@spec expired?(t()) :: boolean()

Returns true if the access token has passed its expiry time.

get(client, path, opts \\ [])

@spec get(t(), String.t(), keyword()) :: {:ok, map()} | {:error, Tink.Error.t()}

new(opts)

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

patch(client, path, body \\ nil, opts \\ [])

@spec patch(t(), String.t(), map() | nil, keyword()) ::
  {:ok, map()} | {:error, Tink.Error.t()}

post(client, path, body \\ nil, opts \\ [])

@spec post(t(), String.t(), map() | nil, keyword()) ::
  {:ok, map()} | {:error, Tink.Error.t()}

put(client, path, body \\ nil, opts \\ [])

@spec put(t(), String.t(), map() | nil, keyword()) ::
  {:ok, map()} | {:error, Tink.Error.t()}