Class: Gamewisp::TokenStore

Inherits:
Object
  • Object
show all
Defined in:
lib/gamewisp/token_store.rb

Instance Method Summary collapse

Constructor Details

#initializeTokenStore

Returns a new instance of TokenStore.



13
14
15
16
17
18
19
20
# File 'lib/gamewisp/token_store.rb', line 13

def initialize
  @tokens = {
    :access_token => '',
    :refresh_token => '',
  }

  read_token_file
end

Instance Method Details

#access_tokenObject



52
53
54
# File 'lib/gamewisp/token_store.rb', line 52

def access_token
  @tokens[:access_token]
end

#app_nameObject



30
31
32
# File 'lib/gamewisp/token_store.rb', line 30

def app_name
  ENV["GAMEWISP_APP"]
end

#client_idObject



22
23
24
# File 'lib/gamewisp/token_store.rb', line 22

def client_id
  ENV["GAMEWISP_ID"]
end

#client_secretObject



26
27
28
# File 'lib/gamewisp/token_store.rb', line 26

def client_secret
  ENV["GAMEWISP_SECRET"]
end

#endpoint_hostObject



34
35
36
# File 'lib/gamewisp/token_store.rb', line 34

def endpoint_host
  ENV["GAMEWISP_ENDPOINT_HOST"]
end

#endpoint_portObject



38
39
40
# File 'lib/gamewisp/token_store.rb', line 38

def endpoint_port
  ENV["GAMEWISP_ENDPOINT_PORT"]
end

#read_token_fileObject



79
80
81
82
83
84
85
# 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_tokenObject



56
57
58
# File 'lib/gamewisp/token_store.rb', line 56

def refresh_token
  @tokens[:refresh_token]
end

#save_access_token(token) ⇒ Object



42
43
44
45
# 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) ⇒ Object



47
48
49
50
# File 'lib/gamewisp/token_store.rb', line 47

def save_refresh_token token
  @tokens[:refresh_token] = token
  write_token_file
end

#token_file_pathObject



60
61
62
63
64
65
66
67
68
69
# 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_fileObject



71
72
73
74
75
76
77
# 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