Sha256: 188ded5b25167a87c4c32d759f1ac7639894f8c005c24f33f14b6fe6d4b67704

Contents?: true

Size: 934 Bytes

Versions: 4

Compression:

Stored size: 934 Bytes

Contents

class Mandrill::WebHook::Processor

  attr_accessor :mandrill_events, :callback_host

  # Command initialise the processor with +params+ Hash.
  # +params+ is expected to contain an array of mandrill_events
  def initialize(params={})
    @mandrill_events = JSON.parse(params['mandrill_events'] || '[]')
  end

  # Command: processes all +mandrill_events+
  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

  # Returns a suitably ecapsulated +raw_event_payload+
  def wrap_payload(raw_event_payload)
    Mandrill::WebHook::EventDecorator[raw_event_payload]
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mandrill-rails-0.0.4 lib/mandrill/web_hook/processor.rb
mandrill-rails-0.0.3 lib/mandrill/web_hook/processor.rb
mandrill-rails-0.0.2 lib/mandrill/web_hook/processor.rb
mandrill-rails-0.0.1 lib/mandrill/web_hook/processor.rb