1
0

webhook_service.rb 614 B

12345678910111213141516171819202122
  1. # frozen_string_literal: true
  2. class WebhookService < BaseService
  3. def call(event, object)
  4. @event = Webhooks::EventPresenter.new(event, object)
  5. @body = serialize_event
  6. webhooks_for_event.each do |webhook_id|
  7. Webhooks::DeliveryWorker.perform_async(webhook_id, @body)
  8. end
  9. end
  10. private
  11. def webhooks_for_event
  12. Webhook.enabled.where('? = ANY(events)', @event.type).pluck(:id)
  13. end
  14. def serialize_event
  15. Oj.dump(ActiveModelSerializers::SerializableResource.new(@event, serializer: REST::Admin::WebhookEventSerializer, scope: nil, scope_name: :current_user).as_json)
  16. end
  17. end