Module: Particle::Client::ProductFirmwares

Included in:
Particle::Client
Defined in:
lib/particle/client/product_firmwares.rb

Overview

Client methods for the Particle product firmware API

Instance Method Summary collapse

Instance Method Details

#product_firmware(product, target) ⇒ ProductFirmware

Create a domain model for a Particle product firmware object

Parameters:

Returns:



14
15
16
17
18
19
20
# File 'lib/particle/client/product_firmwares.rb', line 14

def product_firmware(product, target)
  if target.is_a? ProductFirmware
    target
  else
    ProductFirmware.new(self, product, target)
  end
end

#product_firmware_attributes(target) ⇒ Hash

Get information about a specific firmware version of a Particle Product

Parameters:

Returns:

  • (Hash)

    The product attributes



50
51
52
53
# File 'lib/particle/client/product_firmwares.rb', line 50

def product_firmware_attributes(target)
  the_product = target.product
  get(the_product.firmware_path(target.version))
end

#product_firmware_file_upload_params(file_path, options) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/particle/client/product_firmwares.rb', line 37

def product_firmware_file_upload_params(file_path, options)
  params = {}
  params[:binary] = Faraday::UploadIO.new(file_path, "application/octet-stream")
  params[:file_type] = "binary"
  params.merge! options
  params
end

#upload_product_firmware(product, params) ⇒ ProductFirmware

Create a domain model for a Particle product firmware object

Parameters:

  • product (String, Product)

    A product id, slug, hash of attributes or Product object

  • params (Hash)

    a hash with required attributes: (:version, :title, :binary) and optional: :description

Returns:



28
29
30
31
32
33
34
35
# File 'lib/particle/client/product_firmwares.rb', line 28

def upload_product_firmware(product, params)
  file_path = params.delete(:binary) || params.delete(:file)

  params = product_firmware_file_upload_params(file_path, params)
  res = post(product.firmware_upload_path, params)

  product.firmware(res)
end