class Lifen::Token
Public Instance Methods
active?()
click to toggle source
# File lib/lifen/token.rb, line 24 def active? valid? and !needs_to_be_refreshed? end
has_expired?()
click to toggle source
# File lib/lifen/token.rb, line 38 def has_expired? return true if expires_at.nil? return expires_at < Time.now.to_i end
needs_to_be_refreshed?()
click to toggle source
# File lib/lifen/token.rb, line 32 def needs_to_be_refreshed? return true if has_expired? return (expires_at - expiration_margin) < Time.now.to_i end
refresh()
click to toggle source
# File lib/lifen/token.rb, line 44 def refresh json = client.post("/oauth/admin/third_party/access_token?accountUuid=#{user.uuid}") self.value = json["access_token"] self.expires_at = Time.now.to_i + json["expires_in"].to_i end
refresh_once_if_needed()
click to toggle source
# File lib/lifen/token.rb, line 51 def refresh_once_if_needed Lifen.configuration.token_refresh_lock.synchronize do load_from_db.call(self) if load_from_db.is_a? Proc return if active? refresh save_to_db.call(self) if save_to_db.is_a? Proc raise Error, "Token can't be refreshed" if !active? end end
to_s()
click to toggle source
# File lib/lifen/token.rb, line 20 def to_s value end
valid?()
click to toggle source
# File lib/lifen/token.rb, line 28 def valid? !value.nil? and value.length > 0 and !expires_at.nil? end
Private Instance Methods
client()
click to toggle source
# File lib/lifen/token.rb, line 68 def client @client ||= AppAuthenticatedClient.new end
expiration_margin()
click to toggle source
# File lib/lifen/token.rb, line 72 def expiration_margin Lifen.configuration.expiration_margin end