Class: Kount::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_type, response = nil) ⇒ Response

Returns a new instance of Response.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/kount/response.rb', line 6

def initialize(service_type,response = nil)
  raise ArgumentError, 'Missing response object' unless response
  begin
    if service_type == :api
      @body = JSON.parse(response.body_str)
    elsif service_type == :risk
      @body = Hash[response.body_str.split("\n").map {|l| l.split("=") }]
    end
  rescue
    raise ["Could not parse JSON response.  Raw response: ",response.body_str].join("\n")
  end
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



3
4
5
# File 'lib/kount/response.rb', line 3

def attributes
  @attributes
end

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/kount/response.rb', line 4

def body
  @body
end

Instance Method Details

#countObject



23
24
25
# File 'lib/kount/response.rb', line 23

def count
  @body['count']
end

#errorsObject



27
28
29
# File 'lib/kount/response.rb', line 27

def errors
  @body['errors']
end

#is_risk_error?Boolean



35
36
37
# File 'lib/kount/response.rb', line 35

def is_risk_error?
  @body['ERRO'].present?
end

#resultObject



19
20
21
# File 'lib/kount/response.rb', line 19

def result
  @body['result']
end

#statusObject



31
32
33
# File 'lib/kount/response.rb', line 31

def status
  @body['status']
end