AccessGrid.Client (AccessGrid v0.1.0)

Copy Markdown View Source

Holds configuration for AccessGrid API authentication.

A client can be created explicitly with new/1 or loaded from application config with from_config/0.

Examples

# Explicit credentials
client = AccessGrid.Client.new(
  account_id: "acct_123",
  api_secret: "secret_456"
)

# From application config (uses Gestalt for process isolation)
client = AccessGrid.Client.from_config()

Summary

Functions

Creates a client from application configuration.

Creates a new client with explicit credentials.

Makes an authenticated request to the AccessGrid API.

Types

method()

@type method() :: :get | :post | :put | :patch | :delete | :head

t()

@type t() :: %AccessGrid.Client{
  account_id: String.t(),
  api_host: String.t(),
  api_secret: String.t()
}

Functions

from_config()

@spec from_config() :: t()

Creates a client from application configuration.

Uses Gestalt for process-specific config overrides, enabling async test isolation.

Configuration

config :accessgrid,
  account_id: "acct_123",
  api_secret: "secret_456",
  api_host: "https://api.accessgrid.com"  # optional

new(opts)

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

Creates a new client with explicit credentials.

Options

  • :account_id - Required. The AccessGrid account ID.
  • :api_secret - Required. The API secret for signing requests.
  • :api_host - Optional. API host URL. Defaults to https://api.accessgrid.com.

Examples

iex> AccessGrid.Client.new(account_id: "acct_123", api_secret: "secret_456")
%AccessGrid.Client{account_id: "acct_123", api_secret: "secret_456", api_host: "https://api.accessgrid.com"}

request(client, method, path, opts \\ [])

@spec request(t() | nil, method(), String.t(), keyword()) ::
  {:ok, AccessGrid.HttpResponse.t()} | {:error, AccessGrid.HttpFailure.t()}

Makes an authenticated request to the AccessGrid API.

Handles URL construction, payload signing, and header generation.

Options

  • :body - Request body (map). Will be JSON encoded for POST/PUT/PATCH.
  • :params - Query parameters (map).
  • :headers - Additional headers (map).

Examples

client = AccessGrid.Client.new(account_id: "acct_123", api_secret: "secret")

# POST with body
Client.request(client, :post, "/v1/key-cards", body: %{name: "Test"})

# GET with params
Client.request(client, :get, "/v1/key-cards", params: %{"page" => "2"})

# Using config (pass nil for client)
Client.request(nil, :get, "/v1/key-cards/card_123")