notifications-ruby-client 2.9.0 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ee6c91540f71825cf6b96f6eb7e170383c2841bdc499bf45b625c2b0d48525c
4
- data.tar.gz: eec0b7042a42330d7ab776eb39815928359a07ac732504738a64db5f2f06bf54
3
+ metadata.gz: 323f2b6f8d75d806a1a9cc63d33f21432791cb3bb806db047376071f819eacc7
4
+ data.tar.gz: 1bd9804348d562a43370f56b1dc00461b99dc5abe21fa5a73c74c8f8fe5cd684
5
5
  SHA512:
6
- metadata.gz: e310f4d25c85ac58d741076fd586b0b6720e49f916ad500d47dbc781dc0e5023375231f1b8ff121523b0a154b34bf00ef1f8a27b3e62347c8b0fb6402889f04e
7
- data.tar.gz: 97c23e6f67ccee843ae3534bd209e7a295322c87c43381109291bd8b78dc1b7dbe4f9b86d465ecfd1b51fc05be49c3af93c64acca9b786b6a2f6d80c4088df2d
6
+ metadata.gz: e6640fb0a6781b566e55951f7d1a8cddf2b9d950780467404a57895f94e8d6c504e4b8883d6e424d9b7a85269a22caf535f05281c605f32cd4aa2ab490a1845b
7
+ data.tar.gz: f0c5ee819a5d1868a4055d19a1af026e2338a7b2bb1ca19478814d5bf18be2b09f8943cd0b02b839a3ee85f070a7e07afd3a2ba0dbc2e3ce3398d74157d3bdca
@@ -1,3 +1,7 @@
1
+ ## 2.10.0
2
+
3
+ * Added subclasses of the `RequestError` class to handle specific types of errors.
4
+
1
5
  ## 2.9.0
2
6
 
3
7
  * Added the `send_precompiled_letter` method which allows the client to send letters as PDF files.
@@ -73,7 +73,7 @@ You can leave out this argument if a template does not have any placeholder fiel
73
73
 
74
74
  #### reference (optional)
75
75
 
76
- A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. For example:
76
+ A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:
77
77
 
78
78
  ```ruby
79
79
  reference: "your_reference_string"
@@ -126,15 +126,15 @@ All messages sent using the [team and whitelist](#team-and-whitelist) or [live](
126
126
 
127
127
  If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code.
128
128
 
129
- |error.code|error.message|How to fix|
130
- |:---|:---|:---|
131
- |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Can't send to this recipient using a team-only API key"`<br>`]}`|Use the correct type of [API key](/ruby.html#api-keys)|
132
- |`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>`}]`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
133
- |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|Check your system clock|
134
- |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
135
- |`429`|`[{`<br>`"error": "RateLimitError",`<br>`"message": "Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds"`<br>`}]`|Refer to [API rate limits](/ruby.html#api-rate-limits) for more information|
136
- |`429`|`[{`<br>`"error": "TooManyRequestsError",`<br>`"message": "Exceeded send limits (LIMIT NUMBER) for today"`<br>`}]`|Refer to [service limits](/ruby.html#service-limits) for the limit number|
137
- |`500`|`[{`<br>`"error": "Exception",`<br>`"message": "Internal server error"`<br>`}]`|Notify was unable to process the request, resend your notification|
129
+ |error.code|error.message|class|How to fix|
130
+ |:---|:---|:---|:---|
131
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Can't send to this recipient using a team-only API key"`<br>`]}`|`BadRequestError`|Use the correct type of [API key](/ruby.html#api-keys)|
132
+ |`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>`}]`|`BadRequestError`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
133
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|`AuthError`|Check your system clock|
134
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
135
+ |`429`|`[{`<br>`"error": "RateLimitError",`<br>`"message": "Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds"`<br>`}]`|`RateLimitError`|Refer to [API rate limits](/ruby.html#api-rate-limits) for more information|
136
+ |`429`|`[{`<br>`"error": "TooManyRequestsError",`<br>`"message": "Exceeded send limits (LIMIT NUMBER) for today"`<br>`}]`|`ClientError`|Refer to [service limits](/ruby.html#service-limits) for the limit number|
137
+ |`500`|`[{`<br>`"error": "Exception",`<br>`"message": "Internal server error"`<br>`}]`|`ServerError`|Notify was unable to process the request, resend your notification|
138
138
 
139
139
  ## Send an email
140
140
 
@@ -180,7 +180,7 @@ You can leave out this argument if a template does not have any placeholder fiel
180
180
 
181
181
  #### reference (optional)
182
182
 
183
- A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. For example:
183
+ A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:
184
184
 
185
185
  ```ruby
186
186
  reference: "your_reference_string"
@@ -207,16 +207,19 @@ email_reply_to_id: '8e222534-7f05-4972-86e3-17c5d9f894e2'
207
207
 
208
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.
209
209
 
210
- ### Send a document by email
210
+ ## Send a document by email
211
+
211
212
  Send files without the need for email attachments.
212
213
 
213
- To send a document by email, add a placeholder field to the template then upload a file. The placeholder field will contain a secure link to download the document.
214
+ 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
215
 
215
- [Contact the GOV.UK Notify team](https://www.notifications.service.gov.uk/support) to enable this function for your service.
216
+ To send a document by email, add a placeholder field to the template then upload a file. The placeholder field will contain a secure link to download the document.
216
217
 
217
218
  #### Add a placeholder field to the template
218
219
 
219
- In Notify, use double brackets to add a placeholder field to the email template. For example:
220
+ 1. Sign in to [GOV.UK Notify](https://www.notifications.service.gov.uk/).
221
+ 1. Go to the __Templates__ page and select the relevant email template.
222
+ 1. Add a placeholder field to the email template using double brackets. For example:
220
223
 
221
224
  "Download your document at: ((link_to_document))"
222
225
 
@@ -224,7 +227,10 @@ In Notify, use double brackets to add a placeholder field to the email template.
224
227
 
225
228
  The document you upload must be a PDF file smaller than 2MB.
226
229
 
227
- Pass the file object as an argument to the `Notifications.prepare_upload` helper method. Then pass the result into the personalisation argument. For example:
230
+ 1. Pass the file object as an argument to the `Notifications.prepare_upload` helper method.
231
+ 1. Pass the result into the personalisation argument.
232
+
233
+ For example:
228
234
 
229
235
  ```ruby
230
236
  File.open("file.pdf", "rb") do |f|
@@ -255,18 +261,19 @@ You can then call different methods on this object to return the requested infor
255
261
 
256
262
  If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code.
257
263
 
258
- |error.code|error.message|How to fix|
259
- |:--- |:---|:---|
260
- |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Can't send to this recipient using a team-only API key"`<br>`]}`|Use the correct type of [API key](/ruby.html#api-keys)|
261
- |`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>`}]`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
262
- |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Unsupported document type '{}'. Supported types are: {}"`<br>`}]`|The document you upload must be a PDF file|
263
- |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Document didn't pass the virus scan"`<br>`}]`|The document you upload must be virus free|
264
- |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|Check your system clock|
265
- |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
266
- |`429`|`[{`<br>`"error": "RateLimitError",`<br>`"message": "Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds"`<br>`}]`|Refer to [API rate limits](/ruby.html#api-rate-limits) for more information|
267
- |`429`|`[{`<br>`"error": "TooManyRequestsError",`<br>`"message": "Exceeded send limits (LIMIT NUMBER) for today"`<br>`}]`|Refer to [service limits](/ruby.html#service-limits) for the limit number|
268
- |`500`|`[{`<br>`"error": "Exception",`<br>`"message": "Internal server error"`<br>`}]`|Notify was unable to process the request, resend your notification|
269
- |-|`[{`<br>`"error": "ArgumentError",`<br>`"message": "Document is larger than 2MB")`<br>`}]`|Document size was too large, upload a smaller document|
264
+ |error.code|error.message|class|How to fix|
265
+ |:--- |:---|:---|:---|
266
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Can't send to this recipient using a team-only API key"`<br>`]}`|`BadRequestError`|Use the correct type of [API key](/ruby.html#api-keys)|
267
+ |`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>`}]`|`BadRequestError`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
268
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Unsupported document type '{}'. Supported types are: {}"`<br>`}]`|`BadRequestError`|The document you upload must be a PDF file|
269
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Document didn't pass the virus scan"`<br>`}]`|`BadRequestError`|The document you upload must be virus free|
270
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Service is not allowed to send documents"`<br>`}]`|`BadRequestError`|Contact the GOV.UK Notify team|
271
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|`AuthError`|Check your system clock|
272
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
273
+ |`429`|`[{`<br>`"error": "RateLimitError",`<br>`"message": "Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds"`<br>`}]`|`RateLimitError`|Refer to [API rate limits](/ruby.html#api-rate-limits) for more information|
274
+ |`429`|`[{`<br>`"error": "TooManyRequestsError",`<br>`"message": "Exceeded send limits (LIMIT NUMBER) for today"`<br>`}]`|`RateLimitError`|Refer to [service limits](/ruby.html#service-limits) for the limit number|
275
+ |`500`|`[{`<br>`"error": "Exception",`<br>`"message": "Internal server error"`<br>`}]`|`ServerError`|Notify was unable to process the request, resend your notification|
276
+ |-|`[{`<br>`"error": "ArgumentError",`<br>`"message": "Document is larger than 2MB")`<br>`}]`|-|Document size was too large, upload a smaller document|
270
277
 
271
278
  ## Send a letter
272
279
 
@@ -335,7 +342,7 @@ personalisation: {
335
342
 
336
343
  #### reference (optional)
337
344
 
338
- A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. For example:
345
+ A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:
339
346
 
340
347
  ```ruby
341
348
  reference: 'your_reference_string'
@@ -360,18 +367,18 @@ You can then call different methods on this object to return the requested infor
360
367
 
361
368
  If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code.
362
369
 
363
- |error.code|error.message|How to fix|
364
- |:--- |:---|:---|
365
- |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Cannot send letters with a team api key"`<br>`]}`|Use the correct type of [API key](/ruby.html#api-keys)|
366
- |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Cannot send letters when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode"`<br>`}]`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
367
- |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "personalisation address_line_1 is a required property"`<br>`}]`|Ensure that your template has a field for the first line of the address, refer to [personalisation](/ruby.html#personalisation-required) for more information|
368
- |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|Check your system clock|
369
- |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
370
- |`429`|`[{`<br>`"error": "RateLimitError",`<br>`"message": "Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds"`<br>`}]`|Refer to [API rate limits](/ruby.html#api-rate-limits) for more information|
371
- |`429`|`[{`<br>`"error": "TooManyRequestsError",`<br>`"message": "Exceeded send limits (LIMIT NUMBER) for today"`<br>`}]`|Refer to [service limits](/ruby.html#service-limits) for the limit number|
372
- |`500`|`[{`<br>`"error": "Exception",`<br>`"message": "Internal server error"`<br>`}]`|Notify was unable to process the request, resend your notification|
373
-
374
- ## Send a pre-compiled letter
370
+ |error.code|error.message|class|How to fix|
371
+ |:--- |:---|:---|:---|
372
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Cannot send letters with a team api key"`<br>`]}`|`BadRequestError`|Use the correct type of [API key](/ruby.html#api-keys)|
373
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Cannot send letters when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode"`<br>`}]`|`BadRequestError`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
374
+ |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "personalisation address_line_1 is a required property"`<br>`}]`|`BadRequestError`|Ensure that your template has a field for the first line of the address, refer to [personalisation](/ruby.html#personalisation-required) for more information|
375
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|`AuthError`|Check your system clock|
376
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
377
+ |`429`|`[{`<br>`"error": "RateLimitError",`<br>`"message": "Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds"`<br>`}]`|`RateLimitError`|Refer to [API rate limits](/ruby.html#api-rate-limits) for more information|
378
+ |`429`|`[{`<br>`"error": "TooManyRequestsError",`<br>`"message": "Exceeded send limits (LIMIT NUMBER) for today"`<br>`}]`|`RateLimitError`|Refer to [service limits](/ruby.html#service-limits) for the limit number|
379
+ |`500`|`[{`<br>`"error": "Exception",`<br>`"message": "Internal server error"`<br>`}]`|`ServerError`|Notify was unable to process the request, resend your notification|
380
+
381
+ ## Send a precompiled letter
375
382
  This is an invitation-only feature. 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/govuk-notify) for more information.
376
383
 
377
384
  ### Method
@@ -385,7 +392,8 @@ precompiled_letter = client.send_precompiled_letter(reference, pdf_file)
385
392
  A unique identifier you create. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address.
386
393
 
387
394
  #### pdf_file (required)
388
- The pre-compiled letter must be a PDF file.
395
+
396
+ The precompiled letter must be a PDF file.
389
397
 
390
398
  ```ruby
391
399
  File.open("path/to/pdf_file", "rb") do |pdf_file|
@@ -411,21 +419,22 @@ You can then call different methods on this object to return the requested infor
411
419
 
412
420
  If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code.
413
421
 
414
- |error.status_code|error.message|How to fix|
415
- |:---|:---|:---|
416
- |`429`|`[{`<br>`"error": "RateLimitError",`<br>`"message": "Exceeded rate limit for key type live of 10 requests per 20 seconds"`<br>`}]`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
417
- |`429`|`[{`<br>`"error": "TooManyRequestsError",`<br>`"message": "Exceeded send limits (50) for today"`<br>`}]`|Refer to [service limits](#service-limits) for the limit number|
418
- |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Cannot send letters with a team api key"`<br>`]}`|Use the correct type of [API key](#api-keys)|
419
- |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Cannot send precompiled letters"`<br>`]}`|This is an invitation-only feature. 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/govuk-notify) for more information|
420
- |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Letter content is not a valid PDF"`<br>`]}`|PDF file format is required|
421
- |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Cannot send letters when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode"`<br>`}]`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
422
- |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "reference is a required property"`<br>`}]`|Add a `reference` argument to the method call|
422
+ |error.status_code|error.message|class|How to fix|
423
+ |:---|:---|:---|:---|
424
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Cannot send letters with a team api key"`<br>`]}`|`BadRequestError`|Use the correct type of [API key](#api-keys)|
425
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Cannot send precompiled letters"`<br>`]}`|`BadRequestError`|This is an invitation-only feature. 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/govuk-notify) for more information|
426
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Letter content is not a valid PDF"`<br>`]}`|`BadRequestError`|PDF file format is required|
427
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Cannot send letters when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode"`<br>`}]`|`BadRequestError`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
428
+ |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "reference is a required property"`<br>`}]`|`BadRequestError`|Add a `reference` argument to the method call|
429
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Service is not allowed to send precompiled letters"`<br>`}]`|`BadRequestError`|Contact the GOV.UK Notify team|
430
+ |`429`|`[{`<br>`"error": "RateLimitError",`<br>`"message": "Exceeded rate limit for key type live of 10 requests per 20 seconds"`<br>`}]`|`RateLimitError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
431
+ |`429`|`[{`<br>`"error": "TooManyRequestsError",`<br>`"message": "Exceeded send limits (50) for today"`<br>`}]`|`RateLimitError`|Refer to [service limits](#service-limits) for the limit number|
423
432
 
424
433
  # Get message status
425
434
 
426
- Message status depends on the type of message that you have sent.
435
+ Message status depends on the type of message you have sent.
427
436
 
428
- You can only get the status of messages that are 7 days old or less.
437
+ You can only get the status of messages that are 7 days old or newer.
429
438
 
430
439
  ## Status - text and email
431
440
 
@@ -451,9 +460,16 @@ You can only get the status of messages that are 7 days old or less.
451
460
  |Accepted|GOV.UK Notify is printing and posting the letter.|
452
461
  |Received|The provider has received the letter to deliver.|
453
462
 
463
+ ## Status - precompiled letter
464
+
465
+ |Status|information|
466
+ |:---|:---|
467
+ |Pending virus check|GOV.UK Notify virus scan of the precompiled letter file is not yet complete.|
468
+ |Virus scan failed|GOV.UK Notify virus scan has identified a potential virus in the precompiled letter file.|
469
+
454
470
  ## Get the status of one message
455
471
 
456
- You can only get the status of messages that are 7 days old or less.
472
+ You can only get the status of messages that are 7 days old or newer.
457
473
 
458
474
  ### Method
459
475
 
@@ -507,18 +523,18 @@ You can then call different methods on this object to return the requested infor
507
523
 
508
524
  If the request is not successful, the client returns a `Notification::Client::RequestError` and an error code:
509
525
 
510
- |error.code|error.message|How to fix|
511
- |:---|:---|:---|
512
- |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "id is not a valid UUID"`<br>`}]`|Check the notification ID|
513
- |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|Check your system clock|
514
- |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
515
- |`404`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No result found"`<br>`}]`|Check the notification ID. This error occurs if the notification is more than 7 days old.|
526
+ |error.code|error.message|class|How to fix|
527
+ |:---|:---|:---|:---|
528
+ |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "id is not a valid UUID"`<br>`}]`|`BadRequestError`|Check the notification ID|
529
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|`AuthError`|Check your system clock|
530
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
531
+ |`404`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No result found"`<br>`}]`|`NotFoundError`|Check the notification ID. This error occurs if the notification is more than 7 days old.|
516
532
 
517
533
  ## Get the status of multiple messages
518
534
 
519
535
  This API call returns one page of up to 250 messages and statuses. You can get either the most recent messages, or get older messages by specifying a particular notification ID in the `older_than` argument.
520
536
 
521
- You can only get messages that are 7 days old or less.
537
+ You can only get messages that are 7 days old or newer.
522
538
 
523
539
  ### Method
524
540
 
@@ -566,7 +582,7 @@ You can filter by:
566
582
 
567
583
  #### reference (optional)
568
584
 
569
- A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. For example:
585
+ A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:
570
586
 
571
587
  ```ruby
572
588
  reference: 'your_reference_string'
@@ -582,7 +598,7 @@ older_than: 'e194efd1-c34d-49c9-9915-e4267e01e92e'
582
598
 
583
599
  If you leave out this argument, the client returns the most recent 250 notifications.
584
600
 
585
- The client only returns notifications that are 7 days old or less. If the notification specified in this argument is older than 7 days, the client returns an empty response.
601
+ The client only returns notifications that are 7 days old or newer. If the notification specified in this argument is older than 7 days, the client returns an empty response.
586
602
 
587
603
  ### Response
588
604
 
@@ -626,12 +642,12 @@ If the notification specified in the `older_than` argument is older than 7 days,
626
642
 
627
643
  If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code.
628
644
 
629
- |error.code|error.message|How to fix|
630
- |:---|:---|:---|
631
- |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "bad status is not one of [created, sending, sent, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure, accepted, received]"`<br>`}]`|Contact the Notify team|
632
- |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "Template type is not one of [sms, email, letter]"`<br>`}]`|Contact the Notify team|
633
- |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|Check your system clock|
634
- |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
645
+ |error.code|error.message|class|How to fix|
646
+ |:---|:---|:---|:---|
647
+ |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "bad status is not one of [created, sending, sent, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure, accepted, received]"`<br>`}]`|`BadRequestError`|Contact the GOV.UK Notify team|
648
+ |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "Template type is not one of [sms, email, letter]"`<br>`}]`|`BadRequestError`|Contact the GOV.UK Notify team|
649
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|`AuthError`|Check your system clock|
650
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
635
651
 
636
652
  # Get a template
637
653
 
@@ -677,19 +693,17 @@ You can then call different methods on this object to return the requested infor
677
693
 
678
694
  If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code:
679
695
 
680
- |error.code|error.message|How to fix|
696
+ |error.code|error.message|class|How to fix|
681
697
  |:---|:---|:---|
682
- |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "id is not a valid UUID"`<br>`}]`|Check the notification ID|
683
- |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|Check your system clock|
684
- |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
685
- |`404`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No Result Found"`<br>`}]`|Check your [template ID](/ruby.html#get-a-template-by-id-arguments-id-required)|
698
+ |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "id is not a valid UUID"`<br>`}]`|`BadRequestError`|Check the notification ID|
699
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|`AuthError`|Check your system clock|
700
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
701
+ |`404`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No Result Found"`<br>`}]`|`NotFoundError`|Check your [template ID](/ruby.html#get-a-template-by-id-arguments-id-required)|
686
702
 
687
703
  ## Get a template by ID and version
688
704
 
689
705
  ### Method
690
706
 
691
- This returns the latest version of the template.
692
-
693
707
  ```ruby
694
708
  response = client.get_template_version(id, version)
695
709
  ```
@@ -730,12 +744,12 @@ You can then call different methods on this object to return the requested infor
730
744
 
731
745
  If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code:
732
746
 
733
- |error.code|error.message|How to fix|
747
+ |error.code|error.message|class|How to fix|
734
748
  |:---|:---|:---|
735
- |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "id is not a valid UUID"`<br>`}]`|Check the notification ID|
736
- |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|Check your system clock|
737
- |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
738
- |`404`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No Result Found"`<br>`}]`|Check your [template ID](/ruby.html#get-a-template-by-id-and-version-arguments-id-required) and [version](/ruby.html#version-required)|
749
+ |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "id is not a valid UUID"`<br>`}]`|`BadRequestError`|Check the notification ID|
750
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|`AuthError`|Check your system clock|
751
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
752
+ |`404`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No Result Found"`<br>`}]`|`NotFoundError`|Check your [template ID](/ruby.html#get-a-template-by-id-and-version-arguments-id-required) and [version](/ruby.html#version-required)|
739
753
 
740
754
  ## Get all templates
741
755
 
@@ -786,9 +800,9 @@ If no templates exist for a template type or there no templates for a service, t
786
800
 
787
801
  If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code:
788
802
 
789
- |error.code|error.message|How to fix|
803
+ |error.code|error.message|class|How to fix|
790
804
  |:---|:---|:---|
791
- |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "Template type is not one of [sms, email, letter]"`<br>`}]`|Contact the Notify team|
805
+ |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "Template type is not one of [sms, email, letter]"`<br>`}]`|`BadRequestError`|Contact the Notify team|
792
806
 
793
807
  ## Generate a preview template
794
808
 
@@ -843,18 +857,18 @@ You can then call different methods on this object to return the requested infor
843
857
 
844
858
  If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code:
845
859
 
846
- |error.code|error.message|How to fix|
860
+ |error.code|error.message|class|How to fix|
847
861
  |:---|:---|:---|
848
- |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Missing personalisation: [PERSONALISATION FIELD]"`<br>`}]`|Check that the personalisation arguments in the method match the placeholder fields in the template|
849
- |`400`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No result found"`<br>`}]`|Check the [template ID](/ruby.html#generate-a-preview-template-arguments-id-required)|
850
- |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|Check your system clock|
851
- |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
862
+ |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Missing personalisation: [PERSONALISATION FIELD]"`<br>`}]`|`BadRequestError`|Check that the personalisation arguments in the method match the placeholder fields in the template|
863
+ |`400`|`[{`<br>`"error": "NoResultFound",`<br>`"message": "No result found"`<br>`}]`|`BadRequestError`|Check the [template ID](/ruby.html#generate-a-preview-template-arguments-id-required)|
864
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|`AuthError`|Check your system clock|
865
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
852
866
 
853
867
  # Get received text messages
854
868
 
855
869
  This API call returns one page of up to 250 received text messages. You can get either the most recent messages, or get older messages by specifying a particular notification ID in the `older_than` argument.
856
870
 
857
- You can only get the status of messages that are 7 days old or less.
871
+ You can only get the status of messages that are 7 days old or newer.
858
872
 
859
873
  ### Method
860
874
 
@@ -881,7 +895,7 @@ older_than: '8e222534-7f05-4972-86e3-17c5d9f894e2'
881
895
 
882
896
  If you leave out the `older_than` argument, the client returns the most recent 250 notifications.
883
897
 
884
- The client only returns notifications that are 7 days old or less. If the notification specified in this argument is older than 7 days, the client returns an empty `collection` response.
898
+ The client only returns notifications that are 7 days old or newer. If the notification specified in this argument is older than 7 days, the client returns an empty `collection` response.
885
899
 
886
900
  ### Response
887
901
 
@@ -906,3 +920,12 @@ If you call the `collection` method on this object to return an array, you must
906
920
  |`response.user_number`|Number that received text was sent from|String|
907
921
 
908
922
  If the notification specified in the `older_than` argument is older than 7 days, the client returns an empty `collection` response.
923
+
924
+ ### Error codes
925
+
926
+ If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code.
927
+
928
+ |error.code|error.message|class|How to fix|
929
+ |:---|:---|:---|
930
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|`AuthError`|Check your system clock|
931
+ |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Invalid token: signature, api token not found"`<br>`}]`|`AuthError`|Use the correct API key. Refer to [API keys](/ruby.html#api-keys) for more information|
@@ -18,5 +18,38 @@ module Notifications
18
18
  body
19
19
  end
20
20
  end
21
+
22
+ class ClientError < RequestError; end
23
+ class BadRequestError < ClientError; end
24
+ class AuthError < ClientError; end
25
+ class NotFoundError < ClientError; end
26
+ class RateLimitError < ClientError; end
27
+
28
+ class ServerError < RequestError; end
29
+
30
+ module ErrorHandling
31
+ def build_error(response)
32
+ error_class_for_code(response.code.to_i).new(response)
33
+ end
34
+
35
+ def error_class_for_code(code)
36
+ case code
37
+ when 400
38
+ BadRequestError
39
+ when 403
40
+ AuthError
41
+ when 404
42
+ NotFoundError
43
+ when 429
44
+ RateLimitError
45
+ when (400..499)
46
+ ClientError
47
+ when (500..599)
48
+ ServerError
49
+ else
50
+ RequestError
51
+ end
52
+ end
53
+ end
21
54
  end
22
55
  end
@@ -7,6 +7,8 @@ require_relative "request_error"
7
7
  module Notifications
8
8
  class Client
9
9
  class Speaker
10
+ include ErrorHandling
11
+
10
12
  attr_reader :base_url
11
13
  attr_reader :service_id
12
14
  attr_reader :secret_token
@@ -121,7 +123,7 @@ module Notifications
121
123
  def perform_request!(request)
122
124
  response = open(request)
123
125
  if response.is_a?(Net::HTTPClientError) || response.is_a?(Net::HTTPServerError)
124
- raise RequestError.new(response)
126
+ raise build_error(response)
125
127
  else
126
128
  JSON.parse(response.body)
127
129
  end
@@ -9,6 +9,6 @@
9
9
 
10
10
  module Notifications
11
11
  class Client
12
- VERSION = "2.9.0".freeze
12
+ VERSION = "2.10.0".freeze
13
13
  end
14
14
  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.9.0
4
+ version: 2.10.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: 2018-09-12 00:00:00.000000000 Z
11
+ date: 2019-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt