Method: Ecoportal::API::Common::BatchOperation#process_response

Defined in:
lib/ecoportal/api/common/batch_operation.rb

#process_response(response) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ecoportal/api/common/batch_operation.rb', line 27

def process_response(response)
  unless response.success?
    msg = 'Error: total failure in batch operation.'
    log(:debug) { msg }
    raise msg
  end

  log(:debug) { 'Processing batch responses' } if deep_logging?

  body_data(response.body).each.with_index do |subresponse, idx|
    status   = subresponse['status']
    method   = @operations[idx][:method]
    body     = subresponse['response']
    callback = @operations[idx][:callback]

    if status == 200 && method == 'GET'
      batch_response = BatchResponse.new(status, body, @wrapper.new(body))
      log_batch_response(@operations[idx], batch_response)

      callback&.call(batch_response, batch_response.result)
    else
      batch_response = BatchResponse.new(status, body)
      log_batch_response(@operations[idx], batch_response)

      callback&.call(batch_response)
    end
  end
end