Class: NgrokAPI::PagedIterator
- Inherits:
-
Object
- Object
- NgrokAPI::PagedIterator
- Defined in:
- lib/ngrokapi/paged_iterator.rb
Overview
Low level class which allows the user to iterate through the results of a list API call
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#list_property ⇒ Object
readonly
Returns the value of attribute list_property.
-
#n ⇒ Object
Returns the value of attribute n.
-
#page ⇒ Object
Returns the value of attribute page.
Instance Method Summary collapse
-
#get_next ⇒ object
Iterate through the result set, returning the next instance if we already have one, or make a new API call to next_page_uri to get more results and return the next one from that call.
-
#initialize(client:, page:, list_property:, danger: false) ⇒ PagedIterator
constructor
A new instance of PagedIterator.
Constructor Details
#initialize(client:, page:, list_property:, danger: false) ⇒ PagedIterator
Returns a new instance of PagedIterator.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ngrokapi/paged_iterator.rb', line 12 def initialize( client:, page:, list_property:, danger: false ) @n = 0 @client = client @list_property = list_property @page = page @danger = danger end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/ngrokapi/paged_iterator.rb', line 10 def client @client end |
#list_property ⇒ Object (readonly)
Returns the value of attribute list_property.
10 11 12 |
# File 'lib/ngrokapi/paged_iterator.rb', line 10 def list_property @list_property end |
#n ⇒ Object
Returns the value of attribute n.
9 10 11 |
# File 'lib/ngrokapi/paged_iterator.rb', line 9 def n @n end |
#page ⇒ Object
Returns the value of attribute page.
9 10 11 |
# File 'lib/ngrokapi/paged_iterator.rb', line 9 def page @page end |
Instance Method Details
#get_next ⇒ object
Iterate through the result set, returning the next instance if we already have one, or make a new API call to next_page_uri to get more results and return the next one from that call.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ngrokapi/paged_iterator.rb', line 30 def get_next item = @page.attrs[@list_property][@n] raise "None" if item.nil? self.n += 1 item rescue if @page.next_page_uri res = @client.list(danger: @danger, url: @page.next_page_uri) self.n = 0 self.page = res get_next end end |