emarsys-broadcast 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +86 -54
- data/emarsys-broadcast.gemspec +1 -1
- data/lib/emarsys/broadcast/api.rb +1 -0
- data/lib/emarsys/broadcast/batch.rb +3 -2
- data/lib/emarsys/broadcast/batch_xml_builder.rb +1 -0
- data/lib/emarsys/broadcast/configuration.rb +4 -1
- data/lib/emarsys/broadcast/version.rb +1 -1
- data/spec/configuration_spec.rb +23 -1
- metadata +6 -6
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
# Emarsys::Broadcast
|
1
|
+
# Emarsys::Broadcast a ruby wrapper for Emarsys batch mailing API
|
2
2
|
|
3
|
-
Ruby wrapper for Emarsys batch mailing API
|
4
|
-
==========================================
|
5
3
|
[![Build Status](https://travis-ci.org/Valve/emarsys-broadcast-ruby.png)](https://travis-ci.org/Valve/emarsys-broadcast-ruby)
|
6
4
|
[![Code Climate](https://codeclimate.com/github/Valve/emarsys-broadcast-ruby.png)](https://codeclimate.com/github/Valve/emarsys-broadcast-ruby)
|
7
5
|
|
@@ -55,34 +53,6 @@ api.send_batch(batch)
|
|
55
53
|
|
56
54
|
This will synchronously send the batch email to all recipients found in CSV file.
|
57
55
|
|
58
|
-
### Moving batch properties to configuration
|
59
|
-
|
60
|
-
If you find yourself using same batch attributes over and over again, for example `recipients_path`,
|
61
|
-
you can move those values into configuration:
|
62
|
-
|
63
|
-
```ruby
|
64
|
-
Emarsys::Broadcast::configure do |c|
|
65
|
-
c.api_user = your_api_user
|
66
|
-
c.api_password = your_api_password
|
67
|
-
|
68
|
-
c.sftp_user = your_sftp_user
|
69
|
-
c.sftp_password = your_sftp_password
|
70
|
-
|
71
|
-
c.sender = 'sender_id'
|
72
|
-
c.sender_domain = 'mail.your.company.com'
|
73
|
-
c.recipients_path = '/path/to/hyour/csv/with/emails'
|
74
|
-
end
|
75
|
-
|
76
|
-
# now you can omit these attributes when constructing a batch:
|
77
|
-
batch = Emarsys::Broadcast::Batch.new
|
78
|
-
batch.name = 'newsletter_2013_06_01'
|
79
|
-
batch.subject = 'June 2013 company news'
|
80
|
-
batch.body_html = '<h1>Dear 朋友!</h1>'
|
81
|
-
|
82
|
-
# send your batch as above, via api
|
83
|
-
```
|
84
|
-
|
85
|
-
|
86
56
|
### Creating batch from hash
|
87
57
|
|
88
58
|
If you like, you can construct your batch from a hash, like follows:
|
@@ -91,21 +61,39 @@ If you like, you can construct your batch from a hash, like follows:
|
|
91
61
|
batch = Emarsys::Broadcast::Batch.new name: 'name', subject: 'subject', body_html: '<h1>html body</h1>'
|
92
62
|
```
|
93
63
|
|
94
|
-
###
|
64
|
+
### Required batch attributes
|
65
|
+
|
66
|
+
#### Batch#name
|
95
67
|
|
96
68
|
Batch name must be a valid identifier, i.e. start with a letter and contain letters, digits and underscores.
|
97
69
|
Emarsys requires every batch to have a unique name, but you don't have to maintain the uniqueness, because
|
98
70
|
this library internally appends a timestamp to each batch name before submitting it to Emarsys.
|
99
71
|
|
100
|
-
|
72
|
+
#### Batch#subject
|
101
73
|
|
102
74
|
Batch subject must be a string with a maximum length of 255 characters
|
103
75
|
|
104
|
-
|
76
|
+
#### Batch#sender
|
77
|
+
|
78
|
+
Valid email, registed with Emarsys.
|
79
|
+
|
80
|
+
Emarsys maintains a list of allowed sender emails, and restricts
|
81
|
+
sending emails from arbitrary email. If you want to use an email as a
|
82
|
+
sender, refer to
|
83
|
+
|
84
|
+
#### Batch#body_html
|
105
85
|
|
106
86
|
Batch body html can be any HTML text, no restrictions
|
107
87
|
|
108
|
-
|
88
|
+
#### Batch#recipients_path
|
89
|
+
|
90
|
+
Absolute path to CSV file with recipients data.
|
91
|
+
|
92
|
+
_Can be set once via configuration_
|
93
|
+
|
94
|
+
### Optional batch attributes
|
95
|
+
|
96
|
+
#### Batch#body_text
|
109
97
|
|
110
98
|
It is possible to supply the body contents in plain text, this will broaden compatibility,
|
111
99
|
because some email clients don't support HTML and will download textual version instead.
|
@@ -118,6 +106,52 @@ batch.body_html = '<h1>Dear 朋友!</h1>'
|
|
118
106
|
batch.body_text = 'Dear 朋友'
|
119
107
|
```
|
120
108
|
|
109
|
+
#### Batch#send_time
|
110
|
+
|
111
|
+
You can set the batch send time using this optional attribute. If you don't set it
|
112
|
+
it will be scheduled for immediate sending.
|
113
|
+
|
114
|
+
|
115
|
+
#### Batch.import_delay_hours
|
116
|
+
|
117
|
+
Time in hours which is allowed for import to be delayed after batch import. Defaults to 1 hour.
|
118
|
+
|
119
|
+
|
120
|
+
### Moving batch properties to configuration
|
121
|
+
|
122
|
+
If you find yourself using same batch attributes over and over again,
|
123
|
+
you can move these attributes into configuration:
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
Emarsys::Broadcast::configure do |c|
|
127
|
+
c.api_user = your_api_user
|
128
|
+
c.api_password = your_api_password
|
129
|
+
|
130
|
+
c.sftp_user = your_sftp_user
|
131
|
+
c.sftp_password = your_sftp_password
|
132
|
+
|
133
|
+
c.sender = 'sender_id'
|
134
|
+
c.sender_domain = 'mail.your.company.com'
|
135
|
+
c.recipients_path = '/path/to/hyour/csv/with/emails'
|
136
|
+
end
|
137
|
+
|
138
|
+
# now you can omit these attributes when constructing a batch:
|
139
|
+
batch = Emarsys::Broadcast::Batch.new
|
140
|
+
batch.name = 'newsletter_2013_06_01'
|
141
|
+
batch.subject = 'June 2013 company news'
|
142
|
+
batch.body_html = '<h1>Dear 朋友!</h1>'
|
143
|
+
|
144
|
+
# send your batch as above, via api
|
145
|
+
```
|
146
|
+
|
147
|
+
#### List of configurable attributes
|
148
|
+
* sender (required attribute)
|
149
|
+
* sender_domain (required attribute)
|
150
|
+
* recipients_path (required attribute)
|
151
|
+
* import_delay_hours (optional attribute) see more [here](#)
|
152
|
+
|
153
|
+
|
154
|
+
|
121
155
|
### Batch validation
|
122
156
|
|
123
157
|
Emarsys::Broadcast uses ActiveModel for validating plain ruby objects, so you have all the methods for
|
@@ -149,6 +183,18 @@ rescue Emarsys::Broadcast::ValidationException => ex
|
|
149
183
|
end
|
150
184
|
```
|
151
185
|
|
186
|
+
### Scheduling batches
|
187
|
+
|
188
|
+
By default a new batch is scheduled for immediate sending, but you can set the `send_time`
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
# Assuming using ActiveSupport and want to schedule a batch to be sent in 10 days
|
192
|
+
batch.send_time = Time.zone.now + 10.days
|
193
|
+
# .. more attributes
|
194
|
+
|
195
|
+
api.send_batch batch
|
196
|
+
```
|
197
|
+
|
152
198
|
### CSV file requirements
|
153
199
|
|
154
200
|
The recipients must be placed in a `UTF-8` CSV file.
|
@@ -177,12 +223,11 @@ Having additional columns allows you to customize your body_html, for example:
|
|
177
223
|
<h1>Hi, $$FIRST_NAME$$</h1>
|
178
224
|
```
|
179
225
|
|
180
|
-
###
|
226
|
+
### Working with senders
|
181
227
|
|
182
|
-
|
183
|
-
sending emails from arbitrary sender.
|
228
|
+
#### Adding a new sender
|
184
229
|
|
185
|
-
|
230
|
+
Adding a sender is required before you can start using its email address as a Batch#sender attribute
|
186
231
|
|
187
232
|
```ruby
|
188
233
|
# assuming you have API configured already
|
@@ -195,12 +240,10 @@ api.create_sender sender
|
|
195
240
|
Once you upload a sender, you can use its ID in any batch:
|
196
241
|
|
197
242
|
```ruby
|
198
|
-
batch.
|
243
|
+
batch.sender = 'news@company.com'
|
199
244
|
# more attributes
|
200
245
|
```
|
201
246
|
|
202
|
-
### Working with senders
|
203
|
-
|
204
247
|
#### Getting a full list of senders
|
205
248
|
|
206
249
|
```ruby
|
@@ -214,23 +257,12 @@ api.get_senders
|
|
214
257
|
api.get_sender('news@mycompany.ru')
|
215
258
|
```
|
216
259
|
|
217
|
-
####
|
260
|
+
#### Finding if a sender exists by email
|
218
261
|
|
219
262
|
```ruby
|
220
263
|
api.sender_exists? 'news@mycompany.ru'
|
221
264
|
```
|
222
265
|
|
223
|
-
### Scheduling batches
|
224
|
-
|
225
|
-
By default a new batch is scheduled for immediate sending, but you can set the `send_time`
|
226
|
-
|
227
|
-
```ruby
|
228
|
-
# Assuming using ActiveSupport and want to schedule a batch to be sent in 10 days
|
229
|
-
batch.send_time = Time.zone.now + 10.days
|
230
|
-
# .. more attributes
|
231
|
-
|
232
|
-
api.send_batch batch
|
233
|
-
```
|
234
266
|
|
235
267
|
### Compatibility
|
236
268
|
|
data/emarsys-broadcast.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "net-sftp"
|
22
|
-
spec.add_dependency "nokogiri"
|
22
|
+
spec.add_dependency "nokogiri", "1.5.6"
|
23
23
|
spec.add_dependency "activemodel", "~> 3.0"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.3"
|
@@ -7,12 +7,13 @@ module Emarsys
|
|
7
7
|
:name,
|
8
8
|
:subject,
|
9
9
|
:body_html,
|
10
|
-
:body_text,
|
11
10
|
:recipients_path,
|
11
|
+
:body_text,
|
12
12
|
:send_time,
|
13
13
|
:sender,
|
14
14
|
:sender_domain,
|
15
|
-
:sender_id
|
15
|
+
:sender_id,
|
16
|
+
:import_delay_hours
|
16
17
|
|
17
18
|
validates :name, :subject, :body_html, :recipients_path, :sender, :sender_domain, presence: true
|
18
19
|
validates :name, format: {with: /^[^\d\W]\w*\z/i, message: 'must start with a letter and contain only letters, numbers and underscores'}
|
@@ -14,6 +14,7 @@ module Emarsys
|
|
14
14
|
xml.property(key: :Language){xml.text 'en'}
|
15
15
|
xml.property(key: :Encoding){xml.text 'UTF-8'}
|
16
16
|
xml.property(key: :Domain){xml.text batch.sender_domain}
|
17
|
+
xml.property(key: :ImportDelay){xml.text batch.import_delay_hours}
|
17
18
|
}
|
18
19
|
xml.subject batch.subject
|
19
20
|
xml.html batch.body_html
|
@@ -17,7 +17,9 @@ module Emarsys
|
|
17
17
|
:api_timeout,
|
18
18
|
:sender,
|
19
19
|
:sender_domain,
|
20
|
-
:recipients_path
|
20
|
+
:recipients_path,
|
21
|
+
# https://e3.emarsys.net/bmapi/v2/doc/Properties.html#ImportDelay
|
22
|
+
:import_delay_hours
|
21
23
|
|
22
24
|
|
23
25
|
def initialize
|
@@ -27,6 +29,7 @@ module Emarsys
|
|
27
29
|
@api_base_path = '/bmapi/v2'
|
28
30
|
@api_port = 80
|
29
31
|
@api_timeout = 600 #10 minutes
|
32
|
+
@import_delay_hours = 1
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
data/spec/configuration_spec.rb
CHANGED
@@ -189,7 +189,7 @@ describe Emarsys::Broadcast::Configuration do
|
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
192
|
-
|
192
|
+
describe 'when sender is set' do
|
193
193
|
before do
|
194
194
|
Emarsys::Broadcast::configure do |c|
|
195
195
|
c.sender = 'sender'
|
@@ -210,6 +210,28 @@ describe Emarsys::Broadcast::Configuration do
|
|
210
210
|
expect(Emarsys::Broadcast.configuration.sender).to be_nil
|
211
211
|
end
|
212
212
|
end
|
213
|
+
|
214
|
+
describe 'when import_delay_hours is set' do
|
215
|
+
before do
|
216
|
+
Emarsys::Broadcast::configure do |c|
|
217
|
+
c.import_delay_hours = 12
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'returns import_delay_hours' do
|
222
|
+
expect(Emarsys::Broadcast.configuration.import_delay_hours).to eq 12
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
describe 'when import_delay_hours is not set' do
|
227
|
+
before do
|
228
|
+
Emarsys::Broadcast::configure {}
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'defaults to 1 hour' do
|
232
|
+
expect(Emarsys::Broadcast.configuration.import_delay_hours).to eq 1
|
233
|
+
end
|
234
|
+
end
|
213
235
|
end
|
214
236
|
|
215
237
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emarsys-broadcast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
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: 2013-04-
|
12
|
+
date: 2013-04-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-sftp
|
@@ -32,17 +32,17 @@ dependencies:
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - '='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: 1.5.6
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - '='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: 1.5.6
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: activemodel
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|