MishkaPay.Page (Mishka Pay v0.0.1)

Copy Markdown View Source

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)

Summary

Types

t()

The struct that builder/1 returns.

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

t()

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

The struct that builder/1 returns.

FieldTypeRequiredDefaultDescriptionDerives
:itemslist() | nilno[]validate(list)
:has_moreboolean() | nilnofalsevalidate(boolean)
:nextString.t() | nilnovalidate(string, not_empty)

Functions

all(list)

@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).

builder(attrs_or_input, error \\ false)

enforce_keys()

enforce_keys(field)

example()

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

keys()

keys(field)

stream(list)

@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.