mandrill_mailer 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mandrill_mailer (0.2.0)
4
+ mandrill_mailer (0.2.1)
5
5
  actionpack
6
6
  activesupport
7
- mailchimp (= 0.0.7.alpha)
7
+ mandrill-api (~> 1.0.9)
8
8
 
9
9
  GEM
10
10
  remote: http://rubygems.org/
@@ -25,21 +25,20 @@ GEM
25
25
  activesupport (3.2.8)
26
26
  i18n (~> 0.6)
27
27
  multi_json (~> 1.0)
28
- builder (3.0.3)
28
+ builder (3.0.4)
29
29
  coderay (1.0.7)
30
30
  diff-lcs (1.1.3)
31
31
  erubis (2.7.0)
32
+ excon (0.15.5)
32
33
  hike (1.2.1)
33
- httparty (0.9.0)
34
- multi_json (~> 1.0)
35
- multi_xml
36
34
  i18n (0.6.1)
37
35
  journey (1.0.4)
38
- mailchimp (0.0.7.alpha)
39
- httparty
36
+ json (1.7.5)
37
+ mandrill-api (1.0.9)
38
+ excon (~> 0.15.4)
39
+ json (~> 1.7.4)
40
40
  method_source (0.8)
41
41
  multi_json (1.3.6)
42
- multi_xml (0.5.1)
43
42
  pry (0.9.10)
44
43
  coderay (~> 1.0.5)
45
44
  method_source (~> 0.8)
@@ -129,6 +129,15 @@ module MandrillMailer
129
129
 
130
130
  end
131
131
 
132
+ # Public: The name of the template to use
133
+ attr_accessor :template_name
134
+
135
+ # Public: Template content
136
+ attr_accessor :template_content
137
+
138
+ # Public: Other information on the message to send
139
+ attr_accessor :message
140
+
132
141
  # Public: Triggers the stored Mandril params to be sent to the Mandrill api
133
142
  #
134
143
  # text - The String to be duplicated.
@@ -141,8 +150,8 @@ module MandrillMailer
141
150
  #
142
151
  # Returns the duplicated String.
143
152
  def deliver
144
- mandrill = Mailchimp::Mandrill.new(api_key)
145
- mandrill.messages_send_template(@data)
153
+ mandrill = Mandrill::API.new(api_key)
154
+ mandrill.messages.send_template(template_name, template_content, message)
146
155
  end
147
156
 
148
157
  # Public: Build the hash needed to send to the mandrill api
@@ -176,44 +185,53 @@ module MandrillMailer
176
185
  # format the :to param to what Mandrill expects if a string or array is passed
177
186
  args[:to] = format_to_params(args[:to])
178
187
 
179
- @data = {"key" => api_key,
180
- "template_name" => args[:template],
181
- "template_content" => mandrill_args(args[:template_content]),
182
- "message" => {
183
- "subject" => args[:subject],
184
- "from_email" => args[:from] || @@defaults[:from],
185
- "from_name" => args[:from_name] || @@defaults[:from],
186
- "to" => args[:to],
187
- "headers" => args[:headers],
188
- "track_opens" => true,
189
- "track_clicks" => true,
190
- "auto_text" => true,
191
- "url_strip_qs" => true,
192
- "bcc_address" => args[:bcc],
193
- "global_merge_vars" => mandrill_args(args[:vars]),
194
- # "merge_vars" =>[
195
- # {
196
- # "rcpt" => "email@email.com"
197
- # "vars" => {"name" => "VARS", "content" => "vars content"}
198
- # }
199
- # ]
200
-
201
- "tags" => args[:tags],
202
- "google_analytics_domains" => args[:google_analytics_domains],
203
- "google_analytics_campaign" => args[:google_analytics_campaign]
204
- # "metadata" =>["..."],
205
- # "attachments" =>[
206
- # {"type" => "example type", "name" => "example name", "content" => "example content"}
207
- # ]
208
- }
188
+ # Set the template name
189
+ self.template_name = args.delete(:template)
190
+
191
+ # Set the template content
192
+ self.template_content = mandrill_args(args.delete(:template_content))
193
+
194
+ # Construct message hash
195
+ self.message = {
196
+ "subject" => args[:subject],
197
+ "from_email" => args[:from] || @@defaults[:from],
198
+ "from_name" => args[:from_name] || @@defaults[:from],
199
+ "to" => args[:to],
200
+ "headers" => args[:headers],
201
+ "track_opens" => true,
202
+ "track_clicks" => true,
203
+ "auto_text" => true,
204
+ "url_strip_qs" => true,
205
+ "bcc_address" => args[:bcc],
206
+ "global_merge_vars" => mandrill_args(args[:vars]),
207
+ # "merge_vars" =>[
208
+ # {
209
+ # "rcpt" => "email@email.com"
210
+ # "vars" => {"name" => "VARS", "content" => "vars content"}
211
+ # }
212
+ # ]
213
+
214
+ "tags" => args[:tags],
215
+ "google_analytics_domains" => args[:google_analytics_domains],
216
+ "google_analytics_campaign" => args[:google_analytics_campaign]
217
+ # "metadata" =>["..."],
218
+ # "attachments" =>[
219
+ # {"type" => "example type", "name" => "example name", "content" => "example content"}
220
+ # ]
209
221
  }
210
222
 
211
223
  # return self so we can chain deliver after the method call, like a normal mailer.
212
224
  return self
213
225
  end
214
226
 
227
+ # Public: Data hash (deprecated)
215
228
  def data
216
- @data
229
+ {
230
+ "key" => api_key,
231
+ "template_name" => template_name,
232
+ "template_content" => template_content,
233
+ "message" => message
234
+ }
217
235
  end
218
236
 
219
237
  protected
@@ -290,4 +308,4 @@ module MandrillMailer
290
308
  MandrillMailer.config.api_key
291
309
  end
292
310
  end
293
- end
311
+ end
@@ -1,3 +1,3 @@
1
1
  module MandrillMailer
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -5,6 +5,8 @@ require 'mandrill_mailer/template_mailer'
5
5
  require 'mandrill_mailer/version'
6
6
 
7
7
  module MandrillMailer
8
+ autoload :Mandrill, 'mandrill'
9
+
8
10
  if defined?(Rails)
9
11
  def self.configure(&block)
10
12
  if block_given?
@@ -23,4 +25,4 @@ module MandrillMailer
23
25
  @@config
24
26
  end
25
27
  end
26
- end
28
+ end
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.add_dependency 'activesupport'
21
21
  s.add_dependency 'actionpack'
22
- s.add_dependency 'mailchimp', '0.0.7.alpha'
22
+ s.add_dependency 'mandrill-api', '~>1.0.9'
23
23
 
24
24
  s.add_development_dependency 'pry'
25
25
  s.add_development_dependency 'rspec'
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe MandrillMailer::TemplateMailer do
4
4
  let(:image_path) { '/assets/image.jpg' }
5
5
  let(:default_host) { 'localhost:3000' }
6
- let(:mailer) {described_class.new}
6
+ let(:mailer) { described_class.new }
7
7
  let(:api_key) { '1237861278' }
8
8
 
9
9
  before do
@@ -101,7 +101,7 @@ describe MandrillMailer::TemplateMailer do
101
101
  let(:to_email) { 'bob@email.com' }
102
102
  let(:to_name) { 'bob' }
103
103
 
104
- let(:data) do
104
+ let(:args) do
105
105
  {
106
106
  template: 'Email Template',
107
107
  subject: "super secret",
@@ -117,7 +117,8 @@ describe MandrillMailer::TemplateMailer do
117
117
  google_analytics_campaign: '1237423474'
118
118
  }
119
119
  end
120
- subject { mailer.mandrill_mail(data) }
120
+
121
+ subject { mailer.mandrill_mail(args) }
121
122
 
122
123
  before do
123
124
  MandrillMailer::TemplateMailer.default from: from_email
@@ -127,27 +128,39 @@ describe MandrillMailer::TemplateMailer do
127
128
  should eq mailer
128
129
  end
129
130
 
130
- it 'should produce the correct data' do
131
- mail = MandrillMailer::TemplateMailer.new().mandrill_mail(data)
132
- mail.data.should eq ({"key" => api_key,
133
- "template_name" => data[:template],
134
- "template_content" => [{'name' => template_content_name, 'content' => template_content_content}],
135
- "message" => {
136
- "subject" => data[:subject],
137
- "from_email" => from_email,
138
- "from_name" => from_email,
139
- "to" => [{'email' => to_email, 'name' => to_name}],
140
- "headers" => data[:headers],
141
- "track_opens" => true,
142
- "track_clicks" => true,
143
- "auto_text" => true,
144
- "url_strip_qs" => true,
145
- "bcc_address" => data[:bcc],
146
- "global_merge_vars" => [{"name" => var_name, "content" => var_content}],
147
- "tags" => data[:tags],
148
- "google_analytics_domains" => data[:google_analytics_domains],
149
- "google_analytics_campaign" => data[:google_analytics_campaign]
150
- }
131
+ it 'should set the template name' do
132
+ subject.template_name.should eq 'Email Template'
133
+ end
134
+
135
+ it 'should set the template content' do
136
+ subject.template_content.should eq [{'name' => template_content_name, 'content' => template_content_content}]
137
+ end
138
+
139
+ it 'should produce the correct message' do
140
+ subject.message.should eq ({
141
+ "subject" => args[:subject],
142
+ "from_email" => from_email,
143
+ "from_name" => from_email,
144
+ "to" => [{'email' => to_email, 'name' => to_name}],
145
+ "headers" => args[:headers],
146
+ "track_opens" => true,
147
+ "track_clicks" => true,
148
+ "auto_text" => true,
149
+ "url_strip_qs" => true,
150
+ "bcc_address" => args[:bcc],
151
+ "global_merge_vars" => [{"name" => var_name, "content" => var_content}],
152
+ "tags" => args[:tags],
153
+ "google_analytics_domains" => args[:google_analytics_domains],
154
+ "google_analytics_campaign" => args[:google_analytics_campaign]
155
+ })
156
+ end
157
+
158
+ it 'should retain data method' do
159
+ subject.data.should eq({
160
+ "key" => MandrillMailer.config.api_key,
161
+ "template_name" => subject.template_name,
162
+ "template_content" => subject.template_content,
163
+ "message" => subject.message,
151
164
  })
152
165
  end
153
166
  end
@@ -192,4 +205,4 @@ describe MandrillMailer::TemplateMailer do
192
205
  end
193
206
  end
194
207
  end
195
- end
208
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mandrill_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-04 00:00:00.000000000 Z
12
+ date: 2012-12-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -44,21 +44,21 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: mailchimp
47
+ name: mandrill-api
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - '='
51
+ - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 0.0.7.alpha
53
+ version: 1.0.9
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - '='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 0.0.7.alpha
61
+ version: 1.0.9
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: pry
64
64
  requirement: !ruby/object:Gem::Requirement