mandrill-api-delivery-method 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f93e5e4c86d1ed00d16544b53705dda7fa680cf
|
4
|
+
data.tar.gz: 89220324f4a8d2f62f55f986fa80cb33efaeb08d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cd22a5c97918674d9975379af91d518dc29bcb74f1b1526a00cfd060f9781627e1219d9b2c921b5e43922ed689c023739edcd3bb4720f3e59eea73ecc7aa8d4
|
7
|
+
data.tar.gz: 046bad63e0ee100f5f2de538fb168c0d75e31942abd73b927ea358a68d7812fbc205c94a8a127cc25878f721bd2f749dbb0026b6b5d1567aa28e43f155516d7c
|
@@ -4,6 +4,11 @@ module MandrillAPIDeliveryMethod
|
|
4
4
|
class DeliveryMethod
|
5
5
|
class InvalidOption < StandardError; end
|
6
6
|
|
7
|
+
@@deliveries = []
|
8
|
+
class << self
|
9
|
+
attr_accessor :deliveries
|
10
|
+
end
|
11
|
+
|
7
12
|
attr_accessor :settings
|
8
13
|
|
9
14
|
def initialize(options = {})
|
@@ -15,13 +20,20 @@ module MandrillAPIDeliveryMethod
|
|
15
20
|
begin
|
16
21
|
mandrill = Mandrill::API.new self.settings[:api_key]
|
17
22
|
|
18
|
-
message = {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
message = mail.mandrill_options || {}
|
24
|
+
|
25
|
+
unless message.has_key? :subject
|
26
|
+
message[:subject] = mail.subject
|
27
|
+
end
|
28
|
+
unless message.has_key? :from_email
|
29
|
+
message[:from_email] = mail.from.first
|
30
|
+
end
|
31
|
+
unless message.has_key? :to
|
32
|
+
message[:to] = []
|
33
|
+
mail.to.each do |email_address|
|
34
|
+
message[:to] << {email: email_address}
|
35
|
+
end
|
36
|
+
end
|
25
37
|
|
26
38
|
if not mail.text_part.nil?
|
27
39
|
message[:text] = mail.text_part.body.to_s
|
@@ -35,6 +47,10 @@ module MandrillAPIDeliveryMethod
|
|
35
47
|
send_at = mail.deliver_at.nil? ? Time.now.utc.to_s : mail.deliver_at.uts.to_s
|
36
48
|
|
37
49
|
result = mandrill.messages.send message, async, nil, send_at
|
50
|
+
|
51
|
+
if self.settings[:test]
|
52
|
+
self.class.deliveries << result
|
53
|
+
end
|
38
54
|
rescue Mandrill::Error => e
|
39
55
|
puts "Error delivering mail to Mandrill API: #{e.class} - #{e.message}"
|
40
56
|
raise
|
@@ -3,16 +3,22 @@ require "spec_helper"
|
|
3
3
|
describe MandrillAPIDeliveryMethod::DeliveryMethod do
|
4
4
|
before do
|
5
5
|
Mail.defaults do
|
6
|
-
delivery_method MandrillAPIDeliveryMethod::DeliveryMethod, api_key: ENV["MANDRILL_API_KEY"]
|
6
|
+
delivery_method MandrillAPIDeliveryMethod::DeliveryMethod, api_key: ENV["MANDRILL_API_KEY"], test: true
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
let(:deliveries) { MandrillAPIDeliveryMethod::DeliveryMethod.deliveries }
|
11
|
+
before(:each) do
|
12
|
+
# Clear deliveries
|
13
|
+
MandrillAPIDeliveryMethod::DeliveryMethod.deliveries = []
|
14
|
+
end
|
15
|
+
|
10
16
|
it 'raises an exception if no api key specified' do
|
11
17
|
expect { MandrillAPIDeliveryMethod::DeliveryMethod.new }.to raise_exception(MandrillAPIDeliveryMethod::DeliveryMethod::InvalidOption)
|
12
18
|
expect { MandrillAPIDeliveryMethod::DeliveryMethod.new(api_key: "123") }.to_not raise_exception
|
13
19
|
end
|
14
20
|
|
15
|
-
|
21
|
+
describe 'mail message extension' do
|
16
22
|
it 'has deliver_at' do
|
17
23
|
m = Mail::Message.new
|
18
24
|
date = Time.now
|
@@ -28,17 +34,62 @@ describe MandrillAPIDeliveryMethod::DeliveryMethod do
|
|
28
34
|
end
|
29
35
|
end
|
30
36
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
describe 'delivery' do
|
38
|
+
context 'plain' do
|
39
|
+
before(:each) do
|
40
|
+
Mail.deliver do
|
41
|
+
from 'Foo <foo@example.com>'
|
42
|
+
sender 'Baz <baz@example.com>'
|
43
|
+
reply_to 'No Reply <no-reply@example.com>'
|
44
|
+
to 'Bar <bar@example.com>'
|
45
|
+
cc 'Qux <qux@example.com>'
|
46
|
+
bcc 'Qux <qux@example.com>'
|
47
|
+
subject 'Hello'
|
48
|
+
body 'World! http://example.com'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should succeed' do
|
53
|
+
expect(deliveries.length).to eq 1
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'html' do
|
58
|
+
before(:each) do
|
59
|
+
Mail.deliver do
|
60
|
+
from 'Foo <foo@example.com>'
|
61
|
+
to 'Bar <bar@example.com>'
|
62
|
+
subject 'Hello'
|
63
|
+
text_part do
|
64
|
+
body 'World! http://example.com'
|
65
|
+
end
|
66
|
+
html_part do
|
67
|
+
content_type 'text/html; charset=UTF-8'
|
68
|
+
body '<h1>World! http://example.com</h1>'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should succeed' do
|
74
|
+
expect(deliveries.length).to eq 1
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'attachments' do
|
79
|
+
before(:each) do
|
80
|
+
Mail.deliver do
|
81
|
+
from 'Foo <foo@example.com>'
|
82
|
+
to 'Bar <bar@example.com>'
|
83
|
+
subject 'Hello'
|
84
|
+
text_part do
|
85
|
+
body 'World! http://example.com'
|
86
|
+
end
|
87
|
+
attachments[File.basename(__FILE__)] = File.read(__FILE__)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should succeed' do
|
92
|
+
expect(deliveries.length).to eq 1
|
42
93
|
end
|
43
94
|
end
|
44
95
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mandrill-api-delivery-method
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pieter Jongsma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|