Class: TOTP::CLI::Token
- Inherits:
-
Object
- Object
- TOTP::CLI::Token
- Defined in:
- lib/totp/cli/token.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#label ⇒ Object
Returns the value of attribute label.
-
#secret ⇒ Object
Returns the value of attribute secret.
Class Method Summary collapse
- .all ⇒ Object
- .create(label, secret) ⇒ Object
- .find_by_id(id) ⇒ Object
- .find_by_label(label) ⇒ Object
- .store ⇒ Object
Instance Method Summary collapse
- #delete! ⇒ Object
-
#initialize(options = {}) ⇒ Token
constructor
A new instance of Token.
- #now ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Token
Returns a new instance of Token.
42 43 44 45 46 |
# File 'lib/totp/cli/token.rb', line 42 def initialize( = {}) @id = [:id] @label = [:label] @secret = [:secret] end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
40 41 42 |
# File 'lib/totp/cli/token.rb', line 40 def id @id end |
#label ⇒ Object
Returns the value of attribute label.
40 41 42 |
# File 'lib/totp/cli/token.rb', line 40 def label @label end |
#secret ⇒ Object
Returns the value of attribute secret.
40 41 42 |
# File 'lib/totp/cli/token.rb', line 40 def secret @secret end |
Class Method Details
.all ⇒ Object
8 9 10 |
# File 'lib/totp/cli/token.rb', line 8 def all store.read_all end |
.create(label, secret) ⇒ Object
28 29 30 31 32 |
# File 'lib/totp/cli/token.rb', line 28 def create(label, secret) store.save(label, secret) find_by_label(label) end |
.find_by_id(id) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/totp/cli/token.rb', line 12 def find_by_id(id) all.each do |token| return token if token.id == id end nil end |
.find_by_label(label) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/totp/cli/token.rb', line 20 def find_by_label(label) all.each do |token| return token if token.label == label end nil end |
Instance Method Details
#delete! ⇒ Object
58 59 60 |
# File 'lib/totp/cli/token.rb', line 58 def delete! self.class.store.remove(label) end |
#now ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/totp/cli/token.rb', line 48 def now otp = totp.now.to_s while otp.length < 6 otp = "0" + otp end otp end |