Class: HiEnergyAi::Paginator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/hi_energy_ai/paginator.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:, path:, params: {}, first_response: nil) ⇒ Paginator

Returns a new instance of Paginator.



7
8
9
10
11
12
# File 'lib/hi_energy_ai/paginator.rb', line 7

def initialize(client:, path:, params: {}, first_response: nil)
  @client = client
  @path = path
  @params = params
  @first_response = first_response
end

Instance Method Details

#eachObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/hi_energy_ai/paginator.rb', line 14

def each
  response = @first_response || @client.get(@path, params: @params)

  loop do
    yield response

    break unless response.has_more?

    next_params = @params.merge(response.next_page_params)
    response = @client.get(@path, params: next_params)
  end
end