QlikElixir.Pagination (qlik_elixir v0.3.5)

View Source

Helpers for cursor-based pagination used by Qlik Cloud APIs.

Qlik APIs use cursor-based pagination with next and prev tokens in the response links.

Summary

Functions

Builds a query string from pagination options.

Extracts a cursor value from a URL query string.

Parses a paginated API response into a structured format.

Types

cursor()

@type cursor() :: String.t() | nil

paginated_response()

@type paginated_response() :: %{
  data: [map()],
  next_cursor: cursor(),
  prev_cursor: cursor(),
  has_more: boolean(),
  total: non_neg_integer() | nil
}

Functions

build_query(opts)

@spec build_query(keyword()) :: String.t()

Builds a query string from pagination options.

Options

  • :limit - Maximum items per page
  • :offset - Number of items to skip (offset-based)
  • :next - Cursor for next page (cursor-based)
  • :prev - Cursor for previous page (cursor-based)

Examples

iex> QlikElixir.Pagination.build_query(limit: 50)
"limit=50"

iex> QlikElixir.Pagination.build_query(limit: 50, next: "abc123")
"limit=50&next=abc123"

extract_cursor(url, param)

@spec extract_cursor(String.t() | nil, String.t()) :: cursor()

Extracts a cursor value from a URL query string.

Examples

iex> QlikElixir.Pagination.extract_cursor("/api?next=abc123", "next")
"abc123"

iex> QlikElixir.Pagination.extract_cursor("/api?limit=50", "next")
nil

parse_response(response)

@spec parse_response(map()) :: paginated_response()

Parses a paginated API response into a structured format.

Extracts data, pagination cursors, and metadata from the response.

Examples

iex> response = %{"data" => [%{"id" => "1"}], "links" => %{"next" => %{"href" => "/api?next=abc"}}}
iex> QlikElixir.Pagination.parse_response(response)
%{data: [%{"id" => "1"}], next_cursor: "abc", prev_cursor: nil, has_more: true, total: nil}