Class: Oshpark::Token
Instance Attribute Summary collapse
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
Class Method Summary collapse
Instance Method Summary collapse
- #authentic? ⇒ Boolean
-
#initialize(json = {}) ⇒ Token
constructor
A new instance of Token.
- #ttl ⇒ Object
- #user ⇒ Object
- #valid? ⇒ Boolean
Methods included from Model
Constructor Details
#initialize(json = {}) ⇒ Token
Returns a new instance of Token.
6 7 8 9 |
# File 'lib/oshpark/token.rb', line 6 def initialize json={} super @expires_at = Time.now + (@ttl || 0) end |
Instance Attribute Details
#expires_at ⇒ Object
Returns the value of attribute expires_at.
4 5 6 |
# File 'lib/oshpark/token.rb', line 4 def expires_at @expires_at end |
Class Method Details
.attrs ⇒ Object
11 12 13 |
# File 'lib/oshpark/token.rb', line 11 def self.attrs %w| token ttl user_id | end |
Instance Method Details
#authentic? ⇒ Boolean
29 30 31 |
# File 'lib/oshpark/token.rb', line 29 def authentic? valid? && !!user_id end |
#ttl ⇒ Object
17 18 19 |
# File 'lib/oshpark/token.rb', line 17 def ttl expires_at - Time.now end |
#user ⇒ Object
21 22 23 |
# File 'lib/oshpark/token.rb', line 21 def user User.from_json 'id' => user_id end |
#valid? ⇒ Boolean
25 26 27 |
# File 'lib/oshpark/token.rb', line 25 def valid? ttl > 0 end |