Module: Nimbu::Pagination::PagedRequest

Includes:
Utils::Constants
Included in:
PageIterator
Defined in:
lib/nimbu-api/pagination/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 Utils::Constants

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

Instance Method Summary collapse

Instance Method Details

#default_pageObject



22
23
24
# File 'lib/nimbu-api/pagination/paged_request.rb', line 22

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.



18
19
20
# File 'lib/nimbu-api/pagination/paged_request.rb', line 18

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 paginatoin parameters



28
29
30
31
32
33
34
35
36
37
# File 'lib/nimbu-api/pagination/paged_request.rb', line 28

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, params)
end