Class: Ruhue::Response
- Inherits:
-
Object
- Object
- Ruhue::Response
- Defined in:
- lib/ruhue/response.rb
Instance Attribute Summary collapse
-
#data ⇒ Array, Hash
readonly
Data.
-
#response ⇒ String
readonly
Body.
Instance Method Summary collapse
-
#error? ⇒ Boolean
True if the response is an error.
-
#error_messages ⇒ Array<String>?
Array of error messages and their address, nil if no error.
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
3 4 5 6 |
# File 'lib/ruhue/response.rb', line 3 def initialize(response) @response = response @data = JSON.load(response.body) end |
Instance Attribute Details
#data ⇒ Array, Hash (readonly)
Returns data.
12 13 14 |
# File 'lib/ruhue/response.rb', line 12 def data @data end |
#response ⇒ String (readonly)
Returns body.
9 10 11 |
# File 'lib/ruhue/response.rb', line 9 def response @response end |
Instance Method Details
#error? ⇒ Boolean
Returns true if the response is an error.
15 16 17 |
# File 'lib/ruhue/response.rb', line 15 def error? data.is_a?(Array) and data.any? { |hash| hash.has_key?("error") } end |
#error_messages ⇒ Array<String>?
Returns array of error messages and their address, nil if no error.
20 21 22 |
# File 'lib/ruhue/response.rb', line 20 def data.map { |hash| "#{hash["error"]["address"]}: #{hash["error"]["description"]}" } if error? end |