You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
495 B

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