Class: Particle::Token
Overview
Domain model for one Particle token
Class Method Summary collapse
Instance Method Summary collapse
-
#create(username, password) ⇒ Object
Create a Particle token.
-
#get_attributes ⇒ Object
Tokens can’t be loaded.
-
#initialize(client, attributes) ⇒ Token
constructor
A new instance of Token.
-
#inspect ⇒ String
Text representation of the token, masking the secret part.
- #path ⇒ Object
-
#remove(username, password) ⇒ Object
Remove a Particle token.
-
#token ⇒ Object
(also: #id, #access_token)
The id of the token.
Methods inherited from Model
Constructor Details
#initialize(client, attributes) ⇒ Token
Returns a new instance of Token.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/particle/token.rb', line 5 def initialize(client, attributes) @client = client @attributes = if attributes.is_a? String { token: attributes } else # Consider attributes loaded when passed in through constructor @loaded = true attributes end end |
Class Method Details
.create_path ⇒ Object
68 69 70 |
# File 'lib/particle/token.rb', line 68 def self.create_path "/oauth/token" end |
.list_path ⇒ Object
64 65 66 |
# File 'lib/particle/token.rb', line 64 def self.list_path "v1/access_tokens" end |
Instance Method Details
#create(username, password) ⇒ Object
Create a Particle token
51 52 53 |
# File 'lib/particle/token.rb', line 51 def create(username, password) @client.create_token(username, password) end |
#get_attributes ⇒ Object
Tokens can’t be loaded. What you see is what you get…
27 28 29 30 |
# File 'lib/particle/token.rb', line 27 def get_attributes @loaded = true @attributes end |
#inspect ⇒ String
Text representation of the token, masking the secret part
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/particle/token.rb', line 35 def inspect inspected = super # Only show last 4 of token, secret if id inspected = inspected.gsub! id, "#{'*'*36}#{id[36..-1]}" end inspected end |
#path ⇒ Object
72 73 74 |
# File 'lib/particle/token.rb', line 72 def path "/v1/access_tokens/#{access_token}" end |
#remove(username, password) ⇒ Object
Remove a Particle token
60 61 62 |
# File 'lib/particle/token.rb', line 60 def remove(username, password) @client.remove_token(username, password, self) end |
#token ⇒ Object Also known as: id, access_token
The id of the token
18 19 20 |
# File 'lib/particle/token.rb', line 18 def token @attributes[:token] end |