# `AccessGrid.Client`
[🔗](https://github.com/Access-Grid/accessgrid-ex/blob/main/lib/access_grid/client.ex#L1)

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()

# `method`

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

# `t`

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

# `from_config`

```elixir
@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`

```elixir
@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`

```elixir
@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")

---

*Consult [api-reference.md](api-reference.md) for complete listing*
