Class: RedfishClient::Response
- Inherits:
-
Object
- Object
- RedfishClient::Response
- Defined in:
- lib/redfish_client/response.rb
Overview
Response struct.
This struct is returned from the methods that interact with the remote API.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
-
#done? ⇒ true
Returns wether the request is completed or ongoing.
-
#initialize(status, headers, body) ⇒ Response
constructor
A new instance of Response.
- #monitor ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(status, headers, body) ⇒ Response
Returns a new instance of Response.
14 15 16 17 18 |
# File 'lib/redfish_client/response.rb', line 14 def initialize(status, headers, body) @status = status @headers = headers @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
12 13 14 |
# File 'lib/redfish_client/response.rb', line 12 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
11 12 13 |
# File 'lib/redfish_client/response.rb', line 11 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
10 11 12 |
# File 'lib/redfish_client/response.rb', line 10 def status @status end |
Class Method Details
.from_hash(data) ⇒ Object
43 44 45 |
# File 'lib/redfish_client/response.rb', line 43 def self.from_hash(data) new(*data.values_at("status", "headers", "body")) end |
Instance Method Details
#done? ⇒ true
Returns wether the request is completed or ongoing. Be aware than completed doesn't mean completed successfully, and that you still need to check status for success or failure.
24 25 26 |
# File 'lib/redfish_client/response.rb', line 24 def done? status != 202 end |
#monitor ⇒ Object
28 29 30 31 32 33 |
# File 'lib/redfish_client/response.rb', line 28 def monitor return nil if done? uri = URI.parse(headers["location"]) [uri.path, uri.query].compact.join("?") end |
#to_h ⇒ Object
35 36 37 |
# File 'lib/redfish_client/response.rb', line 35 def to_h { "status" => status, "headers" => headers, "body" => body } end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/redfish_client/response.rb', line 39 def to_s "Response[status=#{status}, headers=#{headers}, body='#{body}']" end |