class Ruhue::Response

Attributes

data[R]

@return [Array, Hash] data

response[R]

@return [String] body

Public Class Methods

new(response) click to toggle source

@param [HTTPI::Response] response

# File lib/ruhue/response.rb, line 3
def initialize(response)
  @response = response
  @data = JSON.load(response.body)
end

Public Instance Methods

error?() click to toggle source

@return [Boolean] true if the response is an error.

# File lib/ruhue/response.rb, line 15
def error?
  data.is_a?(Array) and data.any? { |hash| hash.has_key?("error") }
end
error_messages() click to toggle source

@return [Array<String>, nil] array of error messages and their address, nil if no error.

# File lib/ruhue/response.rb, line 20
def error_messages
  data.map { |hash| "#{hash["error"]["address"]}: #{hash["error"]["description"]}" } if error?
end