Class: BoxCli::AuthTokenManager
- Inherits:
-
Object
- Object
- BoxCli::AuthTokenManager
- Defined in:
- lib/box_cli/auth_token_manager.rb
Constant Summary collapse
- DEFAULT_RC =
"~/.box_cli_rc"
Instance Method Summary collapse
- #get_auth_token ⇒ Object
-
#initialize(username) ⇒ AuthTokenManager
constructor
A new instance of AuthTokenManager.
- #remove ⇒ Object
- #save(auth_token) ⇒ Object
Constructor Details
#initialize(username) ⇒ AuthTokenManager
Returns a new instance of AuthTokenManager.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/box_cli/auth_token_manager.rb', line 5 def initialize(username) @username = username @auth_tokens = {} if File.exists?(rc_path) begin @auth_tokens = YAML.load_file(rc_path) rescue StandardError => e STDERR.puts "Couldn't load auth tokens from '#{rc_path}': #{e.}" end else remove end end |
Instance Method Details
#get_auth_token ⇒ Object
19 20 21 |
# File 'lib/box_cli/auth_token_manager.rb', line 19 def get_auth_token @auth_tokens[@username] end |
#remove ⇒ Object
23 24 25 |
# File 'lib/box_cli/auth_token_manager.rb', line 23 def remove save(nil) end |
#save(auth_token) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/box_cli/auth_token_manager.rb', line 27 def save(auth_token) @auth_tokens[@username] = auth_token File.open(rc_path, 'w') { |f| YAML.dump(@auth_tokens, f) } rescue StandardError => e STDERR.puts "Couldn't save auth tokens to '#{rc_path}': #{e.}" end |