Class: Github::PageIterator Private

Inherits:
Object
  • Object
show all
Includes:
Constants, PagedRequest, Utils::Url
Defined in:
lib/github_api/page_iterator.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A class responsible for requesting resources through page links

Constant Summary collapse

ATTRIBUTES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Setup attribute accesor for all the link types

[META_FIRST, META_NEXT, META_PREV, META_LAST]
DEFAULT_SHA =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'master'

Constants included from PagedRequest

Github::PagedRequest::FIRST_PAGE, Github::PagedRequest::NOT_FOUND, Github::PagedRequest::PER_PAGE

Constants included from Constants

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

Constants included from Utils::Url

Utils::Url::DEFAULT_QUERY_SEP, Utils::Url::KEY_VALUE_SEP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PagedRequest

#default_page, #default_page_size, #page_request

Methods included from Utils::Url

#build_query, #escape, #escape_uri, #normalize, #parse_query, #parse_query_for_param, #unescape

Constructor Details

#initialize(links, current_api) ⇒ PageIterator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of PageIterator.


26
27
28
29
30
# File 'lib/github_api/page_iterator.rb', line 26

def initialize(links, current_api)
  @links       = links
  @current_api = current_api
  update_page_links(@links)
end

Instance Attribute Details

#current_apiObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


24
25
26
# File 'lib/github_api/page_iterator.rb', line 24

def current_api
  @current_api
end

Instance Method Details

#countObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


36
37
38
# File 'lib/github_api/page_iterator.rb', line 36

def count
  parse_query(URI(last_page_uri).query)['page'] if last_page_uri
end

#firstObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Perform http get request for the first resource


42
43
44
# File 'lib/github_api/page_iterator.rb', line 42

def first
  perform_request(first_page_uri) if first_page_uri
end

#get_page(page_number) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the result for a specific page.


66
67
68
69
70
71
72
73
# File 'lib/github_api/page_iterator.rb', line 66

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

  perform_request(page_uri, page_number)
end

#lastObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Perform http get request for the last resource


60
61
62
# File 'lib/github_api/page_iterator.rb', line 60

def last
  perform_request(last_page_uri) if last_page_uri
end

#nextObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Perform http get request for the next resource


48
49
50
# File 'lib/github_api/page_iterator.rb', line 48

def next
  perform_request(next_page_uri) if next?
end

#next?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

32
33
34
# File 'lib/github_api/page_iterator.rb', line 32

def next?
  next_page == 0 || !next_page_uri.nil?
end

#prevObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Perform http get request for the previous resource


54
55
56
# File 'lib/github_api/page_iterator.rb', line 54

def prev
  perform_request(prev_page_uri) if prev_page_uri
end