Class: Skydrive::Token

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/skydrive/token.rb

Instance Method Summary collapse

Instance Method Details

#is_valid?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'app/models/skydrive/token.rb', line 10

def is_valid?
  !!self.access_token && self.expires_on && self.expires_on > Time.now
end

#refresh!Object



14
15
16
17
18
19
20
21
# File 'app/models/skydrive/token.rb', line 14

def refresh!
  results = {}
  results = self.user.skydrive_client.update_api_tokens(resource: resource, refresh_token: refresh_token, token: access_token)
  if results.key? 'access_token'
    attrs = ['token_type', 'expires_in', 'expires_on', 'not_before', 'resource', 'access_token', 'refresh_token']
    update_attributes(results.reject{|a| !attrs.include?(a)})
  end
end

#requires_refresh?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'app/models/skydrive/token.rb', line 6

def requires_refresh?
  !!(self.not_before && !self.not_before.is_a?(Time) && self.not_before < Time.now)
end