Module: XboxApi::TokenHelper

Extended by:
TokenHelper
Included in:
TokenHelper
Defined in:
lib/xbox-api/xboxlive.rb

Instance Method Summary collapse

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_runObject



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_tokenObject



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_tokenObject



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

Returns:

  • (Boolean)


67
68
69
# File 'lib/xbox-api/xboxlive.rb', line 67

def token_exists?
  File.exists?(token_file)
end

#token_fileObject



80
81
82
# File 'lib/xbox-api/xboxlive.rb', line 80

def token_file
  File.join(token_path, XboxApi::TOKEN_FILE)
end

#token_pathObject



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