class Ebay::Oauth::ClientCredentialsGrant

Mints an access token to use in API requests

@see developer.ebay.com/api-docs/static/oauth-client-credentials-grant.html

Attributes

app_id[R]

@return [String]

cert_id[R]

@return [String]

Public Class Methods

new(app_id: Config.app_id, cert_id: Config.cert_id) click to toggle source

@param [String] app_id @param [String] cert_id

# File lib/ebay/oauth/client_credentials_grant.rb, line 24
def initialize(app_id: Config.app_id, cert_id: Config.cert_id)
  @app_id = app_id
  @cert_id = cert_id
end

Public Instance Methods

mint_access_token() click to toggle source

Mints a new access token

@return [String]

# File lib/ebay/oauth/client_credentials_grant.rb, line 32
def mint_access_token
  JSON.parse(request).fetch('access_token')
end
request() click to toggle source

Requests a client credentials grant

@return [HTTP::Response]

# File lib/ebay/oauth/client_credentials_grant.rb, line 39
def request
  http.basic_auth(user: app_id, pass: cert_id)
      .post(endpoint, form: payload)
end

Private Instance Methods

payload() click to toggle source
# File lib/ebay/oauth/client_credentials_grant.rb, line 46
def payload
  { grant_type: 'client_credentials',
    scope: 'https://api.ebay.com/oauth/api_scope' }
end