Class: Github::PageIterator Private

Inherits:
Object
  • Object
show all
Includes:
Constants, PagedRequest, Utils::Url
Defined in:
lib/github_api2/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.



29
30
31
32
33
# File 'lib/github_api2/page_iterator.rb', line 29

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.



27
28
29
# File 'lib/github_api2/page_iterator.rb', line 27

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.



39
40
41
# File 'lib/github_api2/page_iterator.rb', line 39

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



45
46
47
# File 'lib/github_api2/page_iterator.rb', line 45

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.



69
70
71
72
73
74
75
76
# File 'lib/github_api2/page_iterator.rb', line 69

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



63
64
65
# File 'lib/github_api2/page_iterator.rb', line 63

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



51
52
53
# File 'lib/github_api2/page_iterator.rb', line 51

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)


35
36
37
# File 'lib/github_api2/page_iterator.rb', line 35

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



57
58
59
# File 'lib/github_api2/page_iterator.rb', line 57

def prev
  perform_request(prev_page_uri) if prev_page_uri
end