notifications-ruby-client 4.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/DOCUMENTATION.md +91 -57
- data/Dockerfile +13 -0
- data/bin/test_client.rb +23 -0
- data/docker/Dockerfile +1 -2
- data/lib/notifications/client.rb +8 -0
- data/lib/notifications/client/speaker.rb +13 -0
- data/lib/notifications/client/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8273dcafdfbd624d66c297df116923b57e7dbc336403f982c605a97842b4753
|
4
|
+
data.tar.gz: eedca7b3d118bea2476cedebb32c6c802ffb8322612ec1c97eb0bbb0bbe21408
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cc4249443eb6e24751de8b9c7ac410afabd6b1235ae9cbde437984734602ba3b5466de56afa02143278d5fcef2425f5b7243792bf5bce9a5a0a917e7bd51fbf
|
7
|
+
data.tar.gz: 910a3f1e534c95a7d1fc547bcd4752eb439b73d54208819f735bdf540b48473e7455e20cbd3ee281429df063ddd049c99300f3ac800fa141010d7cf0830bf5ae
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## 5.1.0
|
2
|
+
|
3
|
+
* Added new `get_pdf_for_letter` method
|
4
|
+
* accepts a notification id argument
|
5
|
+
* returns a string containing the final printable PDF for a precompiled or templated letter
|
6
|
+
|
7
|
+
## 5.0.0
|
8
|
+
|
9
|
+
* Dropped support for Ruby 2.3. Official support for this version ended in March (https://www.ruby-lang.org/en/news/2019/03/31/support-of-ruby-2-3-has-ended/)
|
10
|
+
|
1
11
|
## 4.0.0
|
2
12
|
|
3
13
|
* `RequestError.message` now returns a string, not an array of hashes – see https://github.com/alphagov/notifications-ruby-client/pull/72
|
data/DOCUMENTATION.md
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
This documentation is for developers interested in using the GOV.UK Notify Ruby client to send emails, text messages or letters.
|
4
4
|
|
5
|
-
We recommend that you use this client library rather than use the [GOV.UK Notify API](https://github.com/alphagov/notifications-api) directly, as there is no documentation for using the API in this way.
|
6
|
-
|
7
5
|
# Set up the client
|
8
6
|
|
9
7
|
## Install the client
|
@@ -25,7 +23,7 @@ require 'notifications/client'
|
|
25
23
|
client = Notifications::Client.new(api_key)
|
26
24
|
```
|
27
25
|
|
28
|
-
To get an API key, [sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/) and go to the __API integration__ page. You can find more information in the [API keys](
|
26
|
+
To get an API key, [sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/) and go to the __API integration__ page. You can find more information in the [API keys](#api-keys) section of this documentation.
|
29
27
|
|
30
28
|
# Send a message
|
31
29
|
|
@@ -67,7 +65,7 @@ If a template has placeholder fields for personalised information such as name o
|
|
67
65
|
```ruby
|
68
66
|
personalisation: {
|
69
67
|
name: "John Smith",
|
70
|
-
ID: "300241",
|
68
|
+
ID: "300241",
|
71
69
|
}
|
72
70
|
```
|
73
71
|
|
@@ -108,7 +106,7 @@ You can leave out this argument if your service only has one text message sender
|
|
108
106
|
|
109
107
|
### Response
|
110
108
|
|
111
|
-
If the request to the client is successful, the client returns a `Notifications::Client:ResponseNotification` object. In the example shown in the [Method section](
|
109
|
+
If the request to the client is successful, the client returns a `Notifications::Client:ResponseNotification` object. In the example shown in the [Method section](#method), the object is named `smsresponse`.
|
112
110
|
|
113
111
|
You can then call different methods on this object:
|
114
112
|
|
@@ -120,7 +118,7 @@ You can then call different methods on this object:
|
|
120
118
|
|`smsresponse.template`|Contains the `id`, `version` and `uri` of the template|Hash|
|
121
119
|
|`smsresponse.uri`|Notification URL|String|
|
122
120
|
|
123
|
-
If you are using the [test API key](
|
121
|
+
If you are using the [test API key](#test), all your messages come back with a `delivered` status.
|
124
122
|
|
125
123
|
All messages sent using the [team and whitelist](#team-and-whitelist) or [live](#live) keys appear on your GOV.UK Notify dashboard.
|
126
124
|
|
@@ -130,12 +128,12 @@ If the request is not successful, the client returns a `Notifications::Client::R
|
|
130
128
|
|
131
129
|
|error.code|error.message|class|How to fix|
|
132
130
|
|:---|:---|:---|:---|
|
133
|
-
|`400`|`BadRequestError: Can't send to this recipient using a team-only API key`|`BadRequestError`|Use the correct type of [API key](
|
131
|
+
|`400`|`BadRequestError: Can't send to this recipient using a team-only API key`|`BadRequestError`|Use the correct type of [API key](#api-keys)|
|
134
132
|
|`400`|`BadRequestError: Can't send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode`|`BadRequestError`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
|
135
133
|
|`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
|
136
|
-
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](
|
137
|
-
|`429`|`RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds`|`RateLimitError`|Refer to [API rate limits](
|
138
|
-
|`429`|`TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today`|`ClientError`|Refer to [service limits](
|
134
|
+
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
|
135
|
+
|`429`|`RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds`|`RateLimitError`|Refer to [API rate limits](#api-rate-limits) for more information|
|
136
|
+
|`429`|`TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today`|`ClientError`|Refer to [service limits](#service-limits) for the limit number|
|
139
137
|
|`500`|`Exception: Internal server error`|`ServerError`|Notify was unable to process the request, resend your notification|
|
140
138
|
|
141
139
|
## Send an email
|
@@ -174,7 +172,7 @@ If a template has placeholder fields for personalised information such as name o
|
|
174
172
|
```ruby
|
175
173
|
personalisation: {
|
176
174
|
name: "John Smith",
|
177
|
-
year: "2016"
|
175
|
+
year: "2016"
|
178
176
|
}
|
179
177
|
```
|
180
178
|
|
@@ -209,13 +207,15 @@ email_reply_to_id: '8e222534-7f05-4972-86e3-17c5d9f894e2'
|
|
209
207
|
|
210
208
|
You can leave out this argument if your service only has one email reply-to address, or you want to use the default email address.
|
211
209
|
|
212
|
-
## Send a
|
210
|
+
## Send a file by email
|
213
211
|
|
214
212
|
Send files without the need for email attachments.
|
215
213
|
|
216
|
-
This is an invitation-only feature. [Contact the GOV.UK Notify team](https://www.notifications.service.gov.uk/support) to enable this function for your service.
|
214
|
+
This is an invitation-only feature. [Contact the GOV.UK Notify team](https://www.notifications.service.gov.uk/support/ask-question-give-feedback) to enable this function for your service.
|
215
|
+
|
216
|
+
To send a file by email, add a placeholder field to the template then upload a file. The placeholder field will contain a secure link to download the file.
|
217
217
|
|
218
|
-
|
218
|
+
The links are unique and unguessable. GOV.UK Notify cannot access or decrypt your file.
|
219
219
|
|
220
220
|
### Add a placeholder field to the template
|
221
221
|
|
@@ -223,11 +223,11 @@ To send a document by email, add a placeholder field to the template then upload
|
|
223
223
|
1. Go to the __Templates__ page and select the relevant email template.
|
224
224
|
1. Add a placeholder field to the email template using double brackets. For example:
|
225
225
|
|
226
|
-
"Download your
|
226
|
+
"Download your file at: ((link_to_document))"
|
227
227
|
|
228
|
-
### Upload your
|
228
|
+
### Upload your file
|
229
229
|
|
230
|
-
The
|
230
|
+
The file you upload must be a PDF file smaller than 2MB.
|
231
231
|
|
232
232
|
1. Pass the file object as an argument to the `Notifications.prepare_upload` helper method.
|
233
233
|
1. Pass the result into the personalisation argument.
|
@@ -247,7 +247,7 @@ end
|
|
247
247
|
|
248
248
|
### Response
|
249
249
|
|
250
|
-
If the request to the client is successful, the client returns a `Notifications::Client:ResponseNotification` object. In the example shown in the [Method section](
|
250
|
+
If the request to the client is successful, the client returns a `Notifications::Client:ResponseNotification` object. In the example shown in the [Method section](#send-an-email-method), the object is named `emailresponse`.
|
251
251
|
|
252
252
|
You can then call different methods on this object to return the requested information.
|
253
253
|
|
@@ -265,15 +265,15 @@ If the request is not successful, the client returns a `Notifications::Client::R
|
|
265
265
|
|
266
266
|
|error.code|error.message|class|How to fix|
|
267
267
|
|:--- |:---|:---|:---|
|
268
|
-
|`400`|`BadRequestError: Can't send to this recipient using a team-only API key`|`BadRequestError`|Use the correct type of [API key](
|
268
|
+
|`400`|`BadRequestError: Can't send to this recipient using a team-only API key`|`BadRequestError`|Use the correct type of [API key](#api-keys)|
|
269
269
|
|`400`|`BadRequestError: Can't send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode`|`BadRequestError`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
|
270
270
|
|`400`|`BadRequestError: Unsupported document type '{}'. Supported types are: {}`|`BadRequestError`|The document you upload must be a PDF file|
|
271
271
|
|`400`|`BadRequestError: Document didn't pass the virus scan`|`BadRequestError`|The document you upload must be virus free|
|
272
272
|
|`400`|`BadRequestError: Service is not allowed to send documents`|`BadRequestError`|Contact the GOV.UK Notify team|
|
273
273
|
|`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
|
274
|
-
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](
|
275
|
-
|`429`|`RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds`|`RateLimitError`|Refer to [API rate limits](
|
276
|
-
|`429`|`TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today`|`RateLimitError`|Refer to [service limits](
|
274
|
+
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
|
275
|
+
|`429`|`RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds`|`RateLimitError`|Refer to [API rate limits](#api-rate-limits) for more information|
|
276
|
+
|`429`|`TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today`|`RateLimitError`|Refer to [service limits](#service-limits) for the limit number|
|
277
277
|
|`500`|`Exception: Internal server error`|`ServerError`|Notify was unable to process the request, resend your notification|
|
278
278
|
|-|`ArgumentError: Document is larger than 2MB")`|-|Document size was too large, upload a smaller document|
|
279
279
|
|
@@ -291,7 +291,7 @@ When your service first signs up to GOV.UK Notify, you’ll start in trial mode.
|
|
291
291
|
letterresponse = client.send_letter(
|
292
292
|
template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a",
|
293
293
|
personalisation: {
|
294
|
-
address_line_1: 'The Occupier',
|
294
|
+
address_line_1: 'The Occupier',
|
295
295
|
address_line_2: '123 High Street',
|
296
296
|
postcode: 'SW14 6BH',
|
297
297
|
},
|
@@ -352,7 +352,7 @@ reference: 'your_reference_string'
|
|
352
352
|
|
353
353
|
### Response
|
354
354
|
|
355
|
-
If the request to the client is successful, the client returns a `Notifications::Client:ResponseNotification` object. In the example shown in the [Method section](
|
355
|
+
If the request to the client is successful, the client returns a `Notifications::Client:ResponseNotification` object. In the example shown in the [Method section](#send-a-letter-method), the object is named `letterresponse`.
|
356
356
|
|
357
357
|
You can then call different methods on this object to return the requested information.
|
358
358
|
|
@@ -371,13 +371,13 @@ If the request is not successful, the client returns a `Notifications::Client::R
|
|
371
371
|
|
372
372
|
|error.code|error.message|class|How to fix|
|
373
373
|
|:--- |:---|:---|:---|
|
374
|
-
|`400`|`BadRequestError: Cannot send letters with a team api key`|`BadRequestError`|Use the correct type of [API key](
|
374
|
+
|`400`|`BadRequestError: Cannot send letters with a team api key`|`BadRequestError`|Use the correct type of [API key](#api-keys)|
|
375
375
|
|`400`|`BadRequestError: Cannot send letters when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode`|`BadRequestError`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
|
376
|
-
|`400`|`ValidationError: personalisation address_line_1 is a required property`|`BadRequestError`|Ensure that your template has a field for the first line of the address, refer to [personalisation](
|
376
|
+
|`400`|`ValidationError: personalisation address_line_1 is a required property`|`BadRequestError`|Ensure that your template has a field for the first line of the address, refer to [personalisation](#personalisation-required) for more information|
|
377
377
|
|`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
|
378
|
-
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](
|
379
|
-
|`429`|`RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds`|`RateLimitError`|Refer to [API rate limits](
|
380
|
-
|`429`|`TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today`|`RateLimitError`|Refer to [service limits](
|
378
|
+
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
|
379
|
+
|`429`|`RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds`|`RateLimitError`|Refer to [API rate limits](#api-rate-limits) for more information|
|
380
|
+
|`429`|`TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today`|`RateLimitError`|Refer to [service limits](#service-limits) for the limit number|
|
381
381
|
|`500`|`Exception: Internal server error`|`ServerError`|Notify was unable to process the request, resend your notification|
|
382
382
|
|
383
383
|
## Send a precompiled letter
|
@@ -394,7 +394,7 @@ A unique identifier you create. This reference identifies a single unique notifi
|
|
394
394
|
|
395
395
|
#### pdf_file (required)
|
396
396
|
|
397
|
-
The precompiled letter must be a PDF file which meets [the GOV.UK Notify PDF letter specification](https://docs.notifications.service.gov.uk/documentation/images/notify-pdf-letter-spec-v2.
|
397
|
+
The precompiled letter must be a PDF file which meets [the GOV.UK Notify PDF letter specification](https://docs.notifications.service.gov.uk/documentation/images/notify-pdf-letter-spec-v2.4.pdf).
|
398
398
|
|
399
399
|
```ruby
|
400
400
|
File.open("path/to/pdf_file", "rb") do |pdf_file|
|
@@ -409,7 +409,7 @@ You can choose first or second class postage for your precompiled letter. Set th
|
|
409
409
|
|
410
410
|
### Response
|
411
411
|
|
412
|
-
If the request to the client is successful, the client returns a `Notifications::Client:ResponsePrecompiledLetter` object. In the example shown in the [Method section](
|
412
|
+
If the request to the client is successful, the client returns a `Notifications::Client:ResponsePrecompiledLetter` object. In the example shown in the [Method section](#send-a-pre-compiled-letter-method), the object is named `precompiled_letter`.
|
413
413
|
|
414
414
|
You can then call different methods on this object to return the requested information.
|
415
415
|
|
@@ -486,18 +486,13 @@ response = client.get_notification(id)
|
|
486
486
|
|
487
487
|
#### id (required)
|
488
488
|
|
489
|
-
The ID of the notification. You can find the notification ID in the response to the [original notification method call](
|
490
|
-
|
491
|
-
You can also find it in your [GOV.UK Notify Dashboard](https://www.notifications.service.gov.uk).
|
489
|
+
The ID of the notification. You can find the notification ID in the response to the [original notification method call](#response).
|
492
490
|
|
493
|
-
|
494
|
-
1. Select either __emails sent__, __text messages sent__, or __letters sent__.
|
495
|
-
1. Select the relevant notification.
|
496
|
-
1. Copy the notification ID from the end of the page URL, for example `https://www.notifications.service.gov.uk/services/af90d4cb-ae88-4a7c-a197-5c30c7db423b/notification/ID`.
|
491
|
+
You can also find it by signing in to [GOV.UK Notify](https://www.notifications.service.gov.uk) and going to the __API integration__ page.
|
497
492
|
|
498
493
|
### Response
|
499
494
|
|
500
|
-
If the request to the client is successful, the client returns a `Notifications::Client::Notification` object. In the example shown in the [Method section](
|
495
|
+
If the request to the client is successful, the client returns a `Notifications::Client::Notification` object. In the example shown in the [Method section](#get-the-status-of-one-message-method), the object is named `response`.
|
501
496
|
|
502
497
|
You can then call different methods on this object to return the requested information.
|
503
498
|
|
@@ -533,7 +528,7 @@ If the request is not successful, the client returns a `Notification::Client::Re
|
|
533
528
|
|:---|:---|:---|:---|
|
534
529
|
|`400`|`ValidationError: id is not a valid UUID`|`BadRequestError`|Check the notification ID|
|
535
530
|
|`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
|
536
|
-
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](
|
531
|
+
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
|
537
532
|
|`404`|`NoResultFound: No result found`|`NotFoundError`|Check the notification ID. This error occurs if the notification is more than 7 days old.|
|
538
533
|
|
539
534
|
## Get the status of multiple messages
|
@@ -611,7 +606,7 @@ The client only returns notifications that are 7 days old or newer. If the notif
|
|
611
606
|
|
612
607
|
### Response
|
613
608
|
|
614
|
-
If the request to the client is successful, the client returns a `Notifications::Client::NotificationsCollection` object. In the example shown in the [Method section](
|
609
|
+
If the request to the client is successful, the client returns a `Notifications::Client::NotificationsCollection` object. In the example shown in the [Method section](#get-the-status-of-multiple-messages-method), the object is named `response`.
|
615
610
|
|
616
611
|
You must then call either the `.links` method or the `.collection` method on this object.
|
617
612
|
|
@@ -656,7 +651,46 @@ If the request is not successful, the client returns a `Notifications::Client::R
|
|
656
651
|
|`400`|`ValidationError: bad status is not one of [created, sending, sent, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure, accepted, received]`|`BadRequestError`|Contact the GOV.UK Notify team|
|
657
652
|
|`400`|`ValidationError: Template type is not one of [sms, email, letter]`|`BadRequestError`|Contact the GOV.UK Notify team|
|
658
653
|
|`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
|
659
|
-
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](
|
654
|
+
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
|
655
|
+
|
656
|
+
## Get a PDF for a letter notification
|
657
|
+
|
658
|
+
### Method
|
659
|
+
|
660
|
+
This returns the pdf contents of a letter notification.
|
661
|
+
|
662
|
+
```ruby
|
663
|
+
pdf_file = client.get_pdf_for_letter(
|
664
|
+
'f33517ff-2a88-4f6e-b855-c550268ce08a' # notification id (required)
|
665
|
+
)
|
666
|
+
```
|
667
|
+
|
668
|
+
### Arguments
|
669
|
+
|
670
|
+
#### id (required)
|
671
|
+
|
672
|
+
The ID of the notification. You can find the notification ID in the response to the [original notification method call](#get-the-status-of-one-message-response).
|
673
|
+
|
674
|
+
You can also find it by signing in to [GOV.UK Notify](https://www.notifications.service.gov.uk) and going to the __API integration__ page.
|
675
|
+
|
676
|
+
### Response
|
677
|
+
|
678
|
+
If the request to the client is successful, the client will return a `string` containing the raw PDF data.
|
679
|
+
|
680
|
+
### Error codes
|
681
|
+
|
682
|
+
If the request is not successful, the client throws a `Notifications::Client::RequestError` and an error code.
|
683
|
+
|error.code|error.message|class|How to fix|
|
684
|
+
|:---|:---|:---|:---|
|
685
|
+
|`400`|`ValidationError: id is not a valid UUID`|`BadRequestError`|Check the notification ID|
|
686
|
+
|`400`|`PDFNotReadyError: PDF not available yet, try again later`|`BadRequestError`|Wait for the notification to finish processing. This usually takes a few seconds|
|
687
|
+
|`400`|`BadRequestError: Document did not pass the virus scan`|`BadRequestError`|You cannot retrieve the contents of a letter notification that contains a virus|
|
688
|
+
|`400`|`BadRequestError: PDF not available for letters in technical-failure`|`BadRequestError`|You cannot retrieve the contents of a letter notification in technical-failure|
|
689
|
+
|`400`|`ValidationError: Notification is not a letter`|`BadRequestError`|Check that you are looking up the correct notification|
|
690
|
+
|`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`BadRequestError`|Check your system clock|
|
691
|
+
|`403`|`AuthError: Invalid token: signature, api token not found`|`BadRequestError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
|
692
|
+
|`404`|`NoResultFound: No result found`|`BadRequestError`|Check the notification ID|
|
693
|
+
|
660
694
|
|
661
695
|
# Get a template
|
662
696
|
|
@@ -682,7 +716,7 @@ The ID of the template. Sign into GOV.UK Notify and go to the __Templates__ page
|
|
682
716
|
|
683
717
|
### Response
|
684
718
|
|
685
|
-
If the request to the client is successful, the client returns a `Notifications::Client::Template` object. In the example shown in the [Method section](
|
719
|
+
If the request to the client is successful, the client returns a `Notifications::Client::Template` object. In the example shown in the [Method section](#get-a-template-by-id-method), the object is named `response`.
|
686
720
|
|
687
721
|
You can then call different methods on this object to return the requested information.
|
688
722
|
|
@@ -706,8 +740,8 @@ If the request is not successful, the client returns a `Notifications::Client::R
|
|
706
740
|
|:---|:---|:---|:---|
|
707
741
|
|`400`|`ValidationError: id is not a valid UUID`|`BadRequestError`|Check the notification ID|
|
708
742
|
|`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
|
709
|
-
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](
|
710
|
-
|`404`|`NoResultFound: No Result Found`|`NotFoundError`|Check your [template ID](
|
743
|
+
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
|
744
|
+
|`404`|`NoResultFound: No Result Found`|`NotFoundError`|Check your [template ID](#get-a-template-by-id-arguments-id-required)|
|
711
745
|
|
712
746
|
## Get a template by ID and version
|
713
747
|
|
@@ -733,7 +767,7 @@ The version number of the template.
|
|
733
767
|
|
734
768
|
### Response
|
735
769
|
|
736
|
-
If the request to the client is successful, the client returns a `Notifications::Client::Template` object. In the example shown in the [Method section](
|
770
|
+
If the request to the client is successful, the client returns a `Notifications::Client::Template` object. In the example shown in the [Method section](#get-a-template-by-id-and-version-method), the object is named `response`.
|
737
771
|
|
738
772
|
You can then call different methods on this object to return the requested information.
|
739
773
|
|
@@ -757,8 +791,8 @@ If the request is not successful, the client returns a `Notifications::Client::R
|
|
757
791
|
|:---|:---|:---|:---|
|
758
792
|
|`400`|`ValidationError: id is not a valid UUID`|`BadRequestError`|Check the notification ID|
|
759
793
|
|`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
|
760
|
-
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](
|
761
|
-
|`404`|`NoResultFound: No Result Found`|`NotFoundError`|Check your [template ID](
|
794
|
+
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
|
795
|
+
|`404`|`NoResultFound: No Result Found`|`NotFoundError`|Check your [template ID](#get-a-template-by-id-and-version-arguments-id-required) and [version](#version-required)|
|
762
796
|
|
763
797
|
## Get all templates
|
764
798
|
|
@@ -785,7 +819,7 @@ If you do not use `type`, the client returns all templates. Otherwise you can fi
|
|
785
819
|
|
786
820
|
### Response
|
787
821
|
|
788
|
-
If the request to the client is successful, the client returns a `Notifications::Client::TemplateCollection` object. In the example shown in the [Method section](
|
822
|
+
If the request to the client is successful, the client returns a `Notifications::Client::TemplateCollection` object. In the example shown in the [Method section](#get-all-templates-method), the object is named `response`.
|
789
823
|
|
790
824
|
You must then call the `.collection` method on this object to return an array of the required templates.
|
791
825
|
|
@@ -842,7 +876,7 @@ If a template has placeholder fields for personalised information such as name o
|
|
842
876
|
```ruby
|
843
877
|
personalisation: {
|
844
878
|
name: "John Smith",
|
845
|
-
ID: "300241",
|
879
|
+
ID: "300241",
|
846
880
|
}
|
847
881
|
```
|
848
882
|
|
@@ -850,7 +884,7 @@ You can leave out this argument if a template does not have any placeholder fiel
|
|
850
884
|
|
851
885
|
### Response
|
852
886
|
|
853
|
-
If the request to the client is successful, the client returns a `Notifications::Client::TemplatePreview` object. In the example shown in the [Method section](
|
887
|
+
If the request to the client is successful, the client returns a `Notifications::Client::TemplatePreview` object. In the example shown in the [Method section](#generate-a-preview-template-method), the object is named `response`.
|
854
888
|
|
855
889
|
You can then call different methods on this object to return the requested information.
|
856
890
|
|
@@ -870,9 +904,9 @@ If the request is not successful, the client returns a `Notifications::Client::R
|
|
870
904
|
|error.code|error.message|class|How to fix|
|
871
905
|
|:---|:---|:---|:---|
|
872
906
|
|`400`|`BadRequestError: Missing personalisation: [PERSONALISATION FIELD]`|`BadRequestError`|Check that the personalisation arguments in the method match the placeholder fields in the template|
|
873
|
-
|`400`|`NoResultFound: No result found`|`BadRequestError`|Check the [template ID](
|
907
|
+
|`400`|`NoResultFound: No result found`|`BadRequestError`|Check the [template ID](#generate-a-preview-template-arguments-id-required)|
|
874
908
|
|`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
|
875
|
-
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](
|
909
|
+
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
|
876
910
|
|
877
911
|
# Get received text messages
|
878
912
|
|
@@ -880,11 +914,11 @@ This API call returns one page of up to 250 received text messages. You can get
|
|
880
914
|
|
881
915
|
You can only get the status of messages that are 7 days old or newer.
|
882
916
|
|
883
|
-
You can also set up [callbacks](
|
917
|
+
You can also set up [callbacks](#callbacks) for received text messages.
|
884
918
|
|
885
919
|
## Enable received text messages
|
886
920
|
|
887
|
-
Contact the GOV.UK Notify team on the [support page](https://www.notifications.service.gov.uk/support) or through the [Slack channel](https://ukgovernmentdigital.slack.com/messages/
|
921
|
+
Contact the GOV.UK Notify team on the [support page](https://www.notifications.service.gov.uk/support) or through the [Slack channel](https://ukgovernmentdigital.slack.com/messages/C0E1ADVPC) to enable receiving text messages for your service.
|
888
922
|
|
889
923
|
## Get a page of received text messages
|
890
924
|
|
@@ -917,7 +951,7 @@ The client only returns notifications that are 7 days old or newer. If the notif
|
|
917
951
|
|
918
952
|
### Response
|
919
953
|
|
920
|
-
If the request to the client is successful, the client returns a `Notifications::Client::ReceivedTextCollection` object. In the example shown in the [Method section](
|
954
|
+
If the request to the client is successful, the client returns a `Notifications::Client::ReceivedTextCollection` object. In the example shown in the [Method section](#get-received-text-messages-method), the object is named `response`.
|
921
955
|
|
922
956
|
You must then call either the `.links` method or the `.collection` method on this object.
|
923
957
|
|
@@ -946,4 +980,4 @@ If the request is not successful, the client returns a `Notifications::Client::R
|
|
946
980
|
|error.code|error.message|class|How to fix|
|
947
981
|
|:---|:---|:---|:---|
|
948
982
|
|`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
|
949
|
-
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](
|
983
|
+
|`403`|`AuthError: Invalid token: signature, api token not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
|
data/Dockerfile
ADDED
data/bin/test_client.rb
CHANGED
@@ -20,6 +20,7 @@ def main
|
|
20
20
|
test_get_notification_by_id_endpoint(client, precompiled_letter_notification.id, 'precompiled_letter')
|
21
21
|
test_get_all_notifications(client)
|
22
22
|
test_get_received_texts
|
23
|
+
test_get_pdf_for_letter(client, letter_notification.id)
|
23
24
|
p 'ruby client integration tests pass'
|
24
25
|
exit 0
|
25
26
|
end
|
@@ -205,6 +206,28 @@ def test_get_notification_by_id_endpoint(client, id, message_type)
|
|
205
206
|
end
|
206
207
|
end
|
207
208
|
|
209
|
+
def test_get_pdf_for_letter(client, id)
|
210
|
+
response = nil
|
211
|
+
|
212
|
+
# try 15 times with 3 secs sleep between each attempt, to get the PDF
|
213
|
+
15.times do
|
214
|
+
begin
|
215
|
+
response = client.get_pdf_for_letter(id)
|
216
|
+
rescue Notifications::Client::BadRequestError
|
217
|
+
sleep(3)
|
218
|
+
end
|
219
|
+
|
220
|
+
if !response.nil?
|
221
|
+
break
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
unless !response.nil? && response.start_with?("%PDF-")
|
226
|
+
p "get_pdf_for_letter response for " + id + " is not a PDF: " + response.to_s
|
227
|
+
exit 1
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
208
231
|
def hash_key_should_not_be_nil(fields, obj, method_name)
|
209
232
|
fields.each do |field|
|
210
233
|
if obj.has_value?(:"#{field}")
|
data/docker/Dockerfile
CHANGED
data/lib/notifications/client.rb
CHANGED
@@ -67,6 +67,14 @@ module Notifications
|
|
67
67
|
)
|
68
68
|
end
|
69
69
|
|
70
|
+
##
|
71
|
+
# @param id [String]
|
72
|
+
# @see Notifications::Client::Speaker#get
|
73
|
+
# @return [String]
|
74
|
+
def get_pdf_for_letter(id)
|
75
|
+
speaker.get_pdf_for_letter(id)
|
76
|
+
end
|
77
|
+
|
70
78
|
##
|
71
79
|
# @param id [String]
|
72
80
|
# @see Notifications::Client::Speaker#get
|
@@ -118,6 +118,19 @@ module Notifications
|
|
118
118
|
perform_request!(request)
|
119
119
|
end
|
120
120
|
|
121
|
+
def get_pdf_for_letter(id)
|
122
|
+
path = "/v2/notifications/" << id << "/pdf"
|
123
|
+
request = Net::HTTP::Get.new(path, headers)
|
124
|
+
|
125
|
+
# can't use `perform_request!` because we're just returning raw binary data
|
126
|
+
response = open(request)
|
127
|
+
if response.is_a?(Net::HTTPClientError) || response.is_a?(Net::HTTPServerError)
|
128
|
+
raise build_error(response)
|
129
|
+
else
|
130
|
+
response.body
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
121
134
|
private
|
122
135
|
|
123
136
|
##
|
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:
|
4
|
+
version: 5.1.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: 2019-07
|
11
|
+
date: 2019-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- CHANGELOG.md
|
129
129
|
- CONTRIBUTING.md
|
130
130
|
- DOCUMENTATION.md
|
131
|
+
- Dockerfile
|
131
132
|
- Gemfile
|
132
133
|
- LICENSE
|
133
134
|
- Makefile
|
@@ -173,8 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
174
|
- !ruby/object:Gem::Version
|
174
175
|
version: '0'
|
175
176
|
requirements: []
|
176
|
-
|
177
|
-
rubygems_version: 2.7.6
|
177
|
+
rubygems_version: 3.0.3
|
178
178
|
signing_key:
|
179
179
|
specification_version: 4
|
180
180
|
summary: Ruby client for GOV.UK Notifications API
|