Class: Buzz::Paginator
- Inherits:
-
Object
- Object
- Buzz::Paginator
- Includes:
- Enumerable
- Defined in:
- lib/buzz/paginator.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #each_page {|@response| ... } ⇒ Object
-
#initialize(client, path, params = {}) ⇒ Paginator
constructor
A new instance of Paginator.
- #to_a ⇒ Object
Constructor Details
#initialize(client, path, params = {}) ⇒ Paginator
Returns a new instance of Paginator.
9 10 11 12 13 14 |
# File 'lib/buzz/paginator.rb', line 9 def initialize(client, path, params = {}) @client = client @path = path @params = params @response = nil end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/buzz/paginator.rb', line 7 def response @response end |
Instance Method Details
#each(&block) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/buzz/paginator.rb', line 30 def each(&block) return enum_for(:each) unless block_given? each_page do |page| results = page.results || [] results.each(&block) end end |
#each_page {|@response| ... } ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/buzz/paginator.rb', line 16 def each_page return enum_for(:each_page) unless block_given? @response = @client.get(@path, @params) yield @response while @response.next_url next_path = URI.parse(@response.next_url).path next_params = parse_query(URI.parse(@response.next_url).query) @response = @client.get(next_path, next_params) yield @response end end |
#to_a ⇒ Object
39 40 41 42 43 |
# File 'lib/buzz/paginator.rb', line 39 def to_a entries = [] each { |item| entries << item } entries end |