Class: InstagramConnect::Account
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- InstagramConnect::Account
- Defined in:
- app/models/instagram_connect/account.rb
Overview
A connected Instagram professional account. Holds the (encrypted) access token and the identity the Graph client sends as. One row per connected account — the gem supports connecting several.
Class Method Summary collapse
-
.enable_token_encryption! ⇒ Object
Called from the engine initializer (and specs) when token encryption is enabled.
Instance Method Summary collapse
-
#refresh_access_token! ⇒ Object
Refresh via the account's auth strategy and persist the rotated token.
- #token_expired? ⇒ Boolean
Class Method Details
.enable_token_encryption! ⇒ Object
Called from the engine initializer (and specs) when token encryption is enabled. Kept as an explicit toggle so a host without Active Record Encryption configured can opt out via config.encrypt_tokens = false.
22 23 24 |
# File 'app/models/instagram_connect/account.rb', line 22 def self.enable_token_encryption! encrypts :access_token end |
Instance Method Details
#refresh_access_token! ⇒ Object
Refresh via the account's auth strategy and persist the rotated token.
31 32 33 34 |
# File 'app/models/instagram_connect/account.rb', line 31 def refresh_access_token! data = InstagramConnect::Auth.for(InstagramConnect.configuration).refresh_token(access_token: access_token) update!(access_token: data[:access_token], token_expires_at: data[:expires_at]) end |
#token_expired? ⇒ Boolean
26 27 28 |
# File 'app/models/instagram_connect/account.rb', line 26 def token_expired? token_expires_at.present? && token_expires_at <= Time.current end |