SDKsRuby
Pagination
List endpoints, cursors, and auto-pagination helpers.
Easy Labs uses offset-based pagination for all list endpoints. Every
list method on the SDK accepts the same three keyword arguments:
| Param | Type | Meaning |
|---|---|---|
limit: | Integer, nil | Max records per page (server-side default applies if omitted). |
offset: | Integer, nil | Number of records to skip from the start. |
ids: | Array<String> | Filter to a specific set of IDs (joined with ,). |
nil values are dropped from the query string, so you only need to pass
what you want to override.
Manual pagination
page = client.customers.list(limit: 50)
records = page[:data] # array of customers on this page
total = page[:meta][:total] # full count, when the API returns itWalk the next page by incrementing offset:
page = client.customers.list(limit: 50, offset: 50)Auto-pagination
The SDK does not yet ship an auto-paginating iterator. Build one with a
plain Ruby Enumerator when you need it:
def each_customer(client, page_size: 100)
return enum_for(:each_customer, client, page_size: page_size) unless block_given?
offset = 0
loop do
page = client.customers.list(limit: page_size, offset: offset)
records = page[:data] || []
records.each { |c| yield c }
break if records.size < page_size
offset += records.size
end
end
each_customer(client).each { |c| puts c[:email] }