urbanairship 5.4.0 → 5.5.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
  SHA256:
3
- metadata.gz: 6f260b6f4cd6af338f251cc34c473eeb49063c7eb0daa5ad3a569f0d90a3584d
4
- data.tar.gz: 160fcdd2a23b6dea6008b09b03f22a65d601555590810b3d951394aa24d8f51e
3
+ metadata.gz: 473e83567cb51164c9ed471d2e5ecbd73902624f231fd6463a07d2626d6233a6
4
+ data.tar.gz: dd676b778158ed24687223009942bdff1ec105bfc485987767c27f10c6de0344
5
5
  SHA512:
6
- metadata.gz: 4103a2061061355627af7cfee8879fd231a8eccda95a1f5ad1a4af3be9471d8177844e8de8b9a5ba832607249cbf67928df77951da03317d8e9a6c9df209ec0b
7
- data.tar.gz: 4c0e50e54f17166a734c929f33b912b9afcdb593edadf7549bf2a55b548e10b21cbcca69d687fa58dfcae2fa31579a28f355485a6034055933cd6229fdf85e49
6
+ metadata.gz: e0ca4c22e57d83a0d89fa0e32ecb19db0f3ffa3b3ff5913b6f4df38df3dd73dc862b5d526cbb9654ff9fa92535dbad29b50cb516a8772ccdcbc50f416cca6068
7
+ data.tar.gz: 1ce0f4984b438dd40df90ccc29eeb0e4f10c99ef8a9e2f85a5af601f6ad241aa47586f78c4c2b089e989b0e01f5a595414faae82c1b6643271daf213a7b9a92a
data/.gitignore CHANGED
@@ -9,6 +9,7 @@
9
9
  /pkg/
10
10
  /spec/reports/
11
11
  /tmp/
12
+ /csv_file
12
13
 
13
14
  # App
14
15
  urbanairship.log
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ --------------------
2
+ 5.5.0
3
+ --------------------
4
+ - Add Create and Send Functionality for Email
5
+ - Add endpoints for Create and Send Validation and Scheduling
6
+ - Add Create and Send Functionality for SMS
7
+ - Update Rake version from 10.0 to 12.3.3
8
+
1
9
  --------------------
2
10
  5.4.0
3
11
  --------------------
@@ -0,0 +1,489 @@
1
+ Create and Send
2
+ ===============
3
+
4
+ The CreateAndSend class uses various notification classes as the portion of the notification
5
+ part of the payload. Different channels that harness Create and Send will require slightly different
6
+ implementation, and therefore, a different notification object.
7
+
8
+ For more context see EmailNotification and SmsNotification to see how each class method
9
+ operates, and how that is used to create the notification portion of the Create and Send payload.
10
+
11
+ For background information visit out docs here: https://docs.airship.com/api/ua/#tag/create-and-send
12
+
13
+ Create and Send Validation
14
+ --------------------------
15
+
16
+ Here, the payload that is being validated is one that would be used for email override.
17
+ However, this validation method should work on any other create and send notification objects.
18
+
19
+ .. code-block:: ruby
20
+
21
+ require 'urbanairship'
22
+ UA = Urbanairship
23
+ airship = UA::Client.new(key:'<app_key>', secret:'<secret_key>')
24
+ email_notification = UA::EmailNotification.new(client: airship)
25
+ email_notification.bypass_opt_in_level = false
26
+ email_notification.html_body = "<h2>Richtext body goes here</h2><p>Wow!</p><p><a data-ua-unsubscribe=\"1\" title=\"unsubscribe\" href=\"http://unsubscribe.urbanairship.com/email/success.html\">Unsubscribe</a></p>"
27
+ email_notification.message_type = 'transactional'
28
+ email_notification.plaintext_body = 'Plaintext version goes here [[ua-unsubscribe href=\"http://unsubscribe.urbanairship.com/email/success.html\"]]'
29
+ email_notification.reply_to = '<reply_to address>'
30
+ email_notification.sender_address = '<sender_address>'
31
+ email_notification.sender_name = 'Sender Name'
32
+ email_notification.subject = 'Subject Line'
33
+ override = email_notification.email_override
34
+ send_it = UA::CreateAndSend.new(client: airship)
35
+ send_it.addresses = [
36
+ {
37
+ "ua_address": "test@example.com",
38
+ "ua_commercial_opted_in": "2019-12-29T10:34:22"
39
+ }
40
+ ]
41
+ send_it.device_types = [ "email" ]
42
+ send_it.campaigns = ["winter sale", "west coast"]
43
+ send_it.notification = email_notification.email_override
44
+ send_it.validate
45
+
46
+ .. note::
47
+
48
+ Should return a 200 HTTP status code.
49
+
50
+ Schedule Create and Send Operation
51
+ ----------------------------------
52
+
53
+ Here, the payload that is being scheduled is one that would be used for email override.
54
+ However, this operation method should schedule any other create and send notification objects.
55
+
56
+ .. code-block:: ruby
57
+
58
+ require 'urbanairship'
59
+ UA = Urbanairship
60
+ airship = UA::Client.new(key:'<app_key>', secret:'<secret_key>')
61
+ email_notification = UA::EmailNotification.new(client: airship)
62
+ email_notification.bypass_opt_in_level = false
63
+ email_notification.html_body = "<h2>Richtext body goes here</h2><p>Wow!</p><p><a data-ua-unsubscribe=\"1\" title=\"unsubscribe\" href=\"http://unsubscribe.urbanairship.com/email/success.html\">Unsubscribe</a></p>"
64
+ email_notification.message_type = 'transactional'
65
+ email_notification.plaintext_body = 'Plaintext version goes here [[ua-unsubscribe href=\"http://unsubscribe.urbanairship.com/email/success.html\"]]'
66
+ email_notification.reply_to = '<reply_to address>'
67
+ email_notification.sender_address = '<sender_address>'
68
+ email_notification.sender_name = 'Sender Name'
69
+ email_notification.subject = 'Subject Line'
70
+ override = email_notification.email_override
71
+ send_it = UA::CreateAndSend.new(client: airship)
72
+ send_it.addresses = [
73
+ {
74
+ "ua_address": "test@example.com",
75
+ "ua_commercial_opted_in": "2019-12-29T10:34:22"
76
+ }
77
+ ]
78
+ send_it.device_types = [ "email" ]
79
+ send_it.campaigns = ["winter sale", "west coast"]
80
+ send_it.notification = email_notification.email_override
81
+ send_it.name = 'Name for scheduled create and send'
82
+ send_it.scheduled_time = "2019-13-29T10:34:22"
83
+ send_it.schedule
84
+
85
+ .. note::
86
+
87
+ Should return a 201 HTTP status code.
88
+
89
+ Create and Send to Email Channels
90
+ =================================
91
+
92
+ You will need to create an EmailNotification object before adding that to the notification
93
+ field as the create and send object.
94
+
95
+ Create and Send with Email Override
96
+ -----------------------------------
97
+
98
+ The first few lines of code are creating a EmailNotification object, and assigning
99
+ instance variables to the object. The line of code here:
100
+ `override = email_notification.email_override`
101
+ is using a class method on EmailNotification specific for an email override in order
102
+ to format the payload correctly for the notification portion of the CreateAndSend object.
103
+
104
+ .. code-block:: ruby
105
+
106
+ require 'urbanairship'
107
+ UA = Urbanairship
108
+ airship = UA::Client.new(key:'<app_key>', secret:'<secret_key>')
109
+ email_notification = UA::EmailNotification.new(client: airship)
110
+ email_notification.bypass_opt_in_level = false
111
+ email_notification.html_body = "<h2>Richtext body goes here</h2><p>Wow!</p><p><a data-ua-unsubscribe=\"1\" title=\"unsubscribe\" href=\"http://unsubscribe.urbanairship.com/email/success.html\">Unsubscribe</a></p>"
112
+ email_notification.message_type = 'transactional'
113
+ email_notification.plaintext_body = 'Plaintext version goes here [[ua-unsubscribe href=\"http://unsubscribe.urbanairship.com/email/success.html\"]]'
114
+ email_notification.reply_to = '<reply_to address>'
115
+ email_notification.sender_address = '<sender_address>'
116
+ email_notification.sender_name = 'Sender Name'
117
+ email_notification.subject = 'Subject Line'
118
+ override = email_notification.email_override
119
+ send_it = UA::CreateAndSend.new(client: airship)
120
+ send_it.addresses = [
121
+ {
122
+ "ua_address": "test@example.com",
123
+ "ua_commercial_opted_in": "2019-12-29T10:34:22"
124
+ }
125
+ ]
126
+ send_it.device_types = [ "email" ]
127
+ send_it.campaigns = ["winter sale", "west coast"]
128
+ send_it.notification = override
129
+ send_it.create_and_send
130
+
131
+ .. note::
132
+
133
+ Should return a 202 Accepted HTTP response.
134
+
135
+ Create and Send with Email Inline Template/Template ID
136
+ ------------------------------------------------------
137
+
138
+ The first few lines of code are creating a EmailNotification object, and assigning
139
+ instance variables to the object. The line of code here:
140
+ `inline_template = email_notification.email_with_inline_template`
141
+ is using a class method on EmailNotification specific for an inline template. This goes
142
+ on to format the payload correctly for the notification portion of the CreateAndSend object
143
+ shown in the line of code here:
144
+ `send_it.notification = inline_template`
145
+
146
+ .. code-block:: ruby
147
+
148
+ require 'urbanairship'
149
+ UA = Urbanairship
150
+ airship = UA::Client.new(key:'<app_key>', secret:'<secret_key>')
151
+ email_notification = UA::EmailNotification.new(client: airship)
152
+ email_notification.message_type = 'transactional'
153
+ email_notification.reply_to = 'reply_to_this@email.com'
154
+ email_notification.sender_address = 'sends_from_this@email.com'
155
+ email_notification.sender_name = 'Sender Name'
156
+ email_notification.template_id = "<template_id>"
157
+ inline_template = email_notification.email_with_inline_template
158
+ send_it = UA::CreateAndSend.new(client: airship)
159
+ send_it.addresses = [
160
+ {
161
+ "ua_address": "test@example.com",
162
+ "ua_commercial_opted_in": "2019-12-29T10:34:22"
163
+ }
164
+ ]
165
+ send_it.device_types = [ "email" ]
166
+ send_it.campaigns = ["winter sale", "west coast"]
167
+ send_it.notification = inline_template
168
+ send_it.create_and_send
169
+
170
+ .. note::
171
+
172
+ Should return a 202 Accepted HTTP response.
173
+
174
+ Create and Send with Email Inline Template/Fields
175
+ -------------------------------------------------
176
+
177
+ The first few lines of code are creating a EmailNotification object, and assigning
178
+ instance variables to that object. The line of code here:
179
+ `inline_template = email_notification.email_with_inline_template`
180
+ is using a class method on EmailNotification specific for an inline template. This goes
181
+ on to format the payload correctly for the notification portion of the CreateAndSend object
182
+ shown in the line of code here:
183
+ `send_it.notification = inline_template`
184
+
185
+ .. code-block:: ruby
186
+
187
+ require 'urbanairship'
188
+ UA = Urbanairship
189
+ airship = UA::Client.new(key:'<app_key>', secret:'<secret_key>')
190
+ email_notification = UA::EmailNotification.new(client: airship)
191
+ email_notification.message_type = 'transactional'
192
+ email_notification.reply_to = 'reply_to_this@email.com'
193
+ email_notification.sender_address = 'sends_from_this@email.com'
194
+ email_notification.sender_name = 'Sender Name''
195
+ email_notification.subject= "I'm sending some stuff"
196
+ email_notification.plaintext_body = 'Plaintext version goes here [[ua-unsubscribe href=\"http://unsubscribe.urbanairship.com/email/success.html\"]]'
197
+ inline_template = email_notification.email_with_inline_template
198
+ send_it = UA::CreateAndSend.new(client: airship)
199
+ send_it.addresses = [
200
+ {
201
+ "ua_address": "example@test.com",
202
+ "ua_commercial_opted_in": "2019-12-29T10:34:22"
203
+ }
204
+ ]
205
+ send_it.device_types = [ "email" ]
206
+ send_it.campaigns = ["winter sale", "west coast"]
207
+ send_it.notification = inline_template
208
+ send_it.create_and_send
209
+
210
+ .. note::
211
+
212
+ Should return a 202 Accepted HTTP response.
213
+
214
+ Create and Send to SMS Channels
215
+ ================================
216
+
217
+ Create and Send to SMS Override
218
+ -------------------------------
219
+
220
+ The first few lines of code are creating a SmsNotification object, and assigning
221
+ instance variables to that object. The line of code here:
222
+ `override = notification.sms_notification_override`
223
+ is using a class method on SmsNotification specific for a sms override. This goes
224
+ on to format the payload correctly for the notification portion of the CreateAndSend object
225
+ shown in the line of code here:
226
+ `send_it.notification = inline_template`
227
+
228
+ .. code-block:: ruby
229
+
230
+ require 'urbanairship'
231
+ UA = Urbanairship
232
+ airship = UA::Client.new(key:'<app_key>', secret:'<secret_key>')
233
+ notification = UA::SmsNotification.new(client: airship)
234
+ notification.sms_alert = "A shorter alert with a link for SMS users to click https://www.mysite.com/amazingly/long/url-that-takes-up-lots-of-characters"
235
+ notification.generic_alert = "A generic alert sent to all platforms without overrides in device_types"
236
+ notification.expiry = 172800
237
+ notification.shorten_links = true
238
+ override = notification.sms_notification_override
239
+ send_it = UA::CreateAndSend.new(client: airship)
240
+ send_it.addresses = [
241
+ {
242
+ "ua_msisdn": "15558675309",
243
+ "ua_sender": "12345",
244
+ "ua_opted_in": "2018-11-11T18:45:30"
245
+ }
246
+ ]
247
+ send_it.device_types = [ "sms" ]
248
+ send_it.notification = override
249
+ send_it.campaigns = ["winter sale", "west coast"]
250
+ send_it.create_and_send
251
+
252
+ .. note::
253
+
254
+ Should return a 202 Accepted HTTP response.
255
+
256
+ Create and Send to SMS With Inline Template
257
+ -------------------------------------------
258
+
259
+ The first few lines of code are creating a SmsNotification object, and assigning
260
+ instance variables to that object. The line of code here:
261
+ `template = notification.sms_inline_template`
262
+ is using a class method on SmsNotification specific for a sms inline template. This goes
263
+ on to format the payload correctly for the notification portion of the CreateAndSend object
264
+ shown in the line of code here:
265
+ `send_it.notification = template`
266
+
267
+ .. code-block:: ruby
268
+
269
+ require 'urbanairship'
270
+ UA = Urbanairship
271
+ airship = UA::Client.new(key:'<app_key>', secret:'<secret_key>')
272
+ notification = UA::SmsNotification.new(client: airship)
273
+ notification.sms_alert = "Hi, {{customer.first_name}}, your {{#each cart}}{{this.name}}{{/each}} are ready to pickup at our {{customer.location}} location!"
274
+ notification.expiry = 172800
275
+ notification.shorten_links = true
276
+ template = notification.sms_inline_template
277
+ send_it = UA::CreateAndSend.new(client: airship)
278
+ send_it.addresses = [
279
+ {
280
+ "ua_msisdn": "15558675309",
281
+ "ua_sender": "12345",
282
+ "ua_opted_in": "2018-11-11T18:45:30",
283
+ "customer": {
284
+ "first_name": "Customer Name",
285
+ "last_name": "Last Name",
286
+ "location": "Location",
287
+ },
288
+ "cart": [
289
+ {
290
+ "name": "Robot Unicorn",
291
+ "qty": 1
292
+ },
293
+ {
294
+ "name": "Holy Hand Grenade of Antioch",
295
+ "qty": 1
296
+ }
297
+ ]
298
+ }
299
+ ]
300
+ send_it.device_types = [ "sms" ]
301
+ send_it.notification = template
302
+ send_it.campaigns = [ "order-pickup" ]
303
+ send_it.create_and_send
304
+
305
+ .. note::
306
+
307
+ Should return a 202 Accepted HTTP response.
308
+
309
+ Create and Send to SMS With Template ID
310
+ ---------------------------------------
311
+
312
+ The first few lines of code are creating a SmsNotification object, and assigning
313
+ instance variables to that object. The line of code here:
314
+ `template = notification.sms_inline_template`
315
+ is using a class method on SmsNotification specific for a sms template ID. This goes
316
+ on to format the payload correctly for the notification portion of the CreateAndSend object
317
+ shown in the line of code here:
318
+ `send_it.notification = template`
319
+
320
+ .. code-block:: ruby
321
+
322
+ require 'urbanairship'
323
+ UA = Urbanairship
324
+ airship = UA::Client.new(key:'<app_key>', secret:'<secret_key>')
325
+ notification = UA::SmsNotification.new(client: airship)
326
+ notification.template_id = <sms_template_id_for_app>
327
+ notification.expiry = 172800
328
+ notification.shorten_links = true
329
+ template = notification.sms_inline_template
330
+ send_it = UA::CreateAndSend.new(client: airship)
331
+ send_it.addresses = [
332
+ {
333
+ "ua_msisdn": "15558675309",
334
+ "ua_sender": "12345",
335
+ "ua_opted_in": "2018-11-11T18:45:30",
336
+ "customer": {
337
+ "first_name": "Customer Name",
338
+ "last_name": "Last Name",
339
+ "location": "Your Location",
340
+ },
341
+ "cart": [
342
+ {
343
+ "name": "Robot Unicorn",
344
+ "qty": 1
345
+ },
346
+ {
347
+ "name": "Holy Hand Grenade of Antioch",
348
+ "qty": 1
349
+ }
350
+ ]
351
+ }
352
+ ]
353
+ send_it.device_types = [ "sms" ]
354
+ send_it.notification = template
355
+ send_it.campaigns = [ "order-pickup" ]
356
+ send_it.create_and_send
357
+
358
+ .. note::
359
+
360
+ Should return a 202 Accepted HTTP response.
361
+
362
+ Create and Send to MMS Channels
363
+ ================================
364
+
365
+ Create and Send to MMS Override
366
+ -------------------------------
367
+
368
+ The first few lines of code are creating a MmsNotification object, and assigning
369
+ instance variables to that object. The line of code here:
370
+ `mms_notification = override.mms_override`
371
+ is using a class method on MmsNotification specific for a sms template ID. This goes
372
+ on to format the payload correctly for the notification portion of the CreateAndSend object
373
+ shown in the line of code here:
374
+ `send_it.notification = mms_notification`
375
+
376
+ .. code-block:: ruby
377
+
378
+ require 'urbanairship'
379
+ UA = Urbanairship
380
+ airship = UA::Client.new(key:'<app_key>', secret:'<secret_key>')
381
+ override = UA::MmsNotification.new(client: airship)
382
+ override.fallback_text = "See https://urbanairship.com for double rainbows!"
383
+ override.shorten_links = true
384
+ override.content_length = 238686
385
+ override.content_type = "image/jpeg"
386
+ override.url = "https://www.metoffice.gov.uk/binaries/content/gallery/mohippo/images/learning/learn-about-the-weather/rainbows/full_featured_double_rainbow_at_savonlinna_1000px.jpg"
387
+ override.text = "A double rainbow is a wonderful sight where you get two spectacular natural displays for the price of one."
388
+ override.subject = "Double Rainbows"
389
+ mms_notification = override.mms_override
390
+ send_it = UA::CreateAndSend.new(client: airship)
391
+ send_it.addresses = [
392
+ {
393
+ "ua_msisdn": "15558675309",
394
+ "ua_sender": "12345",
395
+ "ua_opted_in": "2018-11-11T18:45:30",
396
+ }
397
+ ]
398
+ send_it.device_types = [ "mms" ]
399
+ send_it.notification = mms_notification
400
+ send_it.campaigns = ["winter sale", "west coast"]
401
+ send_it.create_and_send
402
+
403
+ .. note::
404
+
405
+ Should return a 202 Accepted HTTP response.
406
+
407
+ Create and Send to MMS Template with ID
408
+ ---------------------------------------
409
+
410
+ The first few lines of code are creating a MmsNotification object, and assigning
411
+ instance variables to that object. The line of code here:
412
+ `mms_notification = override.mms_template_with_id`
413
+ is using a class method on MmsNotification specific for a sms template ID. This goes
414
+ on to format the payload correctly for the notification portion of the CreateAndSend object
415
+ shown in the line of code here:
416
+ `send_it.notification = mms_notification`
417
+
418
+ .. code-block:: ruby
419
+
420
+ require 'urbanairship'
421
+ UA = Urbanairship
422
+ airship = UA::Client.new(key:'<app_key>', secret:'<secret_key>')
423
+ override = UA::MmsNotification.new(client: airship)
424
+ override.template_id = "<existing_template_id>"
425
+ override.shorten_links = true
426
+ override.content_length = 19309
427
+ override.content_type = "image/jpeg"
428
+ override.url = "https://images-na.ssl-images-amazon.com/images/I/71eUHxwlMKL._AC_SX425_.jpg"
429
+ mms_notification = override.mms_template_with_id
430
+ send_it = UA::CreateAndSend.new(client: airship)
431
+ send_it.addresses = [
432
+ {
433
+ "ua_msisdn": "123456789",
434
+ "ua_sender": "12345",
435
+ "ua_opted_in": "2020-01-30T18:45:30",
436
+ "customer": {
437
+ "first_name": "Phil",
438
+ "last_name": "Leash",
439
+ }
440
+ }
441
+ ]
442
+ send_it.device_types = [ "mms" ]
443
+ send_it.notification = mms_notification
444
+ send_it.create_and_send
445
+
446
+
447
+ .. note::
448
+
449
+ Should return a 202 Accepted HTTP response.
450
+
451
+ Create and Send to MMS with Inline Template
452
+ ---------------------------------------
453
+
454
+ The first few lines of code are creating a MmsNotification object, and assigning
455
+ instance variables to that object. The line of code here:
456
+ `mms_notification = override.mms_inline_template`
457
+ is using a class method on MmsNotification specific for a sms template ID. This goes
458
+ on to format the payload correctly for the notification portion of the CreateAndSend object
459
+ shown in the line of code here:
460
+ `send_it.notification = mms_notification`
461
+
462
+ .. code-block:: ruby
463
+
464
+ require 'urbanairship'
465
+ UA = Urbanairship
466
+ airship = UA::Client.new(key:'<app_key>', secret:'<master_secret>')
467
+ override = UA::MmsNotification.new(client: airship)
468
+ override.subject = "Subject"
469
+ override.fallback_text = "Fallback text"
470
+ override.text = "Some slide text"
471
+ override.content_length = 123100
472
+ override.content_type = "image/jpeg"
473
+ override.url = 'image ending in allowed image types'
474
+ mms_notification = override.mms_inline_template
475
+ send_it = UA::CreateAndSend.new(client: airship)
476
+ send_it.addresses = [
477
+ {
478
+ "ua_msisdn": "123456789",
479
+ "ua_sender": "12345",
480
+ "ua_opted_in": "2020-01-30T18:45:30"
481
+ }
482
+ ]
483
+ send_it.device_types = [ "mms" ]
484
+ send_it.notification = mms_notification
485
+ send_it.create_and_send
486
+
487
+ .. note::
488
+
489
+ Should return a 202 Accepted HTTP response.
@@ -6,6 +6,10 @@ require 'urbanairship/devices/segment'
6
6
  require 'urbanairship/devices/channel_uninstall'
7
7
  require 'urbanairship/devices/sms'
8
8
  require 'urbanairship/devices/email'
9
+ require 'urbanairship/devices/email_notification'
10
+ require 'urbanairship/devices/sms_notification'
11
+ require 'urbanairship/devices/mms_notification'
12
+ require 'urbanairship/devices/create_and_send'
9
13
  require 'urbanairship/client'
10
14
  require 'urbanairship/common'
11
15
  require 'urbanairship/configuration'
@@ -19,6 +19,7 @@ module Urbanairship
19
19
  PIPELINES_URL = BASE_URL + '/pipelines/'
20
20
  FEEDS_URL = BASE_URL + '/feeds/'
21
21
  LOCATION_URL = BASE_URL + '/location/'
22
+ CREATE_AND_SEND_URL = BASE_URL + '/create-and-send/'
22
23
 
23
24
  # Helper method for required keyword args in Ruby 2.0 that is compatible with 2.1+
24
25
  # @example
@@ -0,0 +1,102 @@
1
+ require 'urbanairship'
2
+ require 'urbanairship/devices/email_notification'
3
+
4
+ module Urbanairship
5
+ module Devices
6
+ class CreateAndSend
7
+ include Urbanairship::Common
8
+ include Urbanairship::Loggable
9
+ attr_accessor :addresses,
10
+ :device_types,
11
+ :notification,
12
+ :campaigns,
13
+ :name,
14
+ :scheduled_time
15
+
16
+ def initialize(client: required('client'))
17
+ @client = client
18
+ @addresses = nil
19
+ @device_types = nil
20
+ @notification = nil
21
+ @campaigns = nil
22
+ @name = nil
23
+ @scheduled_time = nil
24
+ end
25
+
26
+ def validate_address
27
+ @addresses.each do |address|
28
+ unless address.include?(:ua_address) or address.include?(:ua_msisdn && :ua_opted_in && :ua_sender)
29
+ fail ArgumentError, 'Missing a component in address portion of the object'
30
+ end
31
+ end
32
+ end
33
+
34
+ def payload
35
+ fail ArgumentError, 'addresses must be set for defining payload' if @addresses.nil?
36
+ fail ArgumentError, 'device type array must be set for defining payload' if @device_types.nil?
37
+ fail ArgumentError, 'notification object must be set for defining payload' if @notification.nil?
38
+
39
+ validate_address
40
+
41
+ full_payload = {
42
+ 'audience': {
43
+ 'create_and_send': @addresses
44
+ },
45
+ 'device_types': @device_types,
46
+ 'notification': @notification,
47
+ }
48
+
49
+ if @campaigns
50
+ campaign_object = {'categories': @campaigns}
51
+ full_payload[:campaigns] = campaign_object
52
+ end
53
+
54
+ full_payload
55
+ end
56
+
57
+ def create_and_send
58
+ response = @client.send_request(
59
+ method: 'POST',
60
+ body: JSON.dump(payload),
61
+ url: CREATE_AND_SEND_URL,
62
+ content_type: 'application/json'
63
+ )
64
+ logger.info("Running create and send for addresses #{@addresses}")
65
+ response
66
+ end
67
+
68
+ def validate
69
+ response = @client.send_request(
70
+ method: 'POST',
71
+ body: JSON.dump(payload),
72
+ url: CREATE_AND_SEND_URL + 'validate',
73
+ content_type: 'application/json'
74
+ )
75
+ logger.info("Validating payload for create and send")
76
+ response
77
+ end
78
+
79
+ def schedule
80
+ fail ArgumentError, 'scheduled time must be set to run an operation' if @scheduled_time.nil?
81
+
82
+ scheduled_payload = {
83
+ "schedule": {
84
+ "scheduled_time": @scheduled_time
85
+ },
86
+ "name": @name,
87
+ "push": payload
88
+ }
89
+
90
+ response = @client.send_request(
91
+ method: 'POST',
92
+ body: JSON.dump(scheduled_payload),
93
+ url: SCHEDULES_URL + 'create-and-send',
94
+ content_type: 'application/json'
95
+ )
96
+ logger.info("Scheduling create and send operation with name #{@name}")
97
+ response
98
+ end
99
+
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,99 @@
1
+ require 'urbanairship'
2
+ require 'json'
3
+
4
+ module Urbanairship
5
+ module Devices
6
+ class EmailNotification
7
+ include Urbanairship::Common
8
+ include Urbanairship::Loggable
9
+ attr_accessor :bcc,
10
+ :bypass_opt_in_level,
11
+ :html_body,
12
+ :message_type,
13
+ :plaintext_body,
14
+ :reply_to,
15
+ :sender_address,
16
+ :sender_name,
17
+ :subject,
18
+ :template_id,
19
+ :variable_details
20
+
21
+ def initialize(client: required('client'))
22
+ @client = client
23
+ @bcc = nil
24
+ @bypass_opt_in_level = nil
25
+ @html_body = nil
26
+ @message_type = nil
27
+ @plaintext_body = nil
28
+ @reply_to = nil
29
+ @sender_address = nil
30
+ @sender_name = nil
31
+ @subject = nil
32
+ @template_id = nil
33
+ @variable_details = nil
34
+ end
35
+
36
+ def email_override
37
+ fail ArgumentError, 'message_type is needed for email override' if @message_type.nil?
38
+ fail ArgumentError, 'plaintext_body is needed for email override' if @plaintext_body.nil?
39
+ fail ArgumentError, 'reply_to is needed for email override' if @reply_to.nil?
40
+ fail ArgumentError, 'sender_address is needed for email override' if @sender_address.nil?
41
+ fail ArgumentError, 'sender_name is needed for email override' if @sender_name.nil?
42
+ fail ArgumentError, 'subject is needed for email override' if @subject.nil?
43
+
44
+ override = {'email': {
45
+ 'bypass_opt_in_level': @bypass_opt_in_level,
46
+ 'html_body': @html_body,
47
+ 'message_type': @message_type,
48
+ 'plaintext_body': @plaintext_body,
49
+ 'reply_to': @reply_to,
50
+ 'sender_address': @sender_address,
51
+ 'sender_name': @sender_name,
52
+ 'subject': @subject
53
+ }}
54
+
55
+ if @bcc
56
+ override[:email][:bcc] = @bcc
57
+ end
58
+
59
+ override
60
+ end
61
+
62
+ def email_with_inline_template
63
+ fail ArgumentError, 'message_type is needed for email with inline template' if @message_type.nil?
64
+ fail ArgumentError, 'reply_to is needed for email with inline template' if @reply_to.nil?
65
+ fail ArgumentError, 'sender_address is needed for email with inline template' if @sender_address.nil?
66
+ fail ArgumentError, 'sender_name is needed for email with inline template' if @sender_name.nil?
67
+
68
+ inline_template = {'email': {
69
+ 'message_type': @message_type,
70
+ 'reply_to': @reply_to,
71
+ 'sender_address': @sender_address,
72
+ 'sender_name': @sender_name,
73
+ 'template': {}
74
+ }
75
+ }
76
+
77
+ if @subject and @plaintext_body
78
+ fields_object = {'plaintext_body': @plaintext_body, 'subject': @subject}
79
+ inline_template[:email][:template][:fields] = fields_object
80
+ end
81
+
82
+ if @bcc
83
+ inline_template[:email][:bcc] = @bcc
84
+ end
85
+
86
+ if @variable_details
87
+ inline_template[:email][:template][:variable_details] = @variable_details
88
+ end
89
+
90
+ if @template_id
91
+ inline_template[:email][:template][:template_id] = @template_id
92
+ end
93
+
94
+ inline_template
95
+ end
96
+
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,115 @@
1
+ require 'urbanairship'
2
+ require 'json'
3
+
4
+ module Urbanairship
5
+ module Devices
6
+ class MmsNotification
7
+ include Urbanairship::Common
8
+ include Urbanairship::Loggable
9
+
10
+ attr_accessor :fallback_text,
11
+ :shorten_links,
12
+ :content_length,
13
+ :content_type,
14
+ :url,
15
+ :text,
16
+ :subject,
17
+ :template_id,
18
+ :slide_1_text
19
+
20
+ def initialize(client: required('client'))
21
+ @client = client
22
+ @fallback_text = nil
23
+ @shorten_links = nil
24
+ @content_length = nil
25
+ @content_type = nil
26
+ @url = nil
27
+ @text = nil
28
+ @subject = nil
29
+ @template_id = nil
30
+ end
31
+
32
+ def validate_url
33
+ unless @url[-4..-1] == '.jpg' || '.gif' || '.png' || 'jpeg'
34
+ fail ArgumentError, 'url must end in .gif, .jpg, .png, or .jpeg'
35
+ end
36
+ end
37
+
38
+ def mms_override
39
+ fail ArgumentError, 'fallback_text is needed for MMS override' if @fallback_text.nil?
40
+ fail ArgumentError, 'content_length is needed for MMS override' if @content_length.nil?
41
+ fail ArgumentError, 'content_type is needed for MMS override' if @content_type.nil?
42
+ fail ArgumentError, 'url is needed for MMS override' if @url.nil?
43
+
44
+ validate_url
45
+
46
+ override = {"mms": {
47
+ "subject": @subject,
48
+ "fallback_text": @fallback_text,
49
+ "shorten_links": @shorten_links,
50
+ "slides": [
51
+ {
52
+ "text": @text,
53
+ "media": {
54
+ "url": @url,
55
+ "content_type": @content_type,
56
+ "content_length": @content_length
57
+ }
58
+ }
59
+ ]
60
+ }
61
+ }
62
+ override
63
+ end
64
+
65
+ def mms_template_with_id
66
+ fail ArgumentError, 'content_length is needed for MMS Inline Template with ID' if @content_length.nil?
67
+ fail ArgumentError, 'content_type is needed for MMS Inline Template with ID' if @content_type.nil?
68
+ fail ArgumentError, 'url is needed for MMS Inline Template with ID' if @url.nil?
69
+ fail ArgumentError, 'template_id is needed for MMS Inline Template with ID' if @template_id.nil?
70
+
71
+ {"mms": {
72
+ "template": {
73
+ "template_id": @template_id
74
+ },
75
+ "shorten_links": true,
76
+ "slides": [
77
+ {
78
+ "media": {
79
+ "url": @url,
80
+ "content_type": @content_type,
81
+ "content_length": @content_length
82
+ }
83
+ }
84
+ ]
85
+ }
86
+ }
87
+ end
88
+
89
+ def mms_inline_template
90
+ fail ArgumentError, 'slide_1_text text is needed for MMS with inline template' if @text.nil?
91
+
92
+ {"mms": {
93
+ "template": {
94
+ "fields": {
95
+ "subject": @subject,
96
+ "fallback_text": @fallback_text,
97
+ "slide_1_text": @text
98
+ }
99
+ },
100
+ "slides": [
101
+ {
102
+ "media": {
103
+ "url": @url,
104
+ "content_type": @content_type,
105
+ "content_length": @content_length
106
+ }
107
+ }
108
+ ]
109
+ }
110
+ }
111
+ end
112
+
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,59 @@
1
+ require 'urbanairship'
2
+ require 'json'
3
+
4
+ module Urbanairship
5
+ module Devices
6
+ class SmsNotification
7
+ include Urbanairship::Common
8
+ include Urbanairship::Loggable
9
+
10
+ attr_accessor :sms_alert,
11
+ :generic_alert,
12
+ :expiry,
13
+ :shorten_links,
14
+ :template_id
15
+
16
+ def initialize(client: required('client'))
17
+ @client = client
18
+ @alert = nil
19
+ @generic_alert = nil
20
+ @expiry = nil
21
+ @shorten_links = nil
22
+ @template_id = nil
23
+ end
24
+
25
+ def sms_notification_override
26
+ {
27
+ "alert": @generic_alert,
28
+ "sms": {
29
+ "alert": @sms_alert,
30
+ "expiry": @expiry,
31
+ "shorten_links": @shorten_links
32
+ }
33
+ }
34
+ end
35
+
36
+ def sms_inline_template
37
+ inline_template = {
38
+ "sms": {
39
+ "template": {}
40
+ }
41
+ }
42
+
43
+ if @template_id
44
+ inline_template[:sms][:template][:template_id] = @template_id
45
+ end
46
+
47
+ if @sms_alert
48
+ inline_fields= {
49
+ "fields": {"alert": @sms_alert}
50
+ }
51
+ inline_template[:sms][:template] = inline_fields
52
+ end
53
+
54
+ inline_template
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -1,3 +1,3 @@
1
1
  module Urbanairship
2
- VERSION = '5.4.0'
2
+ VERSION = '5.5.0'
3
3
  end
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'bundler', '>= 1'
33
33
  spec.add_development_dependency 'guard-rspec'
34
34
  spec.add_development_dependency 'pry', '~> 0'
35
- spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rake', '~> 12.3.3'
36
36
  spec.add_development_dependency 'rspec', '~> 3'
37
37
  spec.add_development_dependency 'terminal-notifier-guard', '~> 1'
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: urbanairship
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.4.0
4
+ version: 5.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airship
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-03 00:00:00.000000000 Z
11
+ date: 2020-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -78,14 +78,14 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '10.0'
81
+ version: 12.3.3
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '10.0'
88
+ version: 12.3.3
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: rspec
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -140,6 +140,7 @@ files:
140
140
  - docs/Makefile
141
141
  - docs/channel_uninstall.rst
142
142
  - docs/conf.py
143
+ - docs/create_and_send.rst
143
144
  - docs/devices.rst
144
145
  - docs/email.rst
145
146
  - docs/examples.rst
@@ -161,12 +162,16 @@ files:
161
162
  - lib/urbanairship/configuration.rb
162
163
  - lib/urbanairship/devices/channel_tags.rb
163
164
  - lib/urbanairship/devices/channel_uninstall.rb
165
+ - lib/urbanairship/devices/create_and_send.rb
164
166
  - lib/urbanairship/devices/devicelist.rb
165
167
  - lib/urbanairship/devices/email.rb
168
+ - lib/urbanairship/devices/email_notification.rb
169
+ - lib/urbanairship/devices/mms_notification.rb
166
170
  - lib/urbanairship/devices/named_user.rb
167
171
  - lib/urbanairship/devices/open_channel.rb
168
172
  - lib/urbanairship/devices/segment.rb
169
173
  - lib/urbanairship/devices/sms.rb
174
+ - lib/urbanairship/devices/sms_notification.rb
170
175
  - lib/urbanairship/devices/static_lists.rb
171
176
  - lib/urbanairship/loggable.rb
172
177
  - lib/urbanairship/push/audience.rb