Class: Ruberto::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/ruberto/authenticator.rb

Constant Summary collapse

OAUTH_URL =
"https://auth.uber.com/oauth/v2/token"
GRANT_TYPE =
"client_credentials"
SCOPE =
"eats.deliveries"

Class Method Summary collapse

Class Method Details

.access_tokenObject



12
13
14
15
16
17
18
# File 'lib/ruberto/authenticator.rb', line 12

def access_token
  @access_token = cached_token&.fetch(:token) || fetch_new_token

  @access_token = refresh_access_token if token_expired?

  @access_token
end

.cache_keyObject



26
27
28
# File 'lib/ruberto/authenticator.rb', line 26

def cache_key
  @cache_key ||= "#{Ruberto.customer_id}_#{Ruberto.client_id}_access_token"
end

.refresh_access_tokenObject



20
21
22
23
24
# File 'lib/ruberto/authenticator.rb', line 20

def refresh_access_token
  Ruberto.cache.delete(cache_key)

  fetch_new_token
end