Class: DataMapper::Salesforce::SoapWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/dm-salesforce/soap_wrapper.rb

Defined Under Namespace

Classes: ClassesFailedToGenerate

Instance Attribute Summary collapse

Instance Method Summary collapse

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/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.expand_path(wsdl_path), File.expand_path(api_dir)
  generate_soap_classes
  driver
end

Instance Attribute Details

#api_dirObject (readonly)

Returns the value of attribute api_dir.



5
6
7
# File 'lib/dm-salesforce/soap_wrapper.rb', line 5

def api_dir
  @api_dir
end

#driver_nameObject (readonly)

Returns the value of attribute driver_name.



5
6
7
# File 'lib/dm-salesforce/soap_wrapper.rb', line 5

def driver_name
  @driver_name
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



5
6
7
# File 'lib/dm-salesforce/soap_wrapper.rb', line 5

def module_name
  @module_name
end

#wsdl_pathObject (readonly)

Returns the value of attribute wsdl_path.



5
6
7
# File 'lib/dm-salesforce/soap_wrapper.rb', line 5

def wsdl_path
  @wsdl_path
end

Instance Method Details

#driverObject



13
14
15
# File 'lib/dm-salesforce/soap_wrapper.rb', line 13

def driver
  @driver ||= Object.const_get(module_name).const_get(driver_name).new
end

#files_exist?Boolean

Returns:

  • (Boolean)


55
56
57
58
59
# File 'lib/dm-salesforce/soap_wrapper.rb', line 55

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_filesObject

Good candidate for shipping out into a Rakefile.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dm-salesforce/soap_wrapper.rb', line 34

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_classesObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dm-salesforce/soap_wrapper.rb', line 17

def generate_soap_classes
  unless File.file?(wsdl_path)
    raise Errno::ENOENT, "Could not find the WSDL at #{wsdl_path}"
  end

  unless File.directory?(wsdl_api_dir)
    FileUtils.mkdir_p wsdl_api_dir
  end

  generate_files unless files_exist?

  $:.push wsdl_api_dir
  require "#{module_name}Driver"
  $:.delete wsdl_api_dir
end

#wsdl_api_dirObject



61
62
63
# File 'lib/dm-salesforce/soap_wrapper.rb', line 61

def wsdl_api_dir
  "#{api_dir}/#{File.basename(wsdl_path)}"
end