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_description ⇒ Object
readonly
Returns the value of attribute api_error_description.
-
#api_error_issues ⇒ Object
readonly
Returns the value of attribute api_error_issues.
-
#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.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sift/client.rb', line 31 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 begin @body = MultiJson.load(http_response) unless http_response.nil? rescue if @http_status_code == 200 raise TypeError.new end end if not @body.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"] if @body["error"] @api_error_message = @body["error"] @api_error_description = @body["description"] @api_error_issues = @body["issues"] || {} end end end end |
Instance Attribute Details
#api_error_description ⇒ Object (readonly)
Returns the value of attribute api_error_description.
13 14 15 |
# File 'lib/sift/client.rb', line 13 def api_error_description @api_error_description end |
#api_error_issues ⇒ Object (readonly)
Returns the value of attribute api_error_issues.
13 14 15 |
# File 'lib/sift/client.rb', line 13 def api_error_issues @api_error_issues end |
#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.
13 14 15 |
# File 'lib/sift/client.rb', line 13 def api_status @api_status end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
13 14 15 |
# File 'lib/sift/client.rb', line 13 def body @body end |
#http_class ⇒ Object (readonly)
Returns the value of attribute http_class.
13 14 15 |
# File 'lib/sift/client.rb', line 13 def http_class @http_class end |
#http_status_code ⇒ Object (readonly)
Returns the value of attribute http_status_code.
13 14 15 |
# File 'lib/sift/client.rb', line 13 def http_status_code @http_status_code end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
13 14 15 |
# File 'lib/sift/client.rb', line 13 def request @request end |
Instance Method Details
#json ⇒ Object
DEPRECATED Getter method for deprecated ‘json’ member variable.
80 81 82 |
# File 'lib/sift/client.rb', line 80 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
67 68 69 70 71 72 73 74 75 |
# File 'lib/sift/client.rb', line 67 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.
86 87 88 |
# File 'lib/sift/client.rb', line 86 def original_request @request end |