### Home Classes Methods

### In Files

- lib/github_api/pagination.rb

### Methods

- #auto_paginate
- #count_pages
- #each_page
- #first_page
- #has_next_page?
- #last_page
- #links
- #next_page
- #page
- #prev_page
- #previous_page

### Included Modules

- Github::Constants

### Class/Module Index

Quicksearch

- Github
- Github::API
- Github::Activity
- Github::Activity::Events
- Github::Activity::Notifications
- Github::Activity::Starring
- Github::Activity::Watching
- Github::ApiFactory
- Github::Arguments
- Github::Authorization
- Github::Authorizations
- Github::AutoloadHelper
- Github::Client
- Github::Configuration
- Github::Connection
- Github::Constants
- Github::CoreExt
- Github::CoreExt::OrderedHash
- Github::Descendants
- Github::Emojis
- Github::Error
- Github::Error::BadRequest
- Github::Error::ClientError
- Github::Error::Forbidden
- Github::Error::GithubError
- Github::Error::InternalServerError
- Github::Error::InvalidOptions
- Github::Error::NotAcceptable
- Github::Error::NotFound
- Github::Error::RequiredParams
- Github::Error::ServiceError
- Github::Error::ServiceUnavailable
- Github::Error::Unauthorized
- Github::Error::UnknownValue
- Github::Error::UnprocessableEntity
- Github::Error::Validations
- Github::Gists
- Github::Gists::Comments
- Github::GitData
- Github::GitData::Blobs
- Github::GitData::Commits
- Github::GitData::References
- Github::GitData::Tags
- Github::GitData::Trees
- Github::Gitignore
- Github::Issues
- Github::Issues::Assignees
- Github::Issues::Comments
- Github::Issues::Events
- Github::Issues::Labels
- Github::Issues::Milestones
- Github::Jsonable
- Github::Markdown
- Github::Meta
- Github::MimeType
- Github::Normalizer
- Github::Orgs
- Github::Orgs::Members
- Github::Orgs::Teams
- Github::PageIterator
- Github::PageLinks
- Github::PagedRequest
- Github::Pagination
- Github::ParameterFilter
- Github::ParamsHash
- Github::PullRequests
- Github::PullRequests::Comments
- Github::RateLimit
- Github::Repos
- Github::Repos::Collaborators
- Github::Repos::Comments
- Github::Repos::Commits
- Github::Repos::Contents
- Github::Repos::Downloads
- Github::Repos::Forks
- Github::Repos::Hooks
- Github::Repos::Keys
- Github::Repos::Merging
- Github::Repos::PubSubHubbub
- Github::Repos::Statistics
- Github::Repos::Statuses
- Github::Request
- Github::Request::BasicAuth
- Github::Request::Jsonize
- Github::Request::OAuth2
- Github::Resource
- Github::Response
- Github::Response::Header
- Github::Response::Jsonize
- Github::Response::Mashify
- Github::Response::RaiseError
- Github::Response::Xmlize
- Github::ResponseWrapper
- Github::S3Uploader
- Github::Say
- Github::Scopes
- Github::Search
- Github::Users
- Github::Users::Emails
- Github::Users::Followers
- Github::Users::Keys
- Github::Utils
- Github::Utils::Url
- Github::VERSION
- Github::Validations
- Github::Validations::Format
- Github::Validations::Presence
- Github::Validations::Required
- Github::Validations::Token
- Hash

No matching classes.

# Github::Pagination

A module that decorates response with pagination helpers

### Public Instance Methods

auto_paginate(auto=false) click to toggle source

Iterate over results set pages by automatically calling `next_page` until all pages are exhausted. Caution needs to be exercised when using this feature - 100 pages iteration will perform 100 API calls. By default this is off. You can set it on the client, individual API instances or just per given request.

    # File lib/github_api/pagination.rb, line 24
    def auto_paginate(auto=false)
      if (current_api.auto_pagination? || auto) && self.body.is_a?(Array)
        resources_bodies = []
        each_page { |resource| resources_bodies += resource.body }
        self.body = resources_bodies
      end
      self
    end

count_pages() click to toggle source

Retrive number of total pages base on current :per_page parameter

    # File lib/github_api/pagination.rb, line 14
    def count_pages
      page_iterator.count.to_i
    end

each_page() click to toggle source

Iterator like each for response pages. If there are no pages to iterate over this method will return current page.

    # File lib/github_api/pagination.rb, line 35
    def each_page
      yield self
      while page_iterator.has_next?
        yield next_page
      end
    end

first_page() click to toggle source

Retrives the result of the first page. Returns `nil` if there is no first page - either because you are already on the first page or there are no pages at all in the result.

    # File lib/github_api/pagination.rb, line 45
    def first_page
      first_request = page_iterator.first
      self.instance_eval { @env = first_request.env } if first_request
      first_request
    end

has_next_page?() click to toggle source

Returns `true` if there is another page in the result set, otherwise `false`

    # File lib/github_api/pagination.rb, line 89
    def has_next_page?
      page_iterator.has_next?
    end

last_page() click to toggle source

Retrives the result of the last page. Returns `nil` if there is no last page - either because you are already on the last page, there is only one page or there are no pages at all in the result.

    # File lib/github_api/pagination.rb, line 71
    def last_page
      last_request = page_iterator.last
      self.instance_eval { @env = last_request.env } if last_request
      last_request
    end

links() click to toggle source

Return page links

    # File lib/github_api/pagination.rb, line 9
    def links
      @links = Github::PageLinks.new(env[:response_headers])
    end

next_page() click to toggle source

Retrives the result of the next page. Returns `nil` if there is no next page or no pages at all.

    # File lib/github_api/pagination.rb, line 53
    def next_page
      next_request = page_iterator.next
      self.instance_eval { @env = next_request.env } if next_request
      next_request
    end

page(page_number) click to toggle source

Retrives a specific result for a page given page number. The `page_number` parameter is not validate, hitting a page that does not exist will return Github API error. Consequently, if there is only one page, this method returns nil

    # File lib/github_api/pagination.rb, line 81
    def page(page_number)
      request = page_iterator.get_page(page_number)
      self.instance_eval { @env = request.env } if request
      request
    end

prev_page() click to toggle source

Retrives the result of the previous page. Returns `nil` if there is no previous page or no pages at all.

    # File lib/github_api/pagination.rb, line 61
    def prev_page
      prev_request = page_iterator.prev
      self.instance_eval { @env = prev_request.env } if prev_request
      prev_request
    end

Also aliased as: previous_page
previous_page() click to toggle source
Alias for: prev_page

[Validate]

Generated with the Darkfish Rdoc Generator 2.