Module: PaypalAPI::Client::AccessTokenMethods

Included in:
PaypalAPI::Client
Defined in:
lib/paypal-api/client/access_token_methods.rb

Overview

Client methods to get access token

Instance Method Summary collapse

Instance Method Details

#access_tokenAccessToken

Checks cached access token is expired and returns it or generates new one

Returns:



14
15
16
# File 'lib/paypal-api/client/access_token_methods.rb', line 14

def access_token
  (@access_token.nil? || @access_token.expired?) ? refresh_access_token : @access_token
end

#refresh_access_tokenAccessToken

Generates and caches new AccessToken

Returns:



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/paypal-api/client/access_token_methods.rb', line 23

def refresh_access_token
  requested_at = Time.now
  response = authentication.generate_access_token

  @access_token = AccessToken.new(
    requested_at: requested_at,
    expires_in: response.fetch(:expires_in),
    access_token: response.fetch(:access_token),
    token_type: response.fetch(:token_type)
  )
end