class NetSuite::Actions::GetList

Public Class Methods

new(klass, options = { }) click to toggle source
# File lib/netsuite/actions/get_list.rb, line 7
def initialize(klass, options = { })
  @klass = klass
  @options = options
end

Private Instance Methods

request(credentials={}) click to toggle source
# File lib/netsuite/actions/get_list.rb, line 14
def request(credentials={})
  NetSuite::Configuration.connection({}, credentials).call(:get_list, :message => request_body)
end
request_body() click to toggle source
# File lib/netsuite/actions/get_list.rb, line 18
def request_body
  # list of all netsuite types; useful for debugging
  # https://webservices.netsuite.com/xsd/platform/v2014_1_0/coreTypes.xsd

  list = @options.is_a?(Hash) ? @options[:list] : @options

  formatted_list = if @options[:type_id]
    type = @options[:type_id]
    record_type = 'platformCore:CustomRecordRef'

    list.map do |internal_id|
      {
        '@internalId' => internal_id,
        '@typeId' => type,
        '@xsi:type' => record_type
      }
    end
  else
    type = @klass.to_s.split('::').last.lower_camelcase
    record_type = 'platformCore:RecordRef'

    list.map do |internal_id|
      {
        '@internalId' => internal_id,
        '@type' => type,
        '@xsi:type' => record_type
      }
    end
  end

  {
    baseRef: formatted_list
  }
end
response_body() click to toggle source
# File lib/netsuite/actions/get_list.rb, line 61
def response_body
  @response_body ||= @response.body[:get_list_response][:read_response_list][:read_response]
  @response_body = [@response_body] unless @response_body.is_a? Array
  @response_body
end
response_header() click to toggle source
# File lib/netsuite/actions/get_list.rb, line 53
def response_header
  @response_header ||= response_header_hash
end
response_header_hash() click to toggle source
# File lib/netsuite/actions/get_list.rb, line 57
def response_header_hash
  @response_header_hash = @response.header[:document_info]
end
success?() click to toggle source
# File lib/netsuite/actions/get_list.rb, line 67
def success?
  # each returned record has its own status;
  if @options[:allow_incomplete] 
    @success ||= !response_body.detect { |r| r[:status][:@is_success] == 'true' }.nil?
  else
    @success ||= response_body.detect { |r| r[:status][:@is_success] != 'true' }.nil?
  end
end