Class: Mandrill::WebHook::Processor
- Inherits:
-
Object
- Object
- Mandrill::WebHook::Processor
- Defined in:
- lib/mandrill/web_hook/processor.rb
Instance Attribute Summary collapse
-
#callback_host ⇒ Object
Returns the value of attribute callback_host.
-
#mandrill_events ⇒ Object
Returns the value of attribute mandrill_events.
-
#on_unhandled_mandrill_events ⇒ Object
Returns the value of attribute on_unhandled_mandrill_events.
-
#params ⇒ Object
Returns the value of attribute params.
Class Method Summary collapse
-
.authentic?(expected_signature, mandrill_webhook_keys, original_url, params) ⇒ Boolean
Returns true if
params
sent tooriginal_url
are authentic givenexpected_signature
andmandrill_webhook_keys
. -
.generate_signature(webhook_key, original_url, params) ⇒ Object
Method described in docs: help.mandrill.com/entries/23704122-Authenticating-webhook-requests.
Instance Method Summary collapse
-
#initialize(params = {}, callback_host = nil) ⇒ Processor
constructor
Command initialise the processor with
params
Hash. -
#run! ⇒ Object
Command: processes all
mandrill_events
.
Constructor Details
#initialize(params = {}, callback_host = nil) ⇒ Processor
Command initialise the processor with params
Hash. params
is expected to contain an array of mandrill_events. callback_host
is a handle to the controller making the request.
9 10 11 12 |
# File 'lib/mandrill/web_hook/processor.rb', line 9 def initialize(params={},callback_host=nil) self.params = params self.callback_host = callback_host end |
Instance Attribute Details
#callback_host ⇒ Object
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_events ⇒ Object
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 |
#on_unhandled_mandrill_events ⇒ Object
Returns the value of attribute on_unhandled_mandrill_events.
4 5 6 |
# File 'lib/mandrill/web_hook/processor.rb', line 4 def on_unhandled_mandrill_events @on_unhandled_mandrill_events end |
#params ⇒ Object
Returns the value of attribute params.
3 4 5 |
# File 'lib/mandrill/web_hook/processor.rb', line 3 def params @params end |
Class Method Details
.authentic?(expected_signature, mandrill_webhook_keys, original_url, params) ⇒ Boolean
Returns true if params
sent to original_url
are authentic given expected_signature
and mandrill_webhook_keys
.
27 28 29 30 31 32 33 34 35 |
# File 'lib/mandrill/web_hook/processor.rb', line 27 def authentic?(expected_signature, mandrill_webhook_keys, original_url, params) result = true Array(mandrill_webhook_keys).each do |key| signature = generate_signature(key, original_url, params) result = (signature == expected_signature) break if result end result end |
.generate_signature(webhook_key, original_url, params) ⇒ Object
Method described in docs: help.mandrill.com/entries/23704122-Authenticating-webhook-requests
38 39 40 41 42 43 44 45 |
# File 'lib/mandrill/web_hook/processor.rb', line 38 def generate_signature(webhook_key, original_url, params) signed_data = original_url.dup params.keys.sort.each do |key| signed_data << key signed_data << params[key] end Base64.encode64("#{OpenSSL::HMAC.digest('sha1', webhook_key, signed_data)}").strip end |
Instance Method Details
#run! ⇒ Object
Command: processes all mandrill_events
19 20 21 22 23 |
# File 'lib/mandrill/web_hook/processor.rb', line 19 def run! mandrill_events.each do |raw_payload| process_event(Mandrill::WebHook::EventDecorator[raw_payload]) end end |