rails-mailgun-plus 0.2.2

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: aee3e9aadcc954bacd47d0365da98366b59488fb
4
+ data.tar.gz: 64c4e3edb51a35282160d74859d962accf5186f1
5
+ SHA512:
6
+ metadata.gz: 63c3d7feaf0b4c642c94c0403a89400e0c2238bd9f94e8e088818de731fc51fef56e1213bc17fbd0a8f2fcb25bfa6417a5770c7709ed003b7e61cd854a45409f
7
+ data.tar.gz: f0585923ceeeae5210f80d63f9f148f2abdf3a3e0a637421bf3106088976fdffcc0442fb76828cc01d22625c22fb86c7654024e6266bcd08970514108f8cd35a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Codemancers Tech Pvt Ltd
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.md ADDED
@@ -0,0 +1,53 @@
1
+ # RailsMailgun
2
+ [![Build Status](https://travis-ci.org/code-mancers/rails-mailgun.png?branch=master)](https://travis-ci.org/code-mancers/rails-mailgun)
3
+ [![Code Climate](https://codeclimate.com/github/code-mancers/rails-mailgun.png)](https://codeclimate.com/github/code-mancers/rails-mailgun)
4
+
5
+ Mailgun integration for rails
6
+
7
+
8
+ ## Installation
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'rails-mailgun', git: "git://github.com/code-mancers/rails-mailgun.git"
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ ## Usage
18
+ Mailgun needs 2 config variables.
19
+
20
+ 1. `api_host` : the domain which you have used for registration
21
+ 2. `api_key` : the api key for access. it starts with `key-`
22
+
23
+ Add these lines to your `environment/production.rb` file
24
+
25
+ ```ruby
26
+ Your::Application.configure do
27
+ # ....
28
+
29
+ # mailgun deilvery method
30
+ config.action_mailer.delivery_method = :mailgun
31
+ config.action_mailer.mailgun_settings = {
32
+ api_host: "samples.mailgun.org",
33
+ api_key: "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"
34
+ }
35
+ end
36
+ ```
37
+
38
+ ## Running the specs
39
+ Specs can be run via:
40
+
41
+ bundle exec rspec spec/*_spec.rb
42
+
43
+ ## TODO
44
+ 1. Add error handling once the response is received from mailgun
45
+ 2. Write a helper rake task to quickly check whether integration is working or not!
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'RailsMailgun'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
@@ -0,0 +1,8 @@
1
+ require "rails-mailgun/engine"
2
+ require "rails-mailgun/mail"
3
+ require 'mailgun'
4
+
5
+ module RailsMailgun
6
+ end
7
+
8
+ ActionMailer::Base.add_delivery_method :mailgun, RailsMailgun::Mail
@@ -0,0 +1,4 @@
1
+ module RailsMailgun
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,87 @@
1
+ module RailsMailgun
2
+ class Mail
3
+ def initialize(settings)
4
+ @settings = settings
5
+ end
6
+ attr_accessor :settings
7
+
8
+ def deliver!(mail)
9
+ client = Mailgun::Client.new(settings[:api_key])
10
+ client.send_message(settings[:api_host], message_object(mail))
11
+ end
12
+
13
+ private
14
+
15
+ def message_object(mail)
16
+ message_object = Mailgun::MessageBuilder.new
17
+
18
+ message_object.set_from_address( mail.from.join(' ') )
19
+ mail.to.each { |t| message_object.add_recipient(:to, t) }
20
+ add_cc_emails_to_message_object(message_object, mail)
21
+ add_bcc_emails_to_message_object(message_object, mail)
22
+ add_parameters_to_message_object(message_object, mail)
23
+
24
+ message_object.set_subject(mail.subject)
25
+
26
+ if mail.multipart?
27
+ set_message_object_body(message_object, mail.parts.first)
28
+
29
+ mail.attachments.each do |attachment|
30
+ tempfile = create_tempfile_from_attachment(attachment)
31
+ message_object.add_attachment(tempfile.path, attachment.filename)
32
+ end
33
+ else
34
+ set_message_object_body(message_object, mail)
35
+ end
36
+
37
+ message_object
38
+ end
39
+
40
+ def set_message_object_body(message_object, mail)
41
+ if mail.content_type.match(/html/)
42
+ message_object.set_html_body(mail.body.to_s)
43
+ else
44
+ message_object.set_text_body(mail.body.to_s)
45
+ end
46
+ end
47
+
48
+ def add_cc_emails_to_message_object(message_object, mail)
49
+ return unless mail.cc.present?
50
+
51
+ cc_emails = [mail.cc].flatten
52
+ cc_emails.each { |t| message_object.add_recipient(:cc, t) }
53
+ end
54
+
55
+ def add_bcc_emails_to_message_object(message_object, mail)
56
+ return unless mail.bcc.present?
57
+
58
+ bcc_emails = [mail.bcc].flatten
59
+ bcc_emails.each { |t| message_object.add_recipient(:bcc, t) }
60
+ end
61
+
62
+ def add_parameters_to_message_object(message_object, mail)
63
+ return unless mail.header["mailgun"].present?
64
+ parameters = mail.header["mailgun"].as_json["value"]
65
+ message_object.set_test_mode(parameters["testmode"]) if parameters.key?("testmode")
66
+ message_object.set_open_tracking(!!parameters["open_tracking"]) if parameters.key?("open_tracking")
67
+ message_object.set_click_tracking(!!parameters["click_tracking"]) if parameters.key?("click_tracking")
68
+ message_object.set_campaign_id(parameters["campaign"]) if parameters.key?("campaign")
69
+ add_tags_to_message_object(message_object, parameters["tags"])
70
+ end
71
+
72
+ def add_tags_to_message_object(message_object, tags)
73
+ return unless tags.present?
74
+ tags.each do |t|
75
+ message_object.add_tag(t)
76
+ end
77
+ end
78
+
79
+ def create_tempfile_from_attachment(attachment)
80
+ tempfile = Tempfile.new(attachment.filename)
81
+ tempfile.binmode
82
+ tempfile.write(attachment.body.raw_source)
83
+ tempfile.close
84
+ tempfile
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ module RailsMailgun
2
+ VERSION = '0.2.2'
3
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-mailgun-plus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Yuva Kumar
8
+ - Robert Audi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-08-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 3.2.13
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 3.2.13
28
+ - !ruby/object:Gem::Dependency
29
+ name: mailgun-ruby
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 1.0.3
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 1.0.3
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec-rails
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 2.14.0
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 2.14.0
56
+ description:
57
+ email:
58
+ - yuva@codemancers.com
59
+ - hello@codemancers.com
60
+ - robert.audi@captaincrowd.co
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - MIT-LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - lib/rails-mailgun.rb
69
+ - lib/rails-mailgun/engine.rb
70
+ - lib/rails-mailgun/mail.rb
71
+ - lib/rails-mailgun/version.rb
72
+ homepage:
73
+ licenses: []
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.4.8
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Mailgun integration for rails (Fork of https://github.com/code-mancers/rails-mailgun)
95
+ test_files: []