Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

\#4 switch key configuration to use authenticate_with_mandrill_keys!

  • Loading branch information...
commit 01210386aa0f462fd482ad25b457b3b1ab2419db 1 parent 3877548
Paul Gallagher tardate authored
8 README.rdoc
View
@@ -119,14 +119,14 @@ Mandrill now supports {webhook authentication}[http://help.mandrill.com/entries/
If you do not configure your webhook API key, then the handlers will continue to work fine - they just won't be authenticated.
-To enable authentication, use the <tt>mandrill_webhook_keys</tt> method to set your API key. It is recommended you pull
+To enable authentication, use the <tt>authenticate_with_mandrill_keys!</tt> method to set your API key. It is recommended you pull
your API keys from environment settings, or use some other means to avoid committing the API keys in your source code.
For example, to handle inbound email:
class InboxController < ApplicationController
include Mandrill::Rails::WebHookProcessor
- mandrill_webhook_keys 'YOUR_MANDRILL_WEBHOOK_KEY'
+ authenticate_with_mandrill_keys! 'YOUR_MANDRILL_WEBHOOK_KEY'
def handle_inbound(event_payload)
# .. handler methods will only be called if authentication has succeeded.
@@ -138,11 +138,11 @@ For example, to handle inbound email:
Sometimes you may have more than one WebHook sending requests to a single controller, for example if you have one handling 'click' events, and another sending inbound email. Mandrill assigns separate API keys to each of these.
-In this case, just add all the valid API keys you will allow with <tt>mandrill_webhook_keys</tt>, for example:
+In this case, just add all the valid API keys you will allow with <tt>authenticate_with_mandrill_keys!</tt>, for example:
class InboxController < ApplicationController
include Mandrill::Rails::WebHookProcessor
- mandrill_webhook_keys 'MANDRILL_CLICK_WEBHOOK_KEY', 'MANDRILL_INBOUND_WEBHOOK_KEY', 'ANOTHER_WEBHOOK_KEY'
+ authenticate_with_mandrill_keys! 'MANDRILL_CLICK_WEBHOOK_KEY', 'MANDRILL_INBOUND_WEBHOOK_KEY', 'ANOTHER_WEBHOOK_KEY'
def handle_inbound(event_payload)
end
10 lib/mandrill-rails/web_hook_processor.rb
View
@@ -39,10 +39,11 @@ module Mandrill::Rails::WebHookProcessor
end
module ClassMethods
+ # Gets/sets the current Mandrill WebHook Authentication key(s).
# Returns the current WebHook key(s) as an Array if called with no parameters.
# If called with parameters, add the params to the WebHook key array.
# If called with nil as the parameters, clears the WebHook key array.
- def mandrill_webhook_keys(*keys)
+ def authenticate_with_mandrill_keys!(*keys)
@mandrill_webhook_keys ||= []
if keys.present?
if keys.compact.present?
@@ -54,7 +55,12 @@ def mandrill_webhook_keys(*keys)
@mandrill_webhook_keys
end
- # Command: directly assigns the WebHook key array to +keys+
+ # Gets the current Mandrill WebHook Authentication key(s).
+ def mandrill_webhook_keys
+ authenticate_with_mandrill_keys!
+ end
+
+ # Command: directly assigns the WebHook key array to +keys+.
def mandrill_webhook_keys=(keys)
@mandrill_webhook_keys = Array(keys)
end
29 spec/mandrill-rails/web_hook_processor_spec.rb
View
@@ -17,7 +17,7 @@ def head(*args) ; end
let(:processor_class) { WebHookProcessorTestHarness }
let(:processor_instance) { processor_class.new }
before do
- processor_class.mandrill_webhook_keys nil
+ processor_class.authenticate_with_mandrill_keys! nil
end
describe "##skip_before_filter settings" do
@@ -30,32 +30,47 @@ def head(*args) ; end
it { should eql([:authenticate_mandrill_request!, {:only=>[:create]}]) }
end
- describe "##mandrill_webhook_keys" do
+ describe "##authenticate_with_mandrill_keys!" do
subject { processor_class.mandrill_webhook_keys }
it { should eql([]) }
context "when set with a single value" do
let(:key_a) { "key_a" }
- before { processor_class.mandrill_webhook_keys key_a }
+ before { processor_class.authenticate_with_mandrill_keys! key_a }
it { should eql([key_a]) }
context "then called with nil" do
- before { processor_class.mandrill_webhook_keys nil }
+ before { processor_class.authenticate_with_mandrill_keys! nil }
it { should eql([]) }
end
end
context "when set with a list of values" do
let(:key_a) { "key_a" }
let(:key_b) { "key_b" }
- before { processor_class.mandrill_webhook_keys key_a, key_b }
+ before { processor_class.authenticate_with_mandrill_keys! key_a, key_b }
it { should eql([key_a,key_b]) }
end
context "when set with an explicit array of values" do
let(:key_a) { "key_a" }
let(:key_b) { "key_b" }
- before { processor_class.mandrill_webhook_keys [key_a, key_b] }
+ before { processor_class.authenticate_with_mandrill_keys! [key_a, key_b] }
it { should eql([key_a,key_b]) }
end
end
+ describe "#mandrill_webhook_keys" do
+ subject { processor_class.mandrill_webhook_keys }
+ it { should eql([]) }
+ context "when set with mandrill_webhook_keys=" do
+ let(:expected_value) { [1,2,3] }
+ before { processor_class.mandrill_webhook_keys = expected_value }
+ it { should eql(expected_value) }
+ end
+ context "when set with authenticate_with_mandrill_keys!" do
+ let(:expected_value) { [4,5,6] }
+ before { processor_class.authenticate_with_mandrill_keys! expected_value }
+ it { should eql(expected_value) }
+ end
+ end
+
subject { processor_instance }
@@ -101,7 +116,7 @@ def head(*args) ; end
end
context "when authentication enabled" do
before do
- processor_class.mandrill_webhook_keys mandrill_webhook_keys
+ processor_class.authenticate_with_mandrill_keys! mandrill_webhook_keys
end
context "with valid key" do
let(:mandrill_webhook_keys) { valid_webhook_key }
Please sign in to comment.
Something went wrong with that request. Please try again.