Method: APIClientBuilder::GetCollectionRequest#each

Defined in:
lib/api_client_builder/get_collection_request.rb

#eachJSON

Iterates over the pages and yields their items if they’re successful responses. Else handles the error. Will retry the response if a retry strategy is defined concretely on the response handler.

rubocop:disable Metrics/AbcSize

Returns:

  • the http response body



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/api_client_builder/get_collection_request.rb', line 13

def each
  if block_given?
    each_page do |page|
      if page.success?
        page.body.each do |item|
          yield(item)
        end
      elsif response_handler.respond_to?(:retryable?) && response_handler.retryable?(page.status_code)
        retried_page = attempt_retry

        retried_page.body.each do |item|
          yield(item)
        end
      else
        notify_error_handlers(page)
      end
    end
  else
    Enumerator.new(self, :each)
  end
end