Module: Integral::Webhook::Delivery
- Extended by:
- ActiveSupport::Concern
- Included in:
- Observable
- Defined in:
- app/models/concerns/integral/webhook/delivery.rb
Overview
Helper to handle the delivery of webhook events
Instance Method Summary collapse
-
#deliver_webhook(action) ⇒ Object
Build event_name and delivery webhook.
-
#deliver_webhook_event(event_name, payload) ⇒ Object
Create webhook event and deliver it to any endpoint listening.
-
#webhook_payload ⇒ Hash
Abstract method to be overriden.
Instance Method Details
#deliver_webhook(action) ⇒ Object
Build event_name and delivery webhook
15 16 17 18 |
# File 'app/models/concerns/integral/webhook/delivery.rb', line 15 def deliver_webhook(action) event_name = "#{self.class.name.underscore}_#{action}" deliver_webhook_event(event_name, webhook_payload) end |
#deliver_webhook_event(event_name, payload) ⇒ Object
Create webhook event and deliver it to any endpoint listening
21 22 23 24 25 26 27 |
# File 'app/models/concerns/integral/webhook/delivery.rb', line 21 def deliver_webhook_event(event_name, payload) event = Webhook::Event.new(event_name, payload || {}) Endpoint.for_event(event_name).each do |endpoint| endpoint.deliver(event) end end |
#webhook_payload ⇒ Hash
Abstract method to be overriden
10 11 12 |
# File 'app/models/concerns/integral/webhook/delivery.rb', line 10 def webhook_payload {} end |