### Home Classes Methods

### In Files

- lib/github_api/page_iterator.rb

### Parent

Object

### Methods

- ::new
- #count
- #first
- #get_page
- #has_next?
- #last
- #next
- #prev

### Included Modules

- Github::Constants
- Github::Utils::Url
- Github::PagedRequest

### 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::PageIterator

### Constants

ATTRIBUTES

  Setup attribute accesor for all the link types

### Attributes

current_api[R]

### Public Class Methods

new(links, current_api) click to toggle source

    # File lib/github_api/page_iterator.rb, line 20
    def initialize(links, current_api)
      @links       = links
      @current_api = current_api
      update_page_links @links
    end

### Public Instance Methods

count() click to toggle source

    # File lib/github_api/page_iterator.rb, line 30
    def count
      return nil unless last_page_uri
      parse_query(URI(last_page_uri).query)['page']
    end

first() click to toggle source

Perform http get request for the first resource

    # File lib/github_api/page_iterator.rb, line 37
    def first
      return nil unless first_page_uri
      page_uri = URI(first_page_uri)
      params = parse_query(page_uri.query)
      if next_page < 1
        params['sha'] = 'master' if params.keys.include?('sha')
        params['per_page'] = parse_per_page_number(first_page_uri)
      else
        params['page']     = parse_page_number(first_page_uri)
        params['per_page'] = parse_per_page_number(first_page_uri)
      end

      response = page_request(page_uri.path, params)
      update_page_links response.links
      response
    end

get_page(page_number) click to toggle source

Returns the result for a specific page.

    # File lib/github_api/page_iterator.rb, line 103
    def get_page(page_number)
      # Find URI that we can work with, if we cannot get the first or the
      # last page URI then there is only one page.
      page_uri = first_page_uri || last_page_uri
      return nil unless page_uri
      params = parse_query URI(page_uri).query
      params['page']     = page_number
      params['per_page'] = parse_per_page_number(page_uri)

      response = page_request URI(page_uri).path, params
      update_page_links response.links
      response
    end

has_next?() click to toggle source

    # File lib/github_api/page_iterator.rb, line 26
    def has_next?
      next_page == 0 || !next_page_uri.nil?
    end

last() click to toggle source

Perform http get request for the last resource

    # File lib/github_api/page_iterator.rb, line 89
    def last
      return nil unless last_page_uri
      page_uri = URI(last_page_uri)
      params = parse_query(page_uri.query)
      params['page']     = parse_page_number(last_page_uri)
      params['per_page'] = parse_per_page_number(last_page_uri)

      response = page_request(page_uri.path, params)
      update_page_links response.links
      response
    end

next() click to toggle source

Perform http get request for the next resource

    # File lib/github_api/page_iterator.rb, line 56
    def next
      return nil unless has_next?
      page_uri = URI(next_page_uri)
      params   = parse_query(page_uri.query)
      if next_page < 1
        params['sha'] = params['last_sha'] if params.keys.include?('last_sha')
        params['per_page'] = parse_per_page_number(next_page_uri)
      else
        params['page']     = parse_page_number(next_page_uri)
        params['per_page'] = parse_per_page_number(next_page_uri)
      end

      response = page_request(page_uri.path, params)
      update_page_links response.links
      response
    end

prev() click to toggle source

Perform http get request for the previous resource

    # File lib/github_api/page_iterator.rb, line 75
    def prev
      return nil unless prev_page_uri
      page_uri = URI(prev_page_uri)
      params = parse_query(page_uri.query)
      params['page']     = parse_page_number(prev_page_uri)
      params['per_page'] = parse_per_page_number(prev_page_uri)

      response = page_request(page_uri.path, params)
      update_page_links response.links
      response
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.