action_mailer-mandrill 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 40b1ff1b2b82eeed4a9d7f7f669723bd8ce5dfe0
4
+ data.tar.gz: 99bbbe2c1cacc54a6b2341ccf914f1c0bf525195
5
+ SHA512:
6
+ metadata.gz: e170fe53c8191d004f9dd32fcc565e2452690ab03956dffdea52ea787173b599fdef2a4258b36313526873f96a48629c914b92080a074ef54b28a47b7787d3d3
7
+ data.tar.gz: f112d5954a9b2f8b3399252c210b79570c1d0cebe91a6a95651a504b2ebe8c2d662a0db8b8482b83313e9bfd20a5c6799cd990c0d9c663351374be7093ec314e
@@ -0,0 +1,57 @@
1
+ *.gem
2
+ *.rbc
3
+ <<<<<<< HEAD
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
24
+ =======
25
+ /.config
26
+ /coverage/
27
+ /InstalledFiles
28
+ /pkg/
29
+ /spec/reports/
30
+ /test/tmp/
31
+ /test/version_tmp/
32
+ /tmp/
33
+
34
+ ## Specific to RubyMotion:
35
+ .dat*
36
+ .repl_history
37
+ build/
38
+
39
+ ## Documentation cache and generated files:
40
+ /.yardoc/
41
+ /_yardoc/
42
+ /doc/
43
+ /rdoc/
44
+
45
+ ## Environment normalisation:
46
+ /.bundle/
47
+ /lib/bundler/man/
48
+
49
+ # for a library or gem, you might want to ignore these files since the code is
50
+ # intended to run in multiple environments; otherwise, check them in:
51
+ # Gemfile.lock
52
+ # .ruby-version
53
+ # .ruby-gemset
54
+
55
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
56
+ .rvmrc
57
+ >>>>>>> c3fd987e6a92ebbb44c57694c6daf2bbeedf4d07
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in action_mailer-mandrill.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Max Schulze
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.
@@ -0,0 +1,59 @@
1
+ # ActionMailer::Mandrill
2
+
3
+ Use this gem to provide a nice `mandrill_mail` method to all your mailers.
4
+ It allows you to send mails via Mandrill SMTP using Mandrill Templates (only).
5
+ Using the mandrill_mail method you can easily set different Mandrill SMTP headers as well.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'action_mailer-mandrill'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install action_mailer-mandrill
20
+
21
+ ## Usage
22
+
23
+ In your Mailer include the Mandrill Mailer:
24
+
25
+ class UserMailer
26
+ include ActionMailer::Mandrill
27
+ end
28
+
29
+ Now you can use the mandrill mail method in your mail methods:
30
+
31
+ def invitation_instructions(record)
32
+ mandrill_mail 'user-friend-request', # mandrill template slug
33
+ merge_objects: [record.invited_by], # objects which attributes will
34
+ # converted to merge tags
35
+ tags: %w{ invite user }, # tag the email
36
+ to: record.email, # ...
37
+ receiver_name: record.name, # If a receiver name is given the email will be
38
+ # sent to "receiver_name <email>", only works if to
39
+ # is not an array
40
+ from: 'noreply@example.com',
41
+ subject: subject,
42
+ merge_tags: {
43
+ receiver_name: record.name,
44
+ link: accept_invitation_url(record, :invitation_token => @token),
45
+ home_url: root_url
46
+ } # add additional merge tags, e.g. receiver_name = *|RECEIVER_NAME|*
47
+ end
48
+
49
+ See the documentation or inline comment in the code to see all available options.
50
+
51
+ **Also please use the [Mandrill::Serializer](https://github.com/maxschulze/mandrill-serializer) for `merge_objects`!**
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( https://github.com/maxschulze/action_mailer-mandrill/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'action_mailer/mandrill/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "action_mailer-mandrill"
8
+ spec.version = ActionMailer::Mandrill::VERSION
9
+ spec.authors = ["Max Schulze"]
10
+ spec.email = ["max@maxschulze.com"]
11
+ spec.summary = %q{Use this gem to send mails with Mandrill Templates from Action Mailer.}
12
+ # spec.description = %q{TODO: Write a longer description. Optional.}
13
+ spec.homepage = "http://maxschulze.com"
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_dependency "activesupport", '>= 2.0'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,80 @@
1
+ require "action_mailer/mandrill/version"
2
+ require 'active_support/concern'
3
+
4
+ module ActionMailer
5
+ # Adds a new way to send mails via Mandrill (actually uses normal SMTP
6
+ # just sets specific SMTP headers)
7
+ #
8
+ # @example Sending a mail via Mandrill with specific template
9
+ #
10
+ # def notification(user)
11
+ # @user = user
12
+ #
13
+ # mandrill_mail('user_invite',
14
+ # to: 'max@example.com',
15
+ # subject: 'test',
16
+ # merge_objects: [user]
17
+ # )
18
+ # end
19
+ #
20
+ module Mandrill
21
+ extend ActiveSupport::Concern
22
+
23
+ # Sends a mail with a specific mandrill template
24
+ # See http://help.mandrill.com/entries/21688056-Using-SMTP-Headers-to-customize-your-messages
25
+ # to learn more about each option.
26
+ #
27
+ # @param [String] template_slug The slug that identifies the template to use
28
+ # @param [Hash] options The options for the mail, such as sender, receiver, etc.
29
+ #
30
+ # @option options [String|Array] :to Recipient email
31
+ # @option options [String] :from Sender email (respects AM defaults)
32
+ # @option options [String] :subject The subject
33
+ # @option options [String] :link_tracking See X-MC-Track
34
+ # @option options [Array] :merge_objects Used to generate X-MC-MergeVars,
35
+ # need to be Mandrill Serializable (!)
36
+ # @option options [Hash] :merge_tags Used to generate X-MC-MergeVars,
37
+ # need to be Mandrill Serializable (!)
38
+ # @option options [Array] :tags Tag the email
39
+ #
40
+ # @raise [RuntimeError] if receivers are blank
41
+ def mandrill_mail(template_slug, options = {})
42
+ merge_tags = {}
43
+
44
+ headers['X-MC-Template'] = template_slug
45
+ headers['X-MC-Track'] = options.delete(:link_tracking) if options.has_key?(:link_tracking)
46
+ headers['X-MC-Tags'] = options.delete(:tags).join(',') if options.has_key?(:tags)
47
+
48
+ receiver_name = options.delete(:receiver_name)
49
+
50
+ receivers = options.delete(:to)
51
+ receivers = [receivers] unless receivers.is_a?(Array)
52
+ raise RuntimeError.new("Please specify at least one receiver") if receivers.blank?
53
+
54
+ if options.has_key?(:merge_objects)
55
+ options.delete(:merge_objects).each do |o|
56
+ merge_tags = merge_tags.merge!(o.to_mandrill_merge_tags)
57
+ end
58
+ end
59
+
60
+ if options.has_key?(:merge_tags)
61
+ merge_tags = merge_tags.merge! options.delete(:merge_tags)
62
+ end
63
+
64
+ receivers.each do |receiver|
65
+ headers['X-MC-MergeVars'] = JSON.generate(
66
+ merge_tags.merge!('_rcpt' => receiver),
67
+ ascii_only: true
68
+ )
69
+ end
70
+
71
+ options[:to] = receivers
72
+ options[:to] = "#{receiver_name} <#{receivers.first}>" if receivers.length == 1 && receiver_name.present?
73
+
74
+ mail(options) do |format|
75
+ format.text { render text: '' }
76
+ end
77
+ end
78
+
79
+ end
80
+ end
@@ -0,0 +1,5 @@
1
+ module ActionMailer
2
+ module Mandrill
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: action_mailer-mandrill
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Max Schulze
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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
+ description:
56
+ email:
57
+ - max@maxschulze.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - action_mailer-mandrill.gemspec
68
+ - lib/action_mailer/mandrill.rb
69
+ - lib/action_mailer/mandrill/version.rb
70
+ homepage: http://maxschulze.com
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.2.2
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Use this gem to send mails with Mandrill Templates from Action Mailer.
94
+ test_files: []