mandrill_mailer 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NDA1OTI0MDFjNWE3MDU3ZGM3ODEyZWI4ODZlMzFhMjllYmFkMjUwNA==
5
- data.tar.gz: !binary |-
6
- NGJjZGVhNTUyMThkZDlmOGJmNGVlZTM4ZGI4NGEzOTA1MDU1ZDA5MA==
2
+ SHA1:
3
+ metadata.gz: f6f21a3380bcccadc130ad1ff2a66165d9cdb651
4
+ data.tar.gz: 961a5ec4b5d339801a96738ea82eb0b892117dc3
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MDM5MTk5MDM3ODQwMDhjZWZiY2NmMDI3ZTM1NDc0MWE1YTc4ZGY5OWY3MDU3
10
- NTFmNjliZDU5MmZiZWU0Yzk3ZGNmZGU4MDNmNDI0MDgzYTk5YzZmNmYzNTQ2
11
- MzAxNzFjYzQ1NGFkMjEyOTZlNDAzODIyZTczNmQzYjMzMjIyNTQ=
12
- data.tar.gz: !binary |-
13
- MGJkOWE4YmJhNDIzNzIzNzRkZDA0Njk5N2U4NjFiOTRjYzcyM2NiYTUzZjgz
14
- MjUyMzc2ZjIzM2U0ZmQ1ZmQ3OTdmZjdhNDJjMWVhZDIyYjVmOTQ4MDFlNjkz
15
- MmVhYTY5ZWQxMDA4NzJmYTU3YjMwNzIxMDY2Zjk3MWIxZjY2ZTI=
6
+ metadata.gz: 4cb947f8485c7b951ac24fb2fa2dd3f6d800bb7a6ed8a58718003e4eeb8ab79ebdb64626bdde4ae292a343c8d4378d8341bde7644091c7477454e9fae31cc3f2
7
+ data.tar.gz: 8d6a445d241f073487eb0275bd7399481d8e9881ac1a463fa30efd1d941bd9837b49bcd6737bca7312526ef02de36447fab1c57f866d02115bd4aaeea2a3d1cf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 0.4.7
2
+ - [IMPROVEMENT] Reworked how defaults were stored so that they are accessible when being extended
3
+
1
4
  # 0.4.6
2
5
  - [FEATURE] Added support for images array of embedded images
3
6
 
data/README.md CHANGED
@@ -1,14 +1,31 @@
1
- # Mandrill Mailer gem
2
- MandrillMailer class for sending transactional emails through Mandrill.
3
- Only template based emails are supported at this time.
1
+ # Mandrill Mailer
2
+ [![Gem Version](http://img.shields.io/gem/v/mandrill_mailer.svg)](rubygems.org/gems/mandrill_mailer)
3
+ [![Code Climate](http://img.shields.io/codeclimate/github/renz45/mandrill_mailer.svg)](https://codeclimate.com/github/renz45/mandrill_mailer)
4
+ [![Dependencies](http://img.shields.io/gemnasium/renz45/mandrill_mailer.svg)](https://gemnasium.com/renz45/mandrill_mailer)
4
5
 
5
- ## Usage
6
- Add `gem 'mandrill_mailer'` to your Gemfile
6
+ Inherit the MandrillMailer class in your existing Rails mailers to send transactional emails through Mandrill using their template-based emails.
7
+
8
+ ## Installation
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```
12
+ gem 'mandrill_mailer'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```
18
+ $ bundle install
19
+ ```
20
+
21
+ Or install it yourself as:
7
22
 
8
- Add this to your `mail.rb` in initializers.
9
- You don't need to add the ActionMailer stuff unless your still using ActionMailer emails.
10
- This just plugs into the Mandrill smtp servers. If your doing template based emails
11
- through the Mandrill api you really only need the `MandrillMailer.configure` part
23
+ ```
24
+ $ gem install mandrill_mailer
25
+ ```
26
+
27
+ ## Usage
28
+ Add the following to your `mail.rb` in your Rails app's `config/initializers` directory:
12
29
 
13
30
  ```ruby
14
31
  ActionMailer::Base.smtp_settings = {
@@ -25,25 +42,37 @@ MandrillMailer.configure do |config|
25
42
  end
26
43
  ```
27
44
 
28
- Don't forget to setup your ENV variables on your server
45
+ You don't need to add the ActionMailer stuff unless you're still using ActionMailer emails.
46
+
47
+ This uses the Mandrill SMTP servers. If you're using template-based emails
48
+ through the Mandrill API you only need the `MandrillMailer.configure` portion.
29
49
 
30
- You will also need to set default_url_options for the mailer, similar to action mailer
31
- in your environment config files:
50
+ Do not forget to setup the environment (`ENV`) variables on your server instead
51
+ of hardcoding your Mandrill username and password in the `mail.rb` initializer.
32
52
 
33
- `config.mandrill_mailer.default_url_options = { :host => 'localhost' }`
53
+ You will also need to set `default_url_options` for the mailer, similar to ActionMailer
54
+ in your environment config files in `config/environments`:
55
+
56
+ ```ruby
57
+ config.mandrill_mailer.default_url_options = { :host => 'localhost' }
58
+ ```
34
59
 
35
60
  ## Creating a new mailer
36
- Creating a new Mandrill Mailer is similar to a normal Rails mailer:
61
+ Creating a new Mandrill mailer is similar to a typical Rails one:
37
62
 
38
63
  ```ruby
39
64
  class InvitationMailer < MandrillMailer::TemplateMailer
40
65
  default from: 'support@example.com'
41
66
 
42
67
  def invite(invitation)
43
- mandrill_mail template: 'Group Invite',
68
+ # in this example `invitation.invitees` is an Array
69
+ invitees = invitation.invitees.map { |invitee| { email: invitee.email, name: invitee.name } }
70
+
71
+ mandrill_mail template: 'group-invite',
44
72
  subject: I18n.t('invitation_mailer.invite.subject'),
45
- to: invitation.invitees.map {|invitee| { email: invitee.email, name: invitee.name }},
46
- # to: {email: invitation.email, name: 'Honored Guest'},
73
+ to: invitees,
74
+ # to: invitation.email,
75
+ # to: { email: invitation.email, name: 'Honored Guest' },
47
76
  vars: {
48
77
  'OWNER_NAME' => invitation.owner_name,
49
78
  'PROJECT_NAME' => invitation.project_name
@@ -60,34 +89,36 @@ class InvitationMailer < MandrillMailer::TemplateMailer
60
89
  end
61
90
  end
62
91
  end
63
- ```
92
+ ```
64
93
 
65
94
  * `#default:`
66
95
  * `:from` - set the default from email address for the mailer
67
96
  * `:from_name` - set the default from name for the mailer. If not set, defaults to from email address. Setting :from_name in the .mandrill_mail overrides the default.
68
97
 
69
98
  * `.mandrill_mail`
70
- * `:template`(required) - Template name from within Mandrill
99
+ * `:template`(required) - Template slug from within Mandrill (for backwards-compatibility, the template name may also be used but the immutable slug is preferred)
71
100
 
72
101
  * `:subject` - Subject of the email. If no subject supplied, it will fall back to the template default subject from within Mandrill
73
102
 
74
- * `:to`(required) - Accepts an email String, or hash with :name and :email keys
75
- ex. `{email: 'someone@email.com', name: 'Bob Bertly'}`
103
+ * `:to`(required) - Accepts an email String, a Hash with :name and :email keys, or an Array of Hashes with :name and :email keys
104
+ - examples:
105
+ 1. `'example@domain.com'`
106
+ 2. `{ email: 'someone@email.com', name: 'Bob Bertly' }`
107
+ 3. `[{ email: 'someone@email.com', name: 'Bob Bertly' }, { email: 'other@email.com', name: 'Claire Nayo' }]`
76
108
 
77
109
  * `:vars` - A Hash of merge tags made available to the email. Use them in the
78
- email by wrapping them in `*||*` vars: {'OWNER_NAME' => 'Suzy'} is used
79
- by doing: `*|OWNER_NAME|*` in the email template within Mandrill
110
+ email by wrapping them in `*||*`. For example `{'OWNER_NAME' => 'Suzy'}` is used by doing: `*|OWNER_NAME|*` in the email template within Mandrill
80
111
 
81
- * `:recipient_vars` - Similar to `:vars`, this is a Hash of merge tags specific to a particular recipient.
112
+ * `:recipient_vars` - Similar to `:vars`, this is a Hash of merge vars specific to a particular recipient.
82
113
  Use this if you are sending batch transactions and hence need to send multiple emails at one go.
83
114
  ex. `[{'someone@email.com' => {'INVITEE_NAME' => 'Roger'}}, {'another@email.com' => {'INVITEE_NAME' => 'Tommy'}}]`
84
115
 
85
116
  * `:template_content` - A Hash of values and content for Mandrill editable content blocks.
86
117
  In MailChimp templates there are editable regions with 'mc:edit' attributes that look
87
- a little like: `<div mc:edit="header">My email content</div>` You can insert content directly into
118
+ like: `<div mc:edit="header">My email content</div>` You can insert content directly into
88
119
  these fields by passing a Hash `{'header' => 'my email content'}`
89
120
 
90
- * `:headers` - Extra headers to add to the message (currently only Reply-To and X-* headers are allowed) {"...": "..."}
121
+ * `:headers` - Extra headers to add to the message (currently only `Reply-To` and `X-*` headers are allowed) {"...": "..."}
91
122
 
92
123
  * `:bcc` - Add an email to bcc to
93
124
 
@@ -116,7 +147,7 @@ end
116
147
 
117
148
  * `:images` - An array of embedded images to add to the message:
118
149
  * `file:` This is the actual file, it will be converted to byte data in the mailer
119
- * `filename:` The Content ID of the image - use <img src="cid:THIS_VALUE"> to reference the image in your HTML content
150
+ * `filename:` The Content ID of the image - use `<img src="cid:THIS_VALUE">` to reference the image in your HTML content
120
151
  * `mimetype:` The MIME type of the image - must start with "image/"
121
152
 
122
153
  * `:async` - Whether or not this message should be sent asynchronously
@@ -7,9 +7,12 @@
7
7
  # default from: 'support@codeschool.com'
8
8
 
9
9
  # def invite(invitation)
10
+ # invitees = invitation.invitees.map { |invitee| { email: invitee.email, name: invitee.name } }
11
+ #
10
12
  # mandrill_mail template: 'Group Invite',
11
13
  # subject: I18n.t('invitation_mailer.invite.subject'),
12
- # to: invitation.invitees.map {|invitee| { email: invitee.email, name: invitee.name }},
14
+ # to: invitees,
15
+ # # to: invitation.email
13
16
  # # to: { email: invitation.email, name: invitation.recipient_name }
14
17
  # vars: {
15
18
  # 'OWNER_NAME' => invitation.owner_name,
@@ -38,8 +41,17 @@
38
41
 
39
42
  # :subject(required) - Subject of the email
40
43
 
41
- # :to(required) - Accepts an email String, or hash with :name and :email keys
42
- # ex. {email: 'someone@email.com', name: 'Bob Bertly'}
44
+ # :to(required) - Accepts an email String, a Hash with :name and :email keys
45
+ # or an Array of Hashes with :name and :email keys
46
+ # examples:
47
+ # 1)
48
+ # 'example@domain.com`
49
+ # 2)
50
+ # { email: 'someone@email.com', name: 'Bob Bertly' }
51
+ # 3)
52
+ # [{ email: 'someone@email.com', name: 'Bob Bertly' },
53
+ # { email: 'other@email.com', name: 'Claire Nayo' }]
54
+ #
43
55
 
44
56
  # :vars - A Hash of merge tags made available to the email. Use them in the
45
57
  # email by wrapping them in '*||*' vars: {'OWNER_NAME' => 'Suzy'} is used
@@ -108,13 +120,21 @@ module MandrillMailer
108
120
  # default from: 'foo@bar.com'
109
121
  #
110
122
  # Returns options
123
+ def self.defaults
124
+ @defaults || super_defaults
125
+ end
126
+
127
+ def self.super_defaults
128
+ superclass.defaults if superclass.respond_to?(:defaults)
129
+ end
130
+
111
131
  def self.default(args)
112
132
  @defaults ||= {}
113
133
  @defaults[:from] ||= 'example@email.com'
114
134
  @defaults.merge!(args)
115
135
  end
116
136
  class << self
117
- attr_accessor :defaults
137
+ attr_writer :defaults
118
138
  end
119
139
 
120
140
  # Public: setup a way to test mailer methods
@@ -1,3 +1,3 @@
1
1
  module MandrillMailer
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
3
3
  end
@@ -329,6 +329,27 @@ describe MandrillMailer::TemplateMailer do
329
329
  klassA.mandrill_mail({vars: {}}).message['from_name'].should eq 'ClassA'
330
330
  klassB.mandrill_mail({vars: {}}).message['from_name'].should eq 'ClassB'
331
331
  end
332
+
333
+ it 'should use defaults from the parent class' do
334
+ klassA = Class.new(MandrillMailer::TemplateMailer) do
335
+ default from_name: 'ClassA'
336
+ end
337
+ klassB = Class.new(klassA) do
338
+ end
339
+
340
+ klassB.mandrill_mail({vars:{}}).message['from_name'].should eq 'ClassA'
341
+ end
342
+
343
+ it 'should allow overriding defaults from the parent' do
344
+ klassA = Class.new(MandrillMailer::TemplateMailer) do
345
+ default from_name: 'ClassA'
346
+ end
347
+ klassB = Class.new(klassA) do
348
+ default from_name: 'ClassB'
349
+ end
350
+
351
+ klassB.mandrill_mail({vars:{}}).message['from_name'].should eq 'ClassB'
352
+ end
332
353
  end
333
354
 
334
355
  describe '#respond_to' do
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mandrill_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Rensel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-27 00:00:00.000000000 Z
11
+ date: 2014-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: actionpack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mandrill-api
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.0.9
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.0.9
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: Transactional Mailer for Mandrill
@@ -87,8 +87,8 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .gitignore
91
- - .rspec
90
+ - ".gitignore"
91
+ - ".rspec"
92
92
  - CHANGELOG.md
93
93
  - Gemfile
94
94
  - README.md
@@ -113,17 +113,17 @@ require_paths:
113
113
  - lib
114
114
  required_ruby_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - ! '>='
116
+ - - ">="
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - ! '>='
121
+ - - ">="
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.1.9
126
+ rubygems_version: 2.2.2
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: Transactional Mailer for Mandrill