Class: Vesync::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/vesync/event.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Event

Returns a new instance of Event.



3
4
5
6
7
# File 'lib/vesync/event.rb', line 3

def initialize(attributes = {})
  attributes.each {|k, v| send("#{k}=", v) if respond_to?("#{k}=")}
  device = device_id(attributes[:device_name])
  RestClient.put("#{Vesync::SWITCH_URI}/#{device}/status/#{attributes[:event_type]}", {}, headers)
end

Instance Method Details

#account_idObject



9
10
11
# File 'lib/vesync/event.rb', line 9

def 
  Vesync.auth["accountID"]
end

#device_id(device_name) ⇒ Object



21
22
23
24
25
# File 'lib/vesync/event.rb', line 21

def device_id(device_name)
  devices = JSON.parse(RestClient.get(Vesync::DEVICES_URI, headers).body)
  device = devices.detect {|device| device["deviceName"] == device_name }
  device["cid"]
end

#headersObject



17
18
19
# File 'lib/vesync/event.rb', line 17

def headers
  {"tk":token,"accountid":}
end

#tokenObject



13
14
15
# File 'lib/vesync/event.rb', line 13

def token
  Vesync.auth["tk"]
end