class Gamewisp::TokenStore

Public Class Methods

new() click to toggle source
# File lib/gamewisp/token_store.rb, line 13
def initialize
  @tokens = {
    :access_token => '',
    :refresh_token => '',
  }

  read_token_file
end

Public Instance Methods

access_token() click to toggle source
# File lib/gamewisp/token_store.rb, line 52
def access_token
  @tokens[:access_token]
end
app_name() click to toggle source
# File lib/gamewisp/token_store.rb, line 30
def app_name
  ENV["GAMEWISP_APP"]
end
client_id() click to toggle source
# File lib/gamewisp/token_store.rb, line 22
def client_id
  ENV["GAMEWISP_ID"]
end
client_secret() click to toggle source
# File lib/gamewisp/token_store.rb, line 26
def client_secret
  ENV["GAMEWISP_SECRET"]
end
endpoint_host() click to toggle source
# File lib/gamewisp/token_store.rb, line 34
def endpoint_host
  ENV["GAMEWISP_ENDPOINT_HOST"]
end
endpoint_port() click to toggle source
# File lib/gamewisp/token_store.rb, line 38
def endpoint_port
  ENV["GAMEWISP_ENDPOINT_PORT"]
end
read_token_file() click to toggle source
# File lib/gamewisp/token_store.rb, line 79
def read_token_file
  filepath = token_file_path

  if File.exist? filepath
    @tokens = YAML.load_file(filepath)
  end
end
refresh_token() click to toggle source
# File lib/gamewisp/token_store.rb, line 56
def refresh_token
  @tokens[:refresh_token]
end
save_access_token(token) click to toggle source
# File lib/gamewisp/token_store.rb, line 42
def save_access_token token
  @tokens[:access_token] = token
  write_token_file
end
save_refresh_token(token) click to toggle source
# File lib/gamewisp/token_store.rb, line 47
def save_refresh_token token
  @tokens[:refresh_token] = token
  write_token_file
end
token_file_path() click to toggle source
# File lib/gamewisp/token_store.rb, line 60
def token_file_path
  filedir = "#{ENV['HOME']}/.gamewisp"
  filepath = File.join(filedir, "tokens.yml")

  unless File.exist?(filedir)
    FileUtils.mkdir_p filedir
  end

  filepath
end
write_token_file() click to toggle source
# File lib/gamewisp/token_store.rb, line 71
def write_token_file
  filepath = token_file_path

  File.open(filepath, 'w') do |out|
    YAML.dump(@tokens, out)
  end
end