Module: Github::PagedRequest

Includes:
Constants
Included in:
PageIterator
Defined in:
lib/github_api/paged_request.rb

Overview

A module that adds http get request to response pagination

Constant Summary collapse

FIRST_PAGE =

Default request page if none provided

1
PER_PAGE =

Default number of items as specified by API

30
NOT_FOUND =

Either page or per_page parameter not present

-1 # Either page or per_page parameter not present

Constants included from Constants

Constants::ACCEPT, Constants::ACCEPTED_OAUTH_SCOPES, Constants::ACCEPT_CHARSET, Constants::CACHE_CONTROL, Constants::CONTENT_LENGTH, Constants::CONTENT_TYPE, Constants::DATE, Constants::ETAG, Constants::HEADER_LAST, Constants::HEADER_LINK, Constants::HEADER_NEXT, Constants::LOCATION, Constants::META_FIRST, Constants::META_LAST, Constants::META_NEXT, Constants::META_PREV, Constants::META_REL, Constants::OAUTH_SCOPES, Constants::PARAM_PAGE, Constants::PARAM_PER_PAGE, Constants::PARAM_START_PAGE, Constants::RATELIMIT_LIMIT, Constants::RATELIMIT_REMAINING, Constants::RATELIMIT_RESET, Constants::SERVER, Constants::USER_AGENT

Instance Method Summary collapse

Instance Method Details

#default_pageObject



24
25
26
# File 'lib/github_api/paged_request.rb', line 24

def default_page
  current_api.page ? current_api.page : FIRST_PAGE
end

#default_page_sizeObject

Check if current api instance has default per_page param set, otherwise use global default.



20
21
22
# File 'lib/github_api/paged_request.rb', line 20

def default_page_size
  current_api.per_page ? current_api.per_page : PER_PAGE
end

#page_request(path, params = {}) ⇒ Object

Perform http get request with pagination parameters



30
31
32
33
34
35
36
37
38
39
# File 'lib/github_api/paged_request.rb', line 30

def page_request(path, params={})
  if params[PARAM_PER_PAGE] == NOT_FOUND
    params[PARAM_PER_PAGE] = default_page_size
  end
  if params[PARAM_PAGE] && params[PARAM_PAGE] == NOT_FOUND
    params[PARAM_PAGE] = default_page
  end

  current_api.get_request(path, ParamsHash.new(params))
end