Class: SoapyBing::OauthCredentials

Inherits:
Object
  • Object
show all
Defined in:
lib/soapy_bing/oauth_credentials.rb

Defined Under Namespace

Classes: TokenRefreshError

Constant Summary collapse

TOKEN_URL =
'https://login.live.com/oauth20_token.srf'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oauth_options = {}) ⇒ OauthCredentials

Returns a new instance of OauthCredentials.



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

def initialize(oauth_options = {})
  param_guard = ParamGuard.new(oauth_options, env_namespace: 'BING_ADS_OAUTH')
  @client_id = param_guard.require!(:client_id)
  @client_secret = param_guard.require!(:client_secret)
  @refresh_token = param_guard.require!(:refresh_token)
  @token_url = oauth_options.fetch(:token_url, ENV['BING_ADS_OAUTH_TOKEN_URL'] || TOKEN_URL)
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



10
11
12
# File 'lib/soapy_bing/oauth_credentials.rb', line 10

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



10
11
12
# File 'lib/soapy_bing/oauth_credentials.rb', line 10

def client_secret
  @client_secret
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token.



10
11
12
# File 'lib/soapy_bing/oauth_credentials.rb', line 10

def refresh_token
  @refresh_token
end

#token_urlObject (readonly)

Returns the value of attribute token_url.



10
11
12
# File 'lib/soapy_bing/oauth_credentials.rb', line 10

def token_url
  @token_url
end

Instance Method Details

#access_tokenObject



20
21
22
# File 'lib/soapy_bing/oauth_credentials.rb', line 20

def access_token
  @access_token ||= request_access_token
end