class Github::PageIterator
A class responsible for requesting resources through page links
@api private
Constants
- ATTRIBUTES
Setup attribute accesor for all the link types
- DEFAULT_SHA
Attributes
current_api[R]
Public Class Methods
new(links, current_api)
click to toggle source
# File lib/github_api/page_iterator.rb, line 29 def initialize(links, current_api) @links = links @current_api = current_api update_page_links(@links) end
Public Instance Methods
count()
click to toggle source
# File lib/github_api/page_iterator.rb, line 39 def count parse_query(URI(last_page_uri).query)['page'] if last_page_uri end
first()
click to toggle source
Perform http get request for the first resource
# File lib/github_api/page_iterator.rb, line 45 def first perform_request(first_page_uri) if first_page_uri end
get_page(page_number)
click to toggle source
Returns the result for a specific page.
# File lib/github_api/page_iterator.rb, line 69 def get_page(page_number) # Find URI that we can work with, if we cannot get the first or the # last page URI then there is only one page. page_uri = first_page_uri || last_page_uri return nil unless page_uri perform_request(page_uri, page_number) end
last()
click to toggle source
Perform http get request for the last resource
# File lib/github_api/page_iterator.rb, line 63 def last perform_request(last_page_uri) if last_page_uri end
next()
click to toggle source
Perform http get request for the next resource
# File lib/github_api/page_iterator.rb, line 51 def next perform_request(next_page_uri) if next? end
next?()
click to toggle source
# File lib/github_api/page_iterator.rb, line 35 def next? next_page == 0 || !next_page_uri.nil? end
prev()
click to toggle source
Perform http get request for the previous resource
# File lib/github_api/page_iterator.rb, line 57 def prev perform_request(prev_page_uri) if prev_page_uri end
Private Instance Methods
perform_request(page_uri_path, page_number = nil)
click to toggle source
# File lib/github_api/page_iterator.rb, line 80 def perform_request(page_uri_path, page_number = nil) page_uri = URI(page_uri_path) params = parse_query(page_uri.query) if page_number params['page'] = page_number elsif next_page < 1 sha = sha(params) params['sha'] = sha if sha else params['page'] = parse_page_number(page_uri_path) end params['per_page'] = parse_per_page_number(page_uri_path) response = page_request(page_uri.path, params) update_page_links response.links response end
sha(params)
click to toggle source
# File lib/github_api/page_iterator.rb, line 99 def sha(params) return params['last_sha'] if params.keys.include?('last_sha') return DEFAULT_SHA if params.keys.include?('sha') end