module Particle::Client::Products

Client methods for the Particle product API

@see docs.particle.io/reference/api/#products

Public Instance Methods

add_device(product:, device_id:) click to toggle source

Add device to Particle product on the account

@param product [Product] A product to interact with @param device_id [String] A device id @return [Hash] JSON response as a hash

# 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) click to toggle source

List all Particle product devices on the account

@return [Array<Device>] List of Particle product devices to interact with

# 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) click to toggle source

Create a domain model for a Particle product

@param target [String, Hash, Product] A product id, slug, hash of attributes or {Product} object @return [Product] A product object to interact with

# 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) click to toggle source

Get information about a Particle product

@param target [String, Product] A product id, slug or {Product} object @return [Hash] The product attributes

# 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() click to toggle source

List all Particle products on the account

@return [Array<Product>] List of Particle products to interact with

# 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:) click to toggle source

Remove device from a Particle product on the account

@param product [Product] A product to interact with @param device_id [String] A device id @return [Hash] JSON response as a hash

# File lib/particle/client/products.rb, line 65
def remove_product_device(product:, device_id:)
  delete(product.remove_device_path(device_id))
end