Class: SalesforceAdapter::SoapWrapper
- Inherits:
-
Object
- Object
- SalesforceAdapter::SoapWrapper
- Defined in:
- lib/dm-salesforce-adapter/soap_wrapper.rb
Defined Under Namespace
Classes: ClassesFailedToGenerate
Instance Attribute Summary collapse
-
#api_dir ⇒ Object
readonly
Returns the value of attribute api_dir.
-
#driver_name ⇒ Object
readonly
Returns the value of attribute driver_name.
-
#module_name ⇒ Object
readonly
Returns the value of attribute module_name.
-
#wsdl_path ⇒ Object
readonly
Returns the value of attribute wsdl_path.
Instance Method Summary collapse
- #driver ⇒ Object
- #files_exist? ⇒ Boolean
-
#generate_files ⇒ Object
Good candidate for shipping out into a Rakefile.
-
#generate_soap_classes ⇒ Object
# Attempt at a run-time equivalent.
-
#initialize(module_name, driver_name, wsdl_path, api_dir) ⇒ SoapWrapper
constructor
A new instance of SoapWrapper.
- #wsdl_api_dir ⇒ Object
Constructor Details
#initialize(module_name, driver_name, wsdl_path, api_dir) ⇒ SoapWrapper
Returns a new instance of SoapWrapper.
7 8 9 10 11 |
# File 'lib/dm-salesforce-adapter/soap_wrapper.rb', line 7 def initialize(module_name, driver_name, wsdl_path, api_dir) @module_name, @driver_name, @wsdl_path, @api_dir = module_name, driver_name, File.(wsdl_path), File.(api_dir) generate_soap_classes driver end |
Instance Attribute Details
#api_dir ⇒ Object (readonly)
Returns the value of attribute api_dir.
5 6 7 |
# File 'lib/dm-salesforce-adapter/soap_wrapper.rb', line 5 def api_dir @api_dir end |
#driver_name ⇒ Object (readonly)
Returns the value of attribute driver_name.
5 6 7 |
# File 'lib/dm-salesforce-adapter/soap_wrapper.rb', line 5 def driver_name @driver_name end |
#module_name ⇒ Object (readonly)
Returns the value of attribute module_name.
5 6 7 |
# File 'lib/dm-salesforce-adapter/soap_wrapper.rb', line 5 def module_name @module_name end |
#wsdl_path ⇒ Object (readonly)
Returns the value of attribute wsdl_path.
5 6 7 |
# File 'lib/dm-salesforce-adapter/soap_wrapper.rb', line 5 def wsdl_path @wsdl_path end |
Instance Method Details
#driver ⇒ Object
13 14 15 |
# File 'lib/dm-salesforce-adapter/soap_wrapper.rb', line 13 def driver @driver ||= Object.const_get(module_name).const_get(driver_name).new end |
#files_exist? ⇒ Boolean
71 72 73 74 75 |
# File 'lib/dm-salesforce-adapter/soap_wrapper.rb', line 71 def files_exist? ["#{module_name}.rb", "#{module_name}MappingRegistry.rb", "#{module_name}Driver.rb"].all? do |name| File.exist?("#{wsdl_api_dir}/#{name}") end end |
#generate_files ⇒ Object
Good candidate for shipping out into a Rakefile.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dm-salesforce-adapter/soap_wrapper.rb', line 50 def generate_files require 'wsdl/soap/wsdl2ruby' wsdl2ruby = WSDL::SOAP::WSDL2Ruby.new wsdl2ruby.logger = $LOG if $LOG wsdl2ruby.location = wsdl_path wsdl2ruby.basedir = wsdl_api_dir wsdl2ruby.opt.merge!({ 'classdef' => module_name, 'module_path' => module_name, 'mapping_registry' => nil, 'driver' => nil, 'client_skelton' => nil, }) wsdl2ruby.run raise ClassesFailedToGenerate unless files_exist? end |
#generate_soap_classes ⇒ Object
# Attempt at a run-time equivalent. Works except for the API responses are
# in SOAP objects, not native ruby objects. Haven't figured that one out..
def driver
return @driver if @driver
require 'wsdl/soap/wsdl2ruby'
factory = SOAP::WSDLDriverFactory.new(wsdl_path)
class_name_creator = WSDL::SOAP::ClassNameCreator.new
eval(WSDL::SOAP::ClassDefCreator.new(factory.wsdl, class_name_creator, @module_name).dump, TOPLEVEL_BINDING)
eval(WSDL::SOAP::MappingRegistryCreator.new(factory.wsdl, class_name_creator, @module_name).dump, TOPLEVEL_BINDING)
@driver ||= factory.create_rpc_driver
end
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dm-salesforce-adapter/soap_wrapper.rb', line 35 def generate_soap_classes unless File.file?(wsdl_path) raise Errno::ENOENT, "Could not find the WSDL at #{wsdl_path}" end FileUtils.mkdir_p(wsdl_api_dir) generate_files unless files_exist? $:.push wsdl_api_dir require "#{module_name}Driver" $:.delete wsdl_api_dir end |
#wsdl_api_dir ⇒ Object
77 78 79 |
# File 'lib/dm-salesforce-adapter/soap_wrapper.rb', line 77 def wsdl_api_dir "#{api_dir}/#{File.basename(wsdl_path)}" end |