notifications-ruby-client 2.6.0 → 2.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 942f912e7dce40facdd4d15a7554c34366efbbfb
4
- data.tar.gz: 7804cd65bf20d992f480e1f576cd9cab44e6b69c
3
+ metadata.gz: c9e8e3b5a9125d84b62e3015abf89f6aa7b8b7c9
4
+ data.tar.gz: 37f15920e5d4b62f7c6187eebd07473758a29949
5
5
  SHA512:
6
- metadata.gz: e1a019e8ff6e295d6f781aa956aadffdf89e2e116e1cd51dd7739427955d97949122f5d4252b538f03afb50101ad9b151a914efe3848d25933c4123a0cc20968
7
- data.tar.gz: a75e8a79f6cda877bda9f6bf4b4d7f783c14e9d7d7a43e3f305718407e4690cb0a9e162adae3124ca0dac3dd711a74115c84a479416ab857c93c5ed678165fd5
6
+ metadata.gz: 81a60d12905de3b4afe229431036fb8b8cb27c942e531e2e73bb378a5b632a435fc53426e548641545dedf36e5cdd861ea54a2136fe972d82405ec18ff39ca0f
7
+ data.tar.gz: c8739e97c93b0a6ae027c94ddce821505e6e825d865e80c3d436f23576c67f2d2c8d7a995ad400c7470895f2dd6d0c64bb767e0fb62f94ff8dcac81eadee3492
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 2.7.0
2
+
3
+ * The Notification class has a new `created_by_name` property.
4
+ * If the notification was sent manually this will be the name of the sender. If the notification was sent through the API this will be `nil`.
5
+
1
6
  ## 2.6.0
2
7
 
3
8
  ### Changed
data/DOCUMENTATION.md ADDED
@@ -0,0 +1,810 @@
1
+ # GOV.UK Notify Ruby client
2
+
3
+ This documentation is for developers interested in using this Ruby client to integrate their government service with GOV.UK Notify.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/notifications-ruby-client.svg)](https://badge.fury.io/rb/notifications-ruby-client)
6
+
7
+ ## Table of Contents
8
+
9
+ * [Installation](#installation)
10
+ * [Getting started](#getting-started)
11
+ * [Send messages](#send-messages)
12
+ * [Get the status of one message](#get-the-status-of-one-message)
13
+ * [Get the status of all messages](#get-the-status-of-all-messages)
14
+ * [Get a template by ID](#get-a-template-by-id)
15
+ * [Get a template by ID and version](#get-a-template-by-id-and-version)
16
+ * [Get all templates](#get-all-templates)
17
+ * [Generate a preview template](#generate-a-preview-template)
18
+ * [Get received texts](#get-received-texts)
19
+
20
+ ## Installation
21
+
22
+ Prior to usage an account must be created through the Notify admin console. This will allow access to the API credentials you application.
23
+
24
+ You can then install the gem or require it in your application.
25
+
26
+ ```
27
+ gem install 'notifications-ruby-client'
28
+ ```
29
+
30
+ ## Getting started
31
+
32
+ ```ruby
33
+ require 'notifications/client'
34
+ client = Notifications::Client.new(api_key)
35
+ ```
36
+
37
+ Generate an API key by logging in to GOV.UK Notify [GOV.UK Notify](https://www.notifications.service.gov.uk) and going to the **API integration** page.
38
+
39
+ ## Send messages
40
+
41
+ ### Text message
42
+
43
+ #### Method
44
+
45
+ <details>
46
+ <summary>
47
+ Click here to expand for more information.
48
+ </summary>
49
+
50
+ ```ruby
51
+ sms = client.send_sms(
52
+ phone_number: number,
53
+ template_id: template_id,
54
+ personalisation: {
55
+ name: "name",
56
+ year: "2016",
57
+ },
58
+ reference: "your_reference_string",
59
+ sms_sender_id: sms_sender_id
60
+ ) # => Notifications::Client::ResponseNotification
61
+ ```
62
+
63
+ </details>
64
+
65
+ #### Response
66
+
67
+ If the request is successful, a `Notifications::Client:ResponseNotification` is returned.
68
+ <details>
69
+ <summary>
70
+ Click here to expand for more information.
71
+ </summary>
72
+
73
+ ```ruby
74
+ sms => Notifications::Client::ResponseNotification
75
+
76
+ sms.id # => uuid for the notification
77
+ sms.reference # => Reference string you supplied in the request
78
+ sms.content # => Hash containing body => the message sent to the recipient, with placeholders replaced.
79
+ # from_number => the sms sender number of your service found **Settings** page
80
+ sms.template # => Hash containing id => id of the template
81
+ # version => version of the template
82
+ # uri => url of the template
83
+ sms.uri # => URL of the notification
84
+ ```
85
+
86
+
87
+ Otherwise the client will raise a `Notifications::Client::RequestError`:
88
+
89
+ |`error.code`|`error.message`|
90
+ |:---|:---|
91
+ |`429`|`[{`<br>`"error": "RateLimitError",`<br>`"message": "Exceeded rate limit for key type TEAM of 10 requests per 10 seconds"`<br>`}]`|
92
+ |`429`|`[{`<br>`"error": "TooManyRequestsError",`<br>`"message": "Exceeded send limits (50) for today"`<br>`}]`|
93
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Can"t send to this recipient using a team-only API key"`<br>`]}`|
94
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Can"t send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode"`<br>`}]`|
95
+
96
+ </details>
97
+
98
+ #### Arguments
99
+
100
+ <details>
101
+ <summary>
102
+ Click here to expand for more information.
103
+ </summary>
104
+
105
+ ##### `phone_number`
106
+
107
+ The phone number of the recipient, only required for sms notifications.
108
+
109
+ ##### `template_id`
110
+
111
+ Find by clicking **API info** for the template you want to send.
112
+
113
+ ##### `reference`
114
+
115
+ An optional identifier you generate. The `reference` can be used as a unique reference for the notification. Because Notify does not require this reference to be unique you could also use this reference to identify a batch or group of notifications.
116
+
117
+ You can omit this argument if you do not require a reference for the notification.
118
+
119
+ ##### `personalisation`
120
+
121
+ If a template has placeholders, you need to provide their values, for example:
122
+
123
+ ```python
124
+ personalisation={
125
+ 'first_name': 'Amala',
126
+ 'reference_number': '300241',
127
+ }
128
+ ```
129
+ ##### `sms_sender_id`
130
+
131
+ Optional. Specifies the identifier of the sms sender to set for the notification. The identifiers are found in your service Settings, when you 'Manage' your 'Text message sender'.
132
+
133
+ If you omit this argument your default sms sender will be set for the notification.
134
+
135
+ </details>
136
+
137
+
138
+ ### Email
139
+
140
+ #### Method
141
+
142
+ <details>
143
+ <summary>
144
+ Click here to expand for more information.
145
+ </summary>
146
+
147
+ ```ruby
148
+ email = client.send_email(
149
+ email_address: email_address,
150
+ template_id: template_id,
151
+ personalisation: {
152
+ name: "name",
153
+ year: "2016"
154
+ },
155
+ reference: "your_reference_string",
156
+ email_reply_to_id: email_reply_to_id
157
+ ) # => Notifications::Client::ResponseNotification
158
+ ```
159
+
160
+ </details>
161
+
162
+
163
+ #### Response
164
+
165
+ If the request is successful, a `Notifications::Client:ResponseNotification` is returned.
166
+
167
+ <details>
168
+ <summary>
169
+ Click here to expand for more information.
170
+ </summary>
171
+
172
+ ```ruby
173
+ email => Notifications::Client::ResponseNotification
174
+
175
+ email.id # => uuid for the notification
176
+ email.reference # => Reference string you supplied in the request
177
+ email.content # => Hash containing body => the message sent to the recipient, with placeholders replaced.
178
+ # subject => subject of the message sent to the recipient, with placeholders replaced.
179
+ # from_email => the from email of your service found **Settings** page
180
+ email.template # => Hash containing id => id of the template
181
+ # version => version of the template
182
+ # uri => url of the template
183
+ email.uri # => URL of the notification
184
+ ```
185
+
186
+ Otherwise the client will raise a `Notifications::Client::RequestError`:
187
+
188
+ |`error.code`|`error.message`|
189
+ |:---|:---|
190
+ |`429`|`[{`<br>`"error": "RateLimitError",`<br>`"message": "Exceeded rate limit for key type TEAM of 10 requests per 10 seconds"`<br>`}]`|
191
+ |`429`|`[{`<br>`"error": "TooManyRequestsError",`<br>`"message": "Exceeded send limits (50) for today"`<br>`}]`|
192
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Can"t send to this recipient using a team-only API key"`<br>`]}`|
193
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Can"t send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode"`<br>`}]`|
194
+
195
+ </details>
196
+
197
+
198
+ #### Arguments
199
+
200
+ <details>
201
+ <summary>
202
+ Click here to expand for more information.
203
+ </summary>
204
+
205
+ ##### `email_address`
206
+ The email address of the recipient, only required for email notifications.
207
+
208
+ ##### `template_id`
209
+
210
+ Find by clicking **API info** for the template you want to send.
211
+
212
+ ##### `reference`
213
+
214
+ An optional identifier you generate. The `reference` can be used as a unique reference for the notification. Because Notify does not require this reference to be unique you could also use this reference to identify a batch or group of notifications.
215
+
216
+ You can omit this argument if you do not require a reference for the notification.
217
+
218
+ ##### `email_reply_to_id`
219
+
220
+ Optional. Specifies the identifier of the email reply-to address to set for the notification. The identifiers are found in your service Settings, when you 'Manage' your 'Email reply to addresses'.
221
+
222
+ If you omit this argument your default email reply-to address will be set for the notification.
223
+
224
+ ##### `personalisation`
225
+
226
+ If a template has placeholders, you need to provide their values, for example:
227
+
228
+ ```python
229
+ personalisation={
230
+ 'first_name': 'Amala',
231
+ 'application_number': '300241',
232
+ }
233
+ ```
234
+
235
+ </details>
236
+
237
+
238
+ ### Letter
239
+
240
+ #### Method
241
+
242
+ <details>
243
+ <summary>
244
+ Click here to expand for more information.
245
+ </summary>
246
+
247
+ ```ruby
248
+ letter = client.send_letter(
249
+ template_id: template_id,
250
+ personalisation: {
251
+ address_line_1: 'Her Majesty The Queen', # required
252
+ address_line_2: 'Buckingham Palace', # required
253
+ address_line_3: 'London',
254
+ postcode: 'SW1 1AA', # required
255
+
256
+ ... # any other personalisation found in your template
257
+ },
258
+ reference: "your_reference_string"
259
+ ) # => Notifications::Client::ResponseNotification
260
+ ```
261
+
262
+ </details>
263
+
264
+
265
+ #### Response
266
+
267
+ If the request is successful, a `Notifications::Client:ResponseNotification` is returned.
268
+
269
+ <details>
270
+ <summary>
271
+ Click here to expand for more information.
272
+ </summary>
273
+
274
+ ```ruby
275
+ letter => Notifications::Client::ResponseNotification
276
+
277
+ letter.id # => uuid for the notification
278
+ letter.reference # => Reference string you supplied in the request
279
+ letter.content # => Hash containing body => the body of the letter sent to the recipient, with placeholders replaced
280
+ # subject => the main heading of the letter
281
+ letter.template # => Hash containing id => id of the template
282
+ # version => version of the template
283
+ # uri => url of the template
284
+ letter.uri # => URL of the notification
285
+ ```
286
+
287
+ |`error.code`|`error.message`|
288
+ |:---|:---|
289
+ |`429`|`[{`<br>`"error": "RateLimitError",`<br>`"message": "Exceeded rate limit for key type TEAM of 10 requests per 10 seconds"`<br>`}]`|
290
+ |`429`|`[{`<br>`"error": "TooManyRequestsError",`<br>`"message": "Exceeded send limits (50) for today"`<br>`}]`|
291
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Can"t send to this recipient using a team-only API key"`<br>`]}`|
292
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Can"t send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode"`<br>`}]`|
293
+ |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "personalisation address_line_1 is a required property"`<br>`}]`|
294
+
295
+ </details>
296
+
297
+
298
+ #### Arguments
299
+
300
+ <details>
301
+ <summary>
302
+ Click here to expand for more information.
303
+ </summary>
304
+
305
+ #### `template_id`
306
+ Find by clicking **API info** for the template you want to send.
307
+
308
+ #### `reference`
309
+ An optional identifier you generate. The `reference` can be used as a unique reference for the notification. Because Notify does not require this reference to be unique you could also use this reference to identify a batch or group of notifications.
310
+
311
+ You can omit this argument if you do not require a reference for the notification.
312
+
313
+ #### `personalisation`
314
+ If the template has placeholders you need to provide their values as a Hash, for example:
315
+
316
+ ```ruby
317
+ personalisation: {
318
+ 'first_name' => 'Amala',
319
+ 'reference_number' => '300241',
320
+ }
321
+ ```
322
+
323
+ You can omit this argument if the template does not contain placeholders and is for email or sms.
324
+
325
+ #### `personalisation` (for letters)
326
+
327
+ If you are sending a letter, you will need to provide the letter fields in the format `"address_line_#"`, for example:
328
+
329
+ ```ruby
330
+ personalisation: {
331
+ 'address_line_1' => 'The Occupier',
332
+ 'address_line_2' => '123 High Street',
333
+ 'address_line_3' => 'London',
334
+ 'postcode' => 'SW14 6BH',
335
+ 'first_name' => 'Amala',
336
+ 'reference_number' => '300241',
337
+ }
338
+ ```
339
+
340
+ The fields `address_line_1`, `address_line_2` and `postcode` are required.
341
+
342
+ </details>
343
+
344
+
345
+ ## Get the status of one message
346
+
347
+ #### Method
348
+
349
+ <details>
350
+ <summary>
351
+ Click here to expand for more information.
352
+ </summary>
353
+
354
+ ```ruby
355
+ notification = client.get_notification(id) # => Notifications::Client::Notification
356
+ ```
357
+
358
+ </details>
359
+
360
+
361
+ #### Response
362
+
363
+ If successful a `Notifications::Client::Notification` is returned.
364
+
365
+ <details>
366
+ <summary>
367
+ Click here to expand for more information.
368
+ </summary>
369
+
370
+ ```ruby
371
+ notification.id # => uuid for the notification
372
+ notification.to # => recipient email address or mobile number
373
+ notification.status # => status of the message "created|pending|sent|delivered|permanent-failure|temporary-failure"
374
+ notification.created_at # => Date time the message was created
375
+ notification.api_key # => uuid for the api key (not the actual api key)
376
+ notification.billable_units # => units billable or nil for email
377
+ notification.subject # => Subject of email or nil for sms
378
+ notification.body # => Body of message
379
+ notification.job # => job id if created by a csv or nil if message sent via api
380
+ notification.notification_type # => sms | email
381
+ notification.service # => uuid for service
382
+ notification.sent_at # => Date time the message is sent to the provider or nil if status = "created"
383
+ notification.sent_by # => Name of the provider that sent the message or nil if status = "created"
384
+ notification.template # => Hash containing template id, name, version, template type sms|email
385
+ notification.template_version # Template version number
386
+ notification.reference # => reference of the email or nil for sms
387
+ notification.updated_at # => Date time that the notification was last updated
388
+ ```
389
+ Otherwise a `Notification::Client::RequestError` is raised
390
+
391
+ |`error.code`|`error.message`|
392
+ |:---|:---|
393
+ |`404`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No result found"`<br>`}]`|
394
+ |`404`|`[{`<br>`"error": "ValidationError",`<br>`"message": "is not a valid UUID"`<br>`}]`|
395
+
396
+ </details>
397
+
398
+ #### Arguments
399
+
400
+ <details>
401
+ <summary>
402
+ Click here to expand for more information.
403
+ </summary>
404
+
405
+ ##### `id`
406
+
407
+ The ID of the notification.
408
+
409
+ </details>
410
+
411
+ ## Get the status of all messages
412
+
413
+ #### Method
414
+
415
+ <details>
416
+ <summary>
417
+ Click here to expand for more information.
418
+ </summary>
419
+
420
+ ```ruby
421
+ # See section below for a description of the arguments.
422
+ # This will return 250 of the most recent messages if `older_than` is omitted, the following 250 messages can be accessed through the hash `notifications.links["next"]`
423
+ args = {
424
+ 'template_type' => 'sms',
425
+ 'status' => 'failed',
426
+ 'reference' => 'your reference string'
427
+ 'older_than' => 'e194efd1-c34d-49c9-9915-e4267e01e92e' # => Notifications::Client::Notification
428
+ }
429
+ notifications = client.get_notifications(args)
430
+ ```
431
+
432
+ </details>
433
+
434
+
435
+ #### Response
436
+
437
+ If the request is successful a `Notifications::Client::NotificationsCollection` is returned.
438
+
439
+ <details>
440
+ <summary>
441
+ Click here to expand for more information.
442
+ </summary>
443
+
444
+ ```ruby
445
+ notifications.links # => Hash containing current => "/notifications?template_type=sms&status=delivered"
446
+ # next => "/notifications?older_than=last_id_in_list&template_type=sms&status=delivered"
447
+ notifications.collection # => [] (array of notification objects)
448
+ ```
449
+
450
+ Otherwise the client will raise a `Notifications::Client::RequestError`:
451
+
452
+ |`error.status_code`|`error.message`|
453
+ |:---|:---|
454
+ |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "bad status is not one of [created, sending, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure]"`<br>`}]`|
455
+ |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "Apple is not one of [sms, email, letter]"`<br>`}]`|
456
+
457
+ </details>
458
+
459
+ #### Arguments
460
+
461
+ Omit the argument Hash if you do not want to filter the results.
462
+
463
+ <details>
464
+ <summary>
465
+ Click here to expand for more information.
466
+ </summary>
467
+
468
+ ##### `template_type`
469
+
470
+ If omitted all messages are returned. Otherwise you can filter by:
471
+
472
+ * `email`
473
+ * `sms`
474
+ * `letter`
475
+
476
+ You can omit this argument to ignore the filter.
477
+
478
+ ##### `status`
479
+
480
+ You can filter by:
481
+
482
+ * `sending` - the message is queued to be sent by the provider.
483
+ * `delivered` - the message was successfully delivered.
484
+ * `failed` - this will return all failure statuses `permanent-failure`, `temporary-failure` and `technical-failure`.
485
+ * `permanent-failure` - the provider was unable to deliver message, email or phone number does not exist; remove this recipient from your list.
486
+ * `temporary-failure` - the provider was unable to deliver message, email box was full or the phone was turned off; you can try to send the message again.
487
+ * `technical-failure` - Notify had a technical failure; you can try to send the message again.
488
+
489
+ You can omit this argument to ignore the filter.
490
+
491
+ ##### `reference`
492
+
493
+ This is the `reference` you gave at the time of sending the notification. The `reference` can be a unique identifier for the notification or an identifier for a batch of notifications.
494
+
495
+ You can omit this argument to ignore the filter.
496
+
497
+
498
+ ##### `older_than`
499
+ You can get the notifications older than a given `Notification.id`.
500
+ You can omit this argument to ignore this filter.
501
+
502
+ </details>
503
+
504
+
505
+
506
+ ## Get a template by ID
507
+
508
+ #### Method
509
+
510
+ This will return the latest version of the template. Use [getTemplateVersion](#get-a-template-by-id-and-version) to retrieve a specific template version.
511
+
512
+ <details>
513
+ <summary>
514
+ Click here to expand for more information.
515
+ </summary>
516
+
517
+ ```ruby
518
+ template = client.get_template_by_id(id)
519
+ ```
520
+
521
+ </details>
522
+
523
+
524
+ #### Response
525
+
526
+ <details>
527
+ <summary>
528
+ Click here to expand for more information.
529
+ </summary>
530
+
531
+ ```Ruby
532
+ template.id # => uuid for the template
533
+ template.type # => type of template one of email|sms|letter
534
+ template.created_at # => date and time the template was created
535
+ template.updated_at # => date and time the template was last updated, may be null if version 1
536
+ template.created_by # => email address of the person that created the template
537
+ template.version # => version of the template
538
+ template.body # => content of the template
539
+ template.subject # => subject for email templates, will be empty for other template types
540
+ ```
541
+
542
+ Otherwise the client will raise a `Notifications::Client::RequestError`.
543
+
544
+ </details>
545
+
546
+
547
+ #### Arguments
548
+
549
+ <details>
550
+ <summary>
551
+ Click here to expand for more information.
552
+ </summary>
553
+
554
+ |`error.code`|`error.message`|
555
+ |:---|:---|
556
+ |`404`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No result found"`<br>`}]`|
557
+ |`404`|`[{`<br>`"error": "ValidationError",`<br>`"message": "is is not a valid UUID"`<br>`}]`|
558
+
559
+ ##### `id`
560
+ The template id is visible on the template page in the application.
561
+
562
+ </details>
563
+
564
+
565
+ ## Get a template by ID and version
566
+
567
+ #### Method
568
+
569
+ This will return the template for the given id and version.
570
+ <details>
571
+ <summary>
572
+ Click here to expand for more information.
573
+ </summary>
574
+
575
+ ```ruby
576
+ Template template = client.get_template_version(id, version)
577
+ ```
578
+
579
+ </details>
580
+
581
+
582
+ #### Response
583
+
584
+ <details>
585
+ <summary>
586
+ Click here to expand for more information.
587
+ </summary>
588
+
589
+
590
+ ```Ruby
591
+ template.id # => uuid for the template
592
+ template.type # => type of template one of email|sms|letter
593
+ template.created_at # => date and time the template was created
594
+ template.updated_at # => date and time the template was last updated, may be null if version 1
595
+ template.created_by # => email address of the person that created the template
596
+ template.version # => version of the template
597
+ template.body # => content of the template
598
+ template.subject # => subject for email templates, will be empty for other template types
599
+ ```
600
+
601
+ Otherwise the client will raise a `Notifications::Client::RequestError`.
602
+
603
+ |`error.code`|`error.message`|
604
+ |:---|:---|
605
+ |`404`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No result found"`<br>`}]`|
606
+ |`404`|`[{`<br>`"error": "ValidationError",`<br>`"message": "is is not a valid UUID"`<br>`}]`|
607
+
608
+ </details>
609
+
610
+
611
+ #### Arguments
612
+
613
+ <details>
614
+ <summary>
615
+ Click here to expand for more information.
616
+ </summary>
617
+
618
+ #### `id`
619
+ The template id is visible on the template page in the application.
620
+
621
+ #### `version`
622
+ A history of the template is kept. There is a link to `See previous versions` on the template page in the application.
623
+
624
+ </details>
625
+
626
+
627
+ ## Get all templates
628
+
629
+ #### Method
630
+
631
+ This will return the latest version of each template for your service.
632
+
633
+ <details>
634
+ <summary>
635
+ Click here to expand for more information.
636
+ </summary>
637
+
638
+ ```ruby
639
+ args = {
640
+ 'template_type' => 'sms'
641
+ }
642
+ templates = client.get_all_templates(args)
643
+ ```
644
+
645
+
646
+ </details>
647
+
648
+
649
+ #### Response
650
+
651
+ <details>
652
+ <summary>
653
+ Click here to expand for more information.
654
+ </summary>
655
+
656
+ ```ruby
657
+ TemplateCollection templates;
658
+ ```
659
+ If the response is successful, a TemplateCollection is returned.
660
+
661
+ If no templates exist for a template type or there no templates for a service, the templates list will be empty.
662
+
663
+ Otherwise the client will raise a `Notifications::Client::RequestError`.
664
+
665
+ </details>
666
+
667
+
668
+ #### Arguments
669
+
670
+ <details>
671
+ <summary>
672
+ Click here to expand for more information.
673
+ </summary>
674
+
675
+ ##### `template_type`
676
+ If omitted all templates are returned. Otherwise you can filter by:
677
+
678
+ * `email`
679
+ * `sms`
680
+ * `letter`
681
+
682
+ </details>
683
+
684
+
685
+ ## Generate a preview template
686
+
687
+ #### Method
688
+
689
+ This will return the contents of a template with the placeholders replaced with the given personalisation.
690
+
691
+ <details>
692
+ <summary>
693
+ Click here to expand for more information.
694
+ </summary>
695
+
696
+
697
+ ```ruby
698
+ templatePreview = client.generate_template_preview(id,
699
+ personalisation: {
700
+ name: "name",
701
+ year: "2016",
702
+ })
703
+ ```
704
+
705
+ </details>
706
+
707
+
708
+ #### Response
709
+
710
+ <details>
711
+ <summary>
712
+ Click here to expand for more information.
713
+ </summary>
714
+
715
+ ```Ruby
716
+ template.id # => uuid for the template
717
+ template.version # => version of the template
718
+ template.body # => content of the template
719
+ template.subject # => subject for email templates, will be empty for other template types
720
+ ```
721
+ Otherwise a `Notifications::Client::RequestError` is thrown.
722
+
723
+ |`error.code`|`error.message`|
724
+ |:---|:---|
725
+ |`404`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No result found"`<br>`}]`|
726
+ |`404`|`[{`<br>`"error": "ValidationError",`<br>`"message": "is is not a valid UUID"`<br>`}]`|
727
+
728
+ </details>
729
+
730
+
731
+ #### Arguments
732
+
733
+ <details>
734
+ <summary>
735
+ Click here to expand for more information.
736
+ </summary>
737
+
738
+ ##### `id`
739
+ The template id is visible on the template page in the application.
740
+
741
+ ##### `personalisation`
742
+ If a template has placeholders, you need to provide their values. `personalisation` can be an empty or null in which case no placeholders are provided for the notification.
743
+
744
+ </details>
745
+
746
+ ## Get received texts
747
+ #### Method
748
+
749
+ <details>
750
+ <summary>
751
+ Click here to expand for more information.
752
+ </summary>
753
+
754
+ ```ruby
755
+ # See section below for a description of the arguments.
756
+ # This will return 250 of the most recent messages if `older_than` is omitted, the following 250 messages can be accessed through the hash `received_texts.links["next"]`
757
+ args = {
758
+ 'older_than' => 'e194efd1-c34d-49c9-9915-e4267e01e92e' # => Notifications::Client::ReceivedText
759
+ }
760
+ received_texts = client.get_received_texts(args)
761
+ ```
762
+
763
+ </details>
764
+
765
+
766
+ #### Response
767
+
768
+ If the request is successful a `Notifications::Client::ReceivedTextCollection` is returned.
769
+
770
+ <details>
771
+ <summary>
772
+ Click here to expand for more information.
773
+ </summary>
774
+
775
+ `ReceivedTextCollection` -
776
+
777
+ ```ruby
778
+ received_texts.links # => Hash containing current => "/v2/received-text-messages"
779
+ # next => "/v2/received-text-messages?older_than=last_id_in_list"
780
+ received_texts.collection # => [] (array of ReceivedText objects)
781
+ ```
782
+
783
+ `ReceivedText` -
784
+
785
+ ```ruby
786
+ received_text.id # => uuid for the received text
787
+ received_text.created_at # => created_at of the received text
788
+ received_text.content # => content of the received text
789
+ received_text.notify_number # => number received text was sent to
790
+ received_text.service_id # => service id of the received text
791
+ received_text.user_number # => number received text was sent from
792
+
793
+ ```
794
+
795
+ </details>
796
+
797
+ #### Arguments
798
+
799
+ Omit the argument Hash if you do not want to filter the results.
800
+
801
+ <details>
802
+ <summary>
803
+ Click here to expand for more information.
804
+ </summary>
805
+
806
+ ##### `older_than`
807
+ You can get the notifications older than a given `received_text.id`.
808
+ You can omit this argument to ignore this filter.
809
+
810
+ </details>
data/README.md CHANGED
@@ -368,23 +368,26 @@ Click here to expand for more information.
368
368
  </summary>
369
369
 
370
370
  ```ruby
371
- notification.id # => uuid for the notification
372
- notification.to # => recipient email address or mobile number
373
- notification.status # => status of the message "created|pending|sent|delivered|permanent-failure|temporary-failure"
374
- notification.created_at # => Date time the message was created
375
- notification.api_key # => uuid for the api key (not the actual api key)
376
- notification.billable_units # => units billable or nil for email
377
- notification.subject # => Subject of email or nil for sms
378
- notification.body # => Body of message
379
- notification.job # => job id if created by a csv or nil if message sent via api
380
- notification.notification_type # => sms | email
381
- notification.service # => uuid for service
382
- notification.sent_at # => Date time the message is sent to the provider or nil if status = "created"
383
- notification.sent_by # => Name of the provider that sent the message or nil if status = "created"
384
- notification.template # => Hash containing template id, name, version, template type sms|email
385
- notification.template_version # Template version number
386
- notification.reference # => reference of the email or nil for sms
387
- notification.updated_at # => Date time that the notification was last updated
371
+ notification.id # => uuid for the notification
372
+ notification.reference # => reference string you supplied in the request
373
+ notification.email_address # => email address of the recipient (for email notifications)
374
+ notification.phone_number # => phone number of the recipient (for SMS notifications)
375
+ notification.line_1 # => line 1 of the address of the recipient (for letter notifications)
376
+ notification.line_2 # => line 2 of the address of the recipient (for letter notifications)
377
+ notification.line_3 # => line 3 of the address of the recipient (for letter notifications)
378
+ notification.line_4 # => line 4 of the address of the recipient (for letter notifications)
379
+ notification.line_5 # => line 5 of the address of the recipient (for letter notifications)
380
+ notification.line_6 # => line 6 of the address of the recipient (for letter notifications)
381
+ notification.postcode # => postcode of the recipient (for letter notifications)
382
+ notification.type # => type of notification sent (sms, email or letter)
383
+ notification.status # => notification status (sending / delivered / permanent-failure / temporary-failure / technical-failure)
384
+ notification.template # => uuid of the template
385
+ notification.body # => body of the notification
386
+ notification.subject # => the subject of the notification (email notifications only)
387
+ notification.sent_at # => date and time the notification was sent to the provider
388
+ notification.created_at # => date and time the notification was created
389
+ notification.completed_at # => date and time the notification was delivered or failed
390
+ notification.created_by_name # => name of the person who sent the notification if sent manually
388
391
  ```
389
392
  Otherwise a `Notification::Client::RequestError` is raised
390
393
 
@@ -408,7 +411,7 @@ The ID of the notification.
408
411
 
409
412
  </details>
410
413
 
411
- ## Get the status of the all messages
414
+ ## Get the status of all messages
412
415
 
413
416
  #### Method
414
417
 
@@ -419,7 +422,8 @@ Click here to expand for more information.
419
422
 
420
423
  ```ruby
421
424
  # See section below for a description of the arguments.
422
- # This will return 250 of the most recent messages if `older_than` is omitted, the following 250 messages can be accessed through the hash `notifications.links["next"]`
425
+ # This will return 250 of the most recent messages over the last 7 days, if `older_than` is omitted.
426
+ # The following 250 messages can be accessed through the hash `notifications.links["next"]`
423
427
  args = {
424
428
  'template_type' => 'sms',
425
429
  'status' => 'failed',
@@ -467,13 +471,6 @@ Click here to expand for more information.
467
471
 
468
472
  ##### `template_type`
469
473
 
470
- <details>
471
- <summary>
472
- Click here to expand for more information.
473
- </summary>
474
-
475
- ##### `template_type`
476
-
477
474
  If omitted all messages are returned. Otherwise you can filter by:
478
475
 
479
476
  * `email`
@@ -686,10 +683,6 @@ If omitted all templates are returned. Otherwise you can filter by:
686
683
  * `sms`
687
684
  * `letter`
688
685
 
689
-
690
- </details>
691
-
692
-
693
686
  </details>
694
687
 
695
688
 
@@ -728,6 +721,7 @@ template.id # => uuid for the template
728
721
  template.version # => version of the template
729
722
  template.body # => content of the template
730
723
  template.subject # => subject for email templates, will be empty for other template types
724
+ template.type # => type of notification the template is for (sms, email or letter)
731
725
  ```
732
726
  Otherwise a `Notifications::Client::RequestError` is thrown.
733
727
 
@@ -764,7 +758,8 @@ Click here to expand for more information.
764
758
 
765
759
  ```ruby
766
760
  # See section below for a description of the arguments.
767
- # This will return 250 of the most recent messages if `older_than` is omitted, the following 250 messages can be accessed through the hash `received_texts.links["next"]`
761
+ # This will return 250 of the most recent messages over the last 7 days, if `older_than` is omitted.
762
+ # The following 250 messages can be accessed through the hash `received_texts.links["next"]`
768
763
  args = {
769
764
  'older_than' => 'e194efd1-c34d-49c9-9915-e4267e01e92e' # => Notifications::Client::ReceivedText
770
765
  }
data/bin/test_client.rb CHANGED
@@ -252,7 +252,8 @@ def expected_fields_in_email_notification_that_are_nil
252
252
  line_5
253
253
  line_5
254
254
  line_6
255
- postcode)
255
+ postcode
256
+ created_by_name)
256
257
  end
257
258
 
258
259
  def expected_fields_in_sms_notification
@@ -275,7 +276,8 @@ def expected_fields_in_sms_notification_that_are_nil
275
276
  line_5
276
277
  line_6
277
278
  postcode
278
- subject)
279
+ subject
280
+ created_by_name)
279
281
  end
280
282
 
281
283
  def expected_fields_in_letter_notification
@@ -302,6 +304,7 @@ def expected_fields_in_letter_notification_that_are_nil
302
304
  line_5
303
305
  line_5
304
306
  line_6
307
+ created_by_name
305
308
  )
306
309
  end
307
310
 
@@ -23,6 +23,7 @@ module Notifications
23
23
  sent_at
24
24
  created_at
25
25
  completed_at
26
+ created_by_name
26
27
  ).freeze
27
28
 
28
29
  attr_reader(*FIELDS)
@@ -9,6 +9,6 @@
9
9
 
10
10
  module Notifications
11
11
  class Client
12
- VERSION = "2.6.0".freeze
12
+ VERSION = "2.7.0".freeze
13
13
  end
14
14
  end
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "bundler", "~> 1.13"
26
26
  spec.add_development_dependency "rake", "~> 12.3"
27
27
  spec.add_development_dependency "rspec", "~> 3.7"
28
- spec.add_development_dependency "webmock", "~> 3.1"
29
- spec.add_development_dependency "factory_bot", "~> 4.8"
30
- spec.add_development_dependency "govuk-lint", "~> 3.3"
28
+ spec.add_development_dependency "webmock", "~> 3.4"
29
+ spec.add_development_dependency "factory_bot", "~> 4.10"
30
+ spec.add_development_dependency "govuk-lint", "~> 3.8"
31
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifications-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-14 00:00:00.000000000 Z
11
+ date: 2018-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -78,42 +78,42 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '3.1'
81
+ version: '3.4'
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: '3.1'
88
+ version: '3.4'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: factory_bot
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '4.8'
95
+ version: '4.10'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '4.8'
102
+ version: '4.10'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: govuk-lint
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '3.3'
109
+ version: '3.8'
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: '3.3'
116
+ version: '3.8'
117
117
  description:
118
118
  email:
119
119
  - notify@digital.cabinet-office.gov.uk
@@ -126,6 +126,7 @@ files:
126
126
  - ".rspec"
127
127
  - ".rubocop.yml"
128
128
  - CHANGELOG.md
129
+ - DOCUMENTATION.md
129
130
  - Gemfile
130
131
  - LICENSE
131
132
  - Makefile