class RestClientWrapper::Paginator::Echo
Attributes
rest_client[RW]
Public Class Methods
new(limit: Paginate::DEFAULT_PAGINATION_PAGE_SIZE)
click to toggle source
# File lib/rest_client_wrapper/paginators/echo.rb, line 34 def initialize(limit: Paginate::DEFAULT_PAGINATION_PAGE_SIZE) @rest_client = nil @config = { limit: limit } end
Public Instance Methods
paginate(http_method:, uri:, segment_params: {}, query_params: {}, headers: {}, data: false) { |response| ... }
click to toggle source
# 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: http_method, uri: uri, segment_params: segment_params, query_params: query_params, headers: 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
Private Instance Methods
_pagination_links(response)
click to toggle source
# File lib/rest_client_wrapper/paginators/echo.rb, line 57 def _pagination_links(response) next_l = response&.body&.[](:next) || "" next_h = Rack::Utils.parse_query(URI.parse(next_l)&.query) return next_h.symbolize_keys! end