class AlfaInsurance::BaseClient
Constants
- SANDBOX_WSDL
Attributes
log[RW]
log_level[RW]
logger[RW]
operator[RW]
product_code[RW]
timeout[RW]
wsdl[RW]
Public Class Methods
new(debug: false, wsdl: SANDBOX_WSDL, operator:, product_code:, timeout: 5, logger: nil)
click to toggle source
# File lib/alfa_insurance/base_client.rb, line 7 def initialize(debug: false, wsdl: SANDBOX_WSDL, operator:, product_code:, timeout: 5, logger: nil) if debug @log_level = :debug @log = true else @log = false end @wsdl = wsdl @operator = operator @product_code = product_code @timeout = timeout @logger = logger end
Public Instance Methods
calculate(*)
click to toggle source
# File lib/alfa_insurance/base_client.rb, line 35 def calculate(*) raise NotImplementedError end
cancel(insurance_id)
click to toggle source
# File lib/alfa_insurance/base_client.rb, line 51 def cancel(insurance_id) response = send_soap_request(:cancel_policy) do |xml| xml.operator { xml.code(operator) } xml.policyId(insurance_id) end Response.new(response) end
confirm(insurance_id)
click to toggle source
# File lib/alfa_insurance/base_client.rb, line 43 def confirm(insurance_id) response = send_soap_request(:confirm_policy) do |xml| xml.operator { xml.code(operator) } xml.policyId(insurance_id) end ConfirmResponse.new(response) end
create(*)
click to toggle source
# File lib/alfa_insurance/base_client.rb, line 39 def create(*) raise NotImplementedError end
find(insurance_id)
click to toggle source
# File lib/alfa_insurance/base_client.rb, line 59 def find(insurance_id) response = send_soap_request(:get_policy) do |xml| xml.operator { xml.code(operator) } xml.policyId(insurance_id) end FindResponse.new(response) end
get_available_products()
click to toggle source
# File lib/alfa_insurance/base_client.rb, line 22 def get_available_products send_soap_request(:get_available_products) do |xml| xml.operator { xml.code(operator) } end.body end
get_policy_parameters(product_code)
click to toggle source
# File lib/alfa_insurance/base_client.rb, line 28 def get_policy_parameters(product_code) send_soap_request(:get_policy_parameters) do |xml| xml.operator { xml.code(operator) } xml.product { xml.code(product_code) } end.body end
Private Instance Methods
action_namespace(action)
click to toggle source
# File lib/alfa_insurance/base_client.rb, line 91 def action_namespace(action) soap_client.wsdl.operations[action][:namespace_identifier] end
apply_namespace(xml_builder, action)
click to toggle source
# File lib/alfa_insurance/base_client.rb, line 95 def apply_namespace(xml_builder, action) namespace = action_namespace(action) xml_text = xml_builder.doc.root.inner_html xml_text.gsub!('</', "</#{namespace}:") xml_text.gsub!(%r{<(?!/)}, "<#{namespace}:") xml_text end
send_soap_request(action_name) { |xml| ... }
click to toggle source
# File lib/alfa_insurance/base_client.rb, line 69 def send_soap_request(action_name) message = Nokogiri::XML::Builder.new do |xml| xml.root { yield(xml) } end payload = apply_namespace(message, action_name) soap_client.call(action_name, message: payload) end
soap_client()
click to toggle source
# File lib/alfa_insurance/base_client.rb, line 79 def soap_client @client ||= Savon.client( wsdl: wsdl, log_level: log_level, log: log, logger: logger, pretty_print_xml: log, open_timeout: timeout, read_timeout: timeout ) end