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.
-
#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.
-
#ping_device(target) ⇒ boolean
Ping a device to see if it is online.
-
#provision_device(params) ⇒ Device
Create a new 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
85 86 87 88 |
# File 'lib/particle/client/devices.rb', line 85 def call_function(target, name, argument = "") result = post(device(target).function_path(name), arg: argument) result[:return_value] 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
95 96 97 98 |
# File 'lib/particle/client/devices.rb', line 95 def get_variable(target, name) result = get(device(target).variable_path(name)) result[:result] end |
#ping_device(target) ⇒ boolean
Ping a device to see if it is online
104 105 106 107 |
# File 'lib/particle/client/devices.rb', line 104 def ping_device(target) result = put(device(target).ping_path) result[:online] end |
#provision_device(params) ⇒ Device
Create a new Particle device
54 55 56 57 58 |
# File 'lib/particle/client/devices.rb', line 54 def provision_device(params) product_id = params[:product_id] or raise ArgumentError.new("product_id parameter is required") result = post(Device.provision_path, product_id: product_id) device(result[:device_id]) end |
#remove_device(target) ⇒ boolean
Remove a Particle device from your account
64 65 66 67 |
# File 'lib/particle/client/devices.rb', line 64 def remove_device(target) result = delete(device(target).path) result[:ok] end |
#rename_device(target, name) ⇒ boolean
Rename a Particle device in your account
74 75 76 77 |
# File 'lib/particle/client/devices.rb', line 74 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.
115 116 117 118 |
# File 'lib/particle/client/devices.rb', line 115 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
128 129 130 131 132 133 134 |
# File 'lib/particle/client/devices.rb', line 128 def update_device_public_key(target, public_key, algorithm = 'rsa') result = post(device(target).update_keys_path, deviceID: device(target).id, publicKey: public_key, algorithm: algorithm) !result.empty? end |