Sha256: 67a25a036411e82688d0159ce8b8bceae76b7bbdc6ef08b19a8244c7b95f3e37

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

module NetSuite
  module Actions
    class Add
      include SavonSupport

      def initialize(attributes = {})
        @attributes = attributes
      end

      private

      def request
        connection.request :platformMsgs, :add do
          soap.namespaces['xmlns:platformMsgs'] = 'urn:messages_2011_2.platform.webservices.netsuite.com'
          soap.namespaces['xmlns:platformCore'] = 'urn:core_2011_2.platform.webservices.netsuite.com'
          soap.namespaces['xmlns:listRel']      = 'urn:relationships_2011_2.lists.webservices.netsuite.com'
          soap.header = auth_header
          soap.body   = request_body
        end
      end

      # <soap:Body>
      #   <platformMsgs:add>
      #     <platformMsgs:record xsi:type="listRel:Customer">
      #       <listRel:entityId>Shutter Fly</listRel:entityId>
      #       <listRel:companyName>Shutter Fly, Inc</listRel:companyName>
      #     </platformMsgs:record>
      #   </platformMsgs:add>
      # </soap:Body>
      def request_body
        {
          'platformMsgs:record' => {
            'listRel:entityId'    => @attributes[:entity_id],
            'listRel:companyName' => @attributes[:company_name]
          },
          :attributes! => {
            'platformMsgs:record' => {
              'xsi:type' => 'listRel:Customer'
            }
          }
        }
      end

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

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

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

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
netsuite-0.0.4 lib/netsuite/actions/add.rb