access_token_extension.rb 510 B

1234567891011121314151617181920212223
  1. # frozen_string_literal: true
  2. module AccessTokenExtension
  3. extend ActiveSupport::Concern
  4. included do
  5. include Redisable
  6. after_commit :push_to_streaming_api
  7. end
  8. def revoke(clock = Time)
  9. update(revoked_at: clock.now.utc)
  10. end
  11. def update_last_used(request, clock = Time)
  12. update(last_used_at: clock.now.utc, last_used_ip: request.remote_ip)
  13. end
  14. def push_to_streaming_api
  15. redis.publish("timeline:access_token:#{id}", Oj.dump(event: :kill)) if revoked? || destroyed?
  16. end
  17. end