Class: SavonHelper::SOAPInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/savon_helper/soap_interface.rb

Direct Known Subclasses

DeepSecurity::SOAPInterface

Request Helper collapse

Instance Method Summary collapse

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, options = {})
  @client = Savon.client(options.merge({:wsdl => wsdl_url,
                                        :logger => logger,
                                        :log_level => log_level,
                                        :log => (!log_level.nil?),
                                        :ssl_verify_mode => :none}))
  @logger = logger
end

Instance Method Details

#loggerObject



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.

Parameters:

  • method_name (Symbol)

    The SOAP method to call.

  • object_class (MappingObject)

    The element class to typecast the result elements to.

  • collection_name (Symbol) (defaults to: nil)

    The name of the reply parameter.

  • arguments (Hash) (defaults to: {})

    The method arguments

Returns:

  • (Array<object_class>)

    The object filled from the response.



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

Parameters:

  • method_name (Symbol)

    The SOAP method to call.

  • object_class (MappingObject)

    The class to typecast the result to.

  • arguments (Hash) (defaults to: {})

    The method arguments

Returns:

  • (object_class)

    The object filled from the response.



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(options = {}, &block)
  opts = {:tries => 1, :on => Exception}.merge(options)

  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

Parameters:

  • method (Symbol)

    The SOAP method to call.

  • arguments (Hash) (defaults to: {})

    The method arguments

Returns:

  • (Hash)

    The result hash.



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