Builds lazy, auto-paginating Streams over Ramp's cursor-paginated list
endpoints.
Every resource module's list/2 is implemented on top of
stream/4: it fetches one page at a time, as the stream is consumed,
following the page.next cursor Ramp returns until exhausted. Because
it's a Stream, nothing is fetched until you actually enumerate it:
# Only ever fetches as many pages as needed to find one match.
client
|> Ramp.Transactions.list(state: "CLEARED")
|> Enum.find(&(&1.amount.amount > 100_00))
# Fully materializes -- fetches every page.
all = client |> Ramp.Cards.list() |> Enum.to_list()If a page request fails, the stream raises the Ramp.Error (streams
have no other way to signal failure mid-enumeration). If you need
fine-grained, per-page error handling instead, use each resource module's
list_page/2, which returns {:ok, %Ramp.Page{}} | {:error, error}
for a single page and lets you drive the cursor yourself.
Summary
Functions
@spec fetch_page(Ramp.Client.t(), String.t(), keyword(), (map() -> item)) :: {:ok, Ramp.Page.t(item)} | {:error, Ramp.Error.t()} when item: term()
Fetches a single page and returns {:ok, %Ramp.Page{}} | {:error, error},
for manual pagination control.
@spec stream(Ramp.Client.t(), String.t(), keyword(), (map() -> item)) :: Enumerable.t(item) when item: term()
Returns a Stream of individually-decoded items, transparently
paginating through every page starting from query.
item_from_json decodes a single raw JSON item into its typed struct.