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 Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::Requests

#call, included

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

#errorsObject



64
65
66
67
68
69
70
# File 'lib/netsuite/actions/update.rb', line 64

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(credentials = {}) ⇒ Object



14
15
16
# File 'lib/netsuite/actions/update.rb', line 14

def request(credentials={})
  NetSuite::Configuration.connection({}, credentials).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>



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

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



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

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

#response_errorsObject



54
55
56
57
58
# File 'lib/netsuite/actions/update.rb', line 54

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

#success?Boolean

Returns:

  • (Boolean)


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

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

#updated_recordObject



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

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