Class: DeltavistaCrifDvaInterface::AddressUpdate

Inherits:
XmlConverter
  • Object
show all
Defined in:
lib/deltavista_crif_dva_interface/address_update.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :encoding => 'UTF-8',
  :request_type => 'AddressUpdate'
}.freeze
@@reference_id =

unique id for each request

1000

Instance Method Summary collapse

Methods inherited from XmlConverter

#convert_country, #get_value, #response_code, #response_text, #to_string, #valid_response?

Constructor Details

#initialize(options) ⇒ AddressUpdate

Returns a new instance of AddressUpdate.



11
12
13
14
15
16
17
18
19
20
# File 'lib/deltavista_crif_dva_interface/address_update.rb', line 11

def initialize(options)
  @config = {}
  if options.is_a? Hash
    @config = DEFAULT_OPTIONS.merge(options)
  else
    @config[:username] = options.username
    @config[:password] = options.password
    @config = DEFAULT_OPTIONS.merge(@config)
  end
end

Instance Method Details

#higher_delivery_known(xml) ⇒ Object



90
91
92
# File 'lib/deltavista_crif_dva_interface/address_update.rb', line 90

def higher_delivery_known(xml)
  get_value(xml, "//private/payLoad/higherDelivKnown")
end

#match_level(xml) ⇒ Object



86
87
88
# File 'lib/deltavista_crif_dva_interface/address_update.rb', line 86

def match_level(xml)
  get_value(xml, "//private/payLoad/matchLevel")
end

#newer_address_found?(xml) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/deltavista_crif_dva_interface/address_update.rb', line 94

def newer_address_found?(xml)
  higher_delivery_known(xml) != '0.0' ? true : false
end

#to_hash(xml_body) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/deltavista_crif_dva_interface/address_update.rb', line 43

def to_hash(xml_body)
  xml_doc = Nokogiri.XML(xml_body, nil, @config[:encoding])
  if valid_response? xml_doc
    address = {}
     = {}
    xml_doc.xpath("//dvaCheckResponse/private").each do |private_node|
      %w(addressId birthDate sex lastName firstName maidenName street house poBox zip city country phone).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/private/payLoad/highestAddress/private").each do |private_node|
      %w(lastName firstName maidenName street house poBox zip city country phone).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("//private/payLoad").each do |payload_node|
      %w(matchLevel isDeceased dateOfDeath reqDeliverabilityClass higherDelivKnown).each do |key|
        [key.downcase.to_sym] = get_value(payload_node, key)
      end
    end

    xml_doc.xpath("//private/payLoad/highestAddress").each do |highestaddress_node|
      %w(deliverabilityClass).each do |key|
        [key.downcase.to_sym] = get_value(highestaddress_node, key)
      end
    end

    [address, ]
  else
    raise NotFoundError.new response_code(xml_doc), response_text(xml_doc)
  end
end

#to_xml(address) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/deltavista_crif_dva_interface/address_update.rb', line 22

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]
      xml.private {
        %w(title lastName firstName maidenName street house poBox zip city country phone birthDate sex).each do |key|
          value = to_string(address[key.downcase])
          xml.send(key, value) if value && !value.empty?
        end
      }
    }
  end
  @@reference_id += 1
  builder.to_xml
end