Class: NetSuite::Actions::Update

Inherits:
Object
  • Object
show all
Includes:
Support::Requests
Defined in:
lib/netsuite/actions/update.rb

Defined Under Namespace

Modules: Support

Instance Method Summary collapse

Methods included from Support::Requests

#call, included

Constructor Details

#initialize(klass, attributes) ⇒ Update

Returns a new instance of Update.



6
7
8
9
# File 'lib/netsuite/actions/update.rb', line 6

def initialize(klass, attributes)
  @klass      = klass
  @attributes = attributes
end

Instance Method Details

#requestObject



11
12
13
# File 'lib/netsuite/actions/update.rb', line 11

def request
  NetSuite::Configuration.connection.call :update, :message => request_body
end

#request_bodyObject

<platformMsgs:update>

<platformMsgs:record internalId="980" xsi:type="listRel:Customer">
  <listRel:companyName>Shutter Fly Corporation</listRel:companyName>
</platformMsgs:record>

</platformMsgs:update>



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/netsuite/actions/update.rb', line 20

def request_body
  hash = {
    'platformMsgs:record' => {
      :content! => updated_record.to_record,
      '@xsi:type' => updated_record.record_type
    }
  }

  if updated_record.respond_to?(:internal_id) && updated_record.internal_id
    hash['platformMsgs:record']['@platformMsgs:internalId'] = updated_record.internal_id
  end

  if updated_record.respond_to?(:external_id) && updated_record.external_id
    hash['platformMsgs:record']['@platformMsgs:externalId'] = updated_record.external_id
  end
  
  hash
end

#response_bodyObject



47
48
49
# File 'lib/netsuite/actions/update.rb', line 47

def response_body
  @response_body ||= response_hash[:base_ref]
end

#response_hashObject



51
52
53
# File 'lib/netsuite/actions/update.rb', line 51

def response_hash
  @response_hash ||= @response.to_hash[:update_response][:write_response]
end

#success?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/netsuite/actions/update.rb', line 43

def success?
  @success ||= response_hash[:status][:@is_success] == 'true'
end

#updated_recordObject



39
40
41
# File 'lib/netsuite/actions/update.rb', line 39

def updated_record
  @updated_record ||= @klass.new(@attributes)
end