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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf7543d7c4535c14bf3f0a728f48d4c11daa9953
4
- data.tar.gz: 809069c15685e40d2df9dab51843caa3e1ff8051
3
+ metadata.gz: 9b17235bd4f2440fe70e8aa104b5f94e42aa3b21
4
+ data.tar.gz: d951071c220ad2e726a2132664dd9c361ce795ec
5
5
  SHA512:
6
- metadata.gz: a33ab2b97224bc9d508ef4df60be77708f0c1954e76b9aec04b877792d725e76249140f4e367a021eda9d197d2d01886c6913248c7e49ae99bc9dcf118750036
7
- data.tar.gz: 8331b0a4182bbfd24ba252d071088e98eb0f792eecb4d20338db32ff3a4b3cbaf5f1e16fca8653a34d07a9c161cf366b2290fe0a7ffa0ead8bf4e0e60fb30054
6
+ metadata.gz: d3c036b9b37a7f87c785b80c92d5621f9b834eb6e0b078caeedebd33690d8d76ce141b1f1079ec1f36ff754428c9ec4c2e13ff01bbb40a69aa61cd7e0e3060cb
7
+ data.tar.gz: 7013bbcd5ba70bd8d7123bac6e2318e4395ba626841940a79a05c12c1bcbe8ba27eb5456a44d1b6700ac46b272b9b08218282db8c605f6d7f058554c38d793ba
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # HttpMailer
2
2
 
3
- Send emails via Mailgun, Mandrill and SendGrid HTTP APIs.
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
- mailgun_client = HttpMailer.mailgun({
27
- host: "api.mailgun.net",
28
- api_key: "XXXXXXXXX",
29
- subdomain: "samples.mailgun.net"
30
- })
31
-
32
- from = "Excited User <me@samples.mailgun.org>"
33
- to = "baz@example.com"
34
- subject = "Hello"
35
- text = "Testing some Mailgun awesomness!"
36
-
37
- mailgun_client.send_message(from, to, subject, text)
38
- ```
39
-
40
- Mandrill
41
-
42
- ```ruby
43
- mandrill_client = HttpMailer.mandrill({
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
- mandrill_client.send_message(from, to, subject, text, to_name, from_name)
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
@@ -12,6 +12,7 @@ require "http_mailer/sendgrid/sendgrid_service_api"
12
12
  require "http_mailer/sendgrid/sendgrid_service_handler"
13
13
 
14
14
  module HttpMailer
15
+ class EmailDeliveryError < StandardError; end
15
16
 
16
17
  class << self
17
18
  def client(settings)
@@ -22,6 +22,7 @@ module HttpMailer
22
22
  end
23
23
  end
24
24
 
25
+ raise EmailDeliveryError if response.code != 200
25
26
  return response
26
27
  end
27
28
 
@@ -1,3 +1,3 @@
1
1
  module HttpMailer
2
- VERSION = "0.0.5"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -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
 
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dru Ibarra