Module: Poms::Api::PaginationClient

Defined in:
lib/poms/api/pagination_client.rb

Overview

Creates lazy Enumerators to handle pagination of the Poms API and performs the request on demand.

Defined Under Namespace

Classes: Page

Class Method Summary collapse

Class Method Details

.execute(request) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/poms/api/pagination_client.rb', line 11

def execute(request)
  Enumerator.new do |yielder|
    page = Page.new(request.uri)
    loop do
      page.execute { |page_uri| client_execute(request, page_uri) }
      page.items.each { |item| yielder << item }
      raise StopIteration if page.final?
      page = page.next_page
    end
  end.lazy
end