mandrill_mailer 0.3.3 → 0.3.4

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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Y2Y0MTUzMGJiNDc3OGVlODhmOTk2YjIxMmJkOGJiMmYwZjAxNTgwYQ==
5
+ data.tar.gz: !binary |-
6
+ MmQzNTM0ZWZjNjMwNjY3NDUwNDVmZWE1N2FlODI3NmEzZmRiYmY1NQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YTg4NTA2OTY2YzM5NDgzODQ0MTk3MTQyYjgxYmVlODdmYTAyMWU1NGMwZWM0
10
+ MzYwYTZkMTEzYWQ1MzY2YjZmOTk2NGYwMDZmNGFiZWNlYzdjMDAzM2M3ODM0
11
+ MWY4ZTExNWRiMGI2NWNiMWNhNjg4NDM2OWM2YTlhYjU5NThmZTg=
12
+ data.tar.gz: !binary |-
13
+ YzgzNGMzMzM3Y2QwYjZlOGVmNmE5ODUwYWQwNjZhZDk3ZTBjNGY5ZTc3NGZk
14
+ YTcxYjMxMWY0NDY0ZTk1ZDg5MWE4ZjllNmVlZGUzODZlYjUyMmY1MDNlZDNj
15
+ YTg2NjJjNGY2ZmYzMGI1NzU5NjAwOTVkOWQ1ZDEwOGQ0YTE1MWQ=
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  *.gem
2
2
  Gemfile.lock
3
+ .DS_Store
data/README.md CHANGED
@@ -147,5 +147,29 @@ The mailer and options passed to the `.test` method are yielded to the block.
147
147
 
148
148
  The `:email` option is the only required option, make sure to add at least this to your test object.
149
149
 
150
- ## TODO
151
- Either get rid of the mailchimp gem dependancy or hook into actionmailer like the mailchimp does to send normal emails.
150
+ ## Using Delayed Job
151
+ The typical Delayed Job mailer syntax won't work with this as of now. Either create a custom job or que the mailer as you would que a method. Take a look at the following examples:
152
+
153
+ ```ruby
154
+ def send_hallpass_expired_mailer
155
+ HallpassMailer.hallpass_expired(user).deliver
156
+ end
157
+ handle_asynchronously :send_hallpass_expired_mailer
158
+ ```
159
+
160
+ or using a custom job
161
+
162
+ ```ruby
163
+ def update_email_on_newsletter_subscription
164
+ Delayed::Job.enqueue( UpdateEmailJob.new(user, old_email, MAILCHIMP_LIST_ID) )
165
+ end
166
+ ```
167
+ The job looks like:
168
+
169
+ ```ruby
170
+ class UpdateEmailJob < Struct.new(:user, :old_email, :list)
171
+ def perform
172
+ MailchimpNewsletter.update_user_email(user.email, old_email, list)
173
+ end
174
+ end
175
+ ```
@@ -23,7 +23,8 @@
23
23
  # }
24
24
  # }
25
25
  # end,
26
- # template_content: {}
26
+ # template_content: {},
27
+ # attachments: [{file: File.read(File.expand_path('assets/some_image.png')), filename: 'My Image.png', mimetype: 'image/png'}]
27
28
  # end
28
29
  # end
29
30
 
@@ -51,6 +52,11 @@
51
52
  # a little like: '<div mc:edit="header">My email content</div>' You can insert content directly into
52
53
  # these fields by passing a Hash {'header' => 'my email content'}
53
54
 
55
+ # :attachments - An array of file objects with the following keys:
56
+ # file: This is the actual file, it will be converted to byte data in the mailer
57
+ # filename: The name of the file
58
+ # mimetype: This is the mimetype of the file. Ex. png = image/png, pdf = application/pdf, txt = text/plain etc
59
+
54
60
  # :headers - Extra headers to add to the message (currently only Reply-To and X-* headers are allowed) {"...": "..."}
55
61
 
56
62
  # :bcc - Add an email to bcc to
@@ -68,6 +74,7 @@
68
74
  # :google_analytics_campaign - String indicating the value to set for
69
75
  # the utm_campaign tracking parameter. If this isn't provided the email's
70
76
  # from address will be used instead.
77
+ require 'base64'
71
78
 
72
79
  module MandrillMailer
73
80
  class TemplateMailer
@@ -228,11 +235,9 @@ module MandrillMailer
228
235
  "merge_vars" => mandrill_rcpt_args(args[:recipient_vars]),
229
236
  "tags" => args[:tags],
230
237
  "google_analytics_domains" => args[:google_analytics_domains],
231
- "google_analytics_campaign" => args[:google_analytics_campaign]
238
+ "google_analytics_campaign" => args[:google_analytics_campaign],
232
239
  # "metadata" =>["..."],
233
- # "attachments" =>[
234
- # {"type" => "example type", "name" => "example name", "content" => "example content"}
235
- # ]
240
+ "attachments" => mandrill_attachment_args(args[:attachments])
236
241
  }
237
242
 
238
243
  # return self so we can chain deliver after the method call, like a normal mailer.
@@ -251,6 +256,17 @@ module MandrillMailer
251
256
 
252
257
  protected
253
258
 
259
+ def mandrill_attachment_args(args)
260
+ return unless args
261
+ args.map do |attachment|
262
+ attachment.symbolize_keys!
263
+ type = attachment[:mimetype]
264
+ name = attachment[:filename]
265
+ file = attachment[:file]
266
+ {"type" => type, "name" => name, "content" => Base64.encode64(file)}
267
+ end
268
+ end
269
+
254
270
  # Makes this class act as a singleton without it actually being a singleton
255
271
  # This keeps the syntax the same as the orginal mailers so we can swap quickly if something
256
272
  # goes wrong.
@@ -1,3 +1,3 @@
1
1
  module MandrillMailer
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
Binary file
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+ require 'base64'
2
3
 
3
4
  describe MandrillMailer::TemplateMailer do
4
5
  let(:image_path) { '/assets/image.jpg' }
@@ -9,7 +10,7 @@ describe MandrillMailer::TemplateMailer do
9
10
  before do
10
11
  MandrillMailer.config.api_key = api_key
11
12
  MandrillMailer.config.default_url_options = { host: default_host }
12
- MandrillMailer.config.any_instance.stub(:image_path).and_return(image_path)
13
+ MandrillMailer.config.stub(:image_path).and_return(image_path)
13
14
  end
14
15
 
15
16
  describe '#image_path' do
@@ -125,6 +126,9 @@ describe MandrillMailer::TemplateMailer do
125
126
  let(:var_rcpt_content) { 'boboblacksheep' }
126
127
  let(:to_email) { 'bob@email.com' }
127
128
  let(:to_name) { 'bob' }
129
+ let(:attachment_file) { File.read(File.expand_path('spec/support/test_image.png')) }
130
+ let(:attachment_filename) { 'test_image.png' }
131
+ let(:attachment_mimetype) { 'image/png' }
128
132
 
129
133
  let(:args) do
130
134
  {
@@ -143,7 +147,8 @@ describe MandrillMailer::TemplateMailer do
143
147
  bcc: 'email@email.com',
144
148
  tags: ['tag1'],
145
149
  google_analytics_domains: ["http://site.com"],
146
- google_analytics_campaign: '1237423474'
150
+ google_analytics_campaign: '1237423474',
151
+ attachments: [{file: attachment_file, filename: attachment_filename, mimetype: attachment_mimetype}]
147
152
  }
148
153
  end
149
154
 
@@ -182,7 +187,8 @@ describe MandrillMailer::TemplateMailer do
182
187
  "merge_vars" => [{"rcpt" => to_email, "vars" => [{"name" => var_rcpt_name, "content" => var_rcpt_content}]}],
183
188
  "tags" => args[:tags],
184
189
  "google_analytics_domains" => args[:google_analytics_domains],
185
- "google_analytics_campaign" => args[:google_analytics_campaign]
190
+ "google_analytics_campaign" => args[:google_analytics_campaign],
191
+ "attachments" => [{'type' => attachment_mimetype, 'name' => attachment_filename, 'content' => Base64.encode64(attachment_file)}]
186
192
  })
187
193
  end
188
194
 
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mandrill_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
5
- prerelease:
4
+ version: 0.3.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Adam Rensel
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-16 00:00:00.000000000 Z
11
+ date: 2013-06-24 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: actionpack
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: mandrill-api
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: pry
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rspec
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
@@ -110,32 +99,33 @@ files:
110
99
  - mandrill_mailer.gemspec
111
100
  - spec/fake_rails/fake_rails.rb
112
101
  - spec/spec_helper.rb
102
+ - spec/support/test_image.png
113
103
  - spec/template_mailer_spec.rb
114
104
  homepage: https://github.com/renz45/mandrill_mailer
115
105
  licenses: []
106
+ metadata: {}
116
107
  post_install_message:
117
108
  rdoc_options: []
118
109
  require_paths:
119
110
  - lib
120
111
  required_ruby_version: !ruby/object:Gem::Requirement
121
- none: false
122
112
  requirements:
123
113
  - - ! '>='
124
114
  - !ruby/object:Gem::Version
125
115
  version: '0'
126
116
  required_rubygems_version: !ruby/object:Gem::Requirement
127
- none: false
128
117
  requirements:
129
118
  - - ! '>='
130
119
  - !ruby/object:Gem::Version
131
120
  version: '0'
132
121
  requirements: []
133
122
  rubyforge_project:
134
- rubygems_version: 1.8.24
123
+ rubygems_version: 2.0.3
135
124
  signing_key:
136
- specification_version: 3
125
+ specification_version: 4
137
126
  summary: Transactional Mailer for Mandrill
138
127
  test_files:
139
128
  - spec/fake_rails/fake_rails.rb
140
129
  - spec/spec_helper.rb
130
+ - spec/support/test_image.png
141
131
  - spec/template_mailer_spec.rb