mailgunner 2.0.0 → 2.1.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: 16c8da4bf004d3e8b0ce0b398815294a6d5e801d
4
- data.tar.gz: c2fa0a69df8ec9a64648dd3a8979d0bef4bbb593
3
+ metadata.gz: c1e24be43e9330f9378bbd977baabea868042090
4
+ data.tar.gz: 812d150cb717e63be9e99b66c2c695981d711a7f
5
5
  SHA512:
6
- metadata.gz: 7a6464e5137f28e412ba186dab76d85927b12e59362896a4e7cf9da57cffa02aa575d020221ab3f37154204432a4f03eb99c2390425a664d95d0c9bb0ccc645f
7
- data.tar.gz: b7ca7c319178f0c893111a14778e1c4266d12d14b49fe514e47152489a61ed5e1328fc00e7cecc4fe578110cd3edbd4819b554782b9cc41b3644705fd52e5e89
6
+ metadata.gz: 00d1306a5501800bfdc87ec29c9244dd232cd126c87ce7c35a5773100336be0afc4d3cf2c166bfc2b31189e59c71d280328be005b24c83ebda8c2163db2d4ee0
7
+ data.tar.gz: 06664445a8ece38b1dee4bc92850867ac1a098f2aa212ce6be0341ba962dec6838e9d04783157325f7a7838d04cefbe02a7d31def684c3da6a2e52e69c43630a
data/README.md CHANGED
@@ -26,8 +26,8 @@ response = mailgun.get_stats(limit: 5)
26
26
  ```
27
27
 
28
28
 
29
- Environment variables
30
- ---------------------
29
+ Storing the API key
30
+ -------------------
31
31
 
32
32
  Best practice for storing credentials for external services is to use environment
33
33
  variables, as described by [12factor.net/config](http://www.12factor.net/config).
@@ -36,10 +36,24 @@ from the MAILGUN_API_KEY and MAILGUN_SMTP_LOGIN environment variables. These wil
36
36
  exist if you are using Mailgun on Heroku, or you can set them manually.
37
37
 
38
38
 
39
+ ActionMailer integration
40
+ ------------------------
41
+
42
+ Mailgunner integrates with [ActionMailer](https://rubygems.org/gems/actionmailer).
43
+ If you are using Rails, you can use Mailgunner to send mail via Mailgun by adding
44
+ the following line to `config/environments/production.rb`:
45
+
46
+ ```ruby
47
+ config.action_mailer.delivery_method = :mailgun
48
+ ````
49
+
50
+ Outside of Rails you can set `ActionMailer::Base.delivery_method` directly.
51
+
52
+
39
53
  Email validation
40
54
  ----------------
41
55
 
42
- If you only need [email validation](http://documentation.mailgun.com/api-email-validation.html),
56
+ If you only need to use Mailgun's [email address validation service](http://documentation.mailgun.com/api-email-validation.html),
43
57
  you can instead use your Mailgun public key to authenticate like this:
44
58
 
45
59
  ```ruby
data/lib/mailgunner.rb CHANGED
@@ -1,16 +1,28 @@
1
1
  require 'net/http'
2
2
  require 'json'
3
3
  require 'cgi'
4
- require 'mailgunner/delivery_method' if defined?(ActionMailer)
4
+ require 'mailgunner/delivery_method' if defined?(Mail)
5
5
 
6
6
  module Mailgunner
7
7
  class Error < StandardError; end
8
8
 
9
+ module NoDomainProvided
10
+ def self.to_s
11
+ raise Error, 'No domain provided'
12
+ end
13
+ end
14
+
9
15
  class Client
10
16
  attr_accessor :domain, :api_key, :http
11
17
 
12
18
  def initialize(options = {})
13
- @domain = options.fetch(:domain) { ENV['MAILGUN_SMTP_LOGIN'].to_s.split('@').last }
19
+ @domain = if options.key?(:domain)
20
+ options.fetch(:domain)
21
+ elsif ENV.key?('MAILGUN_SMTP_LOGIN')
22
+ ENV['MAILGUN_SMTP_LOGIN'].to_s.split('@').last
23
+ else
24
+ NoDomainProvided
25
+ end
14
26
 
15
27
  @api_key = options.fetch(:api_key) { ENV.fetch('MAILGUN_API_KEY') }
16
28
 
@@ -7,13 +7,7 @@ module Mailgunner
7
7
  attr_accessor :settings
8
8
 
9
9
  def initialize(values)
10
- @settings = values
11
-
12
- @client = if @settings.has_key?(:domain)
13
- Client.new(domain: @settings[:domain])
14
- else
15
- Client.new
16
- end
10
+ @client = Client.new(values)
17
11
  end
18
12
 
19
13
  def deliver!(mail)
@@ -23,5 +17,7 @@ module Mailgunner
23
17
  end
24
18
  end
25
19
 
26
- ActionMailer::Base.add_delivery_method :mailgun, DeliveryMethod
20
+ if defined?(ActionMailer)
21
+ ActionMailer::Base.add_delivery_method :mailgun, DeliveryMethod
22
+ end
27
23
  end
data/mailgunner.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mailgunner'
3
- s.version = '2.0.0'
3
+ s.version = '2.1.0'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ['Tim Craft']
6
6
  s.email = ['mail@timcraft.com']
@@ -24,9 +24,7 @@ describe 'Mailgunner::DeliveryMethod' do
24
24
 
25
25
  ActionMailer::Base.delivery_method = :mailgun
26
26
 
27
- ENV['MAILGUN_API_KEY'] = @api_key
28
-
29
- ENV['MAILGUN_SMTP_LOGIN'] = "postmaster@#@domain"
27
+ ActionMailer::Base.mailgun_settings = {api_key: @api_key, domain: @domain}
30
28
  end
31
29
 
32
30
  it 'delivers the mail to mailgun in mime format' do
@@ -46,14 +44,4 @@ describe 'Mailgunner::DeliveryMethod' do
46
44
 
47
45
  exception.message.must_include('Invalid API key')
48
46
  end
49
-
50
- it 'allows the domain to be specified explicitly via the delivery method settings' do
51
- stub_request(:post, "#@base_url/app123.mailgun.org/messages.mime")
52
-
53
- ActionMailer::Base.mailgun_settings = {domain: 'app123.mailgun.org'}
54
-
55
- ExampleMailer.registration_confirmation(email: @address).deliver
56
-
57
- ActionMailer::Base.mailgun_settings = {}
58
- end
59
47
  end
@@ -42,12 +42,8 @@ describe 'Mailgunner::Client' do
42
42
  ENV['MAILGUN_SMTP_LOGIN'] = 'postmaster@samples.mailgun.org'
43
43
 
44
44
  Mailgunner::Client.new(api_key: @api_key).domain.must_equal(@domain)
45
- end
46
45
 
47
- it 'defaults to nil if the MAILGUN_SMTP_LOGIN environment variable does not exist' do
48
46
  ENV.delete('MAILGUN_SMTP_LOGIN')
49
-
50
- Mailgunner::Client.new(api_key: @api_key).domain.must_be_nil
51
47
  end
52
48
  end
53
49
 
@@ -60,6 +56,8 @@ describe 'Mailgunner::Client' do
60
56
  ENV['MAILGUN_API_KEY'] = @api_key
61
57
 
62
58
  Mailgunner::Client.new(domain: @domain).api_key.must_equal(@api_key)
59
+
60
+ ENV.delete('MAILGUN_API_KEY')
63
61
  end
64
62
  end
65
63
 
@@ -92,6 +90,13 @@ describe 'Mailgunner::Client' do
92
90
  @client.send_message({to: @address})
93
91
  end
94
92
 
93
+ it 'raises an exception if the domain is not provided' do
94
+ @client = Mailgunner::Client.new(api_key: @api_key)
95
+
96
+ exception = proc { @client.send_message({}) }.must_raise(Mailgunner::Error)
97
+ exception.message.must_include('No domain provided')
98
+ end
99
+
95
100
  it 'encodes the message attributes as multipart form data when sending attachments' do
96
101
  # TODO
97
102
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailgunner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Craft
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-29 00:00:00.000000000 Z
11
+ date: 2015-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake