Class: DeltavistaCrifDvaInterface::SoapConverter
- Inherits:
-
Object
- Object
- DeltavistaCrifDvaInterface::SoapConverter
- Defined in:
- lib/deltavista_crif_dva_interface/soap_converter.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#envelope ⇒ Object
readonly
Returns the value of attribute envelope.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #additional_input(key, value) ⇒ Object
- #commit ⇒ Object
-
#convert_country(alpha3_code) ⇒ Object
Converts alpha-3 country code into alpha-2 country code.
- #format_date(date) ⇒ Object
-
#initialize(options) ⇒ SoapConverter
constructor
A new instance of SoapConverter.
- #insert_company_address(address) ⇒ Object
- #insert_control ⇒ Object
- #insert_identity ⇒ Object
- #insert_private_address(address) ⇒ Object
- #insert_reference_number(reference_number) ⇒ Object
- #map_attribute(hash, *path) ⇒ Object
- #parse_location(address) ⇒ Object
Constructor Details
#initialize(options) ⇒ SoapConverter
Returns a new instance of SoapConverter.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 8 def initialize() = @logger = .logger ? .logger : Logger.new(STDOUT) @envelope = { :attributes! => Hash.new } @attributes = Hash.new @client = Savon.client( :wsdl => .wsdl, :endpoint => .endpoint, :soap_version => 2, :env_namespace => 'soapenv', :pretty_print_xml => true, :namespace_identifier => 'ns1', :element_form_default => :qualified, :logger => logger ) @result = { :committed => false, :success => false, :response => nil, :data => Hash.new } @action = .action @response = .response insert_control insert_identity end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
6 7 8 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 6 def action @action end |
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 6 def attributes @attributes end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 6 def client @client end |
#envelope ⇒ Object (readonly)
Returns the value of attribute envelope.
6 7 8 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 6 def envelope @envelope end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 6 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 6 def end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
6 7 8 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 6 def response @response end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
6 7 8 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 6 def result @result end |
Instance Method Details
#additional_input(key, value) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 91 def additional_input(key, value) envelope[:additional_input] = Array.new unless envelope[:additional_input] envelope[:additional_input] << { :key => key, :value => value } end |
#commit ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 37 def commit begin result[:response] = @client.call(action, :message => envelope, :attributes => attributes) result[:data] = result[:response].body[.response] result[:success] = true rescue StandardError => e logger.error e. logger.error e.backtrace.join('\n') if e.backtrace raise e end end |
#convert_country(alpha3_code) ⇒ Object
Converts alpha-3 country code into alpha-2 country code
100 101 102 103 104 105 106 107 108 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 100 def convert_country(alpha3_code) alpha2_code = '' begin alpha2_code = SunDawg::CountryIsoTranslater.translate_standard(alpha3_code, "alpha3", "alpha2") rescue SunDawg::CountryIsoTranslater::NoCountryError ensure alpha2_code end end |
#format_date(date) ⇒ Object
110 111 112 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 110 def format_date(date) date.respond_to?(:strftime) ? date.strftime('%Y-%m-%d') : nil end |
#insert_company_address(address) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 81 def insert_company_address(address) envelope[:searched_address] = { :location => parse_location(address), :company_name => address[:company_name] } map_attribute({ 'xsi:type' => 'ns1:CompanyAddressDescription' }, :searched_address) end |
#insert_control ⇒ Object
60 61 62 63 64 65 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 60 def insert_control envelope[:control] = { :major_version => major_version, :minor_version => minor_version } end |
#insert_identity ⇒ Object
53 54 55 56 57 58 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 53 def insert_identity envelope[:identity_descriptor] = { :user_name => .user_name, :password => .password } end |
#insert_private_address(address) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 67 def insert_private_address(address) envelope[:searched_address] = { :location => parse_location(address), :first_name => address[:first_name], :last_name => address[:last_name], :maiden_name => address[:maiden_name], :sex => address[:sex], :birth_date => format_date(address[:birth_date]) } map_attribute({ 'xsi:type' => 'ns1:PersonAddressDescription' }, :searched_address) end |
#insert_reference_number(reference_number) ⇒ Object
49 50 51 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 49 def insert_reference_number(reference_number) envelope[:reference_number] = reference_number end |
#map_attribute(hash, *path) ⇒ Object
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 124 def map_attribute(hash, *path) target = envelope last_child = path.slice!(-1) path.each do |children| target[children] = Hash.new unless target[children] target = target[children] end target[:attributes!] = Hash.new unless target[:attributes!] target[:attributes!][last_child] = hash end |
#parse_location(address) ⇒ Object
114 115 116 117 118 119 120 121 122 |
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 114 def parse_location(address) { :street => address[:street], :house_number => address[:house_number], :zip => address[:zip], :city => address[:city], :country => address[:country] } end |