Class: Vesync::Event
- Inherits:
-
Object
- Object
- Vesync::Event
- Defined in:
- lib/vesync/event.rb
Instance Method Summary collapse
- #account_id ⇒ Object
- #device_id(device_name) ⇒ Object
- #headers ⇒ Object
-
#initialize(attributes = {}) ⇒ Event
constructor
A new instance of Event.
- #token ⇒ Object
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_id ⇒ Object
9 10 11 |
# File 'lib/vesync/event.rb', line 9 def account_id 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 |
#headers ⇒ Object
17 18 19 |
# File 'lib/vesync/event.rb', line 17 def headers {"tk":token,"accountid":account_id} end |