Class: Gamewisp::TokenStore
- Inherits:
-
Object
- Object
- Gamewisp::TokenStore
- Defined in:
- lib/gamewisp/token_store.rb
Instance Method Summary collapse
- #access_token ⇒ Object
- #app_name ⇒ Object
- #client_id ⇒ Object
- #client_secret ⇒ Object
- #endpoint_host ⇒ Object
- #endpoint_port ⇒ Object
-
#initialize ⇒ TokenStore
constructor
A new instance of TokenStore.
- #read_token_file ⇒ Object
- #refresh_token ⇒ Object
- #save_access_token(token) ⇒ Object
- #save_refresh_token(token) ⇒ Object
- #token_file_path ⇒ Object
- #write_token_file ⇒ Object
Constructor Details
#initialize ⇒ TokenStore
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_token ⇒ Object
52 53 54 |
# File 'lib/gamewisp/token_store.rb', line 52 def access_token @tokens[:access_token] end |
#app_name ⇒ Object
30 31 32 |
# File 'lib/gamewisp/token_store.rb', line 30 def app_name ENV["GAMEWISP_APP"] end |
#client_id ⇒ Object
22 23 24 |
# File 'lib/gamewisp/token_store.rb', line 22 def client_id ENV["GAMEWISP_ID"] end |
#client_secret ⇒ Object
26 27 28 |
# File 'lib/gamewisp/token_store.rb', line 26 def client_secret ENV["GAMEWISP_SECRET"] end |
#endpoint_host ⇒ Object
34 35 36 |
# File 'lib/gamewisp/token_store.rb', line 34 def endpoint_host ENV["GAMEWISP_ENDPOINT_HOST"] end |
#endpoint_port ⇒ Object
38 39 40 |
# File 'lib/gamewisp/token_store.rb', line 38 def endpoint_port ENV["GAMEWISP_ENDPOINT_PORT"] end |
#read_token_file ⇒ Object
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_token ⇒ Object
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_path ⇒ Object
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_file ⇒ Object
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 |