Module: Particle::Client::Devices
- Included in:
- Particle::Client
- Defined in:
- lib/particle/client/devices.rb
Overview
Client methods for the Particle device API
Instance Method Summary collapse
-
#call_function(target, name, argument = "") ⇒ Integer
Call a function in the firmware of a Particle device.
-
#change_device_product(target, product_id, should_update = false) ⇒ boolean
Change the product_id on the device.
-
#claim_device(target) ⇒ Device
Add a Particle device to your account.
-
#device(target) ⇒ Device
Create a domain model for a Particle device.
-
#device_attributes(target) ⇒ Hash
Get information about a Particle device.
-
#devices ⇒ Array<Device>
List all Particle devices on the account.
-
#get_variable(target, name) ⇒ String, Number
Get the value of a variable in the firmware of a Particle device.
-
#remove_device(target) ⇒ boolean
Remove a Particle device from your account.
-
#rename_device(target, name) ⇒ boolean
Rename a Particle device in your account.
-
#signal_device(target, enabled = true) ⇒ boolean
Signal the device to start blinking the RGB LED in a rainbow pattern.
-
#update_device_public_key(target, public_key, algorithm = 'rsa') ⇒ boolean
Update the public key for a device you own.
Instance Method Details
#call_function(target, name, argument = "") ⇒ Integer
Call a function in the firmware of a Particle device
75 76 77 78 |
# File 'lib/particle/client/devices.rb', line 75 def call_function(target, name, argument = "") result = post(device(target).function_path(name), arg: argument) result[:return_value] end |
#change_device_product(target, product_id, should_update = false) ⇒ boolean
Change the product_id on the device. Use this carefully, it will impact what updates you receive, and can only be used for products that have given their permission
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/particle/client/devices.rb', line 110 def change_device_product(target, product_id, should_update = false) params = { product_id: product_id, update_after_claim: should_update } result = put(device(target).path, params) if result[:error] == "Nothing to do?" result[:ok] = false end result[:ok] end |
#claim_device(target) ⇒ Device
Add a Particle device to your account
45 46 47 48 |
# File 'lib/particle/client/devices.rb', line 45 def claim_device(target) result = post(Device.claim_path, id: device(target).id_or_name) device(result[:id]) end |
#device(target) ⇒ Device
Create a domain model for a Particle device
15 16 17 18 19 20 21 |
# File 'lib/particle/client/devices.rb', line 15 def device(target) if target.is_a? Device target else Device.new(self, target) end end |
#device_attributes(target) ⇒ Hash
Get information about a Particle device
36 37 38 |
# File 'lib/particle/client/devices.rb', line 36 def device_attributes(target) get(device(target).path) end |
#devices ⇒ Array<Device>
List all Particle devices on the account
26 27 28 29 30 |
# File 'lib/particle/client/devices.rb', line 26 def devices get(Device.list_path).map do |attributes| device(attributes) end end |
#get_variable(target, name) ⇒ String, Number
Get the value of a variable in the firmware of a Particle device
85 86 87 88 |
# File 'lib/particle/client/devices.rb', line 85 def get_variable(target, name) result = get(device(target).variable_path(name)) result[:result] end |
#remove_device(target) ⇒ boolean
Remove a Particle device from your account
54 55 56 57 |
# File 'lib/particle/client/devices.rb', line 54 def remove_device(target) result = delete(device(target).path) result[:ok] end |
#rename_device(target, name) ⇒ boolean
Rename a Particle device in your account
64 65 66 67 |
# File 'lib/particle/client/devices.rb', line 64 def rename_device(target, name) result = put(device(target).path, name: name) result[:name] == name end |
#signal_device(target, enabled = true) ⇒ boolean
Signal the device to start blinking the RGB LED in a rainbow pattern. Useful to identify a particular device.
96 97 98 99 |
# File 'lib/particle/client/devices.rb', line 96 def signal_device(target, enabled = true) result = put(device(target).path, signal: enabled ? '1' : '0') result[:signaling] end |
#update_device_public_key(target, public_key, algorithm = 'rsa') ⇒ boolean
Update the public key for a device you own
130 131 132 133 134 135 136 |
# File 'lib/particle/client/devices.rb', line 130 def update_device_public_key(target, public_key, algorithm = 'rsa') result = post(Device.provision_path, deviceID: device(target).id, publicKey: public_key, algorithm: algorithm) !result.empty? end |