Class: Adcloud::Webhook

Inherits:
Object
  • Object
show all
Defined in:
lib/adcloud/webhook.rb

Constant Summary collapse

ALL =
[:on_topic_price_update, :on_campaign_update]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events) ⇒ Webhook

Returns a new instance of Webhook.

Parameters:

  • events (Array<Hash>, String)

    Events



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

#eventsObject

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