Mercadopago.Pagination (mercadopago_sdk_elixir v0.3.1)

Copy Markdown View Source

Lazily walks every page of a search endpoint.

MercadoPago paginates search results with limit and offset. stream/3 drives that loop for you and yields the individual records, fetching the next page only when the consumer asks for it:

client
|> Mercadopago.Payment.search_stream(%{status: "approved"})
|> Stream.filter(&(&1["transaction_amount"] > 100))
|> Enum.take(20)

Because it is a Stream, nothing is requested until the pipeline runs, and a Enum.take/2 stops after the pages it actually needed.

Every resource with a search/3 exposes a search_stream/3 that calls this; reach for stream/3 directly only for an endpoint that has none.

Failures are raised, not yielded

A stream has no place to put an error tuple, so a request that fails mid-walk raises: Mercadopago.Error for a status of 400 or above, and the underlying transport exception (e.g. Req.TransportError) for a connection failure. Wrap the pipeline in a try if a partial result is still useful to you.

Summary

Types

A one-argument search function: takes the filters, returns a response.

Functions

Streams every record matching filters across all pages.

Types

search_fun()

@type search_fun() :: (map() -> Mercadopago.HTTP.response())

A one-argument search function: takes the filters, returns a response.

Functions

stream(search_fun, filters \\ nil, opts \\ [])

@spec stream(search_fun(), map() | nil, keyword()) :: Enumerable.t()

Streams every record matching filters across all pages.

search_fun takes a filters map and returns a Mercadopago.HTTP.response/0 — typically a captured resource call, &Mercadopago.Payment.search(client, &1).

filters is sent as query-string parameters. Any limit/offset in it is replaced: limit by the page size, offset by the walk's position. Pass offset to start partway through.

Options

  • :page_size - records per request (default: 100)