Class: VeratadClient

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

Constant Summary collapse

STANDARD_URL =
'https://idresponse.com:6650/gateway.php'
OFAC_URL =
'https://ofac.idresponse.com:6650/gateway.php'
OUTPUT_TYPE =
'4.3b'
@@url =
'https://idresponse.com:6650/gateway.php'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username = '', password = '', info = {}) ⇒ VeratadClient



18
19
20
21
22
23
# File 'lib/veratad.rb', line 18

def initialize(username='', password='', info={})
  @username = username
  @password = password
  @function = 'age'
  self.populate(info) if info
end

Instance Attribute Details

#billing_addressObject

Returns the value of attribute billing_address.



7
8
9
# File 'lib/veratad.rb', line 7

def billing_address
  @billing_address
end

#billing_cityObject

Returns the value of attribute billing_city.



7
8
9
# File 'lib/veratad.rb', line 7

def billing_city
  @billing_city
end

#billing_stateObject

Returns the value of attribute billing_state.



7
8
9
# File 'lib/veratad.rb', line 7

def billing_state
  @billing_state
end

#billing_zipObject

Returns the value of attribute billing_zip.



7
8
9
# File 'lib/veratad.rb', line 7

def billing_zip
  @billing_zip
end

#dobObject

Returns the value of attribute dob.



7
8
9
# File 'lib/veratad.rb', line 7

def dob
  @dob
end

#first_nameObject

Returns the value of attribute first_name.



7
8
9
# File 'lib/veratad.rb', line 7

def first_name
  @first_name
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/veratad.rb', line 7

def id
  @id
end

#last4Object

Returns the value of attribute last4.



7
8
9
# File 'lib/veratad.rb', line 7

def last4
  @last4
end

#last_nameObject

Returns the value of attribute last_name.



7
8
9
# File 'lib/veratad.rb', line 7

def last_name
  @last_name
end

#messageObject (readonly)

Returns the value of attribute message.



10
11
12
# File 'lib/veratad.rb', line 10

def message
  @message
end

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'lib/veratad.rb', line 7

def password
  @password
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



10
11
12
# File 'lib/veratad.rb', line 10

def raw_response
  @raw_response
end

#responseObject (readonly)

Returns the value of attribute response.



10
11
12
# File 'lib/veratad.rb', line 10

def response
  @response
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/veratad.rb', line 10

def status
  @status
end

#usernameObject

Returns the value of attribute username.



7
8
9
# File 'lib/veratad.rb', line 7

def username
  @username
end

Class Method Details

.ofac?Boolean



93
94
95
# File 'lib/veratad.rb', line 93

def self.ofac?
  @@url == OFAC_URL
end

.standard?Boolean



97
98
99
# File 'lib/veratad.rb', line 97

def self.standard?
  @@url == STANDARD_URL
end

.use_ofac!Object



101
102
103
# File 'lib/veratad.rb', line 101

def self.use_ofac!
  @@url = OFAC_URL
end

.use_standard!Object



105
106
107
# File 'lib/veratad.rb', line 105

def self.use_standard!
  @@url = STANDARD_URL
end

Instance Method Details

#address_query(query, type) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/veratad.rb', line 43

def address_query(query, type)
  if self.send("#{type}ing_address".to_sym)
    query.tag! type do |t|
        t.addr self.send("#{type}ing_address".to_sym)
        t.city self.send("#{type}ing_city".to_sym)
        t.state self.send("#{type}ing_state".to_sym)
        t.zip self.send("#{type}ing_zip".to_sym)
    end
  end
end

#dob_query(query) ⇒ Object



54
55
56
57
58
59
# File 'lib/veratad.rb', line 54

def dob_query(query)
  if @dob
    query.dob format('%0.4d%0.2d%0.2d', @dob.year, @dob.month, @dob.day)
    query.tag! 'dob-type', 'YYYYMMDD'
  end
end

#httpObject



85
86
87
# File 'lib/veratad.rb', line 85

def http
  Net::HTTP.start(self.url.host, self.url.port, :use_ssl => true)
end

#last4_query(query) ⇒ Object



61
62
63
# File 'lib/veratad.rb', line 61

def last4_query(query)
  query.last4 @last4 if @last4
end

#populate(info) ⇒ Object



65
66
67
# File 'lib/veratad.rb', line 65

def populate(info)
  info.keys.each { |k| self.send("#{k.to_s}=".to_sym, info[k]) }
end

#queryObject



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

def query
  builder = Builder::XmlMarkup.new
  builder.query do |q|
    q.user @username
    q.pass @password
    q.function @function
    q.tag! 'output-type', "#{VeratadClient::OUTPUT_TYPE}"
    q.tag! 'client-side' do |cs|
      cs.id @id
    end
    q.fn @first_name
    q.ln @last_name
    self.address_query(q, 'bill')
    self.dob_query(q)
    self.last4_query(q)
  end
end

#query_stringObject



81
82
83
# File 'lib/veratad.rb', line 81

def query_string
  "query=#{URI.escape(self.query)}"
end

#run_verificationObject



77
78
79
# File 'lib/veratad.rb', line 77

def run_verification
  @raw_response = self.http.request_post(url.path, self.query_string)
end

#urlObject



89
90
91
# File 'lib/veratad.rb', line 89

def url
  URI.parse(@@url)
end

#verify!Object



69
70
71
72
73
74
75
# File 'lib/veratad.rb', line 69

def verify!
  @response = REXML::Document.new(self.run_verification.body).root.elements
  @status = @response['status'].text.to_i
  @message = @response['message'].text

  @status === 0
end