Class: SavonHelper::SOAPInterface
- Defined in:
- lib/savon_helper/soap_interface.rb
Direct Known Subclasses
Request Helper collapse
-
#request_array(method_name, object_class, collection_name = nil, arguments = {}) ⇒ Array<object_class>
Helper Method deserializing the SOAP response into an array of objects.
-
#request_object(method_name, object_class, arguments = {}) ⇒ object_class
Helper Method deserializing the SOAP response into an object.
-
#send_soap(method, arguments = {}) ⇒ Hash
Send a Request to the SOAP API for method with arguments and unwrap the response.
Instance Method Summary collapse
-
#initialize(wsdl_url, logger = Logger.new(STDOUT), log_level = nil, options = {}) ⇒ SOAPInterface
constructor
A new instance of SOAPInterface.
- #logger ⇒ Object
- #retryable(options = {}, &block) ⇒ Object
Constructor Details
#initialize(wsdl_url, logger = Logger.new(STDOUT), log_level = nil, options = {}) ⇒ SOAPInterface
Returns a new instance of SOAPInterface.
7 8 9 10 11 12 13 14 |
# File 'lib/savon_helper/soap_interface.rb', line 7 def initialize(wsdl_url, logger = Logger.new(STDOUT), log_level = nil, = {}) @client = Savon.client(.merge({:wsdl => wsdl_url, :logger => logger, :log_level => log_level, :log => (!log_level.nil?), :ssl_verify_mode => :none})) @logger = logger end |
Instance Method Details
#logger ⇒ Object
16 17 18 |
# File 'lib/savon_helper/soap_interface.rb', line 16 def logger @logger end |
#request_array(method_name, object_class, collection_name = nil, arguments = {}) ⇒ Array<object_class>
Helper Method deserializing the SOAP response into an array of objects.
52 53 54 55 56 57 |
# File 'lib/savon_helper/soap_interface.rb', line 52 def request_array(method_name, object_class, collection_name = nil, arguments={}) data = send_soap(method_name, arguments) data = data[collection_name] unless collection_name.blank? ArrayMapping.to_native(ObjectMapping.new(object_class), data, self) # SavonHelper::ArrayMapping.new(SavonHelper::ObjectMapping.new(object_class)).from_savon_data(data) end |
#request_object(method_name, object_class, arguments = {}) ⇒ object_class
Helper Method deserializing the SOAP response into an object
39 40 41 42 43 44 |
# File 'lib/savon_helper/soap_interface.rb', line 39 def request_object(method_name, object_class, arguments={}) data = send_soap(method_name, arguments) # ObjectMapping.to_native(object_class, data, self) object_class.from_savon(data, self) # raise "Halt" end |
#retryable(options = {}, &block) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/savon_helper/soap_interface.rb', line 61 def retryable( = {}, &block) opts = {:tries => 1, :on => Exception}.merge() retry_exception, retries = opts[:on], opts[:tries] begin return yield rescue retry_exception retry if (retries -= 1) > 0 end yield end |
#send_soap(method, arguments = {}) ⇒ Hash
Send a Request to the SOAP API for method with arguments and unwrap the response
26 27 28 29 30 31 32 |
# File 'lib/savon_helper/soap_interface.rb', line 26 def send_soap(method, arguments = {}) logger.debug { "#{self.class}\##{__method__}(#{method.inspect}, #{arguments.inspect})" } retryable(:tries => 5, :on => Errno::ECONNRESET) do response = @client.call method, :message => arguments return response.to_hash[(method.to_s+"_response").to_sym][(method.to_s+"_return").to_sym] end end |