Class: CortexClient::Http::Response
- Inherits:
-
Object
- Object
- CortexClient::Http::Response
- Defined in:
- lib/cortex_client/http/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#response_code ⇒ Object
readonly
Returns the value of attribute response_code.
Instance Method Summary collapse
- #accepted? ⇒ Boolean
- #bad_request? ⇒ Boolean
- #created? ⇒ Boolean
- #forbidden? ⇒ Boolean
-
#initialize(http_response) ⇒ Response
constructor
A new instance of Response.
- #network_error? ⇒ Boolean
- #not_found? ⇒ Boolean
- #ok? ⇒ Boolean
- #server_error? ⇒ Boolean
- #successful? ⇒ Boolean
- #unauthorized? ⇒ Boolean
- #unprocessable_entity? ⇒ Boolean
Constructor Details
#initialize(http_response) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 |
# File 'lib/cortex_client/http/response.rb', line 6 def initialize(http_response) @response_code = http_response.code @body = http_response.body @http_response = http_response end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
4 5 6 |
# File 'lib/cortex_client/http/response.rb', line 4 def body @body end |
#response_code ⇒ Object (readonly)
Returns the value of attribute response_code.
4 5 6 |
# File 'lib/cortex_client/http/response.rb', line 4 def response_code @response_code end |
Instance Method Details
#accepted? ⇒ Boolean
20 21 22 |
# File 'lib/cortex_client/http/response.rb', line 20 def accepted? @response_code == 202 end |
#bad_request? ⇒ Boolean
24 25 26 |
# File 'lib/cortex_client/http/response.rb', line 24 def bad_request? @response_code == 400 end |
#created? ⇒ Boolean
16 17 18 |
# File 'lib/cortex_client/http/response.rb', line 16 def created? @response_code == 201 end |
#forbidden? ⇒ Boolean
28 29 30 |
# File 'lib/cortex_client/http/response.rb', line 28 def forbidden? @response_code == 403 end |
#network_error? ⇒ Boolean
55 56 57 58 59 |
# File 'lib/cortex_client/http/response.rb', line 55 def network_error? server_error_codes = [502, 503, 504] server_error_codes.include?(@response_code) end |
#not_found? ⇒ Boolean
36 37 38 |
# File 'lib/cortex_client/http/response.rb', line 36 def not_found? @response_code == 404 end |
#ok? ⇒ Boolean
12 13 14 |
# File 'lib/cortex_client/http/response.rb', line 12 def ok? @response_code == 200 end |
#server_error? ⇒ Boolean
49 50 51 52 53 |
# File 'lib/cortex_client/http/response.rb', line 49 def server_error? server_error_codes = [500, 502, 503, 504] server_error_codes.include?(@response_code) end |
#successful? ⇒ Boolean
44 45 46 47 |
# File 'lib/cortex_client/http/response.rb', line 44 def successful? successful_codes = [200, 201, 202] successful_codes.include?(@response_code) end |
#unauthorized? ⇒ Boolean
32 33 34 |
# File 'lib/cortex_client/http/response.rb', line 32 def @response_code == 401 end |
#unprocessable_entity? ⇒ Boolean
40 41 42 |
# File 'lib/cortex_client/http/response.rb', line 40 def unprocessable_entity? @response_code == 422 end |