Class: Zooz::Response
- Inherits:
-
Object
- Object
- Zooz::Response
- Defined in:
- lib/zooz/response.rb,
lib/zooz/response/open.rb,
lib/zooz/response/verify.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#http_response ⇒ Object
Returns the value of attribute http_response.
-
#request ⇒ Object
Returns the value of attribute request.
Instance Method Summary collapse
-
#error_message ⇒ Object
Get the ZooZ error message, returned when status_code is not 0.
-
#get_parsed_singular(offset) ⇒ Object
Gets a singular offset from the response data, useful because CGI returns single parameters embedded in an array.
-
#initialize ⇒ Response
constructor
A new instance of Response.
-
#parsed_response ⇒ Object
Get a parsed response as an object from the response text.
-
#status_code ⇒ Object
Get the ZooZ status code, 0 for success.
-
#success? ⇒ Boolean
Whether the request was successful, populates the @errors array on error.
Constructor Details
#initialize ⇒ Response
Returns a new instance of Response.
14 15 16 |
# File 'lib/zooz/response.rb', line 14 def initialize @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
9 10 11 |
# File 'lib/zooz/response.rb', line 9 def errors @errors end |
#http_response ⇒ Object
Returns the value of attribute http_response.
8 9 10 |
# File 'lib/zooz/response.rb', line 8 def http_response @http_response end |
#request ⇒ Object
Returns the value of attribute request.
8 9 10 |
# File 'lib/zooz/response.rb', line 8 def request @request end |
Instance Method Details
#error_message ⇒ Object
Get the ZooZ error message, returned when status_code is not 0.
35 36 37 |
# File 'lib/zooz/response.rb', line 35 def get_parsed_singular('errorMessage') end |
#get_parsed_singular(offset) ⇒ Object
Gets a singular offset from the response data, useful because CGI returns single parameters embedded in an array.
20 21 22 |
# File 'lib/zooz/response.rb', line 20 def get_parsed_singular(offset) (parsed_response[offset] || []).first end |
#parsed_response ⇒ Object
Get a parsed response as an object from the response text.
25 26 27 |
# File 'lib/zooz/response.rb', line 25 def parsed_response CGI::parse(http_body.strip) end |
#status_code ⇒ Object
Get the ZooZ status code, 0 for success.
30 31 32 |
# File 'lib/zooz/response.rb', line 30 def status_code get_parsed_singular('statusCode') end |
#success? ⇒ Boolean
Whether the request was successful, populates the @errors array on error.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/zooz/response.rb', line 40 def success? @errors = [] unless http_code.to_s[0,1] == '2' @errors << "HTTP status #{http_code}: #{}" end unless status_code @errors << "Unable to parse ZooZ response" end unless status_code == '0' @errors << "ZooZ error #{status_code}: #{}" end @errors.empty? end |