Module: Mandrill::Rails::WebHookProcessor
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/mandrill-rails/web_hook_processor.rb
Overview
WebHookProcessor is a module that mixes in Mandrill web hook processing support to a controller in your application.
The controller is expected to be a singlular resource controller. WebHookProcessor provides the :show and :create method implementation.
-
Create a controller that includes Mandrill::Rails::WebHookProcessor
-
Direct a GET :show and POST :create route to the controller
-
Define handlers for each of the event types you want to handle
e.g. in routes.rb:
resource :webhook, :controller => 'webhook', :only => [:show,:create]
e.g. a Webhook controller:
class WebhookController < ApplicationController
include Mandrill::Rails::WebHookProcessor
# Command: handle each 'inbound' +event_payload+ from Mandrill
def handle_inbound(event_payload)
# do some stuff
end
# Define other handlers for each event type required.
# Possible event types: inbound, send, hard_bounce, soft_bounce, open, click, spam, unsub, or reject
# def handle_<event_type>(event_payload)
# # do some stuff
# end
end
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #authenticate_mandrill_request! ⇒ Object
-
#create ⇒ Object
Handles controller :create action (corresponds to a POST from Mandrill).
-
#show ⇒ Object
Handles controller :show action (corresponds to a Mandrill “are you there?” test ping).
Instance Method Details
#authenticate_mandrill_request! ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/mandrill-rails/web_hook_processor.rb', line 83 def authenticate_mandrill_request! expected_signature = request.headers['HTTP_X_MANDRILL_SIGNATURE'] mandrill_webhook_keys = self.class.mandrill_webhook_keys if Mandrill::WebHook::Processor.authentic?(expected_signature,mandrill_webhook_keys,request.original_url,request.params) true else head(:forbidden, :text => "Mandrill signature did not match.") false end end |
#create ⇒ Object
Handles controller :create action (corresponds to a POST from Mandrill).
77 78 79 80 81 |
# File 'lib/mandrill-rails/web_hook_processor.rb', line 77 def create processor = Mandrill::WebHook::Processor.new(params, self) processor.run! head(:ok) end |
#show ⇒ Object
Handles controller :show action (corresponds to a Mandrill “are you there?” test ping). Returns 200 and does nothing else.
72 73 74 |
# File 'lib/mandrill-rails/web_hook_processor.rb', line 72 def show head(:ok) end |