send_with_us 1.8.0 → 1.9.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.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,4 @@
1
+ 1.9.0 - Locale support. Introduce send_email(). Deprecate send_with().
1
2
  1.8.0 - Tags support for send_with
2
3
  1.7.0 -
3
4
  1.6.0 -
data/README.md CHANGED
@@ -23,7 +23,21 @@ bundle install
23
23
 
24
24
  ### Send
25
25
 
26
- #### send_with parameters
26
+ #### send_email arguments
27
+ - **email\_id** - *string* - Template ID being sent
28
+ - **to** - *hash* - Recipients' email address
29
+ - **:data** - *hash* - Email data
30
+ - **:from** - *hash* - From name/address/reply\_to
31
+ - **:cc** - *array* - array of CC addresses
32
+ - **:bcc** - *array* - array of BCC addresses
33
+ - **:files** - *array* - array of files to attach, as strings or hashes (see below)
34
+ - **:esp\_account** - *string* - ESP account used to send email
35
+ - **:version\_name** - *string* - version of template to send
36
+ - **:headers** - *hash* - custom email headers **NOTE** only supported by some ESPs
37
+ - **:tags** - *array* - array of strings to attach as tags
38
+ - **:locale** - *string* - Localization string
39
+
40
+ #### send_with arguments [DEPRECATED]
27
41
  - **email\_id** - *string* - Template ID being sent
28
42
  - **to** - *hash* - Recipients' email address
29
43
  - **data** - *hash* - Email data
@@ -45,40 +59,32 @@ require 'send_with_us'
45
59
  begin
46
60
  obj = SendWithUs::Api.new( api_key: 'YOUR API KEY', debug: true )
47
61
 
48
- # only required params
49
- result = obj.send_with(
62
+ # required params
63
+ result = obj.send_email(
50
64
  'template_id',
51
65
  { address: "user@example.com" })
52
66
  puts result
53
67
 
54
- # with all optional params
55
- result = obj.send_with(
68
+ # required params and locale
69
+ result = obj.send_email(
56
70
  'template_id',
57
- { name: 'Matt', address: 'recipient@example.com' },
58
- { company_name: 'TestCo' },
59
- {
60
- name: 'Company',
61
- address: 'company@example.com',
62
- reply_to: 'info@example.com'
63
- },
64
- ['path/to/attachment.txt'],
65
- 'esp_MYESPACCOUNT',
66
- 'v2') # version name
71
+ { address: "user@example.com" }),
72
+ locale: 'en-US'
67
73
  puts result
68
74
 
69
75
  # full cc/bcc support
70
- result = obj.send_with(
76
+ result = obj.send_email(
71
77
  'template_id',
72
78
  { name: 'Matt', address: 'recipient@example.com' },
73
- { company_name: 'TestCo' },
74
- { name: 'Company',
79
+ data: { company_name: 'TestCo' },
80
+ from: { name: 'Company',
75
81
  address: 'company@example.com',
76
82
  reply_to: 'info@example.com' },
77
- [
83
+ cc: [
78
84
  { name: 'CC',
79
85
  address: 'cc@example.com' }
80
86
  ],
81
- [
87
+ bcc: [
82
88
  { name: 'BCC',
83
89
  address: 'bcc@example.com' },
84
90
  { name: 'BCC2',
@@ -87,16 +93,16 @@ begin
87
93
  puts result
88
94
 
89
95
  # Attachment support
90
- result = obj.send_with(
96
+ result = obj.send_email(
91
97
  'template_id',
92
98
  { name: 'Matt', address: 'recipient@example.com' },
93
- { company_name: 'TestCo' },
94
- { name: 'Company',
99
+ data: { company_name: 'TestCo' },
100
+ from: { name: 'Company',
95
101
  address: 'company@example.com',
96
102
  reply_to: 'info@example.com' },
97
- [],
98
- [],
99
- [
103
+ cc: [],
104
+ bcc: [],
105
+ files: [
100
106
  'path/to/file.txt',
101
107
  { filename: 'customfilename.txt', attachment: 'path/to/file.txt' },
102
108
  { filename: 'anotherfile.txt', attachment: File.open('path/to/file.txt') },
@@ -107,17 +113,71 @@ begin
107
113
 
108
114
  # Set ESP account
109
115
  # See: https://help.sendwithus.com/support/solurtions/articles/1000088976-set-up-and-use-multiple
110
- result = obj.send_with(
116
+ result = obj.send_email(
111
117
  'template_id',
112
118
  { name: 'Matt', address: 'recipient@example.com' },
113
- { company_name: 'TestCo' },
114
- { name: 'Company',
119
+ data: { company_name: 'TestCo' },
120
+ from: { name: 'Company',
115
121
  address: 'company@example.com',
116
122
  reply_to: 'info@example.com' },
117
- [],
118
- [],
119
- [],
120
- 'esp_MYESPACCOUNT')
123
+ cc: [],
124
+ bcc: [],
125
+ files: [],
126
+ esp_account: 'esp_MYESPACCOUNT')
127
+ puts result
128
+
129
+ # all possible arguments
130
+ result = obj.send_email(
131
+ 'template_id',
132
+ { name: 'Matt', address: 'recipient@example.com' },
133
+ data: { company_name: 'TestCo' },
134
+ from: {
135
+ name: 'Company',
136
+ address: 'company@example.com',
137
+ reply_to: 'info@example.com'
138
+ },
139
+ cc: [
140
+ { name: 'CC',
141
+ address: 'cc@example.com' }
142
+ ],
143
+ bcc: [
144
+ { name: 'BCC',
145
+ address: 'bcc@example.com' },
146
+ { name: 'BCC2',
147
+ address: 'bcc2@example.com' }
148
+ ])
149
+ files: ['path/to/attachment.txt'],
150
+ esp_account: 'esp_MYESPACCOUNT',
151
+ version: 'v2',
152
+ tags: ['tag1', 'tag2'],
153
+ locale: 'en-US')
154
+ puts result
155
+
156
+ # send_with - DEPRECATED!
157
+ result = obj.send_with(
158
+ 'template_id',
159
+ { name: 'Matt', address: 'recipient@example.com' },
160
+ { company_name: 'TestCo' },
161
+ {
162
+ name: 'Company',
163
+ address: 'company@example.com',
164
+ reply_to: 'info@example.com'
165
+ },
166
+ [
167
+ { name: 'CC',
168
+ address: 'cc@example.com' }
169
+ ],
170
+ [
171
+ { name: 'BCC',
172
+ address: 'bcc@example.com' },
173
+ { name: 'BCC2',
174
+ address: 'bcc2@example.com' }
175
+ ])
176
+ ['path/to/attachment.txt'],
177
+ 'esp_MYESPACCOUNT',
178
+ 'v2',
179
+ ['tag1', 'tag2'],
180
+ 'en-US')
121
181
  puts result
122
182
  rescue => e
123
183
  puts "Error - #{e.class.name}: #{e.message}"
@@ -23,41 +23,104 @@ module SendWithUs
23
23
  @configuration = SendWithUs::Config.new(settings)
24
24
  end
25
25
 
26
- def send_with(email_id, to, data = {}, from = {}, cc = {}, bcc = {}, files = [], esp_account = '', version_name = '', headers = {}, tags = [])
26
+ # DEPRECATED: Please use 'send_email' instead.
27
+ #
28
+ # Sends the specified email with any arguments.
29
+ #
30
+ # * *Args* :
31
+ # - +email_id+ -> ID of the email to send
32
+ # - +to+ -> Hash of recipient details
33
+ # - +data+ -> Hash of email data
34
+ # - +from+ -> Hash of sender details
35
+ # - +cc+ -> Array of CC recipients
36
+ # - +bcc+ -> Array of BCC recipients
37
+ # - +files+ -> Array of attachments
38
+ # - +esp_account+ -> The ESP account to use
39
+ # - +version_name+ -> The specific email version to use
40
+ # - +headers+ -> Hash of headers
41
+ # - +tags+ -> Array of tags
42
+ # * *Notes* :
43
+ # - "send" is already a ruby-defined method on all classes
44
+ #
45
+ def send_with(email_id, to, data = {}, from = {}, cc = [], bcc = [], files = [], esp_account = '', version_name = '', headers = {}, tags = [])
46
+ warn "[DEPRECATED] 'send_with' is deprecated. Please use 'send_email' instead."
47
+
48
+ send_email(
49
+ email_id,
50
+ to,
51
+ data: data,
52
+ from: from,
53
+ cc: cc,
54
+ bcc: bcc,
55
+ files: files,
56
+ esp_account: esp_account,
57
+ version_name: version_name,
58
+ headers: headers,
59
+ tags: tags
60
+ )
61
+ end
27
62
 
63
+ # Sends the specified email with any optional arguments
64
+ #
65
+ # * *Args* :
66
+ # - +email_id+ -> ID of the email to send
67
+ # - +to+ -> Hash of recipient details
68
+ # * *Options* :
69
+ # - +:data+ -> Hash of email data
70
+ # - +:from+ -> Hash of sender details
71
+ # - +:cc+ -> Array of CC recipients
72
+ # - +:bcc+ -> Array of BCC recipients
73
+ # - +:files+ -> Array of attachments
74
+ # - +:esp_account+ -> The ESP account to use
75
+ # - +:version_name+ -> The specific email version to use
76
+ # - +:headers+ -> Hash of headers
77
+ # - +:tags+ -> Array of tags
78
+ # - +:locale+ -> Localization string
79
+ # * *Notes* :
80
+ # - "send" is already a ruby-defined method on all classes
81
+ #
82
+ def send_email(email_id, to, options = {})
28
83
  if email_id.nil?
29
84
  raise SendWithUs::ApiNilEmailId, 'email_id cannot be nil'
30
85
  end
31
86
 
32
- payload = { email_id: email_id, recipient: to,
33
- email_data: data }
87
+ payload = {
88
+ email_id: email_id,
89
+ recipient: to
90
+ }
34
91
 
35
- if from.any?
36
- payload[:sender] = from
92
+ if options[:data] && options[:data].any?
93
+ payload[:email_data] = options[:data]
37
94
  end
38
- if cc.any?
39
- payload[:cc] = cc
95
+ if options[:from] && options[:from].any?
96
+ payload[:sender] = options[:from]
40
97
  end
41
- if bcc.any?
42
- payload[:bcc] = bcc
98
+ if options[:cc] && options[:cc].any?
99
+ payload[:cc] = options[:cc]
43
100
  end
44
- if esp_account
45
- payload[:esp_account] = esp_account
101
+ if options[:bcc] && options[:bcc].any?
102
+ payload[:bcc] = options[:bcc]
46
103
  end
47
- if version_name
48
- payload[:version_name] = version_name
104
+ if options[:esp_account]
105
+ payload[:esp_account] = options[:esp_account]
49
106
  end
50
- if headers.any?
51
- payload[:headers] = headers
107
+ if options[:version_name]
108
+ payload[:version_name] = options[:version_name]
52
109
  end
53
- if tags.any?
54
- payload[:tags] = tags
110
+ if options[:headers] && options[:headers].any?
111
+ payload[:headers] = options[:headers]
112
+ end
113
+ if options[:tags] && options[:tags].any?
114
+ payload[:tags] = options[:tags]
115
+ end
116
+ if options[:locale]
117
+ payload[:locale] = options[:locale]
55
118
  end
56
119
 
57
- if files.any?
120
+ if options[:files] && options[:files].any?
58
121
  payload[:files] = []
59
122
 
60
- files.each do |file_data|
123
+ options[:files].each do |file_data|
61
124
  if file_data.is_a?(String)
62
125
  attachment = SendWithUs::Attachment.new(file_data)
63
126
  else
@@ -68,18 +131,18 @@ module SendWithUs
68
131
  end
69
132
 
70
133
  payload = payload.to_json
134
+ puts payload
71
135
  SendWithUs::ApiRequest.new(@configuration).post(:send, payload)
72
136
  end
73
137
 
74
138
  def drips_unsubscribe(email_address)
75
-
76
139
  if email_address.nil?
77
140
  raise SendWithUs::ApiNilEmailId, 'email_address cannot be nil'
78
141
  end
79
142
 
80
- payload = { email_address: email_address }
81
- payload = payload.to_json
143
+ payload = {email_address: email_address}
82
144
 
145
+ payload = payload.to_json
83
146
  SendWithUs::ApiRequest.new(@configuration).post(:'drips/unsubscribe', payload)
84
147
  end
85
148
 
@@ -92,9 +155,12 @@ module SendWithUs
92
155
  template_id: template_id,
93
156
  template_data: template_data,
94
157
  }
95
- payload[:version_id] = version_id if version_id
96
- payload = payload.to_json
97
158
 
159
+ if version_id
160
+ payload[:version_id] = version_id
161
+ end
162
+
163
+ payload = payload.to_json
98
164
  SendWithUs::ApiRequest.new(@configuration).post(:'render', payload)
99
165
  end
100
166
 
@@ -104,8 +170,9 @@ module SendWithUs
104
170
  subject: subject,
105
171
  html: html,
106
172
  text: text
107
- }.to_json
173
+ }
108
174
 
175
+ payload = payload.to_json
109
176
  SendWithUs::ApiRequest.new(@configuration).post(:emails, payload)
110
177
  end
111
178
 
@@ -113,27 +180,27 @@ module SendWithUs
113
180
  SendWithUs::ApiRequest.new(@configuration).get(:drip_campaigns)
114
181
  end
115
182
 
116
- def start_on_drip_campaign(recipient_address, drip_campaign_id, email_data={})
183
+ def start_on_drip_campaign(recipient_address, drip_campaign_id, email_data={}, locale=nil)
184
+ payload = {recipient_address: recipient_address}
117
185
 
118
- if email_data.nil?
119
- payload = {
120
- recipient_address: recipient_address
121
- }.to_json
122
- else
123
- payload = {
124
- recipient_address: recipient_address,
125
- email_data: email_data
126
- }.to_json
186
+ if email_data && email_data.any?
187
+ payload[:email_data] = email_data
188
+ end
189
+ if locale
190
+ payload[:locale] = locale
127
191
  end
128
192
 
129
- SendWithUs::ApiRequest.new(@configuration).post("drip_campaigns/#{drip_campaign_id}/activate", payload)
193
+ payload = payload.to_json
194
+ endpoint = "drip_campaigns/#{drip_campaign_id}/activate"
195
+ SendWithUs::ApiRequest.new(@configuration).post(endpoint, payload)
130
196
  end
131
197
 
132
198
  def remove_from_drip_campaign(recipient_address, drip_campaign_id)
133
199
  payload = {
134
200
  recipient_address: recipient_address
135
- }.to_json
201
+ }
136
202
 
203
+ payload = payload.to_json
137
204
  SendWithUs::ApiRequest.new(@configuration).post("drip_campaigns/#{drip_campaign_id}/deactivate", payload)
138
205
  end
139
206
 
@@ -149,27 +216,29 @@ module SendWithUs
149
216
  SendWithUs::ApiRequest.new(@configuration).get("drip_campaigns/#{drip_campaign_id}/step/#{drip_campaign_step_id}/customers")
150
217
  end
151
218
 
152
- # DEPRECATED - use customer_conversion now
219
+ # DEPRECATED: Please use 'customer_conversion' instead.
153
220
  def add_customer_event(customer, event_name, revenue=nil)
221
+ warn "[DEPRECATED] 'add_customer_event' is deprecated. Please use 'customer_conversion' instead."
222
+
223
+ payload = {event_name: event_name}
154
224
 
155
- if revenue.nil?
156
- payload = { event_name: event_name }
157
- else
158
- payload = { event_name: event_name, revenue: revenue}
225
+ if revenue
226
+ payload[:revenue] = revenue
159
227
  end
160
228
 
161
229
  payload = payload.to_json
162
- endpoint = 'customers/' + customer + '/conversions'
230
+ endpoint = "customers/#{customer}/conversions"
163
231
  SendWithUs::ApiRequest.new(@configuration).post(endpoint, payload)
164
232
  end
165
233
 
166
234
  def customer_conversion(customer, revenue=nil)
167
- payload = {}.to_json
235
+ payload = {}
168
236
 
169
237
  if revenue
170
- payload = { revenue: revenue }.to_json
238
+ payload[:revenue] = revenue
171
239
  end
172
240
 
241
+ payload = payload.to_json
173
242
  endpoint = "customers/#{customer}/conversions"
174
243
  SendWithUs::ApiRequest.new(@configuration).post(endpoint, payload)
175
244
  end
@@ -177,16 +246,18 @@ module SendWithUs
177
246
  def customer_create(email, data = {})
178
247
  payload = {email: email}
179
248
 
180
- if data.any?
249
+ if data && data.any?
181
250
  payload[:data] = data
182
251
  end
183
252
 
184
253
  payload = payload.to_json
185
- SendWithUs::ApiRequest.new(@configuration).post("customers", payload)
254
+ endpoint = "customers"
255
+ SendWithUs::ApiRequest.new(@configuration).post(endpoint, payload)
186
256
  end
187
257
 
188
258
  def customer_delete(email)
189
- SendWithUs::ApiRequest.new(@configuration).delete("customers/#{email}")
259
+ endpoint = "customers/#{email}"
260
+ SendWithUs::ApiRequest.new(@configuration).delete(endpoint)
190
261
  end
191
262
  end
192
263
  end
@@ -1,3 +1,3 @@
1
1
  module SendWithUs
2
- VERSION = '1.8.0'
2
+ VERSION = '1.9.0'
3
3
  end
@@ -17,21 +17,6 @@ class TestApiRequest < MiniTest::Unit::TestCase
17
17
  assert_instance_of( Net::HTTPSuccess, @request.post(:send, @payload) )
18
18
  end
19
19
 
20
- def test_attachment
21
- build_objects
22
- email_id = 'test_fixture_1'
23
- result = @api.send_with(
24
- email_id,
25
- {name: 'Ruby Unit Test', address: 'matt@example.com'},
26
- {name: 'sendwithus', address: 'matt@example.com'},
27
- {},
28
- [],
29
- [],
30
- ['README.md']
31
- )
32
- assert_instance_of( Net::HTTPOK, result )
33
- end
34
-
35
20
  def test_unsubscribe
36
21
  build_objects
37
22
  Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPSuccess.new(1.0, 200, "OK"))
@@ -68,14 +53,29 @@ class TestApiRequest < MiniTest::Unit::TestCase
68
53
  assert_raises( SendWithUs::ApiConnectionRefused ) { @request.post(:send, @payload) }
69
54
  end
70
55
 
71
- def test_send_with_version
56
+ def test_send_with_with_attachment
57
+ build_objects
58
+ email_id = 'test_fixture_1'
59
+ result = @api.send_with(
60
+ email_id,
61
+ {name: 'Ruby Unit Test', address: 'matt@example.com'},
62
+ {data: 'I AM DATA'},
63
+ {name: 'sendwithus', address: 'matt@example.com'},
64
+ [],
65
+ [],
66
+ ['README.md']
67
+ )
68
+ assert_instance_of( Net::HTTPOK, result )
69
+ end
70
+
71
+ def test_send_with_with_version
72
72
  build_objects
73
73
  email_id = 'tem_9YvYsaLW2Mw4tmPiLcVvpC'
74
74
  result = @api.send_with(
75
75
  email_id,
76
76
  {name: 'Ruby Unit Test', address: 'matt@example.com'},
77
+ {data: 'I AM DATA'},
77
78
  {name: 'sendwithus', address: 'matt@example.com'},
78
- {},
79
79
  [],
80
80
  [],
81
81
  [],
@@ -85,14 +85,14 @@ class TestApiRequest < MiniTest::Unit::TestCase
85
85
  assert_instance_of( Net::HTTPOK, result )
86
86
  end
87
87
 
88
- def test_send_with_headers
88
+ def test_send_with_with_headers
89
89
  build_objects
90
90
  email_id = 'tem_9YvYsaLW2Mw4tmPiLcVvpC'
91
91
  result = @api.send_with(
92
92
  email_id,
93
93
  {name: 'Ruby Unit Test', address: 'matt@example.com'},
94
+ {data: 'I AM DATA'},
94
95
  {name: 'sendwithus', address: 'matt@example.com'},
95
- {},
96
96
  [],
97
97
  [],
98
98
  [],
@@ -103,14 +103,14 @@ class TestApiRequest < MiniTest::Unit::TestCase
103
103
  assert_instance_of( Net::HTTPOK, result )
104
104
  end
105
105
 
106
- def test_send_with_tags
106
+ def test_send_with_with_tags
107
107
  build_objects
108
108
  email_id = 'tem_9YvYsaLW2Mw4tmPiLcVvpC'
109
109
  result = @api.send_with(
110
110
  email_id,
111
111
  {name: 'Ruby Unit Test', address: 'matt@example.com'},
112
+ {data: 'I AM DATA'},
112
113
  {name: 'sendwithus', address: 'matt@example.com'},
113
- {},
114
114
  [],
115
115
  [],
116
116
  [],
@@ -122,6 +122,35 @@ class TestApiRequest < MiniTest::Unit::TestCase
122
122
  assert_instance_of( Net::HTTPOK, result )
123
123
  end
124
124
 
125
+ def test_send_with_tags
126
+ build_objects
127
+ email_id = 'tem_9YvYsaLW2Mw4tmPiLcVvpC'
128
+ result = @api.send_email(
129
+ email_id,
130
+ {name: 'Ruby Unit Test', address: 'matt@example.com'},
131
+ data: {data: 'I AM DATA'},
132
+ from: {name: 'sendwithus', address: 'matt@example.com'},
133
+ version_name: 'v2',
134
+ tags: ['tag1', 'tag2']
135
+ )
136
+ assert_instance_of( Net::HTTPOK, result )
137
+ end
138
+
139
+ def test_send_with_locale
140
+ build_objects
141
+ email_id = 'tem_9YvYsaLW2Mw4tmPiLcVvpC'
142
+ result = @api.send_email(
143
+ email_id,
144
+ {name: 'Ruby Unit Test', address: 'matt@example.com'},
145
+ data: {data: 'I AM DATA'},
146
+ from: {name: 'sendwithus', address: 'matt@example.com'},
147
+ version_name: 'v2',
148
+ tags: ['tag1', 'tag2'],
149
+ locale: 'en-US'
150
+ )
151
+ assert_instance_of( Net::HTTPOK, result )
152
+ end
153
+
125
154
  def test_render
126
155
  build_objects
127
156
  email_id = 'tem_9YvYsaLW2Mw4tmPiLcVvpC'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: send_with_us
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-01-06 00:00:00.000000000 Z
14
+ date: 2015-01-21 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake