Class: Adcloud::Webhook
- Inherits:
-
Object
- Object
- Adcloud::Webhook
- Defined in:
- lib/adcloud/webhook.rb
Constant Summary collapse
- ALL =
[:on_topic_price_update, :on_campaign_update]
Instance Attribute Summary collapse
-
#events ⇒ Object
Returns the value of attribute events.
Instance Method Summary collapse
-
#initialize(events) ⇒ Webhook
constructor
A new instance of Webhook.
- #process! ⇒ Object
Constructor Details
#initialize(events) ⇒ Webhook
Returns a new instance of Webhook.
8 9 10 11 12 |
# File 'lib/adcloud/webhook.rb', line 8 def initialize(events) self.events = events.kind_of?(Array) ? events : JSON.parse(events.to_s) rescue raise ArgumentError.new("Invalid webhook event data!") end |
Instance Attribute Details
#events ⇒ Object
Returns the value of attribute events.
5 6 7 |
# File 'lib/adcloud/webhook.rb', line 5 def events @events end |
Instance Method Details
#process! ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/adcloud/webhook.rb', line 21 def process! self.events.each do |event| proc = case event.type when 'TopicDiscount.update' :on_topic_price_update when 'Booking.update' :on_campaign_update else :on_unknown_webhook end Adcloud.config.webhooks.send(proc).call(event) end end |