mailgun_rails 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = MailgunRails
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'MailgunRails'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+
32
+ task default: :test
@@ -0,0 +1,25 @@
1
+ require 'rest_client'
2
+
3
+
4
+ module Mailgun
5
+ class Client
6
+ attr_reader :api_key, :domain
7
+
8
+ def initialize(api_key, domain)
9
+ @api_key = api_key
10
+ @domain = domain
11
+ end
12
+
13
+ def send_message(options)
14
+ RestClient.post mailgun_url, options
15
+ end
16
+
17
+ def mailgun_url
18
+ api_url+"/messages"
19
+ end
20
+
21
+ def api_url
22
+ "https://api:#{api_key}@api.mailgun.net/v2/#{domain}"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,44 @@
1
+
2
+ module Mailgun
3
+ class Deliverer
4
+
5
+ attr_accessor :settings
6
+
7
+ def initialize(settings)
8
+ self.settings = settings
9
+ end
10
+
11
+ def domain
12
+ self.settings[:domain]
13
+ end
14
+
15
+ def api_key
16
+ self.settings[:api_key]
17
+ end
18
+
19
+ def deliver!(email)
20
+ mailgun_message = {
21
+ :from => email.from,
22
+ :to => email.to,
23
+ :subject => email.subject,
24
+ :html => email.body.to_s
25
+ }
26
+
27
+ mailgun_message['h:Reply-To'] = email.reply_to if email.reply_to
28
+
29
+ email.mailgun_variables.try(:each) do |name, value|
30
+ mailgun_message["v:#{name}"] = value
31
+ end
32
+
33
+ mailgun_message['recipient-variables'] = email.mailgun_recipient_variables.to_json if email.mailgun_recipient_variables
34
+
35
+ mailgun_client.send_message mailgun_message
36
+ end
37
+
38
+ def mailgun_client
39
+ @maingun_client ||= Client.new(api_key, domain)
40
+ end
41
+ end
42
+ end
43
+
44
+ ActionMailer::Base.add_delivery_method :mailgun, Mailgun::Deliverer
@@ -0,0 +1,6 @@
1
+ module Mail
2
+ class Message
3
+ attr_accessor :mailgun_variables
4
+ attr_accessor :mailgun_recipient_variables
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Mailgun
2
+ VERSION = "0.5.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'action_mailer'
2
+ require 'json'
3
+
4
+
5
+ Dir[File.dirname(__FILE__) + '/mailgun/*.rb'].each {|file| require file }
6
+
7
+ module Mailgun
8
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mailgun_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jorge Manrubia
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.13
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.13
30
+ - !ruby/object:Gem::Dependency
31
+ name: rest-client
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.6.7
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.6.7
46
+ - !ruby/object:Gem::Dependency
47
+ name: sqlite3
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.14.1
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.14.1
78
+ description: An adapter for using Mailgun with Rails and Action Mailer
79
+ email:
80
+ - jorge.manrubia@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - lib/mailgun/client.rb
86
+ - lib/mailgun/deliverer.rb
87
+ - lib/mailgun/mail_ext.rb
88
+ - lib/mailgun/version.rb
89
+ - lib/mailgun_rails.rb
90
+ - MIT-LICENSE
91
+ - Rakefile
92
+ - README.rdoc
93
+ homepage: http://jorgemanrubia.net
94
+ licenses: []
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ segments:
106
+ - 0
107
+ hash: 1102208387661220821
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ segments:
115
+ - 0
116
+ hash: 1102208387661220821
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.23
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Rails Action Mailer adapter for Mailgun
123
+ test_files: []