Class: RestClientWrapper::Paginator::Echo
- Inherits:
-
Object
- Object
- RestClientWrapper::Paginator::Echo
- Defined in:
- lib/rest_client_wrapper/paginators/echo.rb,
lib/rest_client_wrapper/paginators/echo_paginator.rb
Overview
Echo
Instance Attribute Summary collapse
-
#rest_client ⇒ Object
Returns the value of attribute rest_client.
Instance Method Summary collapse
-
#initialize(limit: Paginate::DEFAULT_PAGINATION_PAGE_SIZE) ⇒ Echo
constructor
A new instance of Echo.
- #paginate(http_method:, uri:, segment_params: {}, query_params: {}, headers: {}, data: false) ⇒ Object
Constructor Details
#initialize(limit: Paginate::DEFAULT_PAGINATION_PAGE_SIZE) ⇒ Echo
Returns a new instance of Echo.
34 35 36 37 |
# File 'lib/rest_client_wrapper/paginators/echo.rb', line 34 def initialize(limit: Paginate::DEFAULT_PAGINATION_PAGE_SIZE) @rest_client = nil @config = { limit: } end |
Instance Attribute Details
#rest_client ⇒ Object
Returns the value of attribute rest_client.
32 33 34 |
# File 'lib/rest_client_wrapper/paginators/echo.rb', line 32 def rest_client @rest_client end |
Instance Method Details
#paginate(http_method:, uri:, segment_params: {}, query_params: {}, headers: {}, data: false) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rest_client_wrapper/paginators/echo.rb', line 39 def paginate(http_method:, uri:, segment_params: {}, query_params: {}, headers: {}, data: false) raise RestClientError.new("Client not set, unable to make API call", nil, nil) unless @rest_client query_params.reverse_merge!(@config) responses = [] loop do response = @rest_client.make_request(http_method:, uri:, segment_params:, query_params:, headers:) (block_given?) ? yield(response) : (responses << response) links = _pagination_links(response) break unless links.key?(:offset) query_params[:offset] = links[:offset] end return (data) ? responses.map(&:body).pluck(:data).flatten : responses end |