class AdsCommon::Auth::BaseHandler

Public Class Methods

new(config) click to toggle source

Default initializer.

# File lib/ads_common/auth/base_handler.rb, line 27
def initialize(config)
  @config = config
  @token = nil
end

Public Instance Methods

auth_string(credentials) click to toggle source

Returns authorization string. Needs to be overridden.

# File lib/ads_common/auth/base_handler.rb, line 53
def auth_string(credentials)
  raise NotImplementedError, 'auth_string not overridden.'
end
get_token(credentials = nil) click to toggle source

Returns authorization token of some kind. Attempts to create a new one if the token has not yet been created and credentials present.

# File lib/ads_common/auth/base_handler.rb, line 47
def get_token(credentials = nil)
  @token = create_token(credentials) if @token.nil? and credentials
  return @token
end
handle_error(error) click to toggle source

This method handles an error according to the specifics of an authentication mechanism (to regenerate tokens, for example). The generic method simply re-raises the error.

# File lib/ads_common/auth/base_handler.rb, line 41
def handle_error(error)
  raise error
end
property_changed(credential, value) click to toggle source

Callback to be used by CredentialHandlers to notify the auth handler of a change in one of the credentials. Useful for e.g. invalidating a token. The generic method does nothing.

# File lib/ads_common/auth/base_handler.rb, line 35
def property_changed(credential, value)
end

Private Instance Methods

create_token(credentials) click to toggle source

Creates authorization token. Needs to be overridden.

# File lib/ads_common/auth/base_handler.rb, line 60
def create_token(credentials)
  raise NotImplementedError, 'create_token not overridden.'
end