Class: Neura::Client::Device
- Inherits:
-
Object
- Object
- Neura::Client::Device
- Defined in:
- lib/neura-client/device.rb
Instance Method Summary collapse
- #fire_event(event = {}) ⇒ Object
- #get_pending_actions ⇒ Object
-
#initialize(device_id, device) ⇒ Device
constructor
A new instance of Device.
- #perform_pending_actions ⇒ Object
- #update_attributes(attributes) ⇒ Object
Constructor Details
#initialize(device_id, device) ⇒ Device
Returns a new instance of Device.
5 6 7 8 |
# File 'lib/neura-client/device.rb', line 5 def initialize(device_id, device) @id = device_id @device = device end |
Instance Method Details
#fire_event(event = {}) ⇒ Object
14 15 16 |
# File 'lib/neura-client/device.rb', line 14 def fire_event(event = {}) HTTParty.post("#{Neura::Client::HOST}/external_api/v1/nodes/#{@id}/event", body: {event: attributes}, headers: Neura::Client.headers) end |
#get_pending_actions ⇒ Object
18 19 20 21 |
# File 'lib/neura-client/device.rb', line 18 def get_pending_actions result = HTTParty.get("#{Neura::Client::HOST}/external_api/v1/nodes/#{@id}/pending_actions", headers: Neura::Client.headers) [*result["pending_actions"]].map{|pa| Neura::Client::PendingAction.new(pa["pending_action"])} end |
#perform_pending_actions ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/neura-client/device.rb', line 23 def perform_pending_actions actions = get_pending_actions actions.each do |action| if @device.perform!(action) action.done! else action.reject! end end end |
#update_attributes(attributes) ⇒ Object
10 11 12 |
# File 'lib/neura-client/device.rb', line 10 def update_attributes(attributes) HTTParty.post("#{Neura::Client::HOST}/external_api/v1/nodes/#{@id}/update", body: {attributes: attributes}, headers: Neura::Client.headers) end |