module Particle::Client::Firmware
Client
methods for the Particle
firmware flash API
@see docs.particle.io/core/api/#basic-functions-verifying-and-flashing-new-firmware
Constants
- COMPILE_PATH
- PLATFORMS
Public Instance Methods
compile(file_paths, options = {})
click to toggle source
Compile firmware from source code for a specific Particle
device
@param file_paths [Array<String>] File paths to send to cloud
and flash
@param options [Hash] Compilation options
:device_id => Compile for a specific device :platform => Compile for a specific platform (:core or :photon) :platform_id => Compile for a specific platform id :product_id => Compile for a specific product
@return [OpenStruct] Result of flashing.
:ok => true on success :errors => String with compile errors
# File lib/particle/client/firmware.rb, line 54 def compile(file_paths, options = {}) normalize_platform_id(options) params = file_upload_params(file_paths, options) result = post(COMPILE_PATH, params) OpenStruct.new(result) end
download_binary(binary_id)
click to toggle source
Download compiled binary firmware
@param binary_id [String] Id of the compiled binary to download @return [String] Binary bytes
# File lib/particle/client/firmware.rb, line 66 def download_binary(binary_id) get(binary_path(binary_id)) end
flash_device(target, file_paths, options = {})
click to toggle source
Flash new firmware to a Particle
device from source code or binary
@param target [String, Device] A device id, name or {Device} object that will
receive the new firmware
@param file_paths [Array<String>] File paths to send to cloud
and flash
@param options [Hash] Flashing options
:binary => true to skip the compile stage
@return [OpenStruct] Result of flashing.
:ok => true on success :errors => String with compile errors
# File lib/particle/client/firmware.rb, line 32 def flash_device(target, file_paths, options = {}) params = file_upload_params(file_paths, options) result = put(device(target).path, params) if result[:status] == "Update started" result[:ok] = true end OpenStruct.new(result) end
Private Instance Methods
binary_path(id)
click to toggle source
# File lib/particle/client/firmware.rb, line 72 def binary_path(id) COMPILE_PATH + "/#{id}" end
file_upload_params(file_paths, options)
click to toggle source
# File lib/particle/client/firmware.rb, line 76 def file_upload_params(file_paths, options) params = {} mime_type = options[:binary] ? "application/octet-stream" : "text/plain" file_paths = [file_paths] unless file_paths.is_a? Array file_paths.each_with_index do |file, index| params[:"file#{index > 0 ? index : ""}"] = Faraday::UploadIO.new(file, mime_type) end params[:file_type] = "binary" if options.delete(:binary) params.merge! options params end
normalize_platform_id(options)
click to toggle source
# File lib/particle/client/firmware.rb, line 90 def normalize_platform_id(options) if options[:platform] options[:platform_id] = PLATFORMS[options.delete(:platform)] end end