Class: TalcOTP

Inherits:
Object
  • Object
show all
Defined in:
lib/talcotp.rb

Instance Method Summary collapse

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

#codesObject



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 ||
     = {
      interval: ['period'],
      digits: ['digits'],
      digest: ['algorithm']
    }
    auth_code = ROTP::TOTP.new(['secret'], ).now

    output += "#{['label']}: #{auth_code}\n"
  end

  output
end