notifications-ruby-client 2.7.0 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/PULL_REQUEST_TEMPLATE.md +1 -1
- data/CHANGELOG.md +5 -0
- data/CONTRIBUTING.md +39 -0
- data/DOCUMENTATION.md +544 -529
- data/README.md +6 -812
- data/bin/test_client.rb +1 -0
- data/lib/notifications/client/response_template.rb +1 -0
- data/lib/notifications/client/version.rb +1 -1
- metadata +4 -3
data/README.md
CHANGED
@@ -1,816 +1,10 @@
|
|
1
1
|
# GOV.UK Notify Ruby client
|
2
2
|
|
3
|
-
|
3
|
+
Use this client to send emails, text messages and letters using the [GOV.UK Notify](https://www.notifications.service.gov.uk) API.
|
4
4
|
|
5
|
-
|
5
|
+
Useful links:
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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.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
|
391
|
-
```
|
392
|
-
Otherwise a `Notification::Client::RequestError` is raised
|
393
|
-
|
394
|
-
|`error.code`|`error.message`|
|
395
|
-
|:---|:---|
|
396
|
-
|`404`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No result found"`<br>`}]`|
|
397
|
-
|`404`|`[{`<br>`"error": "ValidationError",`<br>`"message": "is not a valid UUID"`<br>`}]`|
|
398
|
-
|
399
|
-
</details>
|
400
|
-
|
401
|
-
#### Arguments
|
402
|
-
|
403
|
-
<details>
|
404
|
-
<summary>
|
405
|
-
Click here to expand for more information.
|
406
|
-
</summary>
|
407
|
-
|
408
|
-
##### `id`
|
409
|
-
|
410
|
-
The ID of the notification.
|
411
|
-
|
412
|
-
</details>
|
413
|
-
|
414
|
-
## Get the status of all messages
|
415
|
-
|
416
|
-
#### Method
|
417
|
-
|
418
|
-
<details>
|
419
|
-
<summary>
|
420
|
-
Click here to expand for more information.
|
421
|
-
</summary>
|
422
|
-
|
423
|
-
```ruby
|
424
|
-
# See section below for a description of the arguments.
|
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"]`
|
427
|
-
args = {
|
428
|
-
'template_type' => 'sms',
|
429
|
-
'status' => 'failed',
|
430
|
-
'reference' => 'your reference string'
|
431
|
-
'older_than' => 'e194efd1-c34d-49c9-9915-e4267e01e92e' # => Notifications::Client::Notification
|
432
|
-
}
|
433
|
-
notifications = client.get_notifications(args)
|
434
|
-
```
|
435
|
-
|
436
|
-
</details>
|
437
|
-
|
438
|
-
|
439
|
-
#### Response
|
440
|
-
|
441
|
-
If the request is successful a `Notifications::Client::NotificationsCollection` is returned.
|
442
|
-
|
443
|
-
<details>
|
444
|
-
<summary>
|
445
|
-
Click here to expand for more information.
|
446
|
-
</summary>
|
447
|
-
|
448
|
-
```ruby
|
449
|
-
notifications.links # => Hash containing current => "/notifications?template_type=sms&status=delivered"
|
450
|
-
# next => "/notifications?older_than=last_id_in_list&template_type=sms&status=delivered"
|
451
|
-
notifications.collection # => [] (array of notification objects)
|
452
|
-
```
|
453
|
-
|
454
|
-
Otherwise the client will raise a `Notifications::Client::RequestError`:
|
455
|
-
|
456
|
-
|`error.status_code`|`error.message`|
|
457
|
-
|:---|:---|
|
458
|
-
|`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "bad status is not one of [created, sending, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure]"`<br>`}]`|
|
459
|
-
|`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "Apple is not one of [sms, email, letter]"`<br>`}]`|
|
460
|
-
|
461
|
-
</details>
|
462
|
-
|
463
|
-
#### Arguments
|
464
|
-
|
465
|
-
Omit the argument Hash if you do not want to filter the results.
|
466
|
-
|
467
|
-
<details>
|
468
|
-
<summary>
|
469
|
-
Click here to expand for more information.
|
470
|
-
</summary>
|
471
|
-
|
472
|
-
##### `template_type`
|
473
|
-
|
474
|
-
If omitted all messages are returned. Otherwise you can filter by:
|
475
|
-
|
476
|
-
* `email`
|
477
|
-
* `sms`
|
478
|
-
* `letter`
|
479
|
-
|
480
|
-
You can omit this argument to ignore the filter.
|
481
|
-
|
482
|
-
##### `status`
|
483
|
-
|
484
|
-
You can filter by:
|
485
|
-
|
486
|
-
* `sending` - the message is queued to be sent by the provider.
|
487
|
-
* `delivered` - the message was successfully delivered.
|
488
|
-
* `failed` - this will return all failure statuses `permanent-failure`, `temporary-failure` and `technical-failure`.
|
489
|
-
* `permanent-failure` - the provider was unable to deliver message, email or phone number does not exist; remove this recipient from your list.
|
490
|
-
* `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.
|
491
|
-
* `technical-failure` - Notify had a technical failure; you can try to send the message again.
|
492
|
-
|
493
|
-
You can omit this argument to ignore the filter.
|
494
|
-
|
495
|
-
##### `reference`
|
496
|
-
|
497
|
-
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.
|
498
|
-
|
499
|
-
You can omit this argument to ignore the filter.
|
500
|
-
|
501
|
-
|
502
|
-
##### `older_than`
|
503
|
-
You can get the notifications older than a given `Notification.id`.
|
504
|
-
You can omit this argument to ignore this filter.
|
505
|
-
|
506
|
-
</details>
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
## Get a template by ID
|
511
|
-
|
512
|
-
#### Method
|
513
|
-
|
514
|
-
This will return the latest version of the template. Use [getTemplateVersion](#get-a-template-by-id-and-version) to retrieve a specific template version.
|
515
|
-
|
516
|
-
<details>
|
517
|
-
<summary>
|
518
|
-
Click here to expand for more information.
|
519
|
-
</summary>
|
520
|
-
|
521
|
-
```ruby
|
522
|
-
template = client.get_template_by_id(id)
|
523
|
-
```
|
524
|
-
|
525
|
-
</details>
|
526
|
-
|
527
|
-
|
528
|
-
#### Response
|
529
|
-
|
530
|
-
<details>
|
531
|
-
<summary>
|
532
|
-
Click here to expand for more information.
|
533
|
-
</summary>
|
534
|
-
|
535
|
-
```Ruby
|
536
|
-
template.id # => uuid for the template
|
537
|
-
template.type # => type of template one of email|sms|letter
|
538
|
-
template.created_at # => date and time the template was created
|
539
|
-
template.updated_at # => date and time the template was last updated, may be null if version 1
|
540
|
-
template.created_by # => email address of the person that created the template
|
541
|
-
template.version # => version of the template
|
542
|
-
template.body # => content of the template
|
543
|
-
template.subject # => subject for email templates, will be empty for other template types
|
544
|
-
```
|
545
|
-
|
546
|
-
Otherwise the client will raise a `Notifications::Client::RequestError`.
|
547
|
-
|
548
|
-
</details>
|
549
|
-
|
550
|
-
|
551
|
-
#### Arguments
|
552
|
-
|
553
|
-
<details>
|
554
|
-
<summary>
|
555
|
-
Click here to expand for more information.
|
556
|
-
</summary>
|
557
|
-
|
558
|
-
|`error.code`|`error.message`|
|
559
|
-
|:---|:---|
|
560
|
-
|`404`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No result found"`<br>`}]`|
|
561
|
-
|`404`|`[{`<br>`"error": "ValidationError",`<br>`"message": "is is not a valid UUID"`<br>`}]`|
|
562
|
-
|
563
|
-
##### `id`
|
564
|
-
The template id is visible on the template page in the application.
|
565
|
-
|
566
|
-
</details>
|
567
|
-
|
568
|
-
|
569
|
-
## Get a template by ID and version
|
570
|
-
|
571
|
-
#### Method
|
572
|
-
|
573
|
-
This will return the template for the given id and version.
|
574
|
-
<details>
|
575
|
-
<summary>
|
576
|
-
Click here to expand for more information.
|
577
|
-
</summary>
|
578
|
-
|
579
|
-
```ruby
|
580
|
-
Template template = client.get_template_version(id, version)
|
581
|
-
```
|
582
|
-
|
583
|
-
</details>
|
584
|
-
|
585
|
-
|
586
|
-
#### Response
|
587
|
-
|
588
|
-
<details>
|
589
|
-
<summary>
|
590
|
-
Click here to expand for more information.
|
591
|
-
</summary>
|
592
|
-
|
593
|
-
|
594
|
-
```Ruby
|
595
|
-
template.id # => uuid for the template
|
596
|
-
template.type # => type of template one of email|sms|letter
|
597
|
-
template.created_at # => date and time the template was created
|
598
|
-
template.updated_at # => date and time the template was last updated, may be null if version 1
|
599
|
-
template.created_by # => email address of the person that created the template
|
600
|
-
template.version # => version of the template
|
601
|
-
template.body # => content of the template
|
602
|
-
template.subject # => subject for email templates, will be empty for other template types
|
603
|
-
```
|
604
|
-
|
605
|
-
Otherwise the client will raise a `Notifications::Client::RequestError`.
|
606
|
-
|
607
|
-
|`error.code`|`error.message`|
|
608
|
-
|:---|:---|
|
609
|
-
|`404`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No result found"`<br>`}]`|
|
610
|
-
|`404`|`[{`<br>`"error": "ValidationError",`<br>`"message": "is is not a valid UUID"`<br>`}]`|
|
611
|
-
|
612
|
-
</details>
|
613
|
-
|
614
|
-
|
615
|
-
#### Arguments
|
616
|
-
|
617
|
-
<details>
|
618
|
-
<summary>
|
619
|
-
Click here to expand for more information.
|
620
|
-
</summary>
|
621
|
-
|
622
|
-
#### `id`
|
623
|
-
The template id is visible on the template page in the application.
|
624
|
-
|
625
|
-
#### `version`
|
626
|
-
A history of the template is kept. There is a link to `See previous versions` on the template page in the application.
|
627
|
-
|
628
|
-
</details>
|
629
|
-
|
630
|
-
|
631
|
-
## Get all templates
|
632
|
-
|
633
|
-
#### Method
|
634
|
-
|
635
|
-
This will return the latest version of each template for your service.
|
636
|
-
|
637
|
-
<details>
|
638
|
-
<summary>
|
639
|
-
Click here to expand for more information.
|
640
|
-
</summary>
|
641
|
-
|
642
|
-
```ruby
|
643
|
-
args = {
|
644
|
-
'template_type' => 'sms'
|
645
|
-
}
|
646
|
-
templates = client.get_all_templates(args)
|
647
|
-
```
|
648
|
-
|
649
|
-
|
650
|
-
</details>
|
651
|
-
|
652
|
-
|
653
|
-
#### Response
|
654
|
-
|
655
|
-
<details>
|
656
|
-
<summary>
|
657
|
-
Click here to expand for more information.
|
658
|
-
</summary>
|
659
|
-
|
660
|
-
```ruby
|
661
|
-
TemplateCollection templates;
|
662
|
-
```
|
663
|
-
If the response is successful, a TemplateCollection is returned.
|
664
|
-
|
665
|
-
If no templates exist for a template type or there no templates for a service, the templates list will be empty.
|
666
|
-
|
667
|
-
Otherwise the client will raise a `Notifications::Client::RequestError`.
|
668
|
-
|
669
|
-
</details>
|
670
|
-
|
671
|
-
|
672
|
-
#### Arguments
|
673
|
-
|
674
|
-
<details>
|
675
|
-
<summary>
|
676
|
-
Click here to expand for more information.
|
677
|
-
</summary>
|
678
|
-
|
679
|
-
##### `template_type`
|
680
|
-
If omitted all templates are returned. Otherwise you can filter by:
|
681
|
-
|
682
|
-
* `email`
|
683
|
-
* `sms`
|
684
|
-
* `letter`
|
685
|
-
|
686
|
-
</details>
|
687
|
-
|
688
|
-
|
689
|
-
## Generate a preview template
|
690
|
-
|
691
|
-
#### Method
|
692
|
-
|
693
|
-
This will return the contents of a template with the placeholders replaced with the given personalisation.
|
694
|
-
|
695
|
-
<details>
|
696
|
-
<summary>
|
697
|
-
Click here to expand for more information.
|
698
|
-
</summary>
|
699
|
-
|
700
|
-
|
701
|
-
```ruby
|
702
|
-
templatePreview = client.generate_template_preview(id,
|
703
|
-
personalisation: {
|
704
|
-
name: "name",
|
705
|
-
year: "2016",
|
706
|
-
})
|
707
|
-
```
|
708
|
-
|
709
|
-
</details>
|
710
|
-
|
711
|
-
|
712
|
-
#### Response
|
713
|
-
|
714
|
-
<details>
|
715
|
-
<summary>
|
716
|
-
Click here to expand for more information.
|
717
|
-
</summary>
|
718
|
-
|
719
|
-
```Ruby
|
720
|
-
template.id # => uuid for the template
|
721
|
-
template.version # => version of the template
|
722
|
-
template.body # => content of the template
|
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)
|
725
|
-
```
|
726
|
-
Otherwise a `Notifications::Client::RequestError` is thrown.
|
727
|
-
|
728
|
-
|`error.code`|`error.message`|
|
729
|
-
|:---|:---|
|
730
|
-
|`404`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No result found"`<br>`}]`|
|
731
|
-
|`404`|`[{`<br>`"error": "ValidationError",`<br>`"message": "is is not a valid UUID"`<br>`}]`|
|
732
|
-
|
733
|
-
</details>
|
734
|
-
|
735
|
-
|
736
|
-
#### Arguments
|
737
|
-
|
738
|
-
<details>
|
739
|
-
<summary>
|
740
|
-
Click here to expand for more information.
|
741
|
-
</summary>
|
742
|
-
|
743
|
-
##### `id`
|
744
|
-
The template id is visible on the template page in the application.
|
745
|
-
|
746
|
-
##### `personalisation`
|
747
|
-
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.
|
748
|
-
|
749
|
-
</details>
|
750
|
-
|
751
|
-
## Get received texts
|
752
|
-
#### Method
|
753
|
-
|
754
|
-
<details>
|
755
|
-
<summary>
|
756
|
-
Click here to expand for more information.
|
757
|
-
</summary>
|
758
|
-
|
759
|
-
```ruby
|
760
|
-
# See section below for a description of the arguments.
|
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"]`
|
763
|
-
args = {
|
764
|
-
'older_than' => 'e194efd1-c34d-49c9-9915-e4267e01e92e' # => Notifications::Client::ReceivedText
|
765
|
-
}
|
766
|
-
received_texts = client.get_received_texts(args)
|
767
|
-
```
|
768
|
-
|
769
|
-
</details>
|
770
|
-
|
771
|
-
|
772
|
-
#### Response
|
773
|
-
|
774
|
-
If the request is successful a `Notifications::Client::ReceivedTextCollection` is returned.
|
775
|
-
|
776
|
-
<details>
|
777
|
-
<summary>
|
778
|
-
Click here to expand for more information.
|
779
|
-
</summary>
|
780
|
-
|
781
|
-
`ReceivedTextCollection` -
|
782
|
-
|
783
|
-
```ruby
|
784
|
-
received_texts.links # => Hash containing current => "/v2/received-text-messages"
|
785
|
-
# next => "/v2/received-text-messages?older_than=last_id_in_list"
|
786
|
-
received_texts.collection # => [] (array of ReceivedText objects)
|
787
|
-
```
|
788
|
-
|
789
|
-
`ReceivedText` -
|
790
|
-
|
791
|
-
```ruby
|
792
|
-
received_text.id # => uuid for the received text
|
793
|
-
received_text.created_at # => created_at of the received text
|
794
|
-
received_text.content # => content of the received text
|
795
|
-
received_text.notify_number # => number received text was sent to
|
796
|
-
received_text.service_id # => service id of the received text
|
797
|
-
received_text.user_number # => number received text was sent from
|
798
|
-
|
799
|
-
```
|
800
|
-
|
801
|
-
</details>
|
802
|
-
|
803
|
-
#### Arguments
|
804
|
-
|
805
|
-
Omit the argument Hash if you do not want to filter the results.
|
806
|
-
|
807
|
-
<details>
|
808
|
-
<summary>
|
809
|
-
Click here to expand for more information.
|
810
|
-
</summary>
|
811
|
-
|
812
|
-
##### `older_than`
|
813
|
-
You can get the notifications older than a given `received_text.id`.
|
814
|
-
You can omit this argument to ignore this filter.
|
815
|
-
|
816
|
-
</details>
|
7
|
+
- [Documentation](https://docs.notifications.service.gov.uk/ruby.html)
|
8
|
+
- [Ruby gem](https://rubygems.org/gems/notifications-ruby-client)
|
9
|
+
- [Changelog](https://github.com/alphagov/notifications-ruby-client/blob/master/CHANGELOG.md)
|
10
|
+
- [Contributing to this client](https://github.com/alphagov/notifications-ruby-client/blob/master/CONTRIBUTING.md)
|