Class: Trustpilot::Auth::Token
- Inherits:
-
Object
- Object
- Trustpilot::Auth::Token
- Defined in:
- lib/trustpilot/auth/token.rb
Class Method Summary collapse
- .destroy ⇒ Object
- .expired? ⇒ Boolean
- .get ⇒ Object
- .set(value, expires_at) ⇒ Object
- .valid? ⇒ Boolean
Class Method Details
.destroy ⇒ Object
21 22 23 24 25 |
# File 'lib/trustpilot/auth/token.rb', line 21 def destroy Trustpilot.with_redis do |r| r.del _redis_key( 'token' ), _redis_key( 'expires_at' ) end end |
.expired? ⇒ Boolean
27 28 29 30 31 32 33 34 |
# File 'lib/trustpilot/auth/token.rb', line 27 def expired? expiration = _token_expires_at return true unless expiration # TODO: is this timezone compatible? expiration <= Time.now end |
.get ⇒ Object
9 10 11 12 13 |
# File 'lib/trustpilot/auth/token.rb', line 9 def get Trustpilot.with_redis do |r| r.get _redis_key( 'token' ) end end |
.set(value, expires_at) ⇒ Object
15 16 17 18 19 |
# File 'lib/trustpilot/auth/token.rb', line 15 def set value, expires_at Trustpilot.with_redis do |r| r.mset _redis_key( 'token' ), value, _redis_key( 'expires_at' ), expires_at end end |
.valid? ⇒ Boolean
36 37 38 |
# File 'lib/trustpilot/auth/token.rb', line 36 def valid? !expired? end |