Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication with role and GetSelectValue #1

Merged
merged 4 commits into from
Jul 15, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/netsuite_client.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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