Class: Mandrill::WebHook::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/mandrill/web_hook/processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Processor

Command initialise the processor with params Hash. params is expected to contain an array of mandrill_events



7
8
9
# File 'lib/mandrill/web_hook/processor.rb', line 7

def initialize(params={})
  @mandrill_events = JSON.parse(params['mandrill_events'] || '[]')
end

Instance Attribute Details

#callback_hostObject

Returns the value of attribute callback_host.



3
4
5
# File 'lib/mandrill/web_hook/processor.rb', line 3

def callback_host
  @callback_host
end

#mandrill_eventsObject

Returns the value of attribute mandrill_events.



3
4
5
# File 'lib/mandrill/web_hook/processor.rb', line 3

def mandrill_events
  @mandrill_events
end

Instance Method Details

#run!Object

Command: processes all mandrill_events



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mandrill/web_hook/processor.rb', line 12

def run!
  mandrill_events.each do |raw_payload|
    event_payload = wrap_payload(raw_payload)
    handler = "handle_#{event_payload.event_type}".to_sym
    if callback_host && callback_host.respond_to?(handler)
      callback_host.send(handler,event_payload)
    elsif self.respond_to?(handler)
      self.send(handler,event_payload)
    else
      # TODO raise an error
    end
  end
end

#wrap_payload(raw_event_payload) ⇒ Object

Returns a suitably ecapsulated raw_event_payload



27
28
29
# File 'lib/mandrill/web_hook/processor.rb', line 27

def wrap_payload(raw_event_payload)
  Mandrill::WebHook::EventDecorator[raw_event_payload]
end