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,nilon the last one. Pass it back asafter:.
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)
Summary
Functions
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).
A sample %MishkaPay.Page{} populated from defaults + type-based fallbacks.
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.
Types
@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) |
Functions
@spec all((keyword() -> {: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).
A sample %MishkaPay.Page{} populated from defaults + type-based fallbacks.
@spec stream((keyword() -> {: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.