Class: Kount::Response
- Inherits:
-
Object
- Object
- Kount::Response
- Defined in:
- lib/kount/response.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
Instance Method Summary collapse
- #count ⇒ Object
- #errors ⇒ Object
-
#initialize(service_type, response = nil) ⇒ Response
constructor
A new instance of Response.
- #is_risk_error? ⇒ Boolean
- #result ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(service_type, response = nil) ⇒ Response
Returns a new instance of Response.
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
#attributes ⇒ Object
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/kount/response.rb', line 3 def attributes @attributes end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
4 5 6 |
# File 'lib/kount/response.rb', line 4 def body @body end |
Instance Method Details
#count ⇒ Object
23 24 25 |
# File 'lib/kount/response.rb', line 23 def count @body['count'] end |
#errors ⇒ Object
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 |
#result ⇒ Object
19 20 21 |
# File 'lib/kount/response.rb', line 19 def result @body['result'] end |
#status ⇒ Object
31 32 33 |
# File 'lib/kount/response.rb', line 31 def status @body['status'] end |