Sha256: 5952ffeccdaf7c78a5a9d0dea78dd0e4c19747747df5698dbd48fa95da1888a0

Contents?: true

Size: 1016 Bytes

Versions: 27

Compression:

Stored size: 1016 Bytes

Contents

module Github
  module PagedRequest
    include Github::Constants

    extend self

    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

    class << self
      attr_accessor :page, :per_page
    end

    def default_page_size
      Github.api_client.per_page ? Github.api_client.per_page : PER_PAGE
    end

    def default_page
      Github.api_client.page ? Github.api_client.page : FIRST_PAGE
    end

    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

      Github::PagedRequest.page = params[PARAM_PAGE]
      Github::PagedRequest.per_page = params[PARAM_PER_PAGE]

      Github.api_client.get_request path, params
    end

  end # PagedRequest
end # Github

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
github_api-0.6.0 lib/github_api/paged_request.rb
github_api-0.5.4 lib/github_api/paged_request.rb
github_api-0.5.3 lib/github_api/paged_request.rb
github_api-0.5.2 lib/github_api/paged_request.rb
github_api-0.5.1 lib/github_api/paged_request.rb
github_api-0.5.0 lib/github_api/paged_request.rb
github_api-0.5.0.rc1 lib/github_api/paged_request.rb