class Google::Gax::PagedEnumerable::Page

A class to represent a page in a PagedEnumerable. This also implements Enumerable, so it can iterate over the resource elements.

@attribute [r] response

@return [Object] the actual response object.

@attribute [r] next_page_token

@return [Object] the page token to be used for the next API call.

Attributes

response[R]

Public Class Methods

new(response, response_page_token_field, resource_field) click to toggle source

@param response [Object]

The response object for the page.

@param response_page_token_field [String]

The name of the field in response which holds the next page token.

@param resource_field [String]

The name of the field in response which holds the resources.
# File lib/google/gax/api_callable.rb, line 87
def initialize(response, response_page_token_field, resource_field)
  @response = response
  @response_page_token_field = response_page_token_field
  @resource_field = resource_field
end

Public Instance Methods

dup_with(response) click to toggle source

Creates another instance of Page with replacing the new response. @param response [Object] a new response object.

# File lib/google/gax/api_callable.rb, line 95
def dup_with(response)
  self.class.new(response, @response_page_token_field, @resource_field)
end
each() { |obj| ... } click to toggle source

Iterate over the resources. @yield [Object] Gives the resource objects in the page.

# File lib/google/gax/api_callable.rb, line 101
def each
  @response[@resource_field].each do |obj|
    yield obj
  end
end
next_page_token() click to toggle source
# File lib/google/gax/api_callable.rb, line 107
def next_page_token
  @response[@response_page_token_field]
end
next_page_token?() click to toggle source

Truthiness of next_page_token.

# File lib/google/gax/api_callable.rb, line 112
def next_page_token?
  !@response.nil? && !next_page_token.nil? && next_page_token != 0 &&
    (!next_page_token.respond_to?(:empty?) || !next_page_token.empty?)
end