Class: CobotClient::Response
- Inherits:
-
Object
- Object
- CobotClient::Response
- Defined in:
- lib/cobot_client/response.rb
Instance Method Summary collapse
- #body ⇒ Object
- #client_error? ⇒ Boolean
- #code ⇒ Object
- #headers ⇒ Object
-
#initialize(net_http_response) ⇒ Response
constructor
A new instance of Response.
- #parsed_body ⇒ Object
- #server_error? ⇒ Boolean
- #success? ⇒ Boolean
- #to_error ⇒ Object
Constructor Details
#initialize(net_http_response) ⇒ Response
Returns a new instance of Response.
5 6 7 |
# File 'lib/cobot_client/response.rb', line 5 def initialize(net_http_response) @net_http_response = net_http_response end |
Instance Method Details
#body ⇒ Object
9 10 11 |
# File 'lib/cobot_client/response.rb', line 9 def body @net_http_response.body end |
#client_error? ⇒ Boolean
27 28 29 |
# File 'lib/cobot_client/response.rb', line 27 def client_error? (400..499).cover?(code) end |
#code ⇒ Object
17 18 19 |
# File 'lib/cobot_client/response.rb', line 17 def code Integer(@net_http_response.code) end |
#headers ⇒ Object
13 14 15 |
# File 'lib/cobot_client/response.rb', line 13 def headers @net_http_response.to_hash end |
#parsed_body ⇒ Object
21 22 23 24 25 |
# File 'lib/cobot_client/response.rb', line 21 def parsed_body return if !success? || code == 204 JSON.parse(@net_http_response.body, symbolize_names: true) end |
#server_error? ⇒ Boolean
31 32 33 |
# File 'lib/cobot_client/response.rb', line 31 def server_error? (500..599).cover?(code) end |
#success? ⇒ Boolean
35 36 37 |
# File 'lib/cobot_client/response.rb', line 35 def success? (200..299).cover?(code) end |
#to_error ⇒ Object
39 40 41 42 43 |
# File 'lib/cobot_client/response.rb', line 39 def to_error return if success? ResponseError.build(@net_http_response., response: self) end |