Class: Wsaa::Credentials

Inherits:
Object
  • Object
show all
Defined in:
lib/wsaa/credentials.rb

Overview

Immutable value object for WSAA authentication credentials.

Holds the TOKEN and SIGN values returned by WSAA after successful authentication.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:, sign:, expiration_time:) ⇒ Credentials

Creates new Credentials.

Parameters:

  • token (String)

    The authentication token from WSAA.

  • sign (String)

    The authentication signature from WSAA.

  • expiration_time (Time)

    When the credentials expire.



19
20
21
22
23
24
# File 'lib/wsaa/credentials.rb', line 19

def initialize(token:, sign:, expiration_time:)
  @token = token.freeze
  @sign = sign.freeze
  @expiration_time = expiration_time
  freeze
end

Instance Attribute Details

#expiration_timeTime (readonly)

When the credentials expire.

Returns:

  • (Time)

    the current value of expiration_time



10
11
12
# File 'lib/wsaa/credentials.rb', line 10

def expiration_time
  @expiration_time
end

#signString (readonly)

The authentication signature.

Returns:

  • (String)

    the current value of sign



10
11
12
# File 'lib/wsaa/credentials.rb', line 10

def sign
  @sign
end

#tokenString (readonly)

The authentication token.

Returns:

  • (String)

    the current value of token



10
11
12
# File 'lib/wsaa/credentials.rb', line 10

def token
  @token
end

Instance Method Details

#expired?Boolean

Checks if the credentials have expired.

Returns:

  • (Boolean)

    True if expired.



30
31
32
# File 'lib/wsaa/credentials.rb', line 30

def expired?
  Time.now > expiration_time
end

#to_hHash

Converts credentials to a hash.

Returns:

  • (Hash)

    Hash with :token, :sign, and :expiration_time keys.



46
47
48
49
50
51
52
# File 'lib/wsaa/credentials.rb', line 46

def to_h
  {
    token: token,
    sign: sign,
    expiration_time: expiration_time.iso8601
  }
end

#valid?Boolean

Checks if the credentials are valid.

Returns:

  • (Boolean)

    True if not expired and has token and sign.



38
39
40
# File 'lib/wsaa/credentials.rb', line 38

def valid?
  !expired? && !token.nil? && !sign.nil?
end