http_mailer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 08d14cc679ccd7fda4823dcb4b57eb136f2422e4
4
+ data.tar.gz: 842ba83b3cb0e69c85dec8e90ce3a89a0b078e24
5
+ SHA512:
6
+ metadata.gz: 03e799edaa77bdf52060a630f1d74f7a9af6048566a893fb364a7343267a8c3c3ec2bae7183df80781629265b7ec40154a00cead45c6b1b239c70a8b2cbf0340
7
+ data.tar.gz: 033a30a294f410497af7fe1c692bbeb65c7c537fb5376181d25d82b25076e90effc682f95052af54367fefded87a72b2a84c9c09e674bc86044e3131a1ab7a68
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in http_mailer.gemspec
4
+ gemspec
5
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Dru Ibarra
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # HttpMailer
2
+
3
+ Send emails via Mailgun, Mandrill and SendGrid HTTP APIs.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'http_mailer'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install http_mailer
20
+
21
+ ## Usage
22
+
23
+ Mailgun
24
+
25
+ ```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
+ })
47
+
48
+ from = "papa@prose.com"
49
+ from_name = "Ernest Hemingway"
50
+ to = "jd@catcher.com"
51
+ to_name = "JD Salinger"
52
+ subject = "Hello"
53
+ text = "Every man's life ends the same way. \
54
+ It is only the details of how he lived and \
55
+ how he died that distinguish one man from another."
56
+
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)
77
+ ```
78
+
79
+ ## Contributing
80
+
81
+ 1. Fork it ( https://github.com/[my-github-username]/http_mailer/fork )
82
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
83
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
84
+ 4. Push to the branch (`git push origin my-new-feature`)
85
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "rspec/core/rake_task"
2
+ require "bundler/gem_tasks"
3
+
4
+ # Default directory to look in is `/specs`
5
+ # Run with `rake spec`
6
+ RSpec::Core::RakeTask.new(:spec) do |task|
7
+ task.rspec_opts = ['--color']
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'http_mailer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "http_mailer"
8
+ spec.version = HttpMailer::VERSION
9
+ spec.authors = ["Dru Ibarra"]
10
+ spec.email = ["Druwerd@gmail.com"]
11
+ spec.summary = %q{Sends email via HTTP APIs}
12
+ spec.description = %q{Sends email via HTTP APIs}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "webmock"
25
+ spec.add_development_dependency "vcr"
26
+
27
+ spec.add_runtime_dependency "rest-client", "~> 1.7.2"
28
+ end
@@ -0,0 +1,17 @@
1
+ module HttpMailer
2
+ class MailgunServiceApi
3
+ attr_accessor :host, :api_key, :version, :subdomain, :protocol
4
+
5
+ def initialize(host, api_key, subdomain, protocol='https', version='v2')
6
+ @host = host
7
+ @api_key = api_key
8
+ @subdomain = subdomain
9
+ @protocol = protocol
10
+ @version = version
11
+ end
12
+
13
+ def send_messages_url
14
+ "#{self.protocol}://api:key-#{self.api_key}@#{self.host}/#{self.version}/#{self.subdomain}/messages"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ module HttpMailer
2
+ class MailgunServiceHandler < ServiceHandler
3
+ attr_accessor :sevice_api
4
+
5
+ def initialize(settings)
6
+ super(settings)
7
+ @service_api = ::HttpMailer::MailgunServiceApi.new(self.service_configuration.settings.host,
8
+ self.service_configuration.settings.api_key,
9
+ self.service_configuration.settings.subdomain
10
+ )
11
+ end
12
+
13
+ def send_message(from, to, subject, text)
14
+ ::RestClient.post self.service_api.send_messages_url,
15
+ :from => from,
16
+ :to => to,
17
+ :subject => subject,
18
+ :text => text
19
+ rescue => e
20
+ puts e.inspect
21
+ e.response
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,81 @@
1
+ module HttpMailer
2
+ class MandrillMessage
3
+ attr_accessor :to, :to_name, :from, :from_name, :subject, :text, :html
4
+ attr_reader :structure
5
+
6
+ def initialize(to, from, subject, text=nil, html=nil, to_name=nil, from_name=nil)
7
+ @to = to
8
+ @from = from
9
+ @subject = subject
10
+ @text = text
11
+ @html = html
12
+ @to_name = to_name
13
+ @from_name = from_name
14
+ @structure = json_message_struct
15
+ build_message
16
+ end
17
+
18
+ def to_h
19
+ self.structure.to_h
20
+ end
21
+
22
+ private
23
+ def build_message
24
+ to_struct = json_to_struct
25
+ to_struct[:email] = self.to
26
+ to_struct[:name] = self.to_name if self.to_name
27
+
28
+ self.structure[:from_email] = self.from
29
+ self.structure[:from_name] = self.from_name if self.from_name
30
+
31
+ self.structure[:subject] = self.subject
32
+ self.structure[:text] = self.text if self.text
33
+ self.structure[:html] = self.html if self.html
34
+ self.structure[:to] << to_struct
35
+ end
36
+
37
+ def json_message_struct
38
+ {
39
+ html: nil,
40
+ text: nil,
41
+ subject: nil,
42
+ from_email: nil,
43
+ from_name: nil,
44
+ to: [],
45
+ headers: {},
46
+ important: nil,
47
+ track_opens: nil,
48
+ track_clicks: nil,
49
+ auto_text: nil,
50
+ auto_html: nil,
51
+ inline_css: nil,
52
+ url_strip_qs: nil,
53
+ preserve_recipients: nil,
54
+ view_content_link: nil,
55
+ bcc_address: nil,
56
+ tracking_domain: nil,
57
+ signing_domain: nil,
58
+ return_path_domain: nil,
59
+ merge: nil,
60
+ merge_language: nil,
61
+ global_merge_vars: [],
62
+ merge_vars: [],
63
+ tags: [],
64
+ subaccount: nil,
65
+ google_analytics_domains: [],
66
+ google_analytics_campaign: nil,
67
+ metadata: [],
68
+ recipient_metadata: [],
69
+ attachments: [],
70
+ images: []
71
+ }
72
+ end
73
+
74
+ def json_to_struct
75
+ {
76
+ email: nil,
77
+ name: nil
78
+ }
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,20 @@
1
+ module HttpMailer
2
+ class MandrillServiceApi
3
+ attr_accessor :host, :protocol, :version
4
+
5
+ def initialize(host, protocol='https', version='1.0')
6
+ @host = host
7
+ @protocol = protocol
8
+ @version = version
9
+ end
10
+
11
+ def send_messages_url
12
+ "#{api_root_url}/messages/send.json"
13
+ end
14
+
15
+ private
16
+ def api_root_url
17
+ "#{self.protocol}://#{self.host}/api/#{self.version}"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ module HttpMailer
2
+ class MandrillServiceHandler < ServiceHandler
3
+ attr_accessor :sevice_api
4
+
5
+ def initialize(settings)
6
+ super(settings)
7
+ @service_api = ::HttpMailer::MandrillServiceApi.new(self.service_configuration.settings.host)
8
+ end
9
+
10
+ def send_message(from, to, subject, text, to_name='', from_name='')
11
+ message = MandrillMessage.new(from, to, subject, text, nil, to_name, from_name)
12
+ payload = {
13
+ :key => self.service_configuration.settings.api_key,
14
+ :message => message.to_h
15
+ }.to_json
16
+
17
+ ::RestClient.post(self.service_api.send_messages_url, payload,
18
+ :content_type => :json,
19
+ :accept => :json
20
+ )
21
+ rescue => e
22
+ puts e.inspect
23
+ e.response
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ module HttpMailer
2
+ class SendGridServiceApi
3
+ attr_accessor :host, :protocol
4
+
5
+ def initialize(host, protocol='https')
6
+ @host = host
7
+ @protocol = protocol
8
+ end
9
+
10
+ def send_messages_url
11
+ "#{self.protocol}://#{self.host}/api/mail.send.json"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ module HttpMailer
2
+ class SendGridServiceHandler < ServiceHandler
3
+ attr_accessor :sevice_api
4
+
5
+ def initialize(settings)
6
+ super(settings)
7
+ @service_api = ::HttpMailer::SendGridServiceApi.new(self.service_configuration.settings.host)
8
+ end
9
+
10
+ def send_message(from, to, subject, text, to_name='', from_name='')
11
+ ::RestClient.post self.service_api.send_messages_url,
12
+ :api_user => self.service_configuration.settings.api_user,
13
+ :api_key => self.service_configuration.settings.api_key,
14
+ :from => from,
15
+ :fromname => from_name,
16
+ :to => to,
17
+ :toname => to_name,
18
+ :subject => subject,
19
+ :text => text
20
+ rescue => e
21
+ puts e.inspect
22
+ e.response
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ module HttpMailer
2
+ class ServiceConfiguration
3
+ Settings = Struct.new(:host, :api_key, :api_user, :subdomain)
4
+ attr_accessor :settings
5
+
6
+ def initialize(settings_hash)
7
+ self.settings = Settings.new
8
+
9
+ self.settings.host = settings_hash[:host]
10
+ self.settings.api_user = settings_hash[:api_user]
11
+ self.settings.api_key = settings_hash[:api_key]
12
+ self.settings.subdomain = settings_hash[:subdomain]
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ module HttpMailer
2
+ class ServiceHandler
3
+ attr_accessor :service_api, :service_configuration
4
+
5
+ def initialize(settings)
6
+ @service_configuration = ServiceConfiguration.new(settings)
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module HttpMailer
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ require 'rest_client'
2
+ require "http_mailer/version"
3
+ require "http_mailer/service_handler"
4
+ require "http_mailer/service_configuration"
5
+ require "http_mailer/mailgun/mailgun_service_api"
6
+ require "http_mailer/mailgun/mailgun_service_handler"
7
+ require "http_mailer/mandrill/mandrill_message"
8
+ require "http_mailer/mandrill/mandrill_service_api"
9
+ require "http_mailer/mandrill/mandrill_service_handler"
10
+ require "http_mailer/sendgrid/sendgrid_service_api"
11
+ require "http_mailer/sendgrid/sendgrid_service_handler"
12
+
13
+ module HttpMailer
14
+
15
+ class << self
16
+ def mailgun(settings)
17
+ MailgunServiceHandler.new(settings)
18
+ end
19
+
20
+ def sendgrid(settings)
21
+ SendGridServiceHandler.new(settings)
22
+ end
23
+
24
+ def mandrill(settings)
25
+ MandrillServiceHandler.new(settings)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe HttpMailer do
4
+
5
+ context "when configured for Mailgun" do
6
+ let(:settings){ {:host => "api.mailgun.net", :api_key => "12345", :subdomain => "sandbox12345.mailgun.org"} }
7
+
8
+ describe ".mailgun" do
9
+ it "creates a service handler for Mailgun" do
10
+ expect(HttpMailer.mailgun(settings)).to be_a HttpMailer::MailgunServiceHandler
11
+ end
12
+ end
13
+ end
14
+
15
+ context "when configured for SendGrid" do
16
+ let(:settings){ {:host => "sendgrid.com", :api_user=> "test", :api_key => "1234"} }
17
+
18
+ describe ".sendgrid" do
19
+ it "creates a service handler for SendGrid" do
20
+ expect(HttpMailer.sendgrid(settings)).to be_a HttpMailer::SendGridServiceHandler
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ context "when configured for Mandrill" do
27
+ let(:settings){ {:host => "mandrillapp.com", :api_key => "1234567890"} }
28
+
29
+ describe ".mandrill" do
30
+ it "creates a service handler for Mandrill" do
31
+ expect(HttpMailer.mandrill(settings)).to be_a HttpMailer::MandrillServiceHandler
32
+ end
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe HttpMailer::MailgunServiceApi do
4
+
5
+ describe "#send_messages_url" do
6
+ let(:host){ "api.mailgun.net" }
7
+ let(:api_key){ "1234567890" }
8
+ let(:subdomain){ "sandbox1234567890.mailgun.org" }
9
+ let(:protocol){ "https" }
10
+ let(:version){ "v2" }
11
+ let(:service_api){ HttpMailer::MailgunServiceApi.new(host, api_key, subdomain, protocol, version) }
12
+
13
+ it 'returns the Mailgun send message endpoint URL' do
14
+ expect(service_api.send_messages_url).to eq("https://api:key-1234567890@api.mailgun.net/v2/sandbox1234567890.mailgun.org/messages")
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe HttpMailer::MailgunServiceHandler do
4
+
5
+ describe "#send_message" do
6
+ let(:settings){ {:host => "api.mailgun.net", :api_key => "12345", :subdomain => "sandbox12345.mailgun.org"} }
7
+ let(:mailer){ HttpMailer::MailgunServiceHandler.new(settings) }
8
+ let(:sender){ "Mailgun Sandbox <postmaster@sandbox12345.mailgun.org>"}
9
+ let(:reciever){ "Test <test@gmail.com>" }
10
+ let(:subject){ "Hello" }
11
+ let(:email_body){ "Congratulations, you just sent an email with Mailgun! You are truly awesome!" }
12
+
13
+ it 'sends an email message' do
14
+ response = mailer.send_message(sender, reciever, subject, email_body)
15
+ expect(response.code).to eq(200)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe HttpMailer::MandrillMessage do
4
+
5
+ describe "#initialize" do
6
+ let(:from){ "jcash@tennesseethree.com"}
7
+ let(:from_name){ "Johnny Cash"}
8
+ let(:to){ "elvis@graceland.com" }
9
+ let(:to_name){ "Elvis Presley"}
10
+ let(:subject){ "Hello" }
11
+ let(:text_body){ "Congratulations, you just sent an email with Mandrill! You are truly awesome!" }
12
+ let(:html_body){ "<h1>Congratulations, you just sent an email with Mandrill! You are truly awesome!</h1>"}
13
+ let(:message){ HttpMailer::MandrillMessage.new(to, from, subject, text_body, html_body, to_name, from_name) }
14
+
15
+ it 'builds a propery formated Mandrill message' do
16
+ expect(message.to_h[:to]).to eq [{:email => to, :name => to_name}]
17
+ expect(message.to_h[:from_email]).to eq from
18
+ expect(message.to_h[:from_name]).to eq from_name
19
+ expect(message.to_h[:subject]).to eq subject
20
+ expect(message.to_h[:text]).to eq text_body
21
+ expect(message.to_h[:html]).to eq html_body
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe HttpMailer::MandrillServiceApi do
4
+
5
+ describe "#send_messages_url" do
6
+ let(:host){ "mandrillapp.com" }
7
+ let(:protocol){ "https" }
8
+ let(:version){ "1.0" }
9
+ let(:service_api){ HttpMailer::MandrillServiceApi.new(host, protocol, version) }
10
+
11
+ it 'returns the Mandrill send message endpoint URL' do
12
+ expect(service_api.send_messages_url).to eq("https://mandrillapp.com/api/1.0/messages/send.json")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe HttpMailer::MandrillServiceHandler do
4
+
5
+ describe "#send_message" do
6
+ let(:settings){ {:host => "mandrillapp.com", :api_key => "1234567890"} }
7
+ let(:mailer){ HttpMailer::MandrillServiceHandler.new(settings) }
8
+ let(:from){ "papa@prose.com"}
9
+ let(:from_name){ "Ernest Hemingway"}
10
+ let(:to){ "jd@catcher.com" }
11
+ let(:to_name){ "JD Salinger"}
12
+ let(:subject){ "Hello" }
13
+ let(:email_body){ "Congratulations, you just sent an email with Mandrill! You are truly awesome!" }
14
+
15
+ it 'sends an email message' do
16
+ response = mailer.send_message(to, from, subject, email_body, to_name, from_name)
17
+ expect(response.code).to eq(200)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe HttpMailer::SendGridServiceApi do
4
+
5
+ describe "#send_messages_url" do
6
+ let(:host){ "api.sendgrid.com" }
7
+ let(:protocol){ "https" }
8
+ let(:service_api){ HttpMailer::SendGridServiceApi.new(host, protocol) }
9
+
10
+ it 'returns the SendGrid send message endpoint URL' do
11
+ expect(service_api.send_messages_url).to eq("https://api.sendgrid.com/api/mail.send.json")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe HttpMailer::SendGridServiceHandler do
4
+
5
+ describe "#send_message" do
6
+ let(:settings){ {:host => "sendgrid.com", :api_user=> "test", :api_key => "1234"} }
7
+ let(:mailer){ HttpMailer::SendGridServiceHandler.new(settings) }
8
+ let(:sender){ "test@test.com"}
9
+ let(:reciever){ "test@test.com" }
10
+ let(:subject){ "Hello" }
11
+ let(:email_body){ "Congratulations, you just sent an email with SendGrid! You are truly awesome!" }
12
+
13
+ it 'sends an email message' do
14
+ response = mailer.send_message(sender, reciever, subject, email_body)
15
+ expect(response.code).to eq(200)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe HttpMailer::ServiceConfiguration do
4
+
5
+ describe "#initialize" do
6
+ let(:settings){ {:host => "test.com", :api_user => "test_api_user", :api_key => "test_api_key", :subdomain => "test_subdomain"} }
7
+ let(:service_configuration){ HttpMailer::ServiceConfiguration.new(settings) }
8
+
9
+ it "creates an instance" do
10
+ expect(service_configuration).to respond_to(:settings)
11
+ expect(service_configuration.settings.host).to eq(settings[:host])
12
+ expect(service_configuration.settings.api_user).to eq(settings[:api_user])
13
+ expect(service_configuration.settings.api_key).to eq(settings[:api_key])
14
+ expect(service_configuration.settings.subdomain).to eq(settings[:subdomain])
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe HttpMailer::ServiceHandler do
4
+
5
+ describe "#initialize" do
6
+ let(:settings){ {:host => "host.com", :api_user=> "test_api_user", :api_key => "1357924680"} }
7
+ let(:service_handler){ HttpMailer::ServiceHandler.new(settings) }
8
+
9
+ it "creates an instance" do
10
+ expect(service_handler).to respond_to(:service_api)
11
+ expect(service_handler).to respond_to(:service_configuration)
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,28 @@
1
+ require 'http_mailer'
2
+ require 'webmock/rspec'
3
+
4
+ WebMock.disable_net_connect!(allow_localhost: true)
5
+
6
+ RSpec.configure do |config|
7
+ config.before(:each) do
8
+
9
+ # Stub Mailgun HTTP requests
10
+ stub_request(:post, %r{https://api:key-\w+@api.mailgun.net/v2/\w+.mailgun.org/messages}).
11
+ with(:body => {"from"=>/.*/, "subject"=>/.*/, "text"=>/.*/, "to"=>/.*/},
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
+ to_return(:status => 200, :body => "", :headers => {})
14
+
15
+ # Stub SendGrid HTTP requests
16
+ stub_request(:post, "https://sendgrid.com/api/mail.send.json").
17
+ with(:body => {"api_key"=>/.*/, "api_user"=>/.*/, "from"=>/.*/, "fromname"=>/.*/, "subject"=>/.*/, "text"=>/.*/, "to"=>/.*/, "toname"=>/.*/},
18
+ :headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'208', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
19
+ to_return(:status => 200, :body => "", :headers => {})
20
+
21
+ # Stub Mandrill HTTP requests
22
+ stub_request(:post, "https://mandrillapp.com/api/1.0/messages/send.json").
23
+ 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\":[]}}",
24
+ :headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'781', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
25
+ to_return(:status => 200, :body => "", :headers => {})
26
+
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: http_mailer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dru Ibarra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rest-client
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.7.2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.7.2
97
+ description: Sends email via HTTP APIs
98
+ email:
99
+ - Druwerd@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - http_mailer.gemspec
110
+ - lib/http_mailer.rb
111
+ - lib/http_mailer/mailgun/mailgun_service_api.rb
112
+ - lib/http_mailer/mailgun/mailgun_service_handler.rb
113
+ - lib/http_mailer/mandrill/mandrill_message.rb
114
+ - lib/http_mailer/mandrill/mandrill_service_api.rb
115
+ - lib/http_mailer/mandrill/mandrill_service_handler.rb
116
+ - lib/http_mailer/sendgrid/sendgrid_service_api.rb
117
+ - lib/http_mailer/sendgrid/sendgrid_service_handler.rb
118
+ - lib/http_mailer/service_configuration.rb
119
+ - lib/http_mailer/service_handler.rb
120
+ - lib/http_mailer/version.rb
121
+ - spec/http_mailer_spec.rb
122
+ - spec/mailgun/mailgun_service_api_spec.rb
123
+ - spec/mailgun/mailgun_service_handler_spec.rb
124
+ - spec/mandrill/mandrill_message_spec.rb
125
+ - spec/mandrill/mandrill_service_api_spec.rb
126
+ - spec/mandrill/mandrill_service_handler_spec.rb
127
+ - spec/sendgrid/sendgrid_service_api_spec.rb
128
+ - spec/sendgrid/sendgrid_service_handler_spec.rb
129
+ - spec/service_configuration_spec.rb
130
+ - spec/service_handler_spec.rb
131
+ - spec/spec_helper.rb
132
+ homepage: ''
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.0.3
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Sends email via HTTP APIs
156
+ test_files:
157
+ - spec/http_mailer_spec.rb
158
+ - spec/mailgun/mailgun_service_api_spec.rb
159
+ - spec/mailgun/mailgun_service_handler_spec.rb
160
+ - spec/mandrill/mandrill_message_spec.rb
161
+ - spec/mandrill/mandrill_service_api_spec.rb
162
+ - spec/mandrill/mandrill_service_handler_spec.rb
163
+ - spec/sendgrid/sendgrid_service_api_spec.rb
164
+ - spec/sendgrid/sendgrid_service_handler_spec.rb
165
+ - spec/service_configuration_spec.rb
166
+ - spec/service_handler_spec.rb
167
+ - spec/spec_helper.rb