Noizu.WhatsApp.Pagination (Noizu.WhatsApp v0.1.0)

Copy Markdown View Source

Lazy cursor walker behind every *_stream helper.

Graph list endpoints (e.g. WABA message_templates) page by opaque cursor (paging.cursors.after in the response). stream/2 calls fetch.(cursor) (cursor is nil for the first page, then the after cursor), emits the page's data items, and stops when there is no after cursor.

A failed page fetch raises the %Noizu.WhatsApp.Error{}; rescue at the enumeration site if desired.

Options

  • :data_key — the list key in the page (default "data").
  • :start — initial cursor (default nil).

Summary

Functions

stream(fetch, opts \\ [])

@spec stream(
  (String.t() | nil -> {:ok, map()} | {:error, Noizu.WhatsApp.Error.t()}),
  keyword()
) ::
  Enumerable.t()