Class: RedfishClient::Response

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#bodyObject (readonly)

Returns the value of attribute body.



12
13
14
# File 'lib/redfish_client/response.rb', line 12

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



11
12
13
# File 'lib/redfish_client/response.rb', line 11

def headers
  @headers
end

#statusObject (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.

Returns:

  • (true)

    if the request was completed



24
25
26
# File 'lib/redfish_client/response.rb', line 24

def done?
  status != 202
end

#monitorObject



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_hObject



35
36
37
# File 'lib/redfish_client/response.rb', line 35

def to_h
  { "status" => status, "headers" => headers, "body" => body }
end

#to_sObject



39
40
41
# File 'lib/redfish_client/response.rb', line 39

def to_s
  "Response[status=#{status}, headers=#{headers}, body='#{body}']"
end