Skip to content

Commit

Permalink
Merge pull request #1 from TalentTech/master
Browse files Browse the repository at this point in the history
Authentication with role and GetSelectValue
  • Loading branch information
vjebelev committed Jul 15, 2012
2 parents 6aa9be6 + e944db0 commit a684ac3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/netsuite_client.rb
Expand Up @@ -5,7 +5,7 @@
require 'netsuite_client/symbol'

require 'rubygems'
gem 'soap4r'
gem 'soap4r-ruby1.9'

DEFAULT_NS_WSDL_VERSION = '2011_2'
if ENV['FORCE_NS_WSDL_VERSION']
Expand Down
14 changes: 13 additions & 1 deletion lib/netsuite_client/client.rb
Expand Up @@ -37,7 +37,12 @@ def initialize(config = {})
@config = config

@driver = NetSuitePortType.new(@config[:endpoint_url] || NetSuitePortType::DefaultEndpointUrl)
@driver.headerhandler.add(PassportHeaderHandler.new(:email => @config[:email], :password => @config[:password], :account => @config[:account_id]))

if @config[:role]
role = {:internalID => config[:role]}
end

@driver.headerhandler.add(PassportHeaderHandler.new(:email => @config[:email], :password => @config[:password], :account => @config[:account_id], :role => role))
@driver.headerhandler.add(PreferencesHeaderHandler.new)
@driver.headerhandler.add(SearchPreferencesHeaderHandler.new)
end
Expand Down Expand Up @@ -123,6 +128,13 @@ def delete(ref)
NetsuiteResult.new(res.writeResponse)
end

def get_select_value(klass, field)
fieldDescription = GetSelectValueFieldDescription.new
fieldDescription.recordType = constantize(klass)
fieldDescription.field = field
res = @driver.getSelectValue(:fieldDescription => fieldDescription, :pageIndex => 1).getSelectValueResult
res.status.xmlattr_isSuccess ? res.baseRefList : nil
end

# Get the full result set (possibly across multiple pages).
def full_basic_search(basic)
Expand Down
2 changes: 1 addition & 1 deletion netsuite_client.gemspec
Expand Up @@ -21,5 +21,5 @@ Gem::Specification.new do |s|
s.summary = %q{Ruby soap4r-based Netsuite client.}
s.test_files = ["test/netsuite_client_test.rb", "test/test_helper.rb"]

s.add_dependency 'soap4r'
s.add_dependency 'soap4r-ruby1.9'
end
19 changes: 17 additions & 2 deletions test/netsuite_client_test.rb
Expand Up @@ -11,8 +11,8 @@ def setup
exit(-1)
end

@client = NetsuiteClient.new(:account_id => ENV['NS_ACCOUNT_ID'], :email => ENV['NS_EMAIL'], :password => ENV['NS_PASSWORD'], :endpoint_url => ENV['NS_ENDPOINT_URL'])
#@client.debug = true
@client = NetsuiteClient.new(:account_id => ENV['NS_ACCOUNT_ID'], :email => ENV['NS_EMAIL'], :password => ENV['NS_PASSWORD'], :role => ENV['NS_ROLE'], :endpoint_url => ENV['NS_ENDPOINT_URL'])
# @client.debug = true
end

def test_init
Expand All @@ -37,6 +37,21 @@ def test_get_all
assert records.all? {|r| r.class.to_s == 'NetSuite::SOAP::Currency'}
end

def test_get_select_value
values = @client.get_select_value('RecordType::SupportCase', 'origin')
assert values.count > 0
assert values.find {|value| value.name == "Web"}
end

def test_add
support_case = SupportCase.new
support_case.title = 'title'
support_case.incomingMessage = 'description'
support_case.email = 'test@example.com'
res = @client.add(support_case)
assert res.success?
end

# inventory item tests are currently disabled
# FIXME: 2011_2 requires cogs and asset accounts
# def test_add_inventory_item
Expand Down

0 comments on commit a684ac3

Please sign in to comment.