Module: BookingSync::Engine::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/bookingsync/engine/model.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #api ⇒ Object
- #clear_token! ⇒ Object
- #token ⇒ Object
- #update_token(token) ⇒ Object
- #update_token!(token) ⇒ Object
Instance Method Details
#api ⇒ Object
39 40 41 |
# File 'lib/bookingsync/engine/model.rb', line 39 def api @api ||= BookingSync::API::Client.new(token.token) end |
#clear_token! ⇒ Object
54 55 56 57 58 59 |
# File 'lib/bookingsync/engine/model.rb', line 54 def clear_token! self.oauth_access_token = nil self.oauth_refresh_token = nil self.oauth_expires_at = nil save! end |
#token ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bookingsync/engine/model.rb', line 19 def token @token ||= begin = {} if oauth_refresh_token [:refresh_token] = oauth_refresh_token [:expires_at] = oauth_expires_at end token = OAuth2::AccessToken.new(BookingSync::Engine.oauth_client, oauth_access_token, ) if token.expired? token = token.refresh! update_token!(token) end token end end |
#update_token(token) ⇒ Object
43 44 45 46 47 |
# File 'lib/bookingsync/engine/model.rb', line 43 def update_token(token) self.oauth_access_token = token.token self.oauth_refresh_token = token.refresh_token self.oauth_expires_at = token.expires_at end |
#update_token!(token) ⇒ Object
49 50 51 52 |
# File 'lib/bookingsync/engine/model.rb', line 49 def update_token!(token) update_token(token) save! end |