Class: Rox::Core::Response
- Inherits:
-
Object
- Object
- Rox::Core::Response
- Defined in:
- lib/rox/core/network/response.rb
Instance Attribute Summary collapse
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#status_code ⇒ Object
Returns the value of attribute status_code.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(status_code, text, content_type = 'application/octet-stream') ⇒ Response
constructor
A new instance of Response.
- #missing_via_response_body? ⇒ Boolean
- #status_code_success? ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(status_code, text, content_type = 'application/octet-stream') ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 |
# File 'lib/rox/core/network/response.rb', line 9 def initialize(status_code, text, content_type = 'application/octet-stream') @status_code = status_code @text = text @content_type = content_type end |
Instance Attribute Details
#content_type ⇒ Object
Returns the value of attribute content_type.
7 8 9 |
# File 'lib/rox/core/network/response.rb', line 7 def content_type @content_type end |
#status_code ⇒ Object
Returns the value of attribute status_code.
7 8 9 |
# File 'lib/rox/core/network/response.rb', line 7 def status_code @status_code end |
#text ⇒ Object
Returns the value of attribute text.
7 8 9 |
# File 'lib/rox/core/network/response.rb', line 7 def text @text end |
Instance Method Details
#missing_via_response_body? ⇒ Boolean
23 24 25 26 27 28 29 |
# File 'lib/rox/core/network/response.rb', line 23 def missing_via_response_body? # api send state respons returns 200 'OK', application/json filters it @status_code == 200 && @content_type == 'application/json' && @text && [404, '404'].include?(JSON.parse(text)['result']) rescue JSON::ParserError Logging.logger.error("Failed to parse JSON response: #{text}") false end |
#status_code_success? ⇒ Boolean
19 20 21 |
# File 'lib/rox/core/network/response.rb', line 19 def status_code_success? @status_code >= 200 && @status_code < 300 end |
#success? ⇒ Boolean
15 16 17 |
# File 'lib/rox/core/network/response.rb', line 15 def success? status_code_success? && !missing_via_response_body? end |