class ApiBanking::SoapClient

Public Class Methods

do_remote_call(env, callbacks = nil, soapAction = nil, &block) click to toggle source
# File lib/api_banking/soap/soap_client.rb, line 9
def self.do_remote_call(env, callbacks = nil, soapAction = nil, &block)
  data = construct_envelope(&block)
  options = {}
  options[:method] = :post
  options[:body] = data.to_xml

  # add soap11/12 specific headers
  add_soap_headers(options, soapAction)

  # TODO: configuration removed for thread-safety, the assumption that one app at one time will connect to one environment
  # isn't valid anymore (starkit)
  # options[:proxy] = self.configuration.proxy
  # options[:timeout] = self.configuration.timeout

  set_options_for_environment(env, options)

  options[:headers]['User-Agent'] = "Quantiguous; API Banking, Ruby Gem #{ApiBanking::VERSION}"

  request = Typhoeus::Request.new(env.endpoints[self.name.split('::').last.to_sym], options)

  callbacks.before_send.call(request) if (callbacks && callbacks.before_send.respond_to?(:call))
  response = request.run
  callbacks.on_complete.call(request.response) if (callbacks && callbacks.on_complete.respond_to?(:call))

  Thread.current[:last_response] = response

  parse_response(response)
end
last_response() click to toggle source
# File lib/api_banking/soap/soap_client.rb, line 5
def self.last_response
  Thread.current[:last_response]
end

Private Class Methods

content_at(node) click to toggle source
# File lib/api_banking/soap/soap_client.rb, line 98
def self.content_at(node)
  node.content unless node.nil?
end
parse_dp_reply(reply) click to toggle source
# File lib/api_banking/soap/soap_client.rb, line 92
def self.parse_dp_reply(reply)
  code = content_at(reply.at_xpath('/errorResponse/httpCode'))
  reasonText = content_at(reply.at_xpath('/errorResponse/moreInformation'))
  return Fault.new(code, "", reasonText)
end
parse_response(response) click to toggle source
# File lib/api_banking/soap/soap_client.rb, line 65
def self.parse_response(response)
  if response.success?
    if response.headers['Content-Type'] =~ /xml/ then
       return Nokogiri::XML(response.response_body)
    end
  elsif response.timed_out?
    return Fault.new("502", "", "#{response.return_message}")
  elsif response.code == 0
    return Fault.new(response.code, "", response.return_message)
  else
    # http status indicating error, is either a datapower failure or a soap fault
    if response.headers['Content-Type'] =~ /xml/ then
       reply = Nokogiri::XML(response.response_body)

       # datapower failures return an xml
       unless reply.at_xpath('//errorResponse').nil? then
         return parse_dp_reply(reply)
       end

       # has to be a soapfault
       return parse_fault(reply)

    end
    return Fault.new("#{response.code.to_s}", "", response.status_message)
  end
end
set_options_for_environment(env, options) click to toggle source
# File lib/api_banking/soap/soap_client.rb, line 41
def self.set_options_for_environment(env, options)
  if env.kind_of?ApiBanking::Environment::YBL::PRD
    options[:username] = env.user
    options[:password] = env.password
    options[:headers]["X-IBM-Client-Id"] = env.client_id
    options[:headers]["X-IBM-Client-Secret"] = env.client_secret
    options[:cainfo] = env.ssl_ca_file
    options[:sslkey] = env.ssl_client_key
    options[:keypasswd] = env.ssl_client_key_pass
    options[:sslcert] = env.ssl_client_cert
    options[:ssl_verifypeer] = true
  elsif env.kind_of?ApiBanking::Environment::YBL::UAT
    options[:username] = env.user
    options[:password] = env.password
    options[:headers]["X-IBM-Client-Id"] = env.client_id
    options[:headers]["X-IBM-Client-Secret"] = env.client_secret
  elsif env.kind_of?ApiBanking::Environment::QG::DEMO
    options[:username] = env.user
    options[:password] = env.password
  end
end