Class: TalcOTP
- Inherits:
-
Object
- Object
- TalcOTP
- Defined in:
- lib/talcotp.rb
Instance Method Summary collapse
- #codes ⇒ Object
-
#initialize(file) ⇒ TalcOTP
constructor
A new instance of TalcOTP.
Constructor Details
#initialize(file) ⇒ TalcOTP
Returns a new instance of TalcOTP.
5 6 7 8 9 10 11 12 13 |
# File 'lib/talcotp.rb', line 5 def initialize file file = File.file?(file) ? File.read(file) : '' begin @accounts = JSON.parse(file) rescue JSON::ParserError @accounts = {} end end |
Instance Method Details
#codes ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/talcotp.rb', line 15 def codes output = '' @accounts.each do |account| account_settings = { interval: account['period'], digits: account['digits'], digest: account['algorithm'] } auth_code = ROTP::TOTP.new(account['secret'], account_settings).now output += "#{account['label']}: #{auth_code}\n" end output end |