class Sparkby::SparkCore

Main core driver. Exposes ability to read Spark variable, call Spark function, view device info, and view other devices.

Attributes

access_token[RW]

Particle API access token

device_id[RW]

Device ID of Particle core

Public Class Methods

new(access_token, device_id) click to toggle source

Arguments

  • access_token - Particle API access token

  • device_id - Device ID of Particle core

# File lib/sparkby/spark_core.rb, line 18
def initialize(access_token, device_id)
  @access_token = access_token
  @device_id = device_id
  @http_caller = HTTPCaller.new
  @header = {"Authorization" => "Bearer #{@access_token}"}
end

Public Instance Methods

device_info() click to toggle source

View information about device

# File lib/sparkby/spark_core.rb, line 31
def device_info
  @http_caller.get '/v1/devices/' + @device_id, @header
end
devices() click to toggle source

View devices authenticated user has access to

# File lib/sparkby/spark_core.rb, line 26
def devices
  @http_caller.get '/v1/devices', @header
end
spark_function(function, args=nil) click to toggle source

Call a Spark function

Arguments

  • function - Name of the Spark function

  • args - Argument string to pass to Spark function

# File lib/sparkby/spark_core.rb, line 46
def spark_function(function, args=nil)
  @http_caller.post '/v1/devices/' + @device_id + '/' + function, {'params' => args}, nil, @header
end
spark_variable(variable_name) click to toggle source

Read the value of a Spark variable

Arguments

  • variable_name - Name of the Spark variable

# File lib/sparkby/spark_core.rb, line 38
def spark_variable(variable_name)
  @http_caller.get '/v1/devices/' + @device_id + '/' + variable_name, @header
end