Class: SpreeUberDirect::Credential

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree_uber_direct/credential.rb

Overview

A Direct account's OAuth client_credentials + Customer ID for one Spree::Store, plus a cached access token. Unlike SpreeDoordash::Credential (a static access key that signs a fresh short-lived JWT per call, nothing to cache), Uber Direct's OAuth2 client_credentials grant issues a genuine bearer token that outlives a single request — SpreeUberDirect::Client caches it here and refreshes it proactively before it actually expires, rather than fetching a fresh one on every call.

Constant Summary collapse

REFRESH_MARGIN =

A short margin before the token's real expiry, not right up against it — avoids a request racing the token's actual expiration mid-flight. Mirrors SpreeSquare::Credential's own needs_refresh? margin rationale.

60

Instance Method Summary collapse

Instance Method Details

#needs_refresh?Boolean

seconds

Returns:

  • (Boolean)


28
29
30
31
# File 'app/models/spree_uber_direct/credential.rb', line 28

def needs_refresh?
  access_token.blank? || access_token_expires_at.blank? ||
    access_token_expires_at <= REFRESH_MARGIN.seconds.from_now
end

#sandbox?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/models/spree_uber_direct/credential.rb', line 19

def sandbox?
  uber_environment == 'sandbox'
end