Module: Genius::Auth

Defined in:
lib/genius/api/authorization.rb

Overview

Genius::Auth module is used to authenticate users with their token. It provides initialization of token instance variable.

Examples:

Genius::Auth.="yuiaYqbncErCVwItjQxFspNWUZLhGpXrPbkvgbgHSEKJRAlToamzMfdOeDB"

Class Method Summary collapse

Class Method Details

.authorized?(token = @token, method_name: "#{Module.nesting[1].name}.#{__method__}") ⇒ Boolean

TODO:

somehow detect exceptions as boolean type

Genius::Auth.authorized? -> true or false

authorized? method checks if user in current session is authorized.

Parameters:

  • method_name (NilClass|String) (defaults to: "#{Module.nesting[1].name}.#{__method__}")

    Optional param to pass method name where exception was raised.

Returns:

  • (Boolean)

Raises:

  • (TokenError)

    if token is invalid.



36
37
38
39
40
41
42
# File 'lib/genius/api/authorization.rb', line 36

def authorized?(token = @token, method_name: "#{Module.nesting[1].name}.#{__method__}")
  Errors.validate_token(token, method_name: method_name)
rescue Genius::Errors::TokenError
  false
else
  true
end

.logout!NilClass

Genius::Auth.logout! -> NilClass

logout! method modifies a token object and revoke session by setting nil to the token.

Returns:

  • (NilClass)


50
51
52
# File 'lib/genius/api/authorization.rb', line 50

def logout!
  @token = nil unless @token.nil?
end

.token=(token) ⇒ String Also known as: login=

Genius::Auth.token= -> true or false

Genius::Auth.token= is a setter which handles all possible exceptions under the hood during authentication. It means that you should never use token= method unless you actually know that your credentials are valid (not recommended).

Parameters:

Returns:

Raises:

  • (TokenError)

    if token is invalid.

See Also:



22
23
24
25
# File 'lib/genius/api/authorization.rb', line 22

def token=(token)
  Genius::Errors.validate_token(token)
  @token = token
end