Module: Restforce::Concerns::BatchAPI
Defined Under Namespace
Classes: Subrequests
Instance Method Summary collapse
Methods included from Verbs
define_api_verb, define_verb, define_verbs
Instance Method Details
#batch(halt_on_error: false) {|subrequests| ... } ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/restforce/concerns/batch_api.rb', line 12 def batch(halt_on_error: false) subrequests = Subrequests.new() yield(subrequests) subrequests.requests.each_slice(25).map do |requests| properties = { batchRequests: requests, haltOnError: halt_on_error } response = api_post('composite/batch', properties.to_json) body = response.body results = body['results'] if halt_on_error && body['hasErrors'] last_error_index = results.rindex { |result| result['statusCode'] != 412 } last_error = results[last_error_index] raise BatchAPIError, last_error['result'][0]['errorCode'] end results.map(&:compact) end.flatten end |
#batch! ⇒ Object
32 33 34 |
# File 'lib/restforce/concerns/batch_api.rb', line 32 def batch!(&) batch(halt_on_error: true, &) end |