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
34 35 36 |
# File 'lib/bookingsync/engine/model.rb', line 34 def api @api ||= BookingSync::API::Client.new(token.token) end |
#clear_token! ⇒ Object
49 50 51 52 53 54 |
# File 'lib/bookingsync/engine/model.rb', line 49 def clear_token! self.oauth_access_token = nil self.oauth_refresh_token = nil self.oauth_expires_at = nil save! end |
#token ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bookingsync/engine/model.rb', line 14 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
38 39 40 41 42 |
# File 'lib/bookingsync/engine/model.rb', line 38 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
44 45 46 47 |
# File 'lib/bookingsync/engine/model.rb', line 44 def update_token!(token) update_token(token) save! end |