module Particle::Configurable

Configuration options for {Client}, defaulting to values in {Default}

Attributes

access_token[RW]

@!attribute [String] access_token

@see http://docs.particle.io/core/api/#introduction-authentication
@return [String] Particle access token for authentication

@!attribute api_endpoint

@return [String] Base URL for API requests. default: https://api.particle.io

@!attribute connection_options

@see https://github.com/lostisland/faraday
@return [Hash] Configure connection options for Faraday

@!attribute user_agent

@return [String] Configure User-Agent header for requests.
api_endpoint[W]
connection_options[RW]

@!attribute [String] access_token

@see http://docs.particle.io/core/api/#introduction-authentication
@return [String] Particle access token for authentication

@!attribute api_endpoint

@return [String] Base URL for API requests. default: https://api.particle.io

@!attribute connection_options

@see https://github.com/lostisland/faraday
@return [Hash] Configure connection options for Faraday

@!attribute user_agent

@return [String] Configure User-Agent header for requests.
user_agent[RW]

@!attribute [String] access_token

@see http://docs.particle.io/core/api/#introduction-authentication
@return [String] Particle access token for authentication

@!attribute api_endpoint

@return [String] Base URL for API requests. default: https://api.particle.io

@!attribute connection_options

@see https://github.com/lostisland/faraday
@return [Hash] Configure connection options for Faraday

@!attribute user_agent

@return [String] Configure User-Agent header for requests.

Public Class Methods

keys() click to toggle source
# File lib/particle/configurable.rb, line 22
def keys
  @keys ||= [
    :access_token,
    :api_endpoint,
    :connection_options,
    :user_agent
  ]
end

Public Instance Methods

api_endpoint() click to toggle source

Clever way to add / at the end of the api_endpoint

# File lib/particle/configurable.rb, line 54
def api_endpoint
  File.join(@api_endpoint, "")
end
configure() { |self| ... } click to toggle source

Yields an object to set up configuration options in an initializer file

# File lib/particle/configurable.rb, line 34
def configure
  yield self
end
reset!() click to toggle source

Reset configuration options to default values

# File lib/particle/configurable.rb, line 39
def reset!
  Particle::Configurable.keys.each do |key|
    instance_variable_set :"@#{key}", Particle::Default.options[key]
  end
end
same_options?(opts) click to toggle source

Compares client options to a Hash of requested options

@param opts [Hash] Options to compare with current client options @return [Boolean]

# File lib/particle/configurable.rb, line 49
def same_options?(opts)
  opts.hash == options.hash
end

Private Instance Methods

options() click to toggle source
# File lib/particle/configurable.rb, line 60
def options
  Hash[Particle::Configurable.keys.map{ |key| [key, instance_variable_get(:"@#{key}")] }]
end