Class: VNCPostAPI::UserLogin

Inherits:
ActiveResource::Base
  • Object
show all
Defined in:
lib/vncpost_api/resources/user_login.rb

Class Method Summary collapse

Class Method Details

.get_bearer_token(username: VNCPostAPI.config.username, password: VNCPostAPI.config.password) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vncpost_api/resources/user_login.rb', line 11

def get_bearer_token(username: VNCPostAPI.config.username, password: VNCPostAPI.config.password)
  cache_key = "VNCPostAPI/bearer_token"
  cached_token = VNCPostAPI.cache.read(cache_key)
  return cached_token if cached_token

  token = create(Username: username, Password: password).token
  VNCPostAPI.cache.write(
    cache_key,
    token,
    expires_in: expires_in(token) - 15
  )

  token
end