Class: Particle::Client

Inherits:
Object
  • Object
show all
Includes:
BuildTargets, Devices, Firmware, Platforms, Publish, Tokens, Webhooks, Configurable, Connection
Defined in:
lib/particle/client.rb,
lib/particle/client/tokens.rb,
lib/particle/client/devices.rb,
lib/particle/client/publish.rb,
lib/particle/client/firmware.rb,
lib/particle/client/webhooks.rb,
lib/particle/client/platforms.rb,
lib/particle/client/build_targets.rb

Overview

Client for the Particle API

Defined Under Namespace

Modules: BuildTargets, Devices, Firmware, Platforms, Publish, Tokens, Webhooks

Constant Summary

Constants included from BuildTargets

BuildTargets::HTTP_PATH

Constants included from Firmware

Firmware::COMPILE_PATH, Firmware::PLATFORMS

Constants included from Publish

Publish::PUBLISH_PATH

Constants included from Connection

Particle::Connection::MIDDLEWARE

Instance Attribute Summary

Attributes included from Connection

#last_response

Attributes included from Configurable

#access_token, #api_endpoint, #connection_options, #user_agent

Instance Method Summary collapse

Methods included from Platforms

#platform, #platforms

Methods included from BuildTargets

#build_target, #build_targets

Methods included from Firmware

#compile, #download_binary, #flash_device

Methods included from Tokens

#create_token, #login, #remove_token, #token, #tokens

Methods included from Webhooks

#create_webhook, #remove_webhook, #webhook, #webhook_attributes, #webhooks

Methods included from Publish

#publish

Methods included from Devices

#call_function, #change_device_product, #claim_device, #device, #device_attributes, #devices, #get_variable, #remove_device, #rename_device, #signal_device, #update_device_public_key

Methods included from Connection

#connection, #delete, #get, #patch, #post, #put

Methods included from Configurable

#configure, keys, #reset!, #same_options?

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



26
27
28
29
30
31
# File 'lib/particle/client.rb', line 26

def initialize(options = {})
  # Use options passed in, but fall back to module defaults
  Particle::Configurable.keys.each do |key|
    instance_variable_set(:"@#{key}", options[key] || Particle.instance_variable_get(:"@#{key}"))
  end
end

Instance Method Details

#access_token=(value) ⇒ Object

Set OAuth2 access token for authentication

Parameters:

  • value (String)

    40 character Particle OAuth2 access token



50
51
52
53
54
55
56
57
58
# File 'lib/particle/client.rb', line 50

def access_token=(value)
  reset_connection
  @access_token = 
    if value.respond_to? :access_token
      value.access_token
    else
      value
    end
end

#inspectString

Text representation of the client, masking tokens

Returns:

  • (String)


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

def inspect
  inspected = super

  # Only show last 4 of token, secret
  if @access_token
    inspected = inspected.gsub! @access_token, "#{'*'*36}#{@access_token[36..-1]}"
  end

  inspected
end