Class: Wsaa::Credentials
- Inherits:
-
Object
- Object
- Wsaa::Credentials
- 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
-
#expiration_time ⇒ Time
readonly
When the credentials expire.
-
#sign ⇒ String
readonly
The authentication signature.
-
#token ⇒ String
readonly
The authentication token.
Instance Method Summary collapse
-
#expired? ⇒ Boolean
Checks if the credentials have expired.
-
#initialize(token:, sign:, expiration_time:) ⇒ Credentials
constructor
Creates new Credentials.
-
#to_h ⇒ Hash
Converts credentials to a hash.
-
#valid? ⇒ Boolean
Checks if the credentials are valid.
Constructor Details
#initialize(token:, sign:, expiration_time:) ⇒ Credentials
Creates new Credentials.
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_time ⇒ Time (readonly)
When the credentials expire.
10 11 12 |
# File 'lib/wsaa/credentials.rb', line 10 def expiration_time @expiration_time end |
#sign ⇒ String (readonly)
The authentication signature.
10 11 12 |
# File 'lib/wsaa/credentials.rb', line 10 def sign @sign end |
#token ⇒ String (readonly)
The authentication 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.
30 31 32 |
# File 'lib/wsaa/credentials.rb', line 30 def expired? Time.now > expiration_time end |
#to_h ⇒ Hash
Converts credentials to a hash.
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.
38 39 40 |
# File 'lib/wsaa/credentials.rb', line 38 def valid? !expired? && !token.nil? && !sign.nil? end |