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.

22 lines
614 B

  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