Class: NetSuite::Actions::Initialize

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

Defined Under Namespace

Modules: Support

Instance Method Summary collapse

Methods included from Support::Requests

#call, included

Constructor Details

#initialize(klass, object) ⇒ Initialize

Returns a new instance of Initialize.



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

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

Instance Method Details

#request(credentials = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/netsuite/actions/initialize.rb', line 12

def request(credentials={})
  NetSuite::Configuration.connection(
    {namespaces: {
      'xmlns:platformMsgs'    => "urn:messages_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com",
      'xmlns:platformCore'    => "urn:core_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com",
      'xmlns:platformCoreTyp' => "urn:types.core_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com",
    }}, credentials
  ).call :initialize, :message => request_body
end

#request_bodyObject

<platformMsgs:initializeRecord>

<platformCore:type>invoice</platformCore:type>
<platformCore:reference internalId="1513" type="salesOrder">
  <platformCore:name>1511</platformCore:name>
</platformCore:reference>

</platformMsgs:initializeRecord>



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/netsuite/actions/initialize.rb', line 28

def request_body
  {
    'platformMsgs:initializeRecord' => {
      'platformCore:type'      => @klass.to_s.split('::').last.lower_camelcase,
      'platformCore:reference' => {},
      :attributes!             => {
        'platformCore:reference' => {
          'internalId' => @object.internal_id,
          :type        => @object.class.to_s.split('::').last.lower_camelcase
        }
      }
    }
  }
end

#response_bodyObject



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

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

#response_hashObject



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

def response_hash
  @response_hash ||= @response.to_hash[:initialize_response][:read_response]
end

#success?Boolean

Returns:

  • (Boolean)


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

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