http_mailer 0.0.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +22 -42
- data/lib/http_mailer.rb +1 -0
- data/lib/http_mailer/client.rb +1 -0
- data/lib/http_mailer/version.rb +1 -1
- data/spec/client_spec.rb +36 -0
- data/spec/spec_helper.rb +25 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b17235bd4f2440fe70e8aa104b5f94e42aa3b21
|
4
|
+
data.tar.gz: d951071c220ad2e726a2132664dd9c361ce795ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3c036b9b37a7f87c785b80c92d5621f9b834eb6e0b078caeedebd33690d8d76ce141b1f1079ec1f36ff754428c9ec4c2e13ff01bbb40a69aa61cd7e0e3060cb
|
7
|
+
data.tar.gz: 7013bbcd5ba70bd8d7123bac6e2318e4395ba626841940a79a05c12c1bcbe8ba27eb5456a44d1b6700ac46b272b9b08218282db8c605f6d7f058554c38d793ba
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# HttpMailer
|
2
2
|
|
3
|
-
|
3
|
+
Sends emails via SendGrid, Mailgun, or Mandrill HTTP APIs.
|
4
|
+
HttpMailer attempts to send an email once with each service
|
5
|
+
until an attempt is completed successfully.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -23,27 +25,24 @@ Or install it yourself as:
|
|
23
25
|
Mailgun
|
24
26
|
|
25
27
|
```ruby
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
host: "mandrillapp.com",
|
45
|
-
api_key: "XXXXXXXXX"
|
46
|
-
})
|
28
|
+
settings = {
|
29
|
+
sendgrid: {
|
30
|
+
host: "sendgrid.com",
|
31
|
+
api_user: "username",
|
32
|
+
api_key: "XXXXXXXXX"
|
33
|
+
},
|
34
|
+
mailgun: {
|
35
|
+
host: "api.mailgun.net",
|
36
|
+
api_key: "XXXXXXXXX",
|
37
|
+
subdomain: "samples.mailgun.net"
|
38
|
+
},
|
39
|
+
mandrill: {
|
40
|
+
host: "mandrillapp.com",
|
41
|
+
api_key: "XXXXXXXXX"
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
http_mailer_client = HttpMailer::Client.new(settings)
|
47
46
|
|
48
47
|
from = "papa@prose.com"
|
49
48
|
from_name = "Ernest Hemingway"
|
@@ -54,26 +53,7 @@ text = "Every man's life ends the same way. \
|
|
54
53
|
It is only the details of how he lived and \
|
55
54
|
how he died that distinguish one man from another."
|
56
55
|
|
57
|
-
|
58
|
-
```
|
59
|
-
|
60
|
-
SendGrid
|
61
|
-
|
62
|
-
```ruby
|
63
|
-
sendgrid_client = HttpMailer.sendgrid({
|
64
|
-
host: "sendgrid.com",
|
65
|
-
api_user: "username",
|
66
|
-
api_key: "XXXXXXXXX"
|
67
|
-
})
|
68
|
-
|
69
|
-
from = "jcash@tennesseethree.com"
|
70
|
-
from_name = "Johnny Cash"
|
71
|
-
to = "elvis@graceland.com"
|
72
|
-
to_name = "Elvis Presley"
|
73
|
-
subject = "Hello"
|
74
|
-
text = "Success is having to worry about every damn thing in the world, except money."
|
75
|
-
|
76
|
-
sendgrid_client.send_message(from, to, subject, text, to_name, from_name)
|
56
|
+
http_mailer_client.send_message(from, to, subject, text, to_name, from_name)
|
77
57
|
```
|
78
58
|
|
79
59
|
## Contributing
|
data/lib/http_mailer.rb
CHANGED
data/lib/http_mailer/client.rb
CHANGED
data/lib/http_mailer/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -28,6 +28,42 @@ describe HttpMailer::Client do
|
|
28
28
|
response = mailer_client.send_message(sender, reciever, subject, email_body)
|
29
29
|
expect(response.code).to eq(200)
|
30
30
|
end
|
31
|
+
|
32
|
+
context 'sendgrid is down' do
|
33
|
+
let(:sendgrid_down_settings){ {:mailgun => {:host => "api.mailgun.net", :api_key => "key-12345", :subdomain => "sandbox12345.mailgun.org"},
|
34
|
+
:sendgrid => {:host => "sendgriddown.com", :api_user=> "test", :api_key => "1234"},
|
35
|
+
:mandrill => {:host => "mandrillapp.com", :api_key => "1234567890"}} }
|
36
|
+
let(:mailer_client_sendgrid_down){ HttpMailer::Client.new(sendgrid_down_settings) }
|
37
|
+
|
38
|
+
it 'sends an email' do
|
39
|
+
response = mailer_client_sendgrid_down.send_message(sender, reciever, subject, email_body)
|
40
|
+
expect(response.code).to eq(200)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'sendgrid and mailgun is down' do
|
45
|
+
let(:sendgrid_and_mailgun_down_settings){ {:mailgun => {:host => "api.mailgundown.net", :api_key => "key-12345", :subdomain => "sandbox12345.mailgun.org"},
|
46
|
+
:sendgrid => {:host => "sendgriddown.com", :api_user=> "test", :api_key => "1234"},
|
47
|
+
:mandrill => {:host => "mandrillapp.com", :api_key => "1234567890"}} }
|
48
|
+
let(:mailer_client_sendgrid_and_mailgun_down){ HttpMailer::Client.new(sendgrid_and_mailgun_down_settings) }
|
49
|
+
|
50
|
+
it 'sends an email' do
|
51
|
+
response = mailer_client_sendgrid_and_mailgun_down.send_message(sender, reciever, subject, email_body)
|
52
|
+
expect(response.code).to eq(200)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'all services are down' do
|
57
|
+
let(:all_down_settings){ {:mailgun => {:host => "api.mailgundown.net", :api_key => "key-12345", :subdomain => "sandbox12345.mailgun.org"},
|
58
|
+
:sendgrid => {:host => "sendgriddown.com", :api_user=> "test", :api_key => "1234"},
|
59
|
+
:mandrill => {:host => "mandrillappdown.com", :api_key => "1234567890"}} }
|
60
|
+
let(:mailer_client_all_down){ HttpMailer::Client.new(all_down_settings) }
|
61
|
+
|
62
|
+
it 'raises an exception' do
|
63
|
+
expect { mailer_client_all_down.send_message(sender, reciever, subject, email_body) }.to raise_exception(HttpMailer::EmailDeliveryError)
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
31
67
|
end
|
32
68
|
end
|
33
69
|
|
data/spec/spec_helper.rb
CHANGED
@@ -12,6 +12,16 @@ RSpec.configure do |config|
|
|
12
12
|
:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'224', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
|
13
13
|
to_return(:status => 200, :body => "", :headers => {})
|
14
14
|
|
15
|
+
stub_request(:post, "https://api:key-12345@api.mailgun.net/v2/sandbox12345.mailgun.org/messages").
|
16
|
+
with(:body => {"from"=>"sender@test.com", "subject"=>"Hello", "text"=>"Congratulations, you just sent an email with HttpMailer! You are truly awesome!", "to"=>"reciever@test.com>"},
|
17
|
+
:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'174', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
|
18
|
+
to_return(:status => 200, :body => "", :headers => {})
|
19
|
+
|
20
|
+
stub_request(:post, "https://api:key-12345@api.mailgundown.net/v2/sandbox12345.mailgun.org/messages").
|
21
|
+
with(:body => {"from"=>"sender@test.com", "subject"=>"Hello", "text"=>"Congratulations, you just sent an email with HttpMailer! You are truly awesome!", "to"=>"reciever@test.com>"},
|
22
|
+
:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'174', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
|
23
|
+
to_return(:status => 500, :body => "", :headers => {})
|
24
|
+
|
15
25
|
# Stub SendGrid HTTP requests
|
16
26
|
stub_request(:post, "https://sendgrid.com/api/mail.send.json").
|
17
27
|
with(:body => {"api_key"=>/.*/, "api_user"=>/.*/, "from"=>/.*/, "fromname"=>/.*/, "subject"=>/.*/, "text"=>/.*/, "to"=>/.*/, "toname"=>/.*/},
|
@@ -23,11 +33,26 @@ RSpec.configure do |config|
|
|
23
33
|
:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'219', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
|
24
34
|
to_return(:status => 200, :body => "", :headers => {})
|
25
35
|
|
36
|
+
stub_request(:post, "https://sendgriddown.com/api/mail.send.json").
|
37
|
+
with(:body => {"api_key"=>"1234", "api_user"=>"test", "from"=>"sender@test.com", "fromname"=>"", "subject"=>"Hello", "text"=>"Congratulations, you just sent an email with HttpMailer! You are truly awesome!", "to"=>"reciever@test.com>", "toname"=>""},
|
38
|
+
:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'219', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
|
39
|
+
to_return(:status => 500, :body => "", :headers => {})
|
40
|
+
|
26
41
|
# Stub Mandrill HTTP requests
|
27
42
|
stub_request(:post, "https://mandrillapp.com/api/1.0/messages/send.json").
|
28
43
|
with(:body => "{\"key\":\"1234567890\",\"message\":{\"html\":null,\"text\":\"Congratulations, you just sent an email with Mandrill! You are truly awesome!\",\"subject\":\"Hello\",\"from_email\":\"papa@prose.com\",\"from_name\":\"Ernest Hemingway\",\"to\":[{\"email\":\"jd@catcher.com\",\"name\":\"JD Salinger\"}],\"headers\":{},\"important\":null,\"track_opens\":null,\"track_clicks\":null,\"auto_text\":null,\"auto_html\":null,\"inline_css\":null,\"url_strip_qs\":null,\"preserve_recipients\":null,\"view_content_link\":null,\"bcc_address\":null,\"tracking_domain\":null,\"signing_domain\":null,\"return_path_domain\":null,\"merge\":null,\"merge_language\":null,\"global_merge_vars\":[],\"merge_vars\":[],\"tags\":[],\"subaccount\":null,\"google_analytics_domains\":[],\"google_analytics_campaign\":null,\"metadata\":[],\"recipient_metadata\":[],\"attachments\":[],\"images\":[]}}",
|
29
44
|
:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'781', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
|
30
45
|
to_return(:status => 200, :body => "", :headers => {})
|
31
46
|
|
47
|
+
stub_request(:post, "https://mandrillapp.com/api/1.0/messages/send.json").
|
48
|
+
with(:body => "{\"key\":\"1234567890\",\"message\":{\"html\":null,\"text\":\"Congratulations, you just sent an email with HttpMailer! You are truly awesome!\",\"subject\":\"Hello\",\"from_email\":\"sender@test.com\",\"from_name\":\"\",\"to\":[{\"email\":\"reciever@test.com>\",\"name\":\"\"}],\"headers\":{},\"important\":null,\"track_opens\":null,\"track_clicks\":null,\"auto_text\":null,\"auto_html\":null,\"inline_css\":null,\"url_strip_qs\":null,\"preserve_recipients\":null,\"view_content_link\":null,\"bcc_address\":null,\"tracking_domain\":null,\"signing_domain\":null,\"return_path_domain\":null,\"merge\":null,\"merge_language\":null,\"global_merge_vars\":[],\"merge_vars\":[],\"tags\":[],\"subaccount\":null,\"google_analytics_domains\":[],\"google_analytics_campaign\":null,\"metadata\":[],\"recipient_metadata\":[],\"attachments\":[],\"images\":[]}}",
|
49
|
+
:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'761', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
|
50
|
+
to_return(:status => 200, :body => "", :headers => {})
|
51
|
+
|
52
|
+
stub_request(:post, "https://mandrillappdown.com/api/1.0/messages/send.json").
|
53
|
+
with(:body => "{\"key\":\"1234567890\",\"message\":{\"html\":null,\"text\":\"Congratulations, you just sent an email with HttpMailer! You are truly awesome!\",\"subject\":\"Hello\",\"from_email\":\"sender@test.com\",\"from_name\":\"\",\"to\":[{\"email\":\"reciever@test.com>\",\"name\":\"\"}],\"headers\":{},\"important\":null,\"track_opens\":null,\"track_clicks\":null,\"auto_text\":null,\"auto_html\":null,\"inline_css\":null,\"url_strip_qs\":null,\"preserve_recipients\":null,\"view_content_link\":null,\"bcc_address\":null,\"tracking_domain\":null,\"signing_domain\":null,\"return_path_domain\":null,\"merge\":null,\"merge_language\":null,\"global_merge_vars\":[],\"merge_vars\":[],\"tags\":[],\"subaccount\":null,\"google_analytics_domains\":[],\"google_analytics_campaign\":null,\"metadata\":[],\"recipient_metadata\":[],\"attachments\":[],\"images\":[]}}",
|
54
|
+
:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'761', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
|
55
|
+
to_return(:status => 500, :body => "", :headers => {})
|
56
|
+
|
32
57
|
end
|
33
58
|
end
|