sparkpost_rails 1.2.0 → 1.3.0
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 +4 -4
- data/README.md +35 -20
- data/lib/sparkpost_rails.rb +4 -0
- data/lib/sparkpost_rails/delivery_method.rb +16 -4
- data/lib/sparkpost_rails/exceptions.rb +1 -1
- data/lib/sparkpost_rails/version.rb +1 -1
- data/spec/inline_content_spec.rb +21 -0
- data/spec/inline_css_spec.rb +49 -0
- metadata +20 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 925047803a24a8f98ba5f888f81c4a1ad472f9fc
|
4
|
+
data.tar.gz: 171842fb600f86f2e65143102ccdba962ac80d17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a783aaf00991597cc6f3b5558db1b43f285e9196cc9cebf22e21f87ba54c5b5cc7cfcc20158cfa1ef9309c70f9ff2da7e6f0fb30f1a6f6f1ae0606bcfa8187ea
|
7
|
+
data.tar.gz: 6ef6d2888ebf9d6b1864ab77df43aaae54d59abd28ab173621b173b9e3d52877931f6415b27efbda4b9454b730026b1b6804e0f665d9543a084f65caa6ee0d54
|
data/README.md
CHANGED
@@ -47,6 +47,9 @@ SparkPostRails.configure do |c|
|
|
47
47
|
c.campaign_id = 'YOUR-CAMPAIGN'
|
48
48
|
c.transactional = true
|
49
49
|
c.ip_pool = "MY-POOL"
|
50
|
+
c.inline_css = true
|
51
|
+
c.html_content_only = true
|
52
|
+
c.subaccount = "123"
|
50
53
|
end
|
51
54
|
```
|
52
55
|
|
@@ -60,6 +63,9 @@ return_path = nil
|
|
60
63
|
campaign_id = nil
|
61
64
|
transactional = false
|
62
65
|
ip_pool = nil
|
66
|
+
inline_css = false
|
67
|
+
html_content_only = false
|
68
|
+
subaccount = nil
|
63
69
|
```
|
64
70
|
|
65
71
|
Usage
|
@@ -97,7 +103,8 @@ data = { track_opens: true,
|
|
97
103
|
campaign_id: "My Campaign",
|
98
104
|
transactional: true,
|
99
105
|
ip_pool = "SPECIAL_POOL",
|
100
|
-
|
106
|
+
api_key = "MESSAGE_SPECIFIC_API_KEY"
|
107
|
+
subaccount = "123"
|
101
108
|
}
|
102
109
|
|
103
110
|
mail(to: to_email, subject: "Test", body: "test", sparkpost_data: data)
|
@@ -137,6 +144,32 @@ data = { description: "My Important Message" }
|
|
137
144
|
mail(to: to_email, subject: "Test", body: "test", sparkpost_data: data)
|
138
145
|
```
|
139
146
|
|
147
|
+
By default, content from single-part messages is sent at plain-text. If you are only intending to send HTML email, with no plain-text part, you can specify this
|
148
|
+
as shown below. You can also set this in the configuration to ensure that all single-part emails are sent as html.
|
149
|
+
|
150
|
+
```
|
151
|
+
data = { html_content_only: true }
|
152
|
+
|
153
|
+
mail(to: to_email, subject: "Test", body: "<h1>test</h1>", sparkpost_data: data)
|
154
|
+
```
|
155
|
+
|
156
|
+
### Subaccounts
|
157
|
+
SparkPostRails supports sending messages via subaccounts in two ways. The default API key set in the configuration can be overriden on a message-by-message basis with a subaccount API key.
|
158
|
+
|
159
|
+
```
|
160
|
+
data = { api_key: "SUBACCOUNT_API_KEY" }
|
161
|
+
|
162
|
+
mail(subject: "Test", body: "test", sparkpost_data: data)
|
163
|
+
```
|
164
|
+
|
165
|
+
Subaccounts can also be leveraged using the subaccount ID with the master API key.
|
166
|
+
|
167
|
+
```
|
168
|
+
data = { subaccount: "123" }
|
169
|
+
|
170
|
+
mail(subject: "Test", body: "test", sparkpost_data: data)
|
171
|
+
```
|
172
|
+
|
140
173
|
### Recipient Lists
|
141
174
|
SparkPostRails supports using SparkPost stored recipient lists. Simply add the list_id to the sparkpost_data hash on the mail message:
|
142
175
|
|
@@ -156,7 +189,7 @@ to your sparkpost_data hash, with the key :substitution_data.
|
|
156
189
|
|
157
190
|
```
|
158
191
|
sub_data = {first_name: "Sam",
|
159
|
-
last_name: "Test
|
192
|
+
last_name: "Test}
|
160
193
|
|
161
194
|
data = { substitution_data: sub_data }
|
162
195
|
|
@@ -187,21 +220,3 @@ headers["Sensitivity"] = "private"
|
|
187
220
|
|
188
221
|
mail(to: to_email, subject: "Test", body: "test")
|
189
222
|
```
|
190
|
-
|
191
|
-
Update Note!
|
192
|
-
============
|
193
|
-
|
194
|
-
If you have been using Version 0.0.5 or earlier of this gem, when you upgrade, you'll need to
|
195
|
-
change your initalizer as follows:
|
196
|
-
|
197
|
-
```
|
198
|
-
SparkpostRails.configure do |c|
|
199
|
-
```
|
200
|
-
|
201
|
-
becomes:
|
202
|
-
|
203
|
-
```
|
204
|
-
SparkPostRails.configure do |c|
|
205
|
-
```
|
206
|
-
|
207
|
-
We have changed the module name to align with the official SparkPost gem's naming convention.
|
data/lib/sparkpost_rails.rb
CHANGED
@@ -24,6 +24,8 @@ module SparkPostRails
|
|
24
24
|
|
25
25
|
attr_accessor :transactional
|
26
26
|
attr_accessor :ip_pool
|
27
|
+
attr_accessor :inline_css
|
28
|
+
attr_accessor :html_content_only
|
27
29
|
|
28
30
|
attr_accessor :subaccount
|
29
31
|
|
@@ -48,6 +50,8 @@ module SparkPostRails
|
|
48
50
|
|
49
51
|
@transactional = false
|
50
52
|
@ip_pool = nil
|
53
|
+
@inline_css = false
|
54
|
+
@html_content_only = false
|
51
55
|
|
52
56
|
@subaccount = nil
|
53
57
|
end
|
@@ -23,7 +23,7 @@ module SparkPostRails
|
|
23
23
|
|
24
24
|
prepare_subject_from mail
|
25
25
|
prepare_cc_headers_from mail, sparkpost_data
|
26
|
-
prepare_inline_content_from mail
|
26
|
+
prepare_inline_content_from mail, sparkpost_data
|
27
27
|
prepare_attachments_from mail
|
28
28
|
end
|
29
29
|
|
@@ -139,8 +139,7 @@ module SparkPostRails
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
-
|
143
|
-
def prepare_inline_content_from mail
|
142
|
+
def prepare_inline_content_from mail, sparkpost_data
|
144
143
|
if mail.multipart?
|
145
144
|
if mail.html_part
|
146
145
|
@data[:content][:html] = cleanse_encoding(mail.html_part.body.to_s)
|
@@ -150,7 +149,11 @@ module SparkPostRails
|
|
150
149
|
@data[:content][:text] = cleanse_encoding(mail.text_part.body.to_s)
|
151
150
|
end
|
152
151
|
else
|
153
|
-
|
152
|
+
if SparkPostRails.configuration.html_content_only || sparkpost_data[:html_content_only]
|
153
|
+
@data[:content][:html] = cleanse_encoding(mail.body.to_s)
|
154
|
+
else
|
155
|
+
@data[:content][:text] = cleanse_encoding(mail.body.to_s)
|
156
|
+
end
|
154
157
|
end
|
155
158
|
end
|
156
159
|
|
@@ -196,6 +199,7 @@ module SparkPostRails
|
|
196
199
|
prepare_transactional_from sparkpost_data
|
197
200
|
prepare_skip_suppression_from sparkpost_data
|
198
201
|
prepare_ip_pool_from sparkpost_data
|
202
|
+
prepare_inline_css_from sparkpost_data
|
199
203
|
prepare_delivery_schedule_from mail
|
200
204
|
end
|
201
205
|
|
@@ -286,6 +290,14 @@ module SparkPostRails
|
|
286
290
|
end
|
287
291
|
end
|
288
292
|
|
293
|
+
def prepare_inline_css_from sparkpost_data
|
294
|
+
@data[:options][:inline_css] = SparkPostRails.configuration.inline_css
|
295
|
+
|
296
|
+
if sparkpost_data.has_key?(:inline_css)
|
297
|
+
@data[:options][:inline_css] = sparkpost_data[:inline_css]
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
289
301
|
def prepare_delivery_schedule_from mail
|
290
302
|
# Format YYYY-MM-DDTHH:MM:SS+-HH:MM or "now". Example: '2015-02-11T08:00:00-04:00'. -From SparkPost API Docs
|
291
303
|
if mail.date && (mail.date > DateTime.now) && (mail.date < (DateTime.now + 1.year))
|
data/spec/inline_content_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe SparkPostRails::DeliveryMethod do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
+
SparkPostRails.configuration.set_defaults
|
6
7
|
@delivery_method = SparkPostRails::DeliveryMethod.new
|
7
8
|
end
|
8
9
|
|
@@ -30,6 +31,26 @@ describe SparkPostRails::DeliveryMethod do
|
|
30
31
|
expect(@delivery_method.data[:content][:html]).to eq("<h1>Hello, Testing!</h1>")
|
31
32
|
end
|
32
33
|
|
34
|
+
it "supports HTML-only content as a configuration setting" do
|
35
|
+
SparkPostRails.configure do |c|
|
36
|
+
c.html_content_only = true
|
37
|
+
end
|
38
|
+
|
39
|
+
test_email = Mailer.test_email
|
40
|
+
@delivery_method.deliver!(test_email)
|
41
|
+
|
42
|
+
expect(@delivery_method.data[:content].has_key?(:text)).to eq(false)
|
43
|
+
expect(@delivery_method.data[:content][:html]).to eq("Hello, Testing!")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "supports HTML-only content as an option on an individual transmission" do
|
47
|
+
test_email = Mailer.test_email sparkpost_data: {html_content_only: true}
|
48
|
+
@delivery_method.deliver!(test_email)
|
49
|
+
|
50
|
+
expect(@delivery_method.data[:content].has_key?(:text)).to eq(false)
|
51
|
+
expect(@delivery_method.data[:content][:html]).to eq("Hello, Testing!")
|
52
|
+
end
|
53
|
+
|
33
54
|
it "should not include template details" do
|
34
55
|
test_email = Mailer.test_email
|
35
56
|
@delivery_method.deliver!(test_email)
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SparkPostRails::DeliveryMethod do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
SparkPostRails.configuration.set_defaults
|
7
|
+
@delivery_method = SparkPostRails::DeliveryMethod.new
|
8
|
+
end
|
9
|
+
|
10
|
+
context "Inline css" do
|
11
|
+
it "handles inline_css set in the configuration" do
|
12
|
+
SparkPostRails.configure do |c|
|
13
|
+
c.inline_css = true
|
14
|
+
end
|
15
|
+
|
16
|
+
test_email = Mailer.test_email
|
17
|
+
@delivery_method.deliver!(test_email)
|
18
|
+
|
19
|
+
expect(@delivery_method.data[:options][:inline_css]).to eq(true)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "handles inline_css set on an individual message" do
|
23
|
+
test_email = Mailer.test_email sparkpost_data: {inline_css: true}
|
24
|
+
|
25
|
+
@delivery_method.deliver!(test_email)
|
26
|
+
|
27
|
+
expect(@delivery_method.data[:options][:inline_css]).to eq(true)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "handles the value on an individual message overriding configuration" do
|
31
|
+
SparkPostRails.configure do |c|
|
32
|
+
c.inline_css = false
|
33
|
+
end
|
34
|
+
|
35
|
+
test_email = Mailer.test_email sparkpost_data: {inline_css: true}
|
36
|
+
|
37
|
+
@delivery_method.deliver!(test_email)
|
38
|
+
|
39
|
+
expect(@delivery_method.data[:options][:inline_css]).to eq(true)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "handles a default setting of inline_css" do
|
43
|
+
test_email = Mailer.test_email
|
44
|
+
@delivery_method.deliver!(test_email)
|
45
|
+
|
46
|
+
expect(@delivery_method.data[:options][:inline_css]).to eq(false)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sparkpost_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Kimball
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-04-
|
12
|
+
date: 2016-04-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- spec/from_spec.rb
|
80
80
|
- spec/headers_spec.rb
|
81
81
|
- spec/inline_content_spec.rb
|
82
|
+
- spec/inline_css_spec.rb
|
82
83
|
- spec/ip_pool_spec.rb
|
83
84
|
- spec/open_tracking_spec.rb
|
84
85
|
- spec/recipients_list_spec.rb
|
@@ -118,27 +119,28 @@ signing_key:
|
|
118
119
|
specification_version: 4
|
119
120
|
summary: SparkPost for Rails
|
120
121
|
test_files:
|
121
|
-
- spec/cc_recipients_spec.rb
|
122
|
-
- spec/subaccount_api_spec.rb
|
123
|
-
- spec/ip_pool_spec.rb
|
124
122
|
- spec/inline_content_spec.rb
|
125
|
-
- spec/return_path_spec.rb
|
126
|
-
- spec/transactional_spec.rb
|
127
|
-
- spec/recipients_list_spec.rb
|
128
|
-
- spec/campaign_id_spec.rb
|
129
|
-
- spec/description_spec.rb
|
130
|
-
- spec/response_spec.rb
|
131
|
-
- spec/bcc_recipients_spec.rb
|
132
|
-
- spec/sandbox_mode_spec.rb
|
133
123
|
- spec/from_spec.rb
|
124
|
+
- spec/subaccount_api_spec.rb
|
134
125
|
- spec/recipients_spec.rb
|
135
|
-
- spec/delivery_schedule_spec.rb
|
136
126
|
- spec/headers_spec.rb
|
137
|
-
- spec/
|
127
|
+
- spec/transactional_spec.rb
|
128
|
+
- spec/bcc_recipients_spec.rb
|
129
|
+
- spec/ip_pool_spec.rb
|
130
|
+
- spec/attachments_spec.rb
|
131
|
+
- spec/cc_recipients_spec.rb
|
132
|
+
- spec/recipients_list_spec.rb
|
138
133
|
- spec/template_spec.rb
|
139
|
-
- spec/
|
134
|
+
- spec/campaign_id_spec.rb
|
140
135
|
- spec/reply_to_spec.rb
|
141
|
-
- spec/
|
136
|
+
- spec/spec_helper.rb
|
137
|
+
- spec/description_spec.rb
|
142
138
|
- spec/click_tracking_spec.rb
|
143
|
-
- spec/substitution_data_spec.rb
|
144
139
|
- spec/skip_suppression_spec.rb
|
140
|
+
- spec/substitution_data_spec.rb
|
141
|
+
- spec/inline_css_spec.rb
|
142
|
+
- spec/response_spec.rb
|
143
|
+
- spec/open_tracking_spec.rb
|
144
|
+
- spec/sandbox_mode_spec.rb
|
145
|
+
- spec/return_path_spec.rb
|
146
|
+
- spec/delivery_schedule_spec.rb
|