Lithic.Page (Lithic v1.0.0)

Copy Markdown View Source

Cursor-based pagination for Lithic list endpoints.

Fetching a single page

{:ok, page} = Lithic.Cards.list(page_size: 10)
page.data          #=> [%{...}, ...]
page.has_more      #=> true
page.next_cursor   #=> "tok_..."

Fetching the next page

{:ok, next_page} = Lithic.Page.next(page)

Streaming all records lazily

Lithic.Cards.stream()
|> Stream.filter(&(&1["state"] == "OPEN"))
|> Enum.take(100)

Collecting all records eagerly (use with care)

{:ok, all_cards} = Lithic.Page.collect_all(page)

Summary

Functions

Collect all items across all pages into a single list.

Wrap a raw decoded response body into a Page struct.

Fetch the next page. Returns {:ok, nil} when there are no more pages.

Lazily stream every item across all pages.

Types

t(item)

@type t(item) :: %Lithic.Page{
  client: Lithic.Client.t(),
  data: [item],
  has_more: boolean(),
  next_cursor: String.t() | nil,
  params: keyword(),
  path: String.t()
}

Functions

collect_all(page)

@spec collect_all(t(map())) :: {:ok, [map()]} | {:error, Lithic.Error.t()}

Collect all items across all pages into a single list.

from_response(body, client, path, params)

@spec from_response(map(), Lithic.Client.t(), String.t(), keyword()) :: t(map())

Wrap a raw decoded response body into a Page struct.

next(page)

@spec next(t(map())) :: {:ok, t(map()) | nil} | {:error, Lithic.Error.t()}

Fetch the next page. Returns {:ok, nil} when there are no more pages.

stream(page)

@spec stream(t(map())) :: Enumerable.t()

Lazily stream every item across all pages.