Class: Ebay::Oauth::ClientCredentialsGrant

Inherits:
Object
  • Object
show all
Includes:
Requestable
Defined in:
lib/ebay/oauth/client_credentials_grant.rb

Overview

Mints an access token to use in API requests

Instance Attribute Summary collapse

Attributes included from Requestable

#endpoint, #headers, #http

Instance Method Summary collapse

Methods included from Requestable

#market_id=, #persistent, #sandbox, #use, #via

Constructor Details

#initialize(app_id: Config.app_id, cert_id: Config.cert_id) ⇒ ClientCredentialsGrant

Returns a new instance of ClientCredentialsGrant.

Parameters:

  • app_id (String) (defaults to: Config.app_id)
  • cert_id (String) (defaults to: Config.cert_id)


24
25
26
27
# 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

Instance Attribute Details

#app_idString (readonly)

Returns:

  • (String)


17
18
19
# File 'lib/ebay/oauth/client_credentials_grant.rb', line 17

def app_id
  @app_id
end

#cert_idString (readonly)

Returns:

  • (String)


20
21
22
# File 'lib/ebay/oauth/client_credentials_grant.rb', line 20

def cert_id
  @cert_id
end

Instance Method Details

#mint_access_tokenString

Mints a new access token

Returns:

  • (String)


32
33
34
# File 'lib/ebay/oauth/client_credentials_grant.rb', line 32

def mint_access_token
  JSON.parse(request).fetch('access_token')
end

#requestHTTP::Response

Requests a client credentials grant

Returns:

  • (HTTP::Response)


39
40
41
42
# 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