ads_common/lib/ads_common/api.rb
# Authorize with specified authentication method.
#
# Args:
#  - parameters - hash of credentials to add to configuration
#  - block - code block to handle auth login url
#
# Returns:
#  - Auth token for the method
#
# Throws:
#  - AdsCommon::Errors::AuthError or derived if authetication error has
#    occured
#
Authorize with specified authentication method.
Args:
parameters - hash of credentials to add to configuration
block - code block to handle auth login url

Auth token for the method

:Errors::AuthError or derived if authetication error has
occured
Authorize with specified authentication method . Args : parameters - hash of credentials to add to configuration block - code block to handle auth login url Auth token for the method : Errors :: AuthError or derived if authetication error has occured
def authorize(parameters = {}, &block)
      parameters.each_pair do |key, value|
        @credential_handler.set_credential(key, value)
      end
      auth_handler = get_auth_handler()
      token = auth_handler.get_token()
      if token.nil?
        begin
          credentials = @credential_handler.credentials
          token = auth_handler.get_token(credentials)
        rescue AdsCommon::Errors::OAuth2VerificationRequired => e
          verification_code = (block_given?) ? yield(e.oauth_url) : nil
          if verification_code
            @credential_handler.set_credential(
                :oauth2_verification_code, verification_code)
            retry
          else
            raise e
          end
        end
      end
      return token
    end
def authorize ( parameters = { } , & block ) parameters . each_pair do | key , value | @credential_handler . set_credential ( key , value ) end auth_handler = get_auth_handler ( ) token = auth_handler . get_token ( ) if token . nil? begin credentials = @credential_handler . credentials token = auth_handler . get_token ( credentials ) rescue AdsCommon :: Errors :: OAuth2VerificationRequired => e verification_code = ( block_given? ) ? yield ( e . oauth_url ) : nil if verification_code @credential_handler . set_credential ( :oauth2_verification_code , verification_code ) retry else raise e end end end return token end
Authorize with specified authentication method.
Authorize with specified authentication method .
# If token is invalid ask for a new one. # Retry with verification code if one provided.
parameters
block