Sha256: 842ccb0bbb06c854a4a10d13721c933304b74213152bed215f6d90565c3a1215

Contents?: true

Size: 1.12 KB

Versions: 20

Compression:

Stored size: 1.12 KB

Contents

# encoding: utf-8

module Nimbu
  module Pagination
    # A module that adds http get request to response pagination
    module PagedRequest
      include Nimbu::Utils::Constants

      FIRST_PAGE = 1 # Default request page if none provided

      PER_PAGE   = 30 # Default number of items as specified by API

      NOT_FOUND  = -1 # Either page or per_page parameter not present

      # Check if current api instance has default per_page param set,
      # otherwise use global default.
      #
      def default_page_size
        current_api.per_page ? current_api.per_page : PER_PAGE
      end

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

      # Perform http get request with paginatoin parameters
      #
      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

    end # PagedRequest
  end # Pagination
end # Nimbu

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
nimbu-api-0.5.0 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.4.4 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.4.3 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.4.2 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.4.1 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.4.0 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.3.0 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.2.1 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.2 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.2.beta.3 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.2.beta.2 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.2.beta.1 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.2.beta lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.1.5 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.1.4 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.1.3 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.1.1 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.1 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.0.2 lib/nimbu-api/pagination/paged_request.rb
nimbu-api-0.0.1 lib/nimbu-api/pagination/paged_request.rb