mandrill-rails 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmQ2MDY0YjM3NjJmMjgxOTAyOWE2Y2JkZjYzMjA1MmY0MDAxNmZmNg==
4
+ M2JlYTA0MzljZWVlNzAzZTNkNzdiMmJkMjEzNTZhNjkyMjIxNzVhZQ==
5
5
  data.tar.gz: !binary |-
6
- ZThjYmEyZTM5NDdjOGIzMWVlYzgwZjNlZDNkYzY2YTY3MGJjZjliNg==
6
+ OGJmZWEwMTI3MzA2MWQ4YjA3MzYwNWIwNTRiMjk4NmI0ODk2M2IxYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YThjYTM1NTA4MDVkNzMzY2I1YjNjZjU3YTEyNzJkODcwOGJhZmZmMjNjYThm
10
- YTRiNDAyZGUzZmVjNTYyODQ0MDdiODllNWVhYjE0ZDI1YTI3NTcwYzhmYTYw
11
- M2ZmYWFhNGM3OWMxZTkxNzZhYjE3ZTU4YmM1MThiYTEzZDQ1YjE=
9
+ N2E3N2ZlZDE1MzMyMzM4ODA2M2IyOTVkMzc5NjdiNmVmMDE4Y2UxYWYwOTQ5
10
+ Mzc2ZGQyNDRiMjBhZGViMWE2MGQ1MGY2OTdhZTA3N2UwMDNhMWI5MGUyM2M5
11
+ YTdkOWNmNWJmYmVjZTgzMzIyMjBjNTkxN2E4OTk5NmMwOTBiYjQ=
12
12
  data.tar.gz: !binary |-
13
- MWU3YWI2ODc4ZGQ3YTdkYzM1NTdiOTcxZTg2OGRlZDJhMDZmYmEzNGI3Nzhj
14
- MzYwMGQ3OWZhNThjYzg2YmVmMzExNmQ5MDBjYzExNjAwZDhkYzU2ZTczZjAy
15
- NjQ4NjkwYTNmM2YwOGY3YTlkOTY0Y2EzNDBkODZhMzViNWFlNmY=
13
+ MzM3OGI2NDhmOGM3ZDkwYWYxY2Y3ZmQ5YzczYTZlMGMxMDk1ZDU3MWZhZDAy
14
+ Mjc2ZDU4ZWE5M2I1ZjI2YTM5YmIzYzRiZGQzYWQ2NGViZWI5YWM4N2M3MjEx
15
+ NGQ1MjQ0ZmI2ZjA0YTFhZWYyMGRiNTAzMDNhYmU5NWUwYmQ1OGM=
@@ -5,4 +5,5 @@ require 'active_support/core_ext'
5
5
 
6
6
  require "mandrill-rails/version"
7
7
  require 'mandrill/web_hook'
8
+ require 'mandrill-rails/errors'
8
9
  require 'mandrill-rails/web_hook_processor'
@@ -0,0 +1,4 @@
1
+ module Mandrill::Rails::Errors
2
+ Base = Class.new(StandardError)
3
+ MissingEventHandler = Class.new(Base)
4
+ end
@@ -3,5 +3,5 @@ module Mandrill
3
3
  end
4
4
  end
5
5
  unless defined?(Mandrill::Rails::VERSION)
6
- Mandrill::Rails::VERSION = "1.0.2"
6
+ Mandrill::Rails::VERSION = "1.1.0"
7
7
  end
@@ -42,6 +42,11 @@ class Mandrill::WebHook::EventDecorator < Hash
42
42
  msg['_version']
43
43
  end
44
44
 
45
+ # Returns, if pre-configured, the metadata.
46
+ def metadata
47
+ msg['metadata']||{}
48
+ end
49
+
45
50
  # Returns the reply-to ID.
46
51
  # Applicable events: inbound
47
52
  def in_reply_to
@@ -21,12 +21,13 @@ class Mandrill::WebHook::Processor
21
21
  mandrill_events.each do |raw_payload|
22
22
  event_payload = wrap_payload(raw_payload)
23
23
  handler = "handle_#{event_payload.event_type}".to_sym
24
- if callback_host && callback_host.respond_to?(handler)
24
+ if callback_host && callback_host.respond_to?(handler, true)
25
25
  callback_host.send(handler,event_payload)
26
26
  elsif self.respond_to?(handler)
27
27
  self.send(handler,event_payload)
28
28
  else
29
- # TODO raise an error
29
+ raise Mandrill::Rails::Errors::MissingEventHandler,
30
+ "Expected handler method `#{handler}` for event type `#{event_payload.event_type}`"
30
31
  end
31
32
  end
32
33
  end
@@ -20,18 +20,67 @@ describe Mandrill::WebHook::Processor do
20
20
  end
21
21
  end
22
22
  context "with callback host" do
23
- let(:callback_host) do
24
- host = double()
25
- host.stub(:handle_inbound)
26
- host
23
+ shared_examples_for 'pass event payload to the handler' do
24
+
27
25
  end
26
+
27
+ let(:callback_host) { callback_host_class.new }
28
28
  let(:processor) { processor_class.new(params,callback_host) }
29
29
  let(:event1) { { "event" => "inbound" } }
30
30
  let(:event2) { { "event" => "inbound" } }
31
31
  let(:params) { { "mandrill_events" => [event1,event2].to_json } }
32
- it "should pass event payload to the handler" do
33
- callback_host.should_receive(:handle_inbound).twice
34
- processor.run!
32
+
33
+ context "with handler method as public" do
34
+ let(:callback_host_class) do
35
+ Class.new do
36
+ public
37
+
38
+ def handle_inbound; end
39
+ end
40
+ end
41
+
42
+ it "should pass event payload to the handler" do
43
+ callback_host.should_receive(:handle_inbound).twice
44
+ processor.run!
45
+ end
46
+ end
47
+ context "with handler method as protected" do
48
+ let(:callback_host_class) do
49
+ Class.new do
50
+ protected
51
+
52
+ def handle_inbound; end
53
+ end
54
+ end
55
+
56
+ it "should pass event payload to the handler" do
57
+ callback_host.should_receive(:handle_inbound).twice
58
+ processor.run!
59
+ end
60
+ end
61
+ context "with handler method as private" do
62
+ let(:callback_host_class) do
63
+ Class.new do
64
+ private
65
+
66
+ def handle_inbound; end
67
+ end
68
+ end
69
+
70
+ it "should pass event payload to the handler" do
71
+ callback_host.should_receive(:handle_inbound).twice
72
+ processor.run!
73
+ end
74
+ end
75
+ end
76
+ context "without handler method" do
77
+ let(:event1) { { "event" => "inbound" } }
78
+ let(:event2) { { "event" => "inbound" } }
79
+ let(:params) { { "mandrill_events" => [event1,event2].to_json } }
80
+
81
+ it "raises error on run!" do
82
+ expect { processor.run! }
83
+ .to raise_error(Mandrill::Rails::Errors::MissingEventHandler)
35
84
  end
36
85
  end
37
86
  end
@@ -79,4 +128,4 @@ describe Mandrill::WebHook::Processor do
79
128
  it { should eql(expected_signature) }
80
129
  end
81
130
 
82
- end
131
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mandrill-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Gallagher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-20 00:00:00.000000000 Z
11
+ date: 2015-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -110,6 +110,7 @@ files:
110
110
  - README.rdoc
111
111
  - Rakefile
112
112
  - lib/mandrill-rails.rb
113
+ - lib/mandrill-rails/errors.rb
113
114
  - lib/mandrill-rails/version.rb
114
115
  - lib/mandrill-rails/web_hook_processor.rb
115
116
  - lib/mandrill/web_hook.rb
@@ -158,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
159
  version: '0'
159
160
  requirements: []
160
161
  rubyforge_project:
161
- rubygems_version: 2.2.2
162
+ rubygems_version: 2.4.5
162
163
  signing_key:
163
164
  specification_version: 4
164
165
  summary: Provides webhook processing and event decoration to make using Mandrill with