Class: Pinnacle::Internal::ItemIterator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/pinnacle/internal/iterators/item_iterator.rb

Direct Known Subclasses

CursorItemIterator, OffsetItemIterator

Instance Method Summary collapse

Instance Method Details

#each(&block) ⇒ NilClass

Iterates over each item returned by the API.

Parameters:

  • block (Proc)

    The block which each retrieved item is yielded to.

Returns:

  • (NilClass)


18
19
20
21
22
# File 'lib/pinnacle/internal/iterators/item_iterator.rb', line 18

def each(&block)
  while (item = next_element)
    block.call(item)
  end
end

#http_responseNet::HTTPResponse?

The raw HTTP response from the most recent page response.

Returns:

  • (Net::HTTPResponse, nil)


10
11
12
# File 'lib/pinnacle/internal/iterators/item_iterator.rb', line 10

def http_response
  @page_iterator&.http_response
end

#next?Boolean

Whether another item will be available from the API.

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
# File 'lib/pinnacle/internal/iterators/item_iterator.rb', line 27

def next?
  load_next_page if @page.nil?
  return false if @page.nil?

  return true if any_items_in_cached_page?

  load_next_page
  any_items_in_cached_page?
end

#next_elementObject

Retrieves the next item from the API.



38
39
40
41
42
43
44
# File 'lib/pinnacle/internal/iterators/item_iterator.rb', line 38

def next_element
  item = next_item_from_cached_page
  return item if item

  load_next_page
  next_item_from_cached_page
end