Nothing particularly Rails-specific about it, but this will get you started...
# netsuite_helper.rb # # This module requires the soap4r gem to run. Confirm you have it by running this from the command-line: # # gem list --local # # If you see soap4r there, you're halfway home. # # You'll need to generate the SOAP class files using the NetSuite WSDL. Look in the local dir for: # * default.rb # * defaultDriver.rb # * defaultMappingRegistry.rb # * NetSuiteServiceClient.rb # If they're there, fire away. If not, change to the local directory in your command window and run: # # wsdl2ruby.rb --wsdl https://webservices.netsuite.com/wsdl/v2_6_0/netsuite.wsdl --type client # # It will take a minute or two. Check for the files again when it completes. # # Now you should be ready to go. Run the file from the command-line to test connectivity: # # ruby netsuite_helper.rb # # Successful output looks like this: # # successful login? true # Do some stuff with #<NetSuitePortType:0x1c0eb48> here # successful logout? true # # Put whatever code you really want to run in the closure, using netsuite as your handle # module NetsuiteHelper require 'rubygems' gem 'soap4r' require 'defaultDriver' class Soap def self.wrap_in_session driver = NetSuitePortType.new driver.proxy.streamhandler.client.ssl_config.verify_mode = nil passport = Passport.new passport.email = 'your.name@your.company.com' #CHANGE THIS passport.password = 'yourPassword' # CHANGE THIS passport.account ='123456' # CHANGE THIS response = driver.login(LoginRequest.new(passport)) p "successful login? #{response.sessionResponse.status.xmlattr_isSuccess}" # driver.wiredump_dev = STDOUT # Un-comment to get verbose output yield driver driver.wiredump_dev = nil response = driver.logout(LogoutRequest.new) p "successful logout? #{response.sessionResponse.status.xmlattr_isSuccess}" end end end if __FILE__ == Nothing particularly Rails-specific about it, but this will get you started...
[CODE]
# netsuite_helper.rb
#
# This module requires the soap4r gem to run. Confirm you have it by running this from the command-line:
#
# gem list --local
#
# If you see soap4r there, you're halfway home.
#
# You'll need to generate the SOAP class files using the NetSuite WSDL. Look in the local dir for:
# * default.rb
# * defaultDriver.rb
# * defaultMappingRegistry.rb
# * NetSuiteServiceClient.rb
# If they're there, fire away. If not, change to the local directory in your command window and run:
#
# wsdl2ruby.rb --wsdl https://webservices.netsuite.com/wsdl/v2_6_0/netsuite.wsdl --type client
#
# It will take a minute or two. Check for the files again when it completes.
#
# Now you should be ready to go. Run the file from the command-line to test connectivity:
#
# ruby netsuite_helper.rb
#
# Successful output looks like this:
#
# successful login? true
# Do some stuff with #<NetSuitePortType:0x1c0eb48> here
# successful logout? true
#
# Put whatever code you really want to run in the closure, using netsuite as your handle
#
module NetsuiteHelper
require 'rubygems'
gem 'soap4r'
require 'defaultDriver'
class Soap
def self.wrap_in_session
driver = NetSuitePortType.new
driver.proxy.streamhandler.client.ssl_config.verify_mode = nil
passport = Passport.new
passport.email = 'your.name@your.company.com' #CHANGE THIS
passport.password = 'yourPassword' # CHANGE THIS
passport.account ='123456' # CHANGE THIS
response = driver.login(LoginRequest.new(passport))
p "successful login? #{response.sessionResponse.status.xmlattr_isSuccess}"
# driver.wiredump_dev = STDOUT # Un-comment to get verbose output
yield driver
driver.wiredump_dev = nil
response = driver.logout(LogoutRequest.new)
p "successful logout? #{response.sessionResponse.status.xmlattr_isSuccess}"
end
end
end
if __FILE__ == $0
NetsuiteHelper::Soap.wrap_in_session { |netsuite|
p "Do something with #{netsuite} here"
}
end
[/CODE] NetsuiteHelper::Soap.wrap_in_session { |netsuite| p "Do something with #{netsuite} here" } end