Class: DeltavistaCrifDvaInterface::DeltaVistaService

Inherits:
RestfulService show all
Defined in:
lib/deltavista_crif_dva_interface/delta_vista_service.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RestfulService

#check_response!, #create_http_request, #get_http_response, #post_http_request, #put_http_request, #to_url, #valid_response?

Constructor Details

#initialize(config) ⇒ DeltaVistaService

Returns a new instance of DeltaVistaService.



7
8
9
10
11
# File 'lib/deltavista_crif_dva_interface/delta_vista_service.rb', line 7

def initialize(config)
  @url = config.deltavista_service_url
  @logger = config.logger || Logger.new(STDOUT)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/deltavista_crif_dva_interface/delta_vista_service.rb', line 5

def config
  @config
end

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/deltavista_crif_dva_interface/delta_vista_service.rb', line 5

def logger
  @logger
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/deltavista_crif_dva_interface/delta_vista_service.rb', line 5

def url
  @url
end

Class Method Details

.genders(language = 'de') ⇒ Array

Returns all available genders for deltavista check.

Parameters:

  • language (String) (defaults to: 'de')

    language of gender, default de

Returns:

  • (Array)

    all available genders for deltavista check



26
27
28
29
30
31
32
33
# File 'lib/deltavista_crif_dva_interface/delta_vista_service.rb', line 26

def self.genders(language = 'de')
  I18n.load_path += Dir["#{File.dirname(__FILE__)}/../../config/*.yml"]
  I18n.backend.load_translations
  I18n.locale = language.to_sym
  [0, 1, 2].map do |key|
    [I18n.t("gender.#{key}"), key]
  end
end

Returns all available legal forms for deltavista check.

Parameters:

  • language (String) (defaults to: 'de')

    language of legal form, default de

Returns:

  • (Array)

    all available legal forms for deltavista check



15
16
17
18
19
20
21
22
# File 'lib/deltavista_crif_dva_interface/delta_vista_service.rb', line 15

def self.legal_forms(language = 'de')
  I18n.load_path += Dir["#{File.dirname(__FILE__)}/../../config/*.yml"]
  I18n.backend.load_translations
  I18n.locale = language.to_sym
  [2, 3, 4, 5, 6, 7, 8, 9, 99].map do |key|
    [I18n.t("legal_form.#{key}"), key]
  end
end

Instance Method Details

#collection_check(address, collection) ⇒ Struct

Takes an address object and sends it as XML to the DeltaVista-Interface. The XML-Response will be converted back into an address object and returned. If no address is available the method returns nil.

If the Service is not available a StandardError will be thrown.

Parameters:

  • address (Struct)

    collection of the address to scan

  • collection (Struct)

    collection to scan

Returns:

  • (Struct)

    address Record



79
80
81
82
83
84
85
86
# File 'lib/deltavista_crif_dva_interface/delta_vista_service.rb', line 79

def collection_check(address, collection)
  @parser = CollectionCheck.new @config
  request_body = @parser.to_xml(address, collection)
  headers = {'Content-Type' => 'text/xml'}
  post_http_request(url, request_body, headers) do |data|
    extract_response data
  end
end

#credit_check(address) ⇒ Struct

Takes an address object and sends it as XML to the DeltaVista-Interface. The XML-Response will be converted back into an address object and returned. If no address is available the method returns nil.

If the Service is not available a StandardError will be thrown.

Parameters:

  • address (Struct)

    collection of the address to verify

Returns:

  • (Struct)

    address Record and score decision



42
43
44
45
46
47
48
49
# File 'lib/deltavista_crif_dva_interface/delta_vista_service.rb', line 42

def credit_check(address)
  @parser = CreditCheckShortV02.new @config
  request_body = @parser.to_xml(address)
  headers = {'Content-Type' => 'text/xml'}
  post_http_request(url, request_body, headers) do |data|
    extract_response data
  end
end

#extract_response(xml_body) ⇒ Struct

Returns XML Body converted to hash.

Parameters:

  • xml_body (String)

    XML Body to parse

Returns:

  • (Struct)

    XML Body converted to hash



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

def extract_response(xml_body)
  @parser.to_hash(xml_body)
end

#verify_address(address) ⇒ Struct

Takes an address object and sends it as XML to the DeltaVista-Interface. The XML-Response will be converted back into an address object and returned. If no address is available the method returns nil.

If the Service is not available a StandardError will be thrown.

Parameters:

  • address (Struct)

    collection of the address to scan

Returns:

  • (Struct)

    address Record



59
60
61
62
63
64
65
66
67
68
# File 'lib/deltavista_crif_dva_interface/delta_vista_service.rb', line 59

def verify_address(address)
  @parser = AddressUpdate.new @config
  request_body = @parser.to_xml(address)
  logger.debug request_body.inspect
  headers = {'Content-Type' => 'text/xml'}
  post_http_request(url, request_body, headers) do |data|
    logger.debug data.inspect
    extract_response data
  end
end