mailgun-api-rails 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 80262a1aa9a30a3eaea8981ac574ed01b996f5b9
4
+ data.tar.gz: 28b491ff33c0e541026bfc2252bb71957b4dc311
5
+ SHA512:
6
+ metadata.gz: a59ebfcd73f2c1d7a95d3d0756682035f8880acdb30603abf346bc208b59108f21d72968b0aba0f1c27abd3dde9212ea76c7f0362e8c6ec767612e0e97bcdec7
7
+ data.tar.gz: 1d7ca1b3279883064bb950f819366fdaa22d15d367aacc72d7e28a3d87a9732f6a494c64509939f89acc786839629eb00034d305923450eba99c2903e4d77bc5
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Mailgun API Action Mailer Adapter
2
+ A simple [Mailgun](https://mailgun.com) API [Action Mailer](https://github.com/rails/rails/tree/master/actionmailer) adapter.
3
+
4
+ The alternatives try to recreate `The Matrix`, while others just utilize the `config.action_mailer.delivery_method = :smtp`. Why make a `gem` for that? Here is what Mailgun says ["Send with SMTP or API"](https://documentation.mailgun.com/quickstart-sending.html#send-with-smtp-or-api).
5
+
6
+ ## Install
7
+
8
+ Plop the gem into your `Gemfile`.
9
+ ```
10
+ gem 'mailgun-api-rails'
11
+ ```
12
+
13
+ Run the `bundle` command.
14
+ ```
15
+ $ bundle
16
+ ```
17
+
18
+ Set the `delivery_method` to `:mailgun` in `config/application.rb` or your environment specific configuration. When it comes to the `mailgun_settings`, I just map them from my `.env` file
19
+ ```
20
+ config.action_mailer.delivery_method = :mailgun
21
+
22
+ ## Settings
23
+ config.action_mailer.mailgun_settings = {
24
+ domain: ENV['MAILGUN_DOMAIN'],
25
+ api_key: ENV['MAILGUN_API_KEY'],
26
+ api_base_url: ENV['MAILGUN_API_BASE_URL'] ## api.mailgun.net/v3
27
+ }
28
+ ```
29
+
30
+ Boom. Done. Works with `devise_mail` as well.
31
+
@@ -0,0 +1,3 @@
1
+ require 'action_mailer'
2
+ Dir["#{File.dirname(__FILE__)}/mailgun-api-rails/*.rb"].each{|file| require file}
3
+ module MailgunApiRails end
@@ -0,0 +1,41 @@
1
+ require 'rest_client'
2
+
3
+ module MailgunApiRails
4
+ class Delivery
5
+ attr_accessor :settings
6
+
7
+ def initialize(settings)
8
+ self.settings = settings
9
+ end
10
+
11
+ ## Config options
12
+ def sender
13
+ self.settings[:sender]
14
+ end
15
+
16
+ def domain
17
+ self.settings[:domain]
18
+ end
19
+
20
+ def api_key
21
+ self.settings[:api_key]
22
+ end
23
+
24
+ def api_base_url
25
+ self.settings[:api_base_url]
26
+ end
27
+
28
+ ## Action mailer call
29
+ def deliver!(mail)
30
+ ## Map mail values to Mailgun request
31
+ RestClient.post "https://api:#{api_key}@#{api_base_url}/#{domain}/messages",
32
+ from: mail.from,
33
+ to: mail.to,
34
+ subject: mail.subject,
35
+ text: mail.multipart? ? (mail.text_part ? mail.text_part.body.decoded : nil) : mail.body.decoded,
36
+ html: mail.body.decoded
37
+ end
38
+ end
39
+ end
40
+
41
+ ActionMailer::Base.add_delivery_method :mailgun, MailgunApiRails::Delivery
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mailgun-api-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Mulloy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionmailer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Mailgun API adapter for Action Mailer
42
+ email: thomas@shoppu.us
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - README.md
48
+ - lib/mailgun-api-rails.rb
49
+ - lib/mailgun-api-rails/delivery.rb
50
+ homepage: https://github.com/shoppu/mailgun-api-rails
51
+ licenses:
52
+ - MIT
53
+ metadata: {}
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements:
69
+ - none
70
+ rubyforge_project:
71
+ rubygems_version: 2.4.6
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Better Mailgun API adapter for Action Mailer
75
+ test_files: []