Class: Sift::Response
- Inherits:
-
Object
- Object
- Sift::Response
- Defined in:
- lib/sift/client.rb
Overview
Represents the payload returned from a call through the track API
Instance Attribute Summary collapse
-
#api_error_message ⇒ Object
readonly
Returns the value of attribute api_error_message.
-
#api_status ⇒ Object
readonly
Returns the value of attribute api_status.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#http_class ⇒ Object
readonly
Returns the value of attribute http_class.
-
#http_status_code ⇒ Object
readonly
Returns the value of attribute http_status_code.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
-
#initialize(http_response, http_response_code, http_raw_response) ⇒ Response
constructor
Constructor.
-
#json ⇒ Object
DEPRECATED Getter method for deprecated ‘json’ member variable.
-
#ok? ⇒ Boolean
Helper method returns true if and only if the response from the API call was successful.
-
#original_request ⇒ Object
DEPRECATED Getter method for deprecated ‘original_request’ member variable.
Constructor Details
#initialize(http_response, http_response_code, http_raw_response) ⇒ Response
Constructor
Parameters:
- http_response
-
The HTTP body text returned from the API call. The body is expected to be a JSON object that can be decoded into status, message and request sections.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sift/client.rb', line 25 def initialize(http_response, http_response_code, http_raw_response) @http_status_code = http_response_code @http_raw_response = http_raw_response # only set these variables if a message-body is expected. if not @http_raw_response.kind_of? Net::HTTPNoContent @body = MultiJson.load(http_response) unless http_response.nil? @request = MultiJson.load(@body["request"].to_s) if @body["request"] @api_status = @body["status"].to_i if @body["status"] @api_error_message = @body["error_message"].to_s if @body["error_message"] end end |
Instance Attribute Details
#api_error_message ⇒ Object (readonly)
Returns the value of attribute api_error_message.
13 14 15 |
# File 'lib/sift/client.rb', line 13 def @api_error_message end |
#api_status ⇒ Object (readonly)
Returns the value of attribute api_status.
12 13 14 |
# File 'lib/sift/client.rb', line 12 def api_status @api_status end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
9 10 11 |
# File 'lib/sift/client.rb', line 9 def body @body end |
#http_class ⇒ Object (readonly)
Returns the value of attribute http_class.
10 11 12 |
# File 'lib/sift/client.rb', line 10 def http_class @http_class end |
#http_status_code ⇒ Object (readonly)
Returns the value of attribute http_status_code.
11 12 13 |
# File 'lib/sift/client.rb', line 11 def http_status_code @http_status_code end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
14 15 16 |
# File 'lib/sift/client.rb', line 14 def request @request end |
Instance Method Details
#json ⇒ Object
DEPRECATED Getter method for deprecated ‘json’ member variable.
58 59 60 |
# File 'lib/sift/client.rb', line 58 def json @body end |
#ok? ⇒ Boolean
Helper method returns true if and only if the response from the API call was successful
Returns:
true on success; false otherwise
45 46 47 48 49 50 51 52 53 |
# File 'lib/sift/client.rb', line 45 def ok? if @http_raw_response.kind_of? Net::HTTPNoContent #if there is no content expected, use HTTP code 204 == @http_status_code else # otherwise use API status @http_raw_response.kind_of? Net::HTTPOK and 0 == @api_status.to_i end end |
#original_request ⇒ Object
DEPRECATED Getter method for deprecated ‘original_request’ member variable.
64 65 66 |
# File 'lib/sift/client.rb', line 64 def original_request @request end |