# `Noizu.WhatsApp.Request`
[🔗](https://github.com/noizu-labs-sdks/elixir-whatsapp/blob/v0.1.0/lib/noizu/whatsapp/request.ex#L1)

Request engine behind every resource module (Graph Cloud API, REST only).

Builds the Req call (`Authorization: Bearer <token>`), decodes JSON, applies
the bounded retry policy, and normalizes failures to `%Noizu.WhatsApp.Error{}`.

## Return shapes

  * `{:ok, decoded_body}` — 2xx.
  * `{:ok, decoded_body, meta}` — when the call is made with `meta: true`.
  * `{:error, %Noizu.WhatsApp.Error{}}`.

## Retry policy

  * **429** — retried with a delay from the `Retry-After` header or JSON
    hint, else exponential-ish backoff, clamped to `:max_delay_ms`.
  * **5xx** — retried for idempotent methods only (`GET`, `HEAD`, `PUT`).
  * At most `:max_attempts` (default 3) total attempts.

# `meta`

```elixir
@type meta() :: %{status: pos_integer(), attempts: pos_integer()}
```

# `method`

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

# `result`

```elixir
@type result() ::
  {:ok, term()} | {:ok, term(), meta()} | {:error, Noizu.WhatsApp.Error.t()}
```

# `encode_segment`

```elixir
@spec encode_segment(term()) :: String.t()
```

Percent-encodes one path segment (ids).

# `perform`

```elixir
@spec perform(Noizu.WhatsApp.Client.t(), method(), String.t(), keyword()) :: result()
```

Performs one API call. `path` is relative to the Graph root (the version is
inserted automatically, e.g. `"12345/messages"`).

Options: `:json` (request body), `:params` (query; `nil` values dropped),
`:form` (multipart form), `:headers`, `:meta`.

# `require_phone_number_id`

```elixir
@spec require_phone_number_id(Noizu.WhatsApp.Client.t(), keyword()) ::
  {:ok, String.t()} | {:error, Noizu.WhatsApp.Error.t()}
```

Resolves the sending phone number id from `opts[:phone_number_id]` or the
client, as `{:ok, id}` or `{:error, %Error{tag: :config}}`.

# `require_recipient`

```elixir
@spec require_recipient(term()) ::
  {:ok, String.t()} | {:error, Noizu.WhatsApp.Error.t()}
```

Normalizes a recipient or returns a masked validation error.

# `require_waba_id`

```elixir
@spec require_waba_id(Noizu.WhatsApp.Client.t(), keyword()) ::
  {:ok, String.t()} | {:error, Noizu.WhatsApp.Error.t()}
```

As `require_phone_number_id/2` for the WABA id.

---

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