gapic-common - Class Gapic::Rest::PagedEnumerable (v0.24.0)

Reference documentation and code samples for the gapic-common class Gapic::Rest::PagedEnumerable.

A class to provide the Enumerable interface to the response of a REST paginated method. PagedEnumerable assumes response message holds a list of resources and the token to the next page.

PagedEnumerable provides the enumerations over the resource data, and also provides the enumerations over the pages themselves.

Inherits

  • Object

Includes

  • Enumerable

Examples

normal iteration over resources.

paged_enumerable.each { |resource| puts resource }

per-page iteration.

paged_enumerable.each_page { |page| puts page }

Enumerable over pages.

paged_enumerable.each_page do |page|
  page.each { |resource| puts resource }
end

more exact operations over pages.

while some_condition()
  page = paged_enumerable.page
  do_something(page)
  break if paged_enumerable.next_page?
  paged_enumerable.next_page
end

Methods

#each

def each(&block) -> Enumerator

Iterate over the individual resources, automatically requesting new pages as needed.

Yields
  • (Object) — Gives the resource objects in the stream.
Returns
  • (Enumerator) — if no block is provided

#each_page

def each_page() -> Enumerator

Iterate over the pages.

Yields
  • (Page) — Gives the pages in the stream.
Returns
  • (Enumerator) — if no block is provided

#next_page

def next_page() -> Page, nil
Alias Of: #next_page!

Load the next page and set it as the current page. If there is no next page, sets nil as a current page.

Returns
  • (Page, nil) — the new page object.

#next_page!

def next_page!() -> Page, nil
Aliases

Load the next page and set it as the current page. If there is no next page, sets nil as a current page.

Returns
  • (Page, nil) — the new page object.

#next_page?

def next_page?() -> Boolean

True if there is at least one more page of results.

Returns
  • (Boolean)

#next_page_token

def next_page_token() -> String, nil

The page token to be used for the next RPC call, or the empty string if there is no next page. nil if the iteration is complete.

Returns
  • (String, nil)

#page

def page() -> Page
Returns
  • (Page) — The current page object.

#response

def response() -> Object, nil

The current response object, for the current page. nil if the iteration is complete.

Returns
  • (Object, nil)