View Source ExPipedrive.Cursor (ex_pipedrive v0.1.0)

Cursor pagination helpers for Pipedrive API v2.

Pipedrive allows up to 500 items per page via limit. Use stream/2 to lazily follow next_cursor until it is nil.

Summary

Functions

Clamps a requested limit into 1..500 (default 100).

Maximum page size accepted by Pipedrive API v2.

Lazily streams entities by repeatedly calling fetch_page.

Functions

@spec clamp_limit(nil | integer()) :: pos_integer()

Clamps a requested limit into 1..500 (default 100).

@spec max_limit() :: pos_integer()

Maximum page size accepted by Pipedrive API v2.

Link to this function

stream(fetch_page, opts \\ [])

View Source
@spec stream(
  (keyword() -> {:ok, ExPipedrive.Page.t()} | {:error, ExPipedrive.Error.t()}),
  keyword()
) :: Enumerable.t()

Lazily streams entities by repeatedly calling fetch_page.

fetch_page receives [cursor: cursor_or_nil, limit: limit] and must return {:ok, %ExPipedrive.Page{}} or {:error, %ExPipedrive.Error{}}.

On error, the stream raises (ExPipedrive.Error is an exception). Empty pages with a nil cursor terminate the stream cleanly.