class Restforce::Concerns::BatchAPI::Subrequests
def batch_api_path(path)
def batch_api_path(path) "v#{options[:api_version]}/sobjects/#{path}" end
def create(sobject, attrs)
def create(sobject, attrs) requests << { method: 'POST', url: batch_api_path(sobject), richInput: attrs } end
def destroy(sobject, id)
def destroy(sobject, id) requests << { method: 'DELETE', url: batch_api_path("#{sobject}/#{id}") } end
def initialize(options)
def initialize(options) @options = options @requests = [] end
def update(sobject, attrs)
def update(sobject, attrs) id = attrs.fetch(attrs.keys.find { |k, v| k.to_s.casecmp?('id') }, nil) raise ArgumentError, 'Id field missing from attrs.' unless id attrs_without_id = attrs.reject { |k, v| k.to_s.casecmp?('id') } requests << { method: 'PATCH', url: batch_api_path("#{sobject}/#{id}"), richInput: attrs_without_id } end
def upsert(sobject, ext_field, attrs)
def upsert(sobject, ext_field, attrs) raise ArgumentError, 'External id field missing.' unless ext_field ext_id = attrs.fetch(attrs.keys.find { |k, v| k.to_s.casecmp?(ext_field.to_s) }, nil) raise ArgumentError, 'External id missing from attrs.' unless ext_id attrs_without_ext_id = attrs.reject { |k, v| k.to_s.casecmp?(ext_field) } requests << { method: 'PATCH', url: batch_api_path("#{sobject}/#{ext_field}/#{ext_id}"), richInput: attrs_without_ext_id } end