Class: DeltavistaCrifDvaInterface::CreditCheckShortV02
- Inherits:
-
XmlConverter
- Object
- XmlConverter
- DeltavistaCrifDvaInterface::CreditCheckShortV02
- Defined in:
- lib/deltavista_crif_dva_interface/credit_check_short_v02.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :encoding => 'UTF-8', :request_type => 'CreditCheckShort' }.freeze
- PRIVATE_NODE =
'private'
- PRIVATE_KEYS =
%w(title lastName firstName maidenName street house poBox zip city country phone birthDate sex)
- PRIVATE_RESPONSE_KEYS =
PRIVATE_KEYS.unshift('addressId')
- COMPANY_NODE =
'company'
- COMPANY_KEYS =
%w(legalForm name street house poBox zip city country phone)
- COMPANY_RESPONSE_KEYS =
COMPANY_KEYS.unshift('addressId')
- PAYLOAD_NODE =
'payLoad'
- PAYLOAD_RESPONSE_KEYS =
%w(personStatus score decision hasDebt decisionComment)
- @@reference_id =
unique id for each request
1000
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(options) ⇒ CreditCheckShortV02
constructor
A new instance of CreditCheckShortV02.
- #to_hash(xml_body) ⇒ Object
- #to_xml(address) ⇒ Object
Methods inherited from XmlConverter
#convert_country, #get_value, #response_code, #response_text, #to_string, #valid_response?
Constructor Details
#initialize(options) ⇒ CreditCheckShortV02
Returns a new instance of CreditCheckShortV02.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/deltavista_crif_dva_interface/credit_check_short_v02.rb', line 24 def initialize() @config = {} if .is_a? Hash @config = DEFAULT_OPTIONS.merge() @logger = [:logger] ? [:logger] : Logger.new(STDOUT) else @config[:username] = .username @config[:password] = .password @logger = .logger ? .logger : Logger.new(STDOUT) @config = DEFAULT_OPTIONS.merge(@config) end end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
3 4 5 |
# File 'lib/deltavista_crif_dva_interface/credit_check_short_v02.rb', line 3 def logger @logger end |
Instance Method Details
#to_hash(xml_body) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/deltavista_crif_dva_interface/credit_check_short_v02.rb', line 67 def to_hash(xml_body) logger.debug xml_body if logger.debug? xml_doc = Nokogiri.XML(xml_body, nil, @config[:encoding]) if valid_response? xml_doc # private tag address = {} if xml_doc.xpath("//dvaCheckResponse/#{PRIVATE_NODE}") node = PRIVATE_NODE keys = PRIVATE_RESPONSE_KEYS elsif xml_doc.xpath("//dvaCheckResponse/#{COMPANY_NODE}") node = COMPANY_NODE keys = COMPANY_RESPONSE_KEYS else logger.error 'Neither company nor private Node were found in the DVA Response' raise NotFoundError.new response_code(xml_doc), response_text(xml_doc) end xml_doc.xpath("//dvaCheckResponse/#{node}").each do |private_node| keys.each do |key| if key == 'country' address[key.downcase.to_sym] = convert_country get_value(private_node, key) else address[key.downcase.to_sym] = get_value(private_node, key) end end end xml_doc.xpath("//dvaCheckResponse/#{node}/#{PAYLOAD_NODE}").each do |payload_node| PAYLOAD_RESPONSE_KEYS.each do |key| address[key.downcase.to_sym] = get_value(payload_node, key) end end address else raise NotFoundError.new response_code(xml_doc), response_text(xml_doc) end end |
#to_xml(address) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/deltavista_crif_dva_interface/credit_check_short_v02.rb', line 37 def to_xml(address) builder = Nokogiri::XML::Builder.new(:encoding => @config[:encoding]) do |xml| xml.dvaCheckRequest { xml.identity { xml.username @config[:username] xml.password @config[:password] } xml.reference @@reference_id xml.requestType @config[:request_type] # Company Flag (to be set in the address scope) if address['is_company'] keys = COMPANY_KEYS node = COMPANY_NODE else keys = PRIVATE_KEYS node = PRIVATE_NODE end xml.__send__(node) { keys.each do |key| xml.send(key, address[key.downcase]) if address[key.downcase] && !address[key.downcase].empty? end } } end @@reference_id += 1 result = builder.to_xml logger.debug result if logger.debug? result end |