class Attio::APIResource::ListObject
Container for API list responses with pagination support
ListObject for handling paginated responses
def [](index)
-
(APIResource, nil)
- The resource at the given index
Parameters:
-
index
(Integer
) -- The index of the item to retrieve
def [](index) @data[index] end
def auto_paging_each(&block)
-
(Enumerator)
- If no block given
Other tags:
- Yield: - Each resource across all pages
def auto_paging_each(&block) return enum_for(:auto_paging_each) unless block_given? page = self loop do page.each(&block) break unless page.has_more? page = page.next_page break unless page end end
def each(&)
-
(Enumerator)
- If no block given
Other tags:
- Yield: - Each resource instance
def each(&) @data.each(&) end
def empty?
def empty? @data.empty? end
def first
-
(APIResource, nil)
- The first resource or nil if empty
def first @data.first end
def has_more?
def has_more? @has_more == true end
def initialize(response, resource_class, params = {}, opts = {})
def initialize(response, resource_class, params = {}, opts = {}) @resource_class = resource_class @params = params @opts = opts @data = [] @has_more = false @cursor = nil if response.is_a?(Hash) raw_data = response["data"] || [] @data = raw_data.map { |attrs| resource_class.new(attrs, opts) } @has_more = response["has_more"] || false @cursor = response["cursor"] end end
def inspect
-
(String)
- Inspection string with data and pagination info
def inspect "#<#{self.class.name} data=#{@data.inspect} has_more=#{@has_more}>" end
def last
-
(APIResource, nil)
- The last resource or nil if empty
def last @data.last end
def length
-
(Integer)
- Number of items
def length @data.length end
def next_page
-
(ListObject, nil)
- The next page or nil if no more pages
def next_page return nil unless has_more? && cursor @resource_class.list(@params.merge(cursor: cursor), **@opts) end
def to_a
-
(Array
- Array of resources in current page)
def to_a @data end