Sha256: 995245418a8250bc1a02a54c0b3b12f012caf8fc3090a207fec370dead9a3989

Contents?: true

Size: 1.68 KB

Versions: 30

Compression:

Stored size: 1.68 KB

Contents

# https://system.netsuite.com/help/helpcenter/en_US/Output/Help/SuiteCloudCustomizationScriptingWebServices/SuiteTalkWebServices/getAll.html
module NetSuite
  module Actions
    class GetAll
      include Support::Requests

      def initialize(klass)
        @klass   = klass
      end

      private

      def request(credentials={})
        NetSuite::Configuration.connection(
          { element_form_default: :unqualified }, credentials
        ).call(:get_all, message: request_body)
      end

      # <soap:Body>
      #   <platformMsgs:getAll>
      #     <record>
      #       <recordType>salesTaxItem</recordType>
      #     </record>
      #   </platformMsgs:getAll>
      # </soap:Body>
      def request_body
        type = @klass.to_s.split('::').last.sub(/[A-Z]/) { |m| m[0].downcase }

        {
          record: [
            record_type: type
          ]
        }
      end

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

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

      def response_hash
        @response_hash = @response.body[:get_all_response][:get_all_result]
      end

      module Support

        def self.included(base)
          base.extend(ClassMethods)
        end

        module ClassMethods
          def get_all(credentials = {})
            response = NetSuite::Actions::GetAll.call([self], credentials)
            if response.success?
              response.body.map { |attr| new(attr) }
            else
              raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
            end
          end
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
netsuite-0.6.5 lib/netsuite/actions/get_all.rb
netsuite-0.6.4 lib/netsuite/actions/get_all.rb
netsuite-0.6.3 lib/netsuite/actions/get_all.rb
netsuite-0.6.2 lib/netsuite/actions/get_all.rb
netsuite-0.6.1 lib/netsuite/actions/get_all.rb
netsuite-0.6.0 lib/netsuite/actions/get_all.rb
netsuite-0.5.9 lib/netsuite/actions/get_all.rb
netsuite-0.5.8 lib/netsuite/actions/get_all.rb
netsuite-0.5.7 lib/netsuite/actions/get_all.rb
netsuite-0.5.6 lib/netsuite/actions/get_all.rb
netsuite-0.5.5 lib/netsuite/actions/get_all.rb
netsuite-0.5.4 lib/netsuite/actions/get_all.rb
netsuite-0.5.3 lib/netsuite/actions/get_all.rb
netsuite-0.5.2 lib/netsuite/actions/get_all.rb
netsuite-0.5.1 lib/netsuite/actions/get_all.rb
netsuite-0.5.0 lib/netsuite/actions/get_all.rb
netsuite-0.4.9 lib/netsuite/actions/get_all.rb
netsuite-0.4.8 lib/netsuite/actions/get_all.rb
netsuite-0.4.7 lib/netsuite/actions/get_all.rb
netsuite-0.4.6 lib/netsuite/actions/get_all.rb