module Github::Pagination
def auto_paginate(auto=false)
instances or just per given request.
By default this is off. You can set it on the client, individual API
using this feature - 100 pages iteration will perform 100 API calls.
until all pages are exhausted. Caution needs to be exercised when
Iterate over results set pages by automatically calling `next_page`
def auto_paginate(auto=false) if (current_api.auto_pagination? || auto) && self.body.is_a?(Array) resources_bodies = [] each_page { |resource| resources_bodies += resource.body } self.body = resources_bodies end self end
def count_pages
def count_pages page_iterator.count.to_i end
def each_page
Iterator like each for response pages. If there are no pages to
def each_page yield self while page_iterator.next? yield next_page end end
def first_page
no first page - either because you are already on the first page
Retrives the result of the first page. Returns nil if there is
def first_page first_request = page_iterator.first self.instance_eval { @env = first_request.env } if first_request first_request end
def has_next_page?
Returns true if there is another page in the result set,
def has_next_page? page_iterator.next? end
def last_page
no last page - either because you are already on the last page,
Retrives the result of the last page. Returns nil if there is
def last_page last_request = page_iterator.last self.instance_eval { @env = last_request.env } if last_request last_request end
def links
def links @links = Github::PageLinks.new(env[:response_headers]) end
def next_page
Retrives the result of the next page. Returns nil if there is
def next_page next_request = page_iterator.next self.instance_eval { @env = next_request.env } if next_request next_request end
def page(page_number)
that does not exist will return Github API error. Consequently, if
The page_number parameter is not validate, hitting a page
Retrives a specific result for a page given page number.
def page(page_number) request = page_iterator.get_page(page_number) self.instance_eval { @env = request.env } if request request end
def page_iterator # :nodoc:
Internally used page iterator
def page_iterator # :nodoc: @page_iterator = Github::PageIterator.new(links, current_api) end
def prev_page
Retrives the result of the previous page. Returns nil if there is
def prev_page prev_request = page_iterator.prev self.instance_eval { @env = prev_request.env } if prev_request prev_request end