Class: Oshpark::Token

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/oshpark/token.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

#dirty?, included

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_atObject

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

.attrsObject



11
12
13
# File 'lib/oshpark/token.rb', line 11

def self.attrs
  %w| token ttl user_id |
end

Instance Method Details

#authentic?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/oshpark/token.rb', line 29

def authentic?
  valid? && !!user_id
end

#ttlObject



17
18
19
# File 'lib/oshpark/token.rb', line 17

def ttl
  expires_at - Time.now
end

#userObject



21
22
23
# File 'lib/oshpark/token.rb', line 21

def user
  User.from_json 'id' => user_id
end

#valid?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/oshpark/token.rb', line 25

def valid?
  ttl > 0
end