Class: NetSuite::Actions::Update

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

Defined Under Namespace

Modules: Support

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::Requests

#call, included

Methods inherited from AbstractAction

#request

Constructor Details

#initialize(klass, attributes) ⇒ Update

Returns a new instance of Update.



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

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

Instance Attribute Details

#response_hashObject (readonly)

Returns the value of attribute response_hash.



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

def response_hash
  @response_hash
end

Instance Method Details

#action_nameObject



68
69
70
# File 'lib/netsuite/actions/update.rb', line 68

def action_name
  :update
end

#errorsObject



60
61
62
63
64
65
66
# File 'lib/netsuite/actions/update.rb', line 60

def errors
  error_obj = response_hash[:status][:status_detail]
  error_obj = [error_obj] if error_obj.class == Hash
  error_obj.map do |error|
    NetSuite::Error.new(error)
  end
end

#request_bodyObject

<platformMsgs:update>

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

</platformMsgs:update>



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

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



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

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

#response_errorsObject



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

def response_errors
  if response_hash[:status] && response_hash[:status][:status_detail]
    @response_errors ||= errors
  end
end

#success?Boolean

Returns:

  • (Boolean)


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

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

#updated_recordObject



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

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