Class: DeltavistaCrifDvaInterface::SoapConverter

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

Direct Known Subclasses

CollectionCheck

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  @options = options
  @logger = options.logger ? options.logger : Logger.new(STDOUT)
  @envelope = {
      :attributes! => Hash.new
  }
  @attributes = Hash.new
  @client = Savon.client(
      :wsdl => options.wsdl,
      :endpoint => options.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 = options.action
  @response = options.response
  insert_control
  insert_identity
end

Instance Attribute Details

#actionObject (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

#attributesObject (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

#clientObject (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

#envelopeObject (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

#loggerObject (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

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 6

def options
  @options
end

#responseObject (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

#resultObject (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

#commitObject



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[options.response]
    result[:success] = true
  rescue StandardError => e
    logger.error e.message
    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_controlObject



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_identityObject



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 => options.user_name,
      :password => options.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