Class: Huey::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/huey/request.rb

Overview

Wraps requests to the actual Hue itself

Class Method Summary collapse

Class Method Details

.error?(response, type) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/huey/request.rb', line 32

def error?(response, type)
  if response.is_a?(Array) && response.first && response.first['error']
    if response.first['error']['type'] == type
      true
    else
      case response.first['error']['type']
      when 5
        raise Huey::Errors::MissingParameters, response
      when 201
        raise Huey::Errors::BulbOff, response
      when 301..302
        raise Huey::Errors::GroupTableFull, response
      when 901
        raise Huey::Errors::InternalBridgeError, response
      else
        raise Huey::Errors::HueResponseError, response
      end
    end
  end
end

.registerObject



22
23
24
25
26
27
28
29
30
# File 'lib/huey/request.rb', line 22

def register
  response = HTTParty.post("http://#{Huey::SSDP.hue_ip}/api",
    body: MultiJson.dump({username: Huey::Config.uuid,
                          devicetype: 'Huey'})).parsed_response

  raise Huey::Errors::PressLinkButton, 'Press the link button and try your request again' if self.error?(response, 101)

  response
end