Class: Minfraud::Response
- Inherits:
-
Object
- Object
- Minfraud::Response
- Defined in:
- lib/minfraud/response.rb
Overview
This class wraps the raw minFraud response. Any minFraud response field is accessible on a Response instance as a snake-cased instance method. For example, if you want the ‘ip_corporateProxy` field from minFraud, you can get it with `#ip_corporate_proxy`.
Constant Summary collapse
- ERROR_CODES =
%w( INVALID_LICENSE_KEY IP_REQUIRED IP_NOT_FOUND LICENSE_REQUIRED COUNTRY_REQUIRED MAX_REQUESTS_REACHED )
- WARNING_CODES =
%w( COUNTRY_NOT_FOUND CITY_NOT_FOUND CITY_REQUIRED POSTAL_CODE_REQUIRED POSTAL_CODE_NOT_FOUND )
Instance Method Summary collapse
-
#initialize(raw) ⇒ Response
constructor
Sets attributes on self using minFraud response keys and values Raises an exception if minFraud returns an error message Does nothing (at the moment) if minFraud returns a warning message Raises an exception if minFraud responds with anything other than an HTTP success code.
Constructor Details
#initialize(raw) ⇒ Response
Sets attributes on self using minFraud response keys and values Raises an exception if minFraud returns an error message Does nothing (at the moment) if minFraud returns a warning message Raises an exception if minFraud responds with anything other than an HTTP success code
16 17 18 19 20 |
# File 'lib/minfraud/response.rb', line 16 def initialize(raw) raise ResponseError, "The minFraud service responded with http error #{raw.class}" unless raw.is_a? Net::HTTPSuccess decode_body(raw.body) raise ResponseError, "Error message from minFraud: #{error}" if errored? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object (private)
Allows keys in hash contained in @body to be used as methods
65 66 67 68 |
# File 'lib/minfraud/response.rb', line 65 def method_missing(meth, *args, &block) # We're not calling super because we want nil if an attribute isn't found @body[meth] end |