class Aws::PageableResponse
Decorates a {Seahorse::Client::Response} with paging methods:
page = PageableResponse.new(response, pager) page.last_page? #=> false # sends a request to receive the next response page page = page.next_page page.last_page? #=> true page.next_page #=> raises PageableResponse::LastPageError
You can enumerate all response pages with a block
page = PageableResponse.new(response, pager) page.each do |page| # yields once per page end
Or using {#next_page} and {#last_page?}:
page = PageableResponse.new(response, pager) page = page.next_page until page.last_page?
@note Normally you should not need to construct a {PageableResponse}
directly. The {Plugins::ResponsePaging} plugin automatically decorates all responses with a {PageableResponse}.
Attributes
@return [Paging::Pager]
Public Class Methods
@param [Seahorse::Client::Response] response @param [Paging::Pager] pager
# File lib/aws-sdk-core/pageable_response.rb, line 39 def initialize(response, pager) @pager = pager super(context:response.context, data:response.data, error:response.error) end
Public Instance Methods
@api private
# File lib/aws-sdk-core/pageable_response.rb, line 86 def count if respond_to?(:count) data.count else raise NotImplementedError end end
Yields the current and each following response to the given block. @yieldparam [Response] response @return [Enumerable,nil] Returns a new Enumerable if no block is given.
# File lib/aws-sdk-core/pageable_response.rb, line 74 def each_page(&block) return enum_for(:each_page) unless block_given? response = self yield(response) until response.last_page? response = response.next_page yield(response) end end
Returns `true` if there are no more results. Calling {#next_page} when this method returns `false` will raise an error. @return [Boolean]
# File lib/aws-sdk-core/pageable_response.rb, line 50 def last_page? @last_page = !@pager.truncated?(self) @last_page end
@return [Seahorse::Client::Response]
# File lib/aws-sdk-core/pageable_response.rb, line 63 def next_page(params = {}) if last_page? raise LastPageError.new(self) else PageableResponse.new(next_response(params), pager) end end
Returns `true` if there are more results. Calling {#next_page} will return the next response. @return [Boolean]
# File lib/aws-sdk-core/pageable_response.rb, line 58 def next_page? !last_page? end
@api private
# File lib/aws-sdk-core/pageable_response.rb, line 95 def respond_to?(method_name, *args) if method_name == :count data.respond_to?(:count) else super end end
Private Instance Methods
@param [Hash] params A hash of additional request params to
merge into the next page request.
@return [Hash] Returns the hash of request parameters for the
next page, merging any given params.
# File lib/aws-sdk-core/pageable_response.rb, line 119 def next_page_params(params) context[:original_params].merge(@pager.next_tokens(self).merge(params)) end
@param [Hash] params A hash of additional request params to
merge into the next page request.
@return [Seahorse::Client::Response] Returns the next page of
results.
# File lib/aws-sdk-core/pageable_response.rb, line 109 def next_response(params) params = next_page_params(params) request = context.client.build_request(context.operation_name, params) request.send_request end