class Sparkby::TokenManager
Attributes
email[RW]
Email address of Particle account
password[RW]
Password of Particle account
Public Class Methods
new(email, password)
click to toggle source
# File lib/sparkby/token_manager.rb, line 12 def initialize(email, password) @email = email @password = password @http_caller = HTTPCaller.new end
Public Instance Methods
del_access_token(token)
click to toggle source
gen_access_token(expires_in = nil, expires_at = nil, client_id = 'particle', client_secret = 'particle')
click to toggle source
Generate a new access token
Arguments¶ ↑
-
expires_in
- Time in seconds when token should expire, nil means token never expires -
expires_at
- Time in YYYY-MM-DD Format when token should expire. At most one of expires_in and expires_at should be specified -
client_id
- Particle client ID -
client_secret
- Particle client secret
Examples¶ ↑
Token that expires in 3600 seconds (one hour)
manager = TokenManager.new email, pass manager.gen_access_token 3600
Token that expires on September 25, 2015
manager = TokenManager.new email, pass manager.gen_access_token nil, '2015-09-25'
# File lib/sparkby/token_manager.rb, line 34 def gen_access_token(expires_in = nil, expires_at = nil, client_id = 'particle', client_secret = 'particle') @http_caller.post '/oauth/token', {:grant_type => 'password', :username => @email, :password => @password, :expires_in => expires_in, :expires_at => expires_at}.reject{ |k,v| v.nil?}, {:username => client_id, :password => client_secret} end
list_tokens()
click to toggle source
List all access tokens the user has
# File lib/sparkby/token_manager.rb, line 48 def list_tokens @http_caller.get '/v1/access_tokens', nil, {:username => @email, :password => @password} end