Module: XboxApi::TokenHelper
Instance Method Summary collapse
- #clear! ⇒ Object
- #create_token_dir! ⇒ Object
- #first_run ⇒ Object
- #get_local_token ⇒ Object
- #get_token ⇒ Object
- #token_exists? ⇒ Boolean
- #token_file ⇒ Object
- #token_path ⇒ Object
- #write_local_token!(token) ⇒ Object
Instance Method Details
#clear! ⇒ Object
51 52 53 54 55 |
# File 'lib/xbox-api/xboxlive.rb', line 51 def clear! if token_exists? FileUtils.rm token_file end end |
#create_token_dir! ⇒ Object
63 64 65 |
# File 'lib/xbox-api/xboxlive.rb', line 63 def create_token_dir! Dir.mkdir(token_path) end |
#first_run ⇒ Object
46 47 48 49 |
# File 'lib/xbox-api/xboxlive.rb', line 46 def first_run write_local_token!(get_token) puts "Token saved!" end |
#get_local_token ⇒ Object
71 72 73 74 |
# File 'lib/xbox-api/xboxlive.rb', line 71 def get_local_token raise "No Token Found at #{token_path}" unless token_exists? File.read(token_file).chomp end |
#get_token ⇒ Object
84 85 86 87 |
# File 'lib/xbox-api/xboxlive.rb', line 84 def get_token print 'XboxAPI Token: ' username = $stdin.gets.chomp end |
#token_exists? ⇒ Boolean
67 68 69 |
# File 'lib/xbox-api/xboxlive.rb', line 67 def token_exists? File.exists?(token_file) end |
#token_file ⇒ Object
80 81 82 |
# File 'lib/xbox-api/xboxlive.rb', line 80 def token_file File.join(token_path, XboxApi::TOKEN_FILE) end |
#token_path ⇒ Object
76 77 78 |
# File 'lib/xbox-api/xboxlive.rb', line 76 def token_path File.join(Dir.home, XboxApi::LIVE_DIR) end |
#write_local_token!(token) ⇒ Object
57 58 59 60 61 |
# File 'lib/xbox-api/xboxlive.rb', line 57 def write_local_token!(token) create_token_dir! unless Dir.exists? token_path File.write(token_file, token) token end |