Sha256: b132ded630a535fa6efd7bba6e459d454b8522b2b36adfcc39b1029647dc06e9

Contents?: true

Size: 1.39 KB

Versions: 55

Compression:

Stored size: 1.39 KB

Contents

require 'date'

require 'spark_api/authentication/base_auth'
require 'spark_api/authentication/api_auth'
require 'spark_api/authentication/oauth2'

module SparkApi
  # =Authentication
  # Mixin module for handling client authentication and reauthentication to the spark api.  Makes 
  # use of the configured authentication mode (API Auth by default).
  module Authentication

    # Main authentication step.  Run before any api request unless the user session exists and is 
    # still valid.
    #
    # *returns*
    #   The user session object when authentication succeeds
    # *raises*
    #   SparkApi::ClientError when authentication fails
    def authenticate
      start_time = Time.now
      request_time = Time.now - start_time
      new_session = @authenticator.authenticate
      SparkApi.logger.info { "[#{(request_time * 1000).to_i}ms]" }
      SparkApi.logger.debug { "Session: #{new_session.inspect}" }
      new_session
    end

    # Test to see if there is an active session
    def authenticated?
      @authenticator.authenticated?
    end
    
    # Delete the current session
    def logout
      SparkApi.logger.info { "Logging out." }
      @authenticator.logout
    end

    # Fetch the active session object
    def session
      @authenticator.session
    end
    # Save the active session object
    def session=(active_session)
      @authenticator.session=active_session
    end
 
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
spark_api-2.0.0 lib/spark_api/authentication.rb
spark_api-1.6.3 lib/spark_api/authentication.rb
spark_api-1.6.2 lib/spark_api/authentication.rb
spark_api-1.6.1 lib/spark_api/authentication.rb
spark_api-1.5.7 lib/spark_api/authentication.rb
spark_api-1.6.0 lib/spark_api/authentication.rb
spark_api-1.5.6 lib/spark_api/authentication.rb
spark_api-1.5.5 lib/spark_api/authentication.rb
spark_api-1.5.4 lib/spark_api/authentication.rb
spark_api-1.5.3 lib/spark_api/authentication.rb
spark_api-1.5.2 lib/spark_api/authentication.rb
spark_api-1.5.1 lib/spark_api/authentication.rb
spark_api-1.5.0 lib/spark_api/authentication.rb
spark_api-1.4.34 lib/spark_api/authentication.rb
spark_api-1.4.32 lib/spark_api/authentication.rb
spark_api-1.4.31 lib/spark_api/authentication.rb
spark_api-1.4.29 lib/spark_api/authentication.rb
spark_api-1.4.28 lib/spark_api/authentication.rb
spark_api-1.4.27 lib/spark_api/authentication.rb
spark_api-1.4.26 lib/spark_api/authentication.rb