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
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 8

def initialize(options)
  @options = options
  @envelope = Hash.new
  @client = Savon.client(
      :wsdl => options.wsdl,
      :endpoint => options.endpoint,
      :soap_version => 2,
      :env_namespace => 'soapenv'
  )
  @result = {
      :committed => false,
      :success => false,
      :data => Hash.new
  }
  @action = options.action
  @logger = options.logger ? options.logger : Logger.new(STDOUT)
  insert_control
  insert_identity
  insert_reference_number
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

#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

#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



84
85
86
87
88
89
90
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 84

def additional_input(key, value)
  envelope[:additional_inputs] = Array.new unless envelope[:additional_inputs]
  envelope[:additional_inputs] << {
      :key => key,
      :value => value
  }
end

#commitObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 29

def commit
  # begin
    result[:data] = @client.call(action, :message => envelope)
    result[:success] = true
  #rescue
  #  result[:data] = Hash.new
  #  result[:success] = false
  #ensure
    result[:committed] = true
  #end
  result
end

#convert_country(alpha3_code) ⇒ Object

Converts alpha-3 country code into alpha-2 country code



93
94
95
96
97
98
99
100
101
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 93

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



103
104
105
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 103

def format_date(date)
  (date.is_a? Date) ? date.strftime('%Y-%m-%d') : nil
end

#insert_company_address(address) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 74

def insert_company_address(address)
  envelope[:searched_address] = {
      :company_name => address[:company_name],
      :location => parse_location(address),
      :attributes! => {
          'xsi:type' => 'CompanyAddressDescription'
      }
  }
end

#insert_controlObject



53
54
55
56
57
58
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 53

def insert_control
  envelope[:control] = {
      :major_version => 1,
      :minor_version => 0
  }
end

#insert_identityObject



46
47
48
49
50
51
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 46

def insert_identity
  envelope[:identity_descriptor] = {
      :user_name => options.user_name,
      :password => options.password
  }
end

#insert_private_address(address) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 60

def insert_private_address(address)
  envelope[:searched_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]),
      :location => parse_location(address),
      :attributes! => {
          'xsi:type' => 'PersonAddressDescription'
      }
  }
end

#insert_reference_numberObject



42
43
44
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 42

def insert_reference_number
  envelope[:reference_number] = rand(3000)
end

#parse_location(address) ⇒ Object



107
108
109
110
111
112
113
114
115
# File 'lib/deltavista_crif_dva_interface/soap_converter.rb', line 107

def parse_location(address)
  {
      :street => address[:street],
      :house_number => address[:house_number],
      :zip => address[:zip],
      :city => address[:city],
      :country => address[:country]
  }
end