module SparkApi::Authentication

Authentication

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

Public Instance Methods

authenticate() click to toggle source

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
# File lib/spark_api/authentication.rb, line 21
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
authenticated?() click to toggle source

Test to see if there is an active session

# File lib/spark_api/authentication.rb, line 31
def authenticated?
  @authenticator.authenticated?
end
logout() click to toggle source

Delete the current session

# File lib/spark_api/authentication.rb, line 36
def logout
  SparkApi.logger.info { "Logging out." }
  @authenticator.logout
end
session() click to toggle source

Fetch the active session object

# File lib/spark_api/authentication.rb, line 42
def session
  @authenticator.session
end
session=(active_session) click to toggle source

Save the active session object

# File lib/spark_api/authentication.rb, line 46
def session=(active_session)
  @authenticator.session=active_session
end