send_with_us 1.10.2 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5021ab6ee37c8f3b1d4be8ab74cfbfe91b20c173
4
- data.tar.gz: abc9a8e4320ff642bc7c468e4b5523d111926359
3
+ metadata.gz: e0648a9da5af356483eb9a6ca360af1e0a6c93e1
4
+ data.tar.gz: 4f4541298cc6e6bdb25381b59c723242c6909d4a
5
5
  SHA512:
6
- metadata.gz: 26fde0be9902431e523a578ecae187fc0b5ee1c86fcc63a498f213000ca045b79abc392bf53de57d8e8ad25c3a20bbfee82e838e9be63050c63a9da9aac56f30
7
- data.tar.gz: 9f662b934c66196d03b31b451b4c6335eac3122ba1e94ea267b0f164967cb8db4c6c7286093259f4bb45650f27f7c30ddf33cd011ae21a60f8c1d9d4e8f9519f
6
+ metadata.gz: 37e8146dc953959ed5d1271894150be499a2fabbc8f5cf7e2b2c1bfd49a0f1e4c5d8f35d80ebe5ceaae52d4f08473538a996654f754c8325e5395b201134d677
7
+ data.tar.gz: 38ad2b4a9707127d48c3f7beba1f57dc2e1c550477fb80545111aafd2d26e64d8671e29e50e86b4464c5e15b6e0358eb07ca316333bc02f8fdf3ae7434ddb6b9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,4 @@
1
+ 1.11.0 - add template create/update methods as well as group create/update methods
1
2
  1.10.2 - include render parameter on locale
2
3
  1.10.1 - tag support, error base class, logs method
3
4
  1.9.0 - Locale support. Introduce send\_email(). Deprecate send\_with().
data/README.md CHANGED
@@ -225,7 +225,7 @@ rescue => e
225
225
  end
226
226
  ```
227
227
 
228
- ### Using Drips 2.0
228
+ ### Using Drip Campaigns
229
229
 
230
230
  ```ruby
231
231
  require 'rubygems'
@@ -269,6 +269,18 @@ result = obj.customer_create("visha@example.com", customer_data)
269
269
  result = obj.customer_delete("visha@example.com")
270
270
  ```
271
271
 
272
+ ### Add customer to group
273
+
274
+ ```ruby
275
+ obj.customer\_add\_to\_group(\email_address, group_id)
276
+ ```
277
+
278
+ ### Remove customer from group
279
+
280
+ ```ruby
281
+ obj.customer\_remove\_from\_group(email\_address, group_id)
282
+ ```
283
+
272
284
  ### Customer Conversion Event
273
285
  You can use the Conversion API to track conversion and revenue data events against your sent emails
274
286
 
@@ -282,6 +294,52 @@ obj.customer_conversion('customer@example.com', 10050)
282
294
  obj.customer_conversion('customer@example.com')
283
295
  ```
284
296
 
297
+ ## Templates
298
+
299
+ ```ruby
300
+
301
+ # List Templates
302
+ obj.list\_templates() # Alternatively, obj.emails()
303
+
304
+ # Create Template
305
+ obj.create\_template(name, subject, html, text)
306
+
307
+ # Delete Template
308
+ obj.delete\_template(template\_id)
309
+
310
+ # List Template Versions
311
+ obj.list\_template\_versions(template\_id)
312
+
313
+ # Update Template Version
314
+ obj.update\_template\_version(template\_id, version\_id, name, subject, html, text)
315
+
316
+ # Create Template Version
317
+ obj.create\_template\_version(template\_id, name, subject, html, text)
318
+
319
+ ```
320
+
321
+
322
+ ## Groups
323
+
324
+ Groups are another way to "tag" customers in sendwithus. They can be thought of as lists.
325
+
326
+
327
+ ```ruby
328
+ # List groups
329
+ obj.get_groups()
330
+
331
+ # Create group
332
+ obj.create\_customer\_group(name, description)
333
+
334
+ # Update group
335
+ obj.update\_customer\_group(group_id, new\_name, new\_description)
336
+
337
+ # Delete group
338
+
339
+ obj.delete_group(group_id)
340
+
341
+ ```
342
+
285
343
  ## Rails
286
344
 
287
345
  For a Rails app, create `send_with_us.rb` in `/config/initializers/`
@@ -149,6 +149,8 @@ module SendWithUs
149
149
  SendWithUs::ApiRequest.new(@configuration).get(:emails)
150
150
  end
151
151
 
152
+ alias list_templates emails
153
+
152
154
  def render(template_id, version_id = nil, template_data = {})
153
155
  locale = template_data.delete(:locale)
154
156
 
@@ -255,8 +257,20 @@ module SendWithUs
255
257
  SendWithUs::ApiRequest.new(@configuration).post(endpoint, payload)
256
258
  end
257
259
 
258
- def customer_delete(email)
259
- endpoint = "customers/#{email}"
260
+ def customer_delete(email_address)
261
+ endpoint = "customers/#{email_address}"
262
+ SendWithUs::ApiRequest.new(@configuration).delete(endpoint)
263
+ end
264
+
265
+ def customer_add_to_group(email_address, group_id)
266
+ payload = nil
267
+
268
+ endpoint = "customers/#{email_address})/groups/#{group_id}"
269
+ SendWithUs::ApiRequest.new(@configuration).post(endpoint, payload)
270
+ end
271
+
272
+ def customer_remove_from_group()
273
+ endpoint = "customers/#{email_address})/groups/#{group_id}"
260
274
  SendWithUs::ApiRequest.new(@configuration).delete(endpoint)
261
275
  end
262
276
 
@@ -285,5 +299,74 @@ module SendWithUs
285
299
 
286
300
  SendWithUs::ApiRequest.new(@configuration).get(endpoint)
287
301
  end
302
+
303
+ def delete_template(template_id)
304
+ endpoint = "templates/#{template_id}"
305
+ SendWithUs::ApiRequest.new(@configuration).delete(endpoint)
306
+ end
307
+
308
+ def list_template_versions(template_id)
309
+ endpoint = "templates/#{template_id}/versions"
310
+ SendWithUs::ApiRequest.new(@configuration).get(endpoint)
311
+ end
312
+
313
+ def get_template_version(template_id, version_id)
314
+ endpoint = "templates/#{template_id}/versions/#{version_id}"
315
+ SendWithUs::ApiRequest.new(@configuration).get(endpoint)
316
+ end
317
+
318
+ def update_template_version(template_id, version_id, name, subject, html, text)
319
+ payload = {
320
+ name: name,
321
+ subject: subject,
322
+ html: html,
323
+ text: text
324
+ }
325
+
326
+ endpoint = "templates/#{template_id}/versions/#{version_id}"
327
+ SendWithUs::ApiRequest.new(@configuration).put(endpoint, payload.to_json)
328
+ end
329
+
330
+ def create_template_version(template_id, name, subject, html, text)
331
+ payload = {
332
+ name: name,
333
+ subject: subject,
334
+ html: html,
335
+ text: text
336
+ }
337
+
338
+ endpoint = "templates/#{template_id}/versions"
339
+ SendWithUs::ApiRequest.new(@configuration).post(endpoint, payload.to_json)
340
+ end
341
+
342
+ def get_groups()
343
+ endpoint = "groups"
344
+ SendWithUs::ApiRequest.new(@configuration).get(endpoint)
345
+ end
346
+
347
+ def create_customer_group(name, description = '')
348
+ payload = {
349
+ name: name,
350
+ description: description
351
+ }
352
+
353
+ endpoint = "groups"
354
+ SendWithUs::ApiRequest.new(@configuration).post(endpoint, payload.to_json)
355
+ end
356
+
357
+ def update_customer_group(group_id, name = '', description = '')
358
+ payload = {
359
+ name: name,
360
+ description: description
361
+ }
362
+
363
+ endpoint = "groups/#{group_id}"
364
+ SendWithUs::ApiRequest.new(@configuration).put(endpoint, payload.to_json)
365
+ end
366
+
367
+ def delete_customer_group(group_id)
368
+ endpoint = "groups/#{group_id}"
369
+ SendWithUs::ApiRequest.new(@configuration).delete(endpoint)
370
+ end
288
371
  end
289
372
  end
@@ -26,6 +26,11 @@ module SendWithUs
26
26
  request(Net::HTTP::Delete, request_path(endpoint))
27
27
  end
28
28
 
29
+ def put(endpoint, payload)
30
+ request(Net::HTTP::Put, request_path(endpoint), payload)
31
+ end
32
+
33
+
29
34
  private
30
35
 
31
36
  def request_path(end_point)
@@ -1,3 +1,3 @@
1
1
  module SendWithUs
2
- VERSION = '1.10.2'
2
+ VERSION = '1.11.0'
3
3
  end
@@ -7,8 +7,25 @@ class TestApiRequest < Minitest::Test
7
7
  @api = SendWithUs::Api.new( api_key: 'THIS_IS_A_TEST_API_KEY', debug: false)
8
8
  @config = SendWithUs::Config.new( api_version: '1_0', api_key: 'THIS_IS_A_TEST_API_KEY', debug: false )
9
9
  @request = SendWithUs::ApiRequest.new(@config)
10
- @drip_campaign = { :drip_campaign_id => 'dc_Rmd7y5oUJ3tn86sPJ8ESCk', :drip_campaign_step_id => 'dcs_yaAMiZNWCLAEGw7GLjBuGY' }
11
- @customer = { :email => "steve@sendwithus.com" }
10
+ @drip_campaign = {
11
+ :drip_campaign_id => 'dc_Rmd7y5oUJ3tn86sPJ8ESCk',
12
+ :drip_campaign_step_id => 'dcs_yaAMiZNWCLAEGw7GLjBuGY'
13
+ }
14
+ @customer = { :email => 'steve@sendwithus.com',
15
+ :groups => ['grp_wnCdAjBWGeBGDUzNwGiTKc']
16
+ }
17
+ @template = {
18
+ :html => '<html><head></head><body>TEST</body></html>',
19
+ :subject => 'A test template',
20
+ :name => 'Test Template',
21
+ :id => 'test_fixture_1'
22
+ }
23
+ end
24
+
25
+ def get_first_template_version_id(template_id)
26
+ templates = @api.list_template_versions(template_id)
27
+ version = JSON.parse(templates.body)[0]["id"]
28
+ return version
12
29
  end
13
30
 
14
31
  def test_payload
@@ -57,9 +74,8 @@ class TestApiRequest < Minitest::Test
57
74
 
58
75
  def test_send_with_with_attachment
59
76
  build_objects
60
- email_id = 'test_fixture_1'
61
77
  result = @api.send_with(
62
- email_id,
78
+ @template[:id],
63
79
  {name: 'Ruby Unit Test', address: 'matt@example.com'},
64
80
  {data: 'I AM DATA'},
65
81
  {name: 'sendwithus', address: 'matt@example.com'},
@@ -183,6 +199,55 @@ class TestApiRequest < Minitest::Test
183
199
  assert_instance_of( Net::HTTPOK, result )
184
200
  end
185
201
 
202
+ def test_list_template_versions
203
+ build_objects
204
+ result = @api.list_template_versions(@template[:id])
205
+
206
+ assert_instance_of( Net::HTTPOK, result )
207
+ end
208
+
209
+ def test_update_template_version
210
+ build_objects
211
+ version_id = get_first_template_version_id(@template[:id])
212
+
213
+ result = @api.update_template_version(
214
+ @template[:id],
215
+ version_id,
216
+ @template[:name],
217
+ @template[:subject],
218
+ @template[:html],
219
+ ''
220
+ )
221
+
222
+ assert_instance_of( Net::HTTPOK, result )
223
+ end
224
+
225
+ def test_create_template_version
226
+ build_objects
227
+ result = @api.create_template_version(
228
+ @template[:id],
229
+ @template[:name],
230
+ @template[:subject],
231
+ @template[:html],
232
+ ''
233
+ )
234
+
235
+ assert_instance_of( Net::HTTPOK, result )
236
+ end
237
+
238
+ def test_delete_template
239
+ build_objects
240
+ template = JSON.parse @api.create_template(
241
+ "test create",
242
+ "test subject",
243
+ @template[:html],
244
+ ''
245
+ ).body
246
+
247
+ result = @api.delete_template(template["id"])
248
+ assert_instance_of( Net::HTTPOK, result )
249
+ end
250
+
186
251
  def test_emails
187
252
  build_objects
188
253
  Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPSuccess.new(1.0, 200, "OK"))
@@ -236,34 +301,78 @@ class TestApiRequest < Minitest::Test
236
301
  assert_equal( true, @request.send(:request_path, :send) == '/api/v1_0/send' )
237
302
  end
238
303
 
239
- def test_add_user_event()
304
+ def test_add_user_event
240
305
  build_objects
241
306
  Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPSuccess.new(1.0, 200, "OK"))
242
307
  assert_instance_of( Net::HTTPSuccess, @request.post(:'customers/test@sendwithus.com/conversions', @payload))
243
308
  end
244
309
 
245
- def test_conversion_event()
310
+ def test_conversion_event
246
311
  build_objects
247
312
  Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPSuccess.new(1.0, 200, "OK"))
248
313
  assert_instance_of( Net::HTTPSuccess, @request.post(:'customers/test@sendwithus.com/conversions', @payload))
249
314
  end
250
315
 
251
- def test_customer_create()
316
+ def test_customer_create
252
317
  build_objects
253
318
  Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPSuccess.new(1.0, 200, "OK"))
254
319
  assert_instance_of( Net::HTTPSuccess, @request.post(:'customers', @customer))
255
320
  end
256
321
 
257
- def test_customer_delete()
322
+ def test_customer_delete
258
323
  build_objects
259
324
  Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPSuccess.new(1.0, 200, "OK"))
260
325
  assert_instance_of( Net::HTTPSuccess, @request.delete(:'customers/#{@customer[:email]}'))
261
326
  end
262
327
 
263
- def test_logs_with_options()
328
+ def test_customer_add_to_group
329
+ build_objects
330
+ Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPSuccess.new(1.0, 200, "OK"))
331
+ assert_instance_of( Net::HTTPSuccess, @request.post(:"customers/#{@customer[:email]})/groups/#{@customer[:email][0]}", @customer))
332
+ end
333
+
334
+ def test_customer_remove_from_group
335
+ build_objects
336
+ Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPSuccess.new(1.0, 200, "OK"))
337
+ assert_instance_of( Net::HTTPSuccess, @request.delete(:"customers/#{@customer[:email]})/groups/#{@customer[:email][0]}"))
338
+ end
339
+
340
+ def test_logs_with_options
264
341
  build_objects
265
342
  Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPSuccess.new(1.0, 200, "OK"))
266
343
  assert_instance_of( Net::HTTPSuccess, @request.get(:'logs?count=2&offset=10'))
267
344
  end
268
345
 
346
+ def test_get_groups
347
+ build_objects
348
+ result = @api.get_groups()
349
+
350
+ assert_instance_of( Net::HTTPOK, result )
351
+ end
352
+
353
+ def test_create_customer_group
354
+ build_objects
355
+ result = @api.create_customer_group('testing')
356
+ result_id = JSON.parse(result.body)["group"]["id"]
357
+
358
+ # clean up
359
+ @api.delete_customer_group(result_id)
360
+
361
+ assert_instance_of( Net::HTTPOK, result )
362
+ end
363
+
364
+ def test_update_customer_group
365
+ build_objects
366
+ result = @api.update_customer_group(@customer[:groups][0], 'test')
367
+ assert_instance_of( Net::HTTPOK, result )
368
+ end
369
+
370
+ def delete_customer_group
371
+ build_objects
372
+ new_group = @api.create_customer_group('deleteme')
373
+ new_group_id = JSON.parse(new_group.body)["group"]["id"]
374
+ result = @api.delete_customer_group(new_group_id)
375
+
376
+ assert_instance_of( Net::HTTPOK, result )
377
+ end
269
378
  end
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.10.2
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Harris
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-06-11 00:00:00.000000000 Z
13
+ date: 2015-07-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.4.6
106
+ rubygems_version: 2.2.2
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: SendWithUs.com Ruby Client