# `MishkaPay.Page`
[🔗](https://github.com/mishka-group/mishka_pay/blob/v0.0.1/lib/mishka_pay/page.ex#L5)

One page of a list: what every `MishkaPay.list_*` call answers. A guarded_struct.

  * `:items`: the structs of this page, newest first.
  * `:has_more`: whether the provider has more after this page.
  * `:next`: the cursor of the next page, `nil` on the last one. Pass it back as `after:`.

Every list call takes `limit:` (1 to 100, 10 by default) and `after:` (a page's `:next`):

    {:ok, page} = MishkaPay.list_customers("stripe", site_id, limit: 50)
    {:ok, more} = MishkaPay.list_customers("stripe", site_id, limit: 50, after: page.next)

`stream/1` pages through everything, one request per page and only as far as it is read:

    "stripe"
    |> then(&fn opts -> MishkaPay.list_products(&1, site_id, opts) end)
    |> MishkaPay.Page.stream()
    |> Enum.take(250)

# `t`

```elixir
@type t() :: %MishkaPay.Page{
  has_more: boolean() | nil,
  items: list() | nil,
  next: String.t() | nil
}
```

The struct that `builder/1` returns.

| Field | Type | Required | Default | Description | Derives |
| --- | --- | --- | --- | --- | --- |
| `:items` | `list()` \| `nil` | no | `[]` |  | `validate(list)` |
| `:has_more` | `boolean()` \| `nil` | no | `false` |  | `validate(boolean)` |
| `:next` | `String.t()` \| `nil` | no |  |  | `validate(string, not_empty)` |

# `all`

```elixir
@spec all((keyword() -&gt; {:ok, t()} | {:error, Exception.t()})) ::
  {:ok, list()} | {:error, Exception.t()}
```

Every item a list call gives, read page by page until the last: `{:ok, items}`, or the first
error, without raising. For lists a caller means to read whole, such as the events a site
missed (`MishkaPay.replay_events/3`).

# `builder`

# `enforce_keys`

# `enforce_keys`

# `example`

A sample %MishkaPay.Page{} populated from defaults + type-based fallbacks.

# `keys`

# `keys`

# `stream`

```elixir
@spec stream((keyword() -&gt; {:ok, t()} | {:error, Exception.t()})) :: Enumerable.t()
```

A lazy stream of every item a list call gives, page by page. `list` is a function of the list
options (`after:` is set from the page before) answering `{:ok, %MishkaPay.Page{}}`. A list that
answers an error raises it, a `MishkaPay.Errors` exception, where the stream is read.

---

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