class Pickpocket::Authentication::TokenHandler
Attributes
logger[RW]
Public Class Methods
new()
click to toggle source
# File lib/pickpocket/authentication/token_handler.rb, line 6 def initialize @logger = Pickpocket::Logger end
Public Instance Methods
read_auth()
click to toggle source
# File lib/pickpocket/authentication/token_handler.rb, line 22 def read_auth read_token(path: Pickpocket.config.authorization_token_file, error_message: 'Authorization Token file does not exist. Make sure you request authorization before proceeding.') end
read_oauth()
click to toggle source
# File lib/pickpocket/authentication/token_handler.rb, line 18 def read_oauth read_token(path: Pickpocket.config.oauth_token_file, error_message: 'OAuth Token file does not exist. Make sure you request authorization before proceeding.') end
save_auth(token)
click to toggle source
# File lib/pickpocket/authentication/token_handler.rb, line 14 def save_auth(token) save_token(token: token, path: Pickpocket.config.authorization_token_file) end
save_oauth(token)
click to toggle source
# File lib/pickpocket/authentication/token_handler.rb, line 10 def save_oauth(token) save_token(token: token, path: Pickpocket.config.oauth_token_file) end
Private Instance Methods
read_token(path:, error_message:)
click to toggle source
# File lib/pickpocket/authentication/token_handler.rb, line 36 def read_token(path:, error_message:) file = File.new(path, 'r') file.read rescue Errno::ENOENT => _ logger.warn(error_message) :no_token end
save_token(token:, path:)
click to toggle source
# File lib/pickpocket/authentication/token_handler.rb, line 28 def save_token(token:, path:) FileUtils.mkdir_p(Pickpocket.config.home_folder) file = File.new(path, 'w') file.write(token) file.close end