class NetSuite::Actions::UpsertList
Public Class Methods
new(*objects)
click to toggle source
# File lib/netsuite/actions/upsert_list.rb, line 7 def initialize(*objects) @objects = objects end
Private Instance Methods
errors()
click to toggle source
# File lib/netsuite/actions/upsert_list.rb, line 61 def errors errors = response_hash.select { |h| h[:status] && h[:status][:status_detail] }.map do |obj| error_obj = obj[:status][:status_detail] error_obj = [error_obj] if error_obj.class == Hash errors = error_obj.map do |error| NetSuite::Error.new(error) end [obj[:base_ref][:@external_id], errors] end Hash[errors] end
request(credentials={})
click to toggle source
# File lib/netsuite/actions/upsert_list.rb, line 13 def request(credentials={}) NetSuite::Configuration.connection( { element_form_default: :unqualified }, credentials ).call(:upsert_list, message: request_body) end
request_body()
click to toggle source
<soap:Body>
<upsertList> <record xsi:type="listRel:Customer" externalId="ext1"> <listRel:entityId>Shutter Fly</listRel:entityId> <listRel:companyName>Shutter Fly, Inc</listRel:companyName> </record> <record xsi:type="listRel:Customer" externalId="ext2"> <listRel:entityId>Target</listRel:entityId> <listRel:companyName>Target</listRel:companyName> </record> </upsertList>
</soap:Body>
# File lib/netsuite/actions/upsert_list.rb, line 31 def request_body attrs = @objects.map do |o| hash = o.to_record.merge({ '@xsi:type' => o.record_type }) if o.respond_to?(:external_id) && o.external_id hash['@externalId'] = o.external_id end hash end { 'record' => attrs } end
response_body()
click to toggle source
# File lib/netsuite/actions/upsert_list.rb, line 51 def response_body @response_body ||= response_hash.map { |h| h[:base_ref] } end
response_errors()
click to toggle source
# File lib/netsuite/actions/upsert_list.rb, line 55 def response_errors if response_hash.any? { |h| h[:status] && h[:status][:status_detail] } @response_errors ||= errors end end
response_hash()
click to toggle source
# File lib/netsuite/actions/upsert_list.rb, line 47 def response_hash @response_hash ||= Array[@response.body[:upsert_list_response][:write_response_list][:write_response]].flatten end
success?()
click to toggle source
# File lib/netsuite/actions/upsert_list.rb, line 74 def success? @success ||= response_hash.all? { |h| h[:status][:@is_success] == 'true' } end