14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/google-api/active_record_inclusions.rb', line 14
def oauthable
define_method :oauth_hash do
{
access_token: GoogleAPI::Encrypter.decrypt!(oauth_access_token),
refresh_token: GoogleAPI::Encrypter.decrypt!(oauth_refresh_token),
expires_at: oauth_access_token_expires_at
}
end
define_method :update_oauth! do |access_token, refresh_token = nil, additional_attrs = {}|
attrs = {
oauth_access_token: GoogleAPI::Encrypter.encrypt!(access_token),
oauth_access_token_expires_at: 59.minutes.from_now }.merge(additional_attrs)
attrs[:oauth_refresh_token] = GoogleAPI::Encrypter.encrypt!(refresh_token) if refresh_token
update_attributes(attrs)
end
define_method :google do
GoogleAPI::Client.new(self)
end
end
|