Module: Particle::Client::Products
- Included in:
- Particle::Client
- Defined in:
- lib/particle/client/products.rb
Overview
Client methods for the Particle product API
Instance Method Summary collapse
-
#add_device(product:, device_id:) ⇒ Hash
Add device to Particle product on the account.
-
#get_devices(target) ⇒ Array<Device>
List all Particle product devices on the account.
-
#product(target) ⇒ Product
Create a domain model for a Particle product.
-
#product_attributes(target) ⇒ Hash
Get information about a Particle product.
-
#products ⇒ Array<Product>
List all Particle products on the account.
-
#remove_product_device(product:, device_id:) ⇒ Hash
Remove device from a Particle product on the account.
Instance Method Details
#add_device(product:, device_id:) ⇒ Hash
Add device to Particle product on the account
56 57 58 |
# File 'lib/particle/client/products.rb', line 56 def add_device(product:, device_id:) post(product.add_device_path, id: device_id) end |
#get_devices(target) ⇒ Array<Device>
List all Particle product devices on the account
46 47 48 49 |
# File 'lib/particle/client/products.rb', line 46 def get_devices(target) response_body = get(product(target).devices_path) (response_body[:devices]).map { |attributes| device(attributes) } end |
#product(target) ⇒ Product
Create a domain model for a Particle product
13 14 15 16 17 18 19 |
# File 'lib/particle/client/products.rb', line 13 def product(target) if target.is_a? Product target else Product.new(self, target) end end |
#product_attributes(target) ⇒ Hash
Get information about a Particle product
33 34 35 36 37 38 39 40 41 |
# File 'lib/particle/client/products.rb', line 33 def product_attributes(target) response_body = get(product(target).path) # originally returned as an array, now seems to just return the 1 product as a hash; # this will handle both cases product = response_body[:product] product = product.first if product.is_a?(Array) product end |
#products ⇒ Array<Product>
List all Particle products on the account
24 25 26 27 |
# File 'lib/particle/client/products.rb', line 24 def products response_body = get(Product.list_path) (response_body[:products]).map { |attributes| product(attributes) } end |
#remove_product_device(product:, device_id:) ⇒ Hash
Remove device from a Particle product on the account
65 66 67 |
# File 'lib/particle/client/products.rb', line 65 def remove_product_device(product:, device_id:) delete(product.remove_device_path(device_id)) end |