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(uri) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/poms/api/pagination_client.rb', line 22 def execute(uri) Enumerator.new do |yielder| page = Page.new(uri) loop do page.execute { |page_uri| yield page_uri } page.items.each { |item| yielder << item } raise StopIteration if page.final? page = page.next_page end end.lazy end |
.get(uri, credentials) ⇒ Object
10 11 12 13 14 |
# File 'lib/poms/api/pagination_client.rb', line 10 def get(uri, credentials) execute(uri) do |page_uri| Api::JsonClient.get(page_uri, credentials) end end |
.post(uri, body, credentials) ⇒ Object
16 17 18 19 20 |
# File 'lib/poms/api/pagination_client.rb', line 16 def post(uri, body, credentials) execute(uri) do |page_uri| Api::JsonClient.post(page_uri, body, credentials) end end |