notifications-ruby-client 5.4.0 → 6.1.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: 6827c0db7ff51cabb102005e382e49fb225344a2856b11f85dc4edc799b9d9a9
4
- data.tar.gz: 222318524a806a4ce707cdc3fff989b6d91f28fffa106fe9235584d14b1cd2f1
3
+ metadata.gz: dcf0cee013cca39da0d0e3da3e7205ec6ab7d33dfea9c182b4aab80555b779a0
4
+ data.tar.gz: 1049787ca14191e6f944cc0029991f49b7d6af3525c998a8e7749b44d9c5f0ba
5
5
  SHA512:
6
- metadata.gz: ef8a9234c0e8a4730d9ce2561d35261882903090bbaeaaad29540b36a1622c77ff0953d395ed0976093e962cae92cd304f2ace1579ce41d5b3e70553528ee1d5
7
- data.tar.gz: 44f09776241452471cacea7cec73bfa4ab158ed24f5a4a631bcdf747923cd18f66f34b0e8742dcc036dd2f4dd646dbc3a095e24736cac10452d4dc555105b4f9
6
+ metadata.gz: a2098a9b4e86f186e46daa0e6f8ae20549aefbce3992c80724d15b1a7e58afa5ef0c73e4ef78f1a2840ac6dd5bde09d2e52cbfe5006492f5a595c57743028c9e
7
+ data.tar.gz: 9de9f0c4b8f41a3dc6b406da037f4b17a33bd3060c30eb991ea4c9013997af051117b6a924a2597d5aa6987b2e70a902c77d43c4f9ad13498a201395fef8ef5a
@@ -8,5 +8,7 @@
8
8
  <!--- All of the following are normally needed. Don’t worry if you haven’t done them or don’t know how – someone from the Notify team will be able to help. -->
9
9
  - [x] I’ve used the pull request template
10
10
  - [ ] I’ve written unit tests for these changes
11
- - [ ] I’ve updated the documentation (in `DOCUMENTATION.md`)
11
+ - [ ] I’ve updated the documentation in
12
+ - [ ] [notifications-tech-docs repository](https://github.com/alphagov/notifications-tech-docs/blob/main/source/documentation/client_docs/_ruby.md)
13
+ - [ ] `CHANGELOG.md`
12
14
  - [ ] I’ve bumped the version number (in `lib/notifications/client/version.rb`)
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 6.1.0
2
+
3
+ * Adds a `one_click_unsubscribe_url` parameter to `send_email` so services can allow users to easily unsubscribe from distribution lists.
4
+ * Adds a `one_click_unsubscribe_url` attribute to `Notification` class, so responses for get_notification include the unsubscribe link.
5
+
6
+ ## 6.0.0
7
+
8
+ * Removes the `is_csv` parameter from `prepare_upload`
9
+ * Adds a `filename` parameter to `prepare_upload` to set the filename of the document upon download. See the documentation for more information.
10
+
1
11
  ## 5.4.0
2
12
 
3
13
  * Add support for new security features when sending a file by email:
data/README.md CHANGED
@@ -6,5 +6,5 @@ Useful links:
6
6
 
7
7
  - [Documentation](https://docs.notifications.service.gov.uk/ruby.html)
8
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)
9
+ - [Changelog](https://github.com/alphagov/notifications-ruby-client/blob/main/CHANGELOG.md)
10
+ - [Contributing to this client](https://github.com/alphagov/notifications-ruby-client/blob/main/CONTRIBUTING.md)
data/bin/test_client.rb CHANGED
@@ -115,11 +115,14 @@ def test_template_preview(response)
115
115
  end
116
116
 
117
117
  def test_send_email_endpoint(client)
118
- email_resp = client.send_email(email_address: ENV['FUNCTIONAL_TEST_EMAIL'],
119
- template_id: ENV['EMAIL_TEMPLATE_ID'],
120
- personalisation: { "name" => "some name" },
121
- reference: "some reference",
122
- email_reply_to_id: ENV['EMAIL_REPLY_TO_ID'])
118
+ email_resp = client.send_email(
119
+ email_address: ENV['FUNCTIONAL_TEST_EMAIL'],
120
+ template_id: ENV['EMAIL_TEMPLATE_ID'],
121
+ personalisation: { "name" => "some name" },
122
+ reference: "some reference",
123
+ email_reply_to_id: ENV['EMAIL_REPLY_TO_ID'],
124
+ one_click_unsubscribe_url: "https://www.clovercouncil.gov.uk/unsubscribe?email_address=faye@example.com"
125
+ )
123
126
  test_notification_response_data_type(email_resp, 'email')
124
127
  email_resp
125
128
  end
@@ -130,7 +133,8 @@ def test_send_email_endpoint_with_document(client)
130
133
  template_id: ENV['EMAIL_TEMPLATE_ID'],
131
134
  personalisation: { name: Notifications.prepare_upload(f) },
132
135
  reference: "some reference",
133
- email_reply_to_id: ENV['EMAIL_REPLY_TO_ID'])
136
+ email_reply_to_id: ENV['EMAIL_REPLY_TO_ID'],
137
+ one_click_unsubscribe_url: "https://www.clovercouncil.gov.uk/unsubscribe?email_address=faye@example.com")
134
138
  end
135
139
 
136
140
  test_notification_response_data_type(email_resp, 'email')
@@ -319,7 +323,8 @@ end
319
323
  def expected_fields_in_email_content
320
324
  %w(from_email
321
325
  body
322
- subject)
326
+ subject
327
+ one_click_unsubscribe_url)
323
328
  end
324
329
 
325
330
  def expected_fields_in_sms_content
@@ -342,7 +347,8 @@ def expected_fields_in_email_notification
342
347
  template
343
348
  body
344
349
  subject
345
- created_at)
350
+ created_at
351
+ one_click_unsubscribe_url)
346
352
  end
347
353
 
348
354
  def expected_fields_in_email_notification_that_are_nil
@@ -381,7 +387,8 @@ def expected_fields_in_sms_notification_that_are_nil
381
387
  postcode
382
388
  subject
383
389
  created_by_name
384
- postage)
390
+ postage
391
+ one_click_unsubscribe_url)
385
392
  end
386
393
 
387
394
  def expected_fields_in_letter_notification
@@ -410,6 +417,7 @@ def expected_fields_in_letter_notification_that_are_nil
410
417
  line_5
411
418
  line_6
412
419
  created_by_name
420
+ one_click_unsubscribe_url
413
421
  )
414
422
  end
415
423
 
@@ -441,6 +449,7 @@ def expected_fields_in_precompiled_letter_notification_that_are_nil
441
449
  phone_number
442
450
  postcode
443
451
  sent_at
452
+ one_click_unsubscribe_url
444
453
  )
445
454
  end
446
455
 
@@ -1,11 +1,12 @@
1
1
  require "base64"
2
2
 
3
3
  module Notifications
4
- def self.prepare_upload(file, is_csv=false, confirm_email_before_download: nil, retention_period: nil)
4
+ def self.prepare_upload(file, filename: nil, confirm_email_before_download: nil, retention_period: nil)
5
5
  raise ArgumentError.new("File is larger than 2MB") if file.size > Client::MAX_FILE_UPLOAD_SIZE
6
6
 
7
- data = { file: Base64.strict_encode64(file.read), is_csv: is_csv }
7
+ data = { file: Base64.strict_encode64(file.read) }
8
8
 
9
+ data[:filename] = filename
9
10
  data[:confirm_email_before_download] = confirm_email_before_download
10
11
  data[:retention_period] = retention_period
11
12
 
@@ -25,6 +25,7 @@ module Notifications
25
25
  created_at
26
26
  completed_at
27
27
  created_by_name
28
+ one_click_unsubscribe_url
28
29
  ).freeze
29
30
 
30
31
  attr_reader(*FIELDS)
@@ -47,6 +47,8 @@ module Notifications
47
47
  # id of the email address that replies to email notifications will be sent to
48
48
  # @option form_data [String] :sms_sender_id
49
49
  # id of the sender to be used for an sms notification
50
+ # @option form_data [String] :one_click_unsubscribe_url
51
+ # link that end user can click to unsubscribe from the distribution list. We will pass this link in the email headers.
50
52
  # @see #perform_request!
51
53
  def post(kind, form_data)
52
54
  request = Net::HTTP::Post.new(
@@ -9,6 +9,6 @@
9
9
 
10
10
  module Notifications
11
11
  class Client
12
- VERSION = "5.4.0".freeze
12
+ VERSION = "6.1.0".freeze
13
13
  end
14
14
  end
@@ -26,5 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rake", "~> 13.0"
27
27
  spec.add_development_dependency "rspec", "~> 3.7"
28
28
  spec.add_development_dependency "webmock", "~> 3.4"
29
- spec.add_development_dependency "factory_bot", "~> 6.1"
29
+ spec.add_development_dependency "factory_bot", "~> 6.1", "<6.4.5"
30
30
  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: 5.4.0
4
+ version: 6.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: 2022-10-06 00:00:00.000000000 Z
11
+ date: 2024-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -93,6 +93,9 @@ dependencies:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
95
  version: '6.1'
96
+ - - "<"
97
+ - !ruby/object:Gem::Version
98
+ version: 6.4.5
96
99
  type: :development
97
100
  prerelease: false
98
101
  version_requirements: !ruby/object:Gem::Requirement
@@ -100,6 +103,9 @@ dependencies:
100
103
  - - "~>"
101
104
  - !ruby/object:Gem::Version
102
105
  version: '6.1'
106
+ - - "<"
107
+ - !ruby/object:Gem::Version
108
+ version: 6.4.5
103
109
  description:
104
110
  email:
105
111
  - notify@digital.cabinet-office.gov.uk
@@ -114,7 +120,6 @@ files:
114
120
  - ".rubocop.yml"
115
121
  - CHANGELOG.md
116
122
  - CONTRIBUTING.md
117
- - DOCUMENTATION.md
118
123
  - Dockerfile
119
124
  - Gemfile
120
125
  - LICENSE
data/DOCUMENTATION.md DELETED
@@ -1,1124 +0,0 @@
1
- # Ruby client documentation
2
-
3
- This documentation is for developers interested in using the GOV.UK Notify Ruby client to send emails, text messages or letters.
4
-
5
- ## Set up the client
6
-
7
- ### Install the client
8
-
9
- Run the following in the command line:
10
-
11
- ```
12
- gem install 'notifications-ruby-client'
13
- ```
14
-
15
- Refer to the [client changelog](https://github.com/alphagov/notifications-ruby-client/blob/master/CHANGELOG.md) for the version number and the latest updates.
16
-
17
- ### Create a new instance of the client
18
-
19
- Add this code to your application:
20
-
21
- ```ruby
22
- require 'notifications/client'
23
- client = Notifications::Client.new(api_key)
24
- ```
25
-
26
- To get an API key, [sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in) and go to the __API integration__ page. You can find more information in the [API keys](#api-keys) section of this documentation.
27
-
28
- ## Send a message
29
-
30
- You can use GOV.UK Notify to send text messages, emails or letters.
31
-
32
- ### Send a text message
33
-
34
- #### Method
35
-
36
- ```ruby
37
- smsresponse = client.send_sms(
38
- phone_number: "+447900900123",
39
- template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a",
40
- )
41
- ```
42
-
43
- #### Arguments
44
-
45
- ##### phone_number (required)
46
-
47
- The phone number of the text message recipient. This can be a UK or international number. For example:
48
-
49
- ```ruby
50
- phone_number:"+447900900123"
51
- ```
52
-
53
- ##### template_id (required)
54
-
55
- To find the template ID:
56
-
57
- 1. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in).
58
- 1. Go to the __Templates__ page and select the relevant template.
59
- 1. Select __Copy template ID to clipboard__.
60
-
61
- For example:
62
-
63
- ```ruby
64
- template_id:"f33517ff-2a88-4f6e-b855-c550268ce08a"
65
- ```
66
-
67
- ##### personalisation (optional)
68
-
69
- If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a hash. For example:
70
-
71
- ```ruby
72
- personalisation: {
73
- name: "John Smith",
74
- ID: "300241",
75
- }
76
- ```
77
-
78
- You can leave out this argument if a template does not have any placeholder fields for personalised information.
79
-
80
- ##### reference (optional)
81
-
82
- 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:
83
-
84
- ```ruby
85
- reference: "your_reference_string"
86
- ```
87
-
88
- You can leave out this argument if you do not have a reference.
89
-
90
- ##### sms_sender_id (optional)
91
-
92
- A unique identifier of the sender of the text message notification.
93
-
94
- To find the text message sender:
95
-
96
- 1. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in).
97
- 1. Go to the __Settings__ page.
98
- 1. In the __Text Messages__ section, select __Manage__ on the __Text Message sender__ row.
99
-
100
- You can then either:
101
-
102
- - copy the sender ID that you want to use and paste it into the method
103
- - select __Change__ to change the default sender that the service uses, and select __Save__
104
-
105
-
106
- For example:
107
-
108
- ```ruby
109
- sms_sender_id: "8e222534-7f05-4972-86e3-17c5d9f894e2"
110
- ```
111
-
112
- You can leave out this argument if your service only has one text message sender, or if you want to use the default sender.
113
-
114
- #### Response
115
-
116
- 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`.
117
-
118
- You can then call different methods on this object:
119
-
120
- |Method|Information|Type|
121
- |:---|:---|:---|
122
- |#`smsresponse.id`|Notification UUID|String|
123
- |#`smsresponse.reference`|`reference` argument|String|
124
- |#`smsresponse.content`|- `body`: Message body sent to the recipient<br>- `from_number`: SMS sender number of your service|Hash|
125
- |#`smsresponse.template`|Contains the `id`, `version` and `uri` of the template|Hash|
126
- |#`smsresponse.uri`|Notification URL|String|
127
-
128
- If you are using the [test API key](#test), all your messages come back with a `delivered` status.
129
-
130
- All messages sent using the [team and guest list](#team-and-guest-list) or [live](#live) keys appear on your GOV.UK Notify dashboard.
131
-
132
- #### Error codes
133
-
134
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
135
-
136
- |error.code|error.message|class|How to fix|
137
- |:---|:---|:---|:---|
138
- |`400`|`BadRequestError: Can't send to this recipient using a team-only API key`|`BadRequestError`|Use the correct type of [API key](#api-keys)|
139
- |`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)|
140
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
141
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
142
- |`429`|`RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds`|`RateLimitError`|Refer to [API rate limits](#rate-limits) for more information|
143
- |`429`|`TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today`|`ClientError`|Refer to [service limits](#daily-limits) for the limit number|
144
- |`500`|`Exception: Internal server error`|`ServerError`|Notify was unable to process the request, resend your notification|
145
-
146
- ### Send an email
147
-
148
- #### Method
149
-
150
- ```ruby
151
- emailresponse = client.send_email(
152
- email_address: "sender@something.com",
153
- template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a",
154
- )
155
- ```
156
-
157
- #### Arguments
158
-
159
- ##### email_address (required)
160
-
161
- The email address of the recipient. For example:
162
-
163
- ```ruby
164
- email_address: "sender@something.com"
165
- ```
166
-
167
- ##### template_id (required)
168
-
169
- To find the template ID:
170
-
171
- 1. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in).
172
- 1. Go to the __Templates__ page and select the relevant template.
173
- 1. Select __Copy template ID to clipboard__.
174
-
175
- For example:
176
-
177
- ```ruby
178
- template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a"
179
- ```
180
-
181
- ##### personalisation (optional)
182
-
183
- If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a hash. For example:
184
-
185
- ```ruby
186
- personalisation: {
187
- name: "John Smith",
188
- year: "2016"
189
- }
190
- ```
191
-
192
- You can leave out this argument if a template does not have any placeholder fields for personalised information.
193
-
194
- ##### reference (optional)
195
-
196
- 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:
197
-
198
- ```ruby
199
- reference: "your_reference_string"
200
- ```
201
-
202
- You can leave out this argument if you do not have a reference.
203
-
204
- ##### email_reply_to_id (optional)
205
-
206
- This is an email address specified by you to receive replies from your users. You must add at least one reply-to email address before your service can go live.
207
-
208
- To add a reply-to email address:
209
-
210
- 1. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in).
211
- 1. Go to the __Settings__ page.
212
- 1. In the __Email__ section, select __Manage__ on the __Reply-to email addresses__ row.
213
- 1. Select __Add reply-to address__.
214
- 1. Enter the email address you want to use, and select __Add__.
215
-
216
- For example:
217
-
218
- ```ruby
219
- email_reply_to_id: '8e222534-7f05-4972-86e3-17c5d9f894e2'
220
- ```
221
-
222
- 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.
223
-
224
- ### Send a file by email
225
-
226
- To send a file by email, add a placeholder to the template then upload a file. The placeholder will contain a secure link to download the file.
227
-
228
- The links are unique and unguessable. GOV.UK Notify cannot access or decrypt your file.
229
-
230
- Your file will be available to download for a default period of 78 weeks (18 months). From 29 March 2023 we will reduce this to 26 weeks (6 months) for all new files. Files sent before 29 March will not be affected.
231
-
232
- To help protect your files you can also:
233
-
234
- * ask recipients to confirm their email address before downloading
235
- * choose the length of time that a file is available to download
236
-
237
- To turn these features on or off, you will need version 5.4.0 of the Ruby client library or a more recent version.
238
-
239
- #### Add contact details to the file download page
240
-
241
- 1. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in).
242
- 1. Go to the __Settings__ page.
243
- 1. In the __Email__ section, select __Manage__ on the __Send files by email__ row.
244
- 1. Enter the contact details you want to use, and select __Save__.
245
-
246
- #### Add a placeholder to the template
247
-
248
- 1. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in).
249
- 1. Go to the __Templates__ page and select the relevant email template.
250
- 1. Select __Edit__.
251
- 1. Add a placeholder to the email template using double brackets. For example: "Download your file at: ((link_to_file))"
252
-
253
- Your email should also tell recipients how long the file will be available to download.
254
-
255
- #### Upload your file
256
-
257
- You can upload PDF, CSV, .odt, .txt, .rtf, .xlsx and MS Word Document files. Your file must be smaller than 2MB. [Contact the GOV.UK Notify team](https://www.notifications.service.gov.uk/support/ask-question-give-feedback) if you need to send other file types.
258
-
259
- 1. Pass the file object as an argument to the `Notifications.prepare_upload` helper method.
260
- 1. Pass the result into the personalisation argument.
261
-
262
- For example:
263
-
264
- ```ruby
265
- File.open("file.pdf", "rb") do |f|
266
- ...
267
- personalisation: {
268
- first_name: "Amala",
269
- application_date: "2018-01-01",
270
- link_to_file: Notifications.prepare_upload(f),
271
- }
272
- end
273
- ```
274
-
275
- ##### CSV Files
276
-
277
- Uploads for CSV files should use the `is_csv` parameter on the `prepare_upload()` helper method. For example:
278
-
279
- ```ruby
280
- File.open("file.csv", "rb") do |f|
281
- ...
282
- personalisation: {
283
- first_name: "Amala",
284
- application_date: "2018-01-01",
285
- link_to_file: Notifications.prepare_upload(f, is_csv=true),
286
- }
287
- end
288
- ```
289
-
290
- #### Ask recipients to confirm their email address before they can download the file
291
-
292
- This new security feature is optional. You should use it if you send files that are sensitive - for example, because they contain personal information about your users.
293
-
294
- When a recipient clicks the link in the email you’ve sent them, they have to enter their email address. Only someone who knows the recipient’s email address can download the file.
295
-
296
- From 29 March 2023, we will turn this feature on by default for every file you send. Files sent before 29 March will not be affected.
297
-
298
- ##### Turn on email address check
299
-
300
- To use this feature before 29 March 2023 you will need version 5.4.0 of the Ruby client library, or a more recent version.
301
-
302
- To make the recipient confirm their email address before downloading the file, set the `confirm_email_before_download` flag to `true`.
303
-
304
- You will not need to do this after 29 March.
305
-
306
- ```ruby
307
- File.open("file.pdf", "rb") do |f|
308
- ...
309
- personalisation: {
310
- first_name: "Amala",
311
- application_date: "2018-01-01",
312
- link_to_file: Notifications.prepare_upload(f, confirm_email_before_download: true),
313
- }
314
- end
315
- ```
316
-
317
- ##### Turn off email address check (not recommended)
318
-
319
- If you do not want to use this feature after 29 March 2023, you can turn it off on a file-by-file basis.
320
-
321
- To do this you will need version 5.4.0 of the Ruby client library, or a more recent version.
322
-
323
- You should not turn this feature off if you send files that contain:
324
-
325
- * personally identifiable information
326
- * commercially sensitive information
327
- * information classified as ‘OFFICIAL’ or ‘OFFICIAL-SENSITIVE’ under the [Government Security Classifications](https://www.gov.uk/government/publications/government-security-classifications) policy
328
-
329
- To let the recipient download the file without confirming their email address, set the `confirm_email_before_download` flag to `false`.
330
-
331
-
332
-
333
- ```ruby
334
- File.open("file.pdf", "rb") do |f|
335
- ...
336
- personalisation: {
337
- first_name: "Amala",
338
- application_date: "2018-01-01",
339
- link_to_file: Notifications.prepare_upload(f, confirm_email_before_download: false),
340
- }
341
- end
342
- ```
343
-
344
- #### Choose the length of time that a file is available to download
345
-
346
- Set the number of weeks you want the file to be available using the `retention_period` key.
347
-
348
- You can choose any value between 1 week and 78 weeks.
349
-
350
- To use this feature will need version 5.4.0 of the Ruby client library, or a more recent version.
351
-
352
- If you do not choose a value, the file will be available for the default period of 78 weeks (18 months).
353
-
354
- ```ruby
355
- File.open("file.pdf", "rb") do |f|
356
- ...
357
- personalisation: {
358
- first_name: "Amala",
359
- application_date: "2018-01-01",
360
- link_to_file: Notifications.prepare_upload(f, retention_period: '52 weeks'),
361
- }
362
- end
363
- ```
364
-
365
- #### Response
366
-
367
- 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`.
368
-
369
- You can then call different methods on this object to return the requested information.
370
-
371
- |Method|Information|Type|
372
- |:---|:---|:---|
373
- |#`emailresponse.id`|Notification UUID|String|
374
- |#`emailresponse.reference`|`reference` argument|String|
375
- |#`emailresponse.content`|- `body`: Message body<br>- `subject`: Message subject<br>- `from_email`: From email address of your service found on the **Settings** page|Hash|
376
- |#`emailresponse.template`|Contains the `id`, `version` and `uri` of the template|Hash|
377
- |#`emailresponse.uri`|Notification URL|String|
378
-
379
- #### Error codes
380
-
381
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
382
-
383
- |error.code|error.message|class|How to fix|
384
- |:--- |:---|:---|:---|
385
- |`400`|`BadRequestError: Can't send to this recipient using a team-only API key`|`BadRequestError`|Use the correct type of [API key](#api-keys)|
386
- |`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)|
387
- |`400`|`BadRequestError: Unsupported file type '(FILE TYPE)'. Supported types are: '(ALLOWED TYPES)'`|`BadRequestError`|Wrong file type. You can only upload .pdf, .csv, .txt, .doc, .docx, .xlsx, .rtf or .odt files|
388
- |`400`|`BadRequestError: Unsupported value for retention_period '(PERIOD)'. Supported periods are from 1 to 78 weeks.`|Choose a period between 1 and 78 weeks|
389
- |`400`|`BadRequestError: Unsupported value for confirm_email_before_download: '(VALUE)'. Use a boolean true or false value.`|Use either true or false|
390
- |`400`|`BadRequestError: File did not pass the virus scan`|`BadRequestError`|The file contains a virus|
391
- |`400`|`BadRequestError: Send files by email has not been set up - add contact details for your service at https://www.notifications.service.gov.uk/services/(SERVICE ID)/service-settings/send-files-by-email`|`BadRequestError`|See how to [add contact details to the file download page](#add-contact-details-to-the-file-download-page)|
392
- |`400`|`BadRequestError: Can only send a file by email` | `BadRequestError`|Make sure you are using an email template|
393
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
394
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
395
- |`429`|`RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds`|`RateLimitError`|Refer to [API rate limits](#rate-limits) for more information|
396
- |`429`|`TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today`|`RateLimitError`|Refer to [service limits](#daily-limits) for the limit number|
397
- |`500`|`Exception: Internal server error`|`ServerError`|Notify was unable to process the request, resend your notification|
398
- |-|`ArgumentError: File is larger than 2MB")`|-|The file is too big. Files must be smaller than 2MB|
399
-
400
- ### Send a letter
401
-
402
- When you add a new service it will start in [trial mode](https://www.notifications.service.gov.uk/features/trial-mode). You can only send letters when your service is live.
403
-
404
- To send Notify a request to go live:
405
-
406
- 1. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in).
407
- 1. Go to the __Settings__ page.
408
- 1. In the __Your service is in trial mode__ section, select __request to go live__.
409
-
410
- #### Method
411
-
412
- ```ruby
413
- letterresponse = client.send_letter(
414
- template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a",
415
- personalisation: {
416
- address_line_1: 'The Occupier',
417
- address_line_2: '123 High Street',
418
- address_line_3: 'SW14 6BH',
419
- },
420
- )
421
- ```
422
-
423
- #### Arguments
424
-
425
- ##### template_id (required)
426
-
427
- To find the template ID:
428
-
429
- 1. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in).
430
- 1. Go to the __Templates__ page and select the relevant template.
431
- 1. Select __Copy template ID to clipboard__.
432
-
433
- For example:
434
-
435
- ```ruby
436
- template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a"
437
- ```
438
-
439
- ##### personalisation (required)
440
-
441
- The personalisation argument always contains the following parameters for the letter recipient’s address:
442
-
443
- - `address_line_1`
444
- - `address_line_2`
445
- - `address_line_3`
446
- - `address_line_4`
447
- - `address_line_5`
448
- - `address_line_6`
449
- - `address_line_7`
450
-
451
- The address must have at least 3 lines.
452
-
453
- The last line needs to be a real UK postcode or the name of a country outside the UK.
454
-
455
- Notify checks for international addresses and will automatically charge you the correct postage.
456
-
457
- The `postcode` personalisation argument has been replaced. If your template still uses `postcode`, Notify will treat it as the last line of the address.
458
-
459
- Any other placeholder fields included in the letter template also count as required parameters. You must provide their values in a hash. For example:
460
-
461
-
462
- ```ruby
463
- personalisation: {
464
- address_line_1: 'The Occupier', # mandatory address field
465
- address_line_2: '123 High Street', # mandatory address field
466
- address_line_3: 'SW14 6BH', # mandatory address field
467
- name: 'John Smith', # field from template
468
- application_date: '2018-01-01' # field from template
469
- },
470
- ```
471
-
472
- ##### reference (optional)
473
-
474
- 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:
475
-
476
- ```ruby
477
- reference: 'your_reference_string'
478
- ```
479
-
480
- #### Response
481
-
482
- 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`.
483
-
484
- You can then call different methods on this object to return the requested information.
485
-
486
- |Method|Information|Type|
487
- |:---|:---|:---|
488
- |#`letterresponse.id`|Notification UUID|String|
489
- |#`letterresponse.reference`|`reference` argument|String|
490
- |#`letterresponse.content`|- `body`: Letter body<br>- `subject`: Letter subject or main heading|Hash|
491
- |#`letterresponse.template`|Contains the `id`, `version` and `uri` of the template|Hash|
492
- |#`letterresponse.uri`|Notification URL|String|
493
-
494
-
495
- #### Error codes
496
-
497
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
498
-
499
- |error.code|error.message|class|How to fix|
500
- |:--- |:---|:---|:---|
501
- |`400`|`BadRequestError: Cannot send letters with a team api key`|`BadRequestError`|Use the correct type of [API key](#api-keys).|
502
- |`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).|
503
- |`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.|
504
- |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "Must be a real UK postcode"`<br>`}]`|Ensure that the value for the last line of the address is a real UK postcode.|
505
- |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "Last line of address must be a real UK postcode or another country"`<br>`}]`|Ensure that the value for the last line of the address is a real UK postcode or the name of a country outside the UK.|
506
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock.|
507
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information.|
508
- |`429`|`RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds`|`RateLimitError`|Refer to [API rate limits](#rate-limits) for more information.|
509
- |`429`|`TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today`|`RateLimitError`|Refer to [service limits](#daily-limits) for the limit number.|
510
- |`500`|`Exception: Internal server error`|`ServerError`|Notify was unable to process the request, resend your notification.|
511
-
512
- ### Send a precompiled letter
513
-
514
- #### Method
515
- ```ruby
516
- precompiled_letter = client.send_precompiled_letter(reference, pdf_file)
517
- ```
518
-
519
- #### Arguments
520
-
521
- ##### reference (required)
522
- 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.
523
-
524
- ##### pdf_file (required)
525
-
526
- The precompiled letter must be a PDF file which meets [the GOV.UK Notify letter specification](https://www.notifications.service.gov.uk/using-notify/guidance/letter-specification).
527
-
528
- ```ruby
529
- File.open("path/to/pdf_file", "rb") do |pdf_file|
530
- client.send_precompiled_letter("your reference", pdf_file)
531
- end
532
- ```
533
-
534
- ##### postage (optional)
535
-
536
- You can choose first or second class postage for your precompiled letter. Set the value to `first` for first class, or `second` for second class. If you do not pass in this argument, the postage will default to second class.
537
-
538
-
539
- #### Response
540
-
541
- 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-precompiled-letter-method), the object is named `precompiled_letter`.
542
-
543
- You can then call different methods on this object to return the requested information.
544
-
545
- |Method|Information|Type|
546
- |:---|:---|:---|
547
- |#`precompiled_letter.id`|Notification UUID|String|
548
- |#`precompiled_letter.reference`|`reference` argument|String|
549
- |#`precompiled_letter.postage`|`postage` argument|String|
550
-
551
-
552
- #### Error codes
553
-
554
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
555
-
556
- |error.status_code|error.message|class|How to fix|
557
- |:---|:---|:---|:---|
558
- |`400`|`BadRequestError: Cannot send letters with a team api key`|`BadRequestError`|Use the correct type of [API key](#api-keys)|
559
- |`400`|`BadRequestError: Letter content is not a valid PDF`|`BadRequestError`|PDF file format is required|
560
- |`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)|
561
- |`400`|`ValidationError: reference is a required property`|`BadRequestError`|Add a `reference` argument to the method call|
562
- |`400`|`ValidationError: postage invalid. It must be either first or second.`|`BadRequestError`|Change the value of `postage` argument in the method call to either 'first' or 'second'|
563
- |`429`|`RateLimitError: Exceeded rate limit for key type live of 10 requests per 20 seconds`|`RateLimitError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
564
- |`429`|`TooManyRequestsError: Exceeded send limits (50) for today`|`RateLimitError`|Refer to [service limits](#daily-limits) for the limit number|
565
-
566
- ## Get message status
567
-
568
-
569
-
570
- ### Get the status of one message
571
-
572
- You can only get the status of messages sent within the retention period. The default retention period is 7 days.
573
-
574
- #### Method
575
-
576
- ```ruby
577
- response = client.get_notification(id)
578
- ```
579
-
580
- #### Arguments
581
-
582
- ##### id (required)
583
-
584
- The ID of the notification. To find the notification ID, you can either:
585
-
586
- * check the response to the [original notification method call](#response)
587
- * [sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in) and go to the __API integration__ page
588
-
589
- #### Response
590
-
591
- 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`.
592
-
593
- You can then call different methods on this object to return the requested information.
594
-
595
- |Method|Information|Type|
596
- |:---|:---|:---|
597
- |#`response.id`|Notification UUID|String|
598
- |#`response.reference`| String supplied in `reference` argument|String|
599
- |#`response.email_address`|Recipient email address (email only)|String|
600
- |#`response.phone_number`|Recipient phone number (SMS only)|String|
601
- |#`response.line_1`|Recipient address line 1 of the address (letter only)|String|
602
- |#`response.line_2`|Recipient address line 2 of the address (letter only)|String|
603
- |#`response.line_3`|Recipient address line 3 of the address (letter only)|String|
604
- |#`response.line_4`|Recipient address line 4 of the address (letter only)|String|
605
- |#`response.line_5`|Recipient address line 5 of the address (letter only)|String|
606
- |#`response.line_6`|Recipient address line 6 of the address (letter only)|String|
607
- |#`response.line_7`|Recipient address line 7 of the address (letter only)|String|
608
- |#`response.postage`|Postage class of the notification sent (letter only)|String|
609
- |#`response.type`|Type of notification sent (sms, email or letter)|String|
610
- |#`response.status`|Notification status (sending / delivered / permanent-failure / temporary-failure / technical-failure)|String|
611
- |#`response.template`|Template UUID|String|
612
- |#`response.body`|Notification body|String|
613
- |#`response.subject`|Notification subject (email and letter)|String|
614
- |#`response.sent_at`|Date and time notification sent to provider|String|
615
- |#`response.created_at`|Date and time notification created|String|
616
- |#`response.completed_at`|Date and time notification delivered or failed|String|
617
- |#`response.created_by_name`|Name of sender if notification sent manually|String|
618
-
619
- #### Error codes
620
-
621
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
622
-
623
- |error.code|error.message|class|How to fix|
624
- |:---|:---|:---|:---|
625
- |`400`|`ValidationError: id is not a valid UUID`|`BadRequestError`|Check the notification ID|
626
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
627
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
628
- |`404`|`NoResultFound: No result found`|`NotFoundError`|Check the notification ID. This error occurs if the notification is more than 7 days old.|
629
-
630
- ### Get the status of multiple messages
631
-
632
- 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.
633
-
634
- You can only get messages that are 7 days old or newer.
635
-
636
- #### Method
637
-
638
- ```ruby
639
- args = {
640
- template_type: 'sms',
641
- status: 'failed',
642
- reference: 'your_reference_string'
643
- older_than: 'e194efd1-c34d-49c9-9915-e4267e01e92e'
644
- }
645
- response = client.get_notifications(args)
646
- ```
647
-
648
- You can leave out the `older_than` argument to get the 250 most recent messages.
649
-
650
- To get older messages, pass the ID of an older notification into the `older_than` argument. This returns the next 250 oldest messages from the specified notification ID.
651
-
652
- #### Arguments
653
-
654
- You can leave out these arguments to ignore these filters.
655
-
656
- ##### status (optional)
657
-
658
- You can filter by each:
659
-
660
- * [email status](#email-status-descriptions)
661
- * [text message status](#text-message-status-descriptions)
662
- * [letter status](#letter-status-descriptions)
663
- * [precompiled letter status](#precompiled-letter-status-descriptions)
664
-
665
- You can leave out this argument to ignore this filter.
666
-
667
- ##### templateType (optional)
668
-
669
- You can filter by:
670
-
671
- * `email`
672
- * `sms`
673
- * `letter`
674
-
675
- ##### reference (optional)
676
-
677
- 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:
678
-
679
- ```ruby
680
- reference: 'your_reference_string'
681
- ```
682
-
683
- ##### older_than (optional)
684
-
685
- Input the ID of a notification into this argument. If you use this argument, the client returns the next 250 received notifications older than the given ID. For example:
686
-
687
- ```ruby
688
- older_than: 'e194efd1-c34d-49c9-9915-e4267e01e92e'
689
- ```
690
-
691
- If you leave out this argument, the client returns the most recent 250 notifications.
692
-
693
- 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.
694
-
695
- #### Response
696
-
697
- 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`.
698
-
699
- You must then call either the `.links` method or the `.collection` method on this object.
700
-
701
- |Method|Information|
702
- |:---|:---|
703
- |#`response.links`|Returns a hash linking to the requested notifications (limited to 250)|
704
- |#`response.collection`|Returns an array of the required notifications|
705
-
706
- If you call the `collection` method on this object to return a notification array, you must then call the following methods on the notifications in this array to return information on those notifications:
707
-
708
- |Method|Information|Type|
709
- |:---|:---|:---|
710
- |#`response.id`|Notification UUID|String|
711
- |#`response.reference`| String supplied in `reference` argument|String|
712
- |#`response.email_address`|Recipient email address (email only)|String|
713
- |#`response.phone_number`|Recipient phone number (SMS only)|String|
714
- |#`response.line_1`|Recipient address line 1 of the address (letter only)|String|
715
- |#`response.line_2`|Recipient address line 2 of the address (letter only)|String|
716
- |#`response.line_3`|Recipient address line 3 of the address (letter only)|String|
717
- |#`response.line_4`|Recipient address line 4 of the address (letter only)|String|
718
- |#`response.line_5`|Recipient address line 5 of the address (letter only)|String|
719
- |#`response.line_6`|Recipient address line 6 of the address (letter only)|String|
720
- |#`response.postcode`|Recipient postcode (letter only)|String|
721
- |#`response.type`|Type of notification sent (sms, email or letter)|String|
722
- |#`response.status`|Notification status (sending / delivered / permanent-failure / temporary-failure / technical-failure)|String|
723
- |#`response.template`|Template UUID|String|
724
- |#`response.body`|Notification body|String|
725
- |#`response.subject`|Notification subject (email and letter)|String|
726
- |#`response.sent_at`|Date and time notification sent to provider|String|
727
- |#`response.created_at`|Date and time notification created|String|
728
- |#`response.completed_at`|Date and time notification delivered or failed|String|
729
- |#`response.created_by_name`|Name of sender if notification sent manually|String|
730
-
731
- If the notification specified in the `older_than` argument is older than 7 days, the client returns an empty `collection` response.
732
-
733
- #### Error codes
734
-
735
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
736
-
737
- |error.code|error.message|class|How to fix|
738
- |:---|:---|:---|:---|
739
- |`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|
740
- |`400`|`ValidationError: Template type is not one of [sms, email, letter]`|`BadRequestError`|Contact the GOV.UK Notify team|
741
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
742
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
743
-
744
- ### Email status descriptions
745
-
746
- |Status|Description|
747
- |:---|:---|
748
- |#`created`|GOV.UK Notify has placed the message in a queue, ready to be sent to the provider. It should only remain in this state for a few seconds.|
749
- |#`sending`|GOV.UK Notify has sent the message to the provider. The provider will try to deliver the message to the recipient for up to 72 hours. GOV.UK Notify is waiting for delivery information.|
750
- |#`delivered`|The message was successfully delivered.|
751
- |#`permanent-failure`|The provider could not deliver the message because the email address was wrong. You should remove these email addresses from your database.|
752
- |#`temporary-failure`|The provider could not deliver the message. This can happen when the recipient’s inbox is full or their anti-spam filter rejects your email. [Check your content does not look like spam](https://www.gov.uk/service-manual/design/sending-emails-and-text-messages#protect-your-users-from-spam-and-phishing) before you try to send the message again.|
753
- |#`technical-failure`|Your message was not sent because there was a problem between Notify and the provider.<br>You’ll have to try sending your messages again.|
754
-
755
- ### Text message status descriptions
756
-
757
- |Status|Description|
758
- |:---|:---|
759
- |#`created`|GOV.UK Notify has placed the message in a queue, ready to be sent to the provider. It should only remain in this state for a few seconds.|
760
- |#`sending`|GOV.UK Notify has sent the message to the provider. The provider will try to deliver the message to the recipient for up to 72 hours. GOV.UK Notify is waiting for delivery information.|
761
- |#`pending`|GOV.UK Notify is waiting for more delivery information.<br>GOV.UK Notify received a callback from the provider but the recipient’s device has not yet responded. Another callback from the provider determines the final status of the text message.|
762
- |#`sent`|The message was sent to an international number. The mobile networks in some countries do not provide any more delivery information. The GOV.UK Notify website displays this status as 'Sent to an international number'.|
763
- |#`delivered`|The message was successfully delivered.|
764
- |#`permanent-failure`|The provider could not deliver the message. This can happen if the phone number was wrong or if the network operator rejects the message. If you’re sure that these phone numbers are correct, you should [contact GOV.UK Notify support](https://www.notifications.service.gov.uk/support). If not, you should remove them from your database. You’ll still be charged for text messages that cannot be delivered.
765
- |#`temporary-failure`|The provider could not deliver the message. This can happen when the recipient’s phone is off, has no signal, or their text message inbox is full. You can try to send the message again. You’ll still be charged for text messages to phones that are not accepting messages.|
766
- |#`technical-failure`|Your message was not sent because there was a problem between Notify and the provider.<br>You’ll have to try sending your messages again. You will not be charged for text messages that are affected by a technical failure.|
767
-
768
- ### Letter status descriptions
769
-
770
- |Status|Description|
771
- |:---|:---|
772
- |#`accepted`|GOV.UK Notify has sent the letter to the provider to be printed.|
773
- |#`received`|The provider has printed and dispatched the letter.|
774
- |#`cancelled`|Sending cancelled. The letter will not be printed or dispatched.|
775
- |#`technical-failure`|GOV.UK Notify had an unexpected error while sending the letter to our printing provider.|
776
- |#`permanent-failure`|The provider cannot print the letter. Your letter will not be dispatched.|
777
-
778
- ### Precompiled letter status descriptions
779
-
780
- |Status|Description|
781
- |:---|:---|
782
- |#`accepted`|GOV.UK Notify has sent the letter to the provider to be printed.|
783
- |#`received`|The provider has printed and dispatched the letter.|
784
- |#`cancelled`|Sending cancelled. The letter will not be printed or dispatched.|
785
- |#`pending-virus-check`|GOV.UK Notify has not completed a virus scan of the precompiled letter file.|
786
- |#`virus-scan-failed`|GOV.UK Notify found a potential virus in the precompiled letter file.|
787
- |#`validation-failed`|Content in the precompiled letter file is outside the printable area. See the [GOV.UK Notify letter specification](https://www.notifications.service.gov.uk/using-notify/guidance/letter-specification) for more information.|
788
- |#`technical-failure`|GOV.UK Notify had an unexpected error while sending the letter to our printing provider.|
789
- |#`permanent-failure`|The provider cannot print the letter. Your letter will not be dispatched.|
790
-
791
-
792
- ### Get a PDF for a letter notification
793
-
794
- #### Method
795
-
796
- This returns the pdf contents of a letter notification.
797
-
798
- ```ruby
799
- pdf_file = client.get_pdf_for_letter(
800
- 'f33517ff-2a88-4f6e-b855-c550268ce08a' # notification id (required)
801
- )
802
- ```
803
-
804
- #### Arguments
805
-
806
- ##### id (required)
807
-
808
- The ID of the notification. To find the notification ID, you can either:
809
-
810
- * check the response to the [original notification method call](#get-the-status-of-one-message-response)
811
- * [sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in) and go to the __API integration__ page
812
-
813
- #### Response
814
-
815
- If the request to the client is successful, the client will return a `string` containing the raw PDF data.
816
-
817
- #### Error codes
818
-
819
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
820
-
821
- |error.code|error.message|class|How to fix|
822
- |:---|:---|:---|:---|
823
- |`400`|`ValidationError: id is not a valid UUID`|`BadRequestError`|Check the notification ID|
824
- |`400`|`PDFNotReadyError: PDF not available yet, try again later`|`BadRequestError`|Wait for the notification to finish processing. This usually takes a few seconds|
825
- |`400`|`BadRequestError: File did not pass the virus scan`|`BadRequestError`|You cannot retrieve the contents of a letter notification that contains a virus|
826
- |`400`|`BadRequestError: PDF not available for letters in technical-failure`|`BadRequestError`|You cannot retrieve the contents of a letter notification in technical-failure|
827
- |`400`|`ValidationError: Notification is not a letter`|`BadRequestError`|Check that you are looking up the correct notification|
828
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`BadRequestError`|Check your system clock|
829
- |`403`|`AuthError: Invalid token: API key not found`|`BadRequestError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
830
- |`404`|`NoResultFound: No result found`|`BadRequestError`|Check the notification ID|
831
-
832
-
833
- ## Get a template
834
-
835
- ### Get a template by ID
836
-
837
- #### Method
838
-
839
- This returns the latest version of the template.
840
-
841
- ```ruby
842
- response = client.get_template_by_id(id)
843
- ```
844
-
845
- #### Arguments
846
-
847
- ##### id (required)
848
-
849
- The ID of the template. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in) and go to the __Templates__ page to find it. For example:
850
-
851
- ```
852
- 'f33517ff-2a88-4f6e-b855-c550268ce08a'
853
- ```
854
-
855
- #### Response
856
-
857
- 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`.
858
-
859
- You can then call different methods on this object to return the requested information.
860
-
861
- |Method|Information|Type|
862
- |:---|:---|:---|
863
- |#`response.id`|Template UUID|String|
864
- |#`response.name`|Template name|String|
865
- |#`response.type`|Template type (email/sms/letter)|String|
866
- |#`response.created_at`|Date and time template created|String|
867
- |#`response.updated_at`|Date and time template last updated (may be nil if version 1)|String|
868
- |#`response.created_by`|Email address of person that created the template|String|
869
- |#`response.version`|Template version|String|
870
- |#`response.body`|Template content|String|
871
- |#`response.subject`|Template subject (email and letter)|String|
872
- |#`response.letter_contact_block`|Template letter contact block (letter)|String|
873
-
874
- #### Error codes
875
-
876
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
877
-
878
- |error.code|error.message|class|How to fix|
879
- |:---|:---|:---|:---|
880
- |`400`|`ValidationError: id is not a valid UUID`|`BadRequestError`|Check the notification ID|
881
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
882
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
883
- |`404`|`NoResultFound: No Result Found`|`NotFoundError`|Check your [template ID](#get-a-template-by-id-arguments-id-required)|
884
-
885
- ### Get a template by ID and version
886
-
887
- #### Method
888
-
889
- ```ruby
890
- response = client.get_template_version(id, version)
891
- ```
892
-
893
- #### Arguments
894
-
895
- ##### id (required)
896
-
897
- The ID of the template. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in) and go to the __Templates__ page to find it. For example:
898
-
899
- ```ruby
900
- 'f33517ff-2a88-4f6e-b855-c550268ce08a'
901
- ```
902
-
903
- ##### version (required)
904
-
905
- The version number of the template.
906
-
907
- #### Response
908
-
909
- 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`.
910
-
911
- You can then call different methods on this object to return the requested information.
912
-
913
- |Method|Information|Type|
914
- |:---|:---|:---|
915
- |#`response.id`|Template UUID|String|
916
- |#`response.name`|Template name|String|
917
- |#`response.type`|Template type (email/sms/letter)|String|
918
- |#`response.created_at`|Date and time template created|String|
919
- |#`response.updated_at`|Date and time template last updated (may be nil if it is the first version)|String|
920
- |#`response.created_by`|Email address of person that created the template|String|
921
- |#`response.version`|Template version|String|
922
- |#`response.body`|Template content|String|
923
- |#`response.subject`|Template subject (email and letter)|String|
924
- |#`response.letter_contact_block`|Template letter contact block (letter)|String|
925
-
926
- #### Error codes
927
-
928
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
929
-
930
- |error.code|error.message|class|How to fix|
931
- |:---|:---|:---|:---|
932
- |`400`|`ValidationError: id is not a valid UUID`|`BadRequestError`|Check the notification ID|
933
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
934
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
935
- |`404`|`NoResultFound: No Result Found`|`NotFoundError`|Check your [template ID](#get-a-template-by-id-and-version-arguments-id-required) and [version](#version-required)|
936
-
937
- ### Get all templates
938
-
939
- #### Method
940
-
941
- This returns the latest version of all templates inside a collection object.
942
-
943
- ```ruby
944
- args = {
945
- type: 'sms'
946
- }
947
- response = client.get_all_templates(args)
948
- ```
949
-
950
- #### Arguments
951
-
952
- ##### type (optional)
953
-
954
- If you do not use `type`, the client returns all templates. Otherwise you can filter by:
955
-
956
- - `email`
957
- - `sms`
958
- - `letter`
959
-
960
- #### Response
961
-
962
- 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`.
963
-
964
- You must then call the `.collection` method on this object to return an array of the required templates.
965
-
966
- Once the client has returned a template array, you must then call the following methods on the templates in this array to return information on those templates.
967
-
968
- |Method|Information|Type|
969
- |:---|:---|:---|
970
- |#`response.id`|Template UUID|String|
971
- |#`response.name`|Template name|String|
972
- |#`response.type`|Template type (email/sms/letter)|String|
973
- |#`response.created_at`|Date and time template created|String|
974
- |#`response.updated_at`|Date and time template last updated (may be nil if it is the first version)|String|
975
- |#`response.created_by`|Email address of person that created the template|String|
976
- |#`response.version`|Template version|String|
977
- |#`response.body`|Template content|String|
978
- |#`response.subject`|Template subject (email and letter)|String|
979
- |#`response.letter_contact_block`|Template letter contact block (letter)|String|
980
-
981
- If no templates exist for a template type or there no templates for a service, the templates array will be empty.
982
-
983
- #### Error codes
984
-
985
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
986
-
987
- |error.code|error.message|class|How to fix|
988
- |:---|:---|:---|:---|
989
- |`400`|`ValidationError: Template type is not one of [sms, email, letter]`|`BadRequestError`|Contact the Notify team|
990
-
991
- ### Generate a preview template
992
-
993
- #### Method
994
-
995
- This generates a preview version of a template.
996
-
997
- ```ruby
998
- response = client.generate_template_preview(id)
999
- ```
1000
-
1001
- The parameters in the personalisation argument must match the placeholder fields in the actual template. The API notification client ignores any extra fields in the method.
1002
-
1003
- #### Arguments
1004
-
1005
- ##### id (required)
1006
-
1007
- The ID of the template. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in) and go to the __Templates__ page to find it. For example:
1008
-
1009
- ```ruby
1010
- 'f33517ff-2a88-4f6e-b855-c550268ce08a'
1011
- ```
1012
-
1013
- ##### personalisation (optional)
1014
-
1015
- If a template has placeholder fields for personalised information such as name or application date, you must provide their values in a hash. For example:
1016
-
1017
- ```ruby
1018
- personalisation: {
1019
- name: "John Smith",
1020
- ID: "300241",
1021
- }
1022
- ```
1023
-
1024
- You can leave out this argument if a template does not have any placeholder fields for personalised information.
1025
-
1026
- #### Response
1027
-
1028
- 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`.
1029
-
1030
- You can then call different methods on this object to return the requested information.
1031
-
1032
- |Method|Information|Type|
1033
- |:---|:---|:---|
1034
- |#`response.id`|Template UUID|String|
1035
- |#`response.version`|Template version|String|
1036
- |#`response.body`|Template content|String|
1037
- |#`response.subject`|Template subject (email and letter)|String|
1038
- |#`response.type`|Template type (sms/email/letter)|String|
1039
- |#`response.html`|Body as rendered HTML (email only)|String|
1040
-
1041
- #### Error codes
1042
-
1043
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
1044
-
1045
- |error.code|error.message|class|How to fix|
1046
- |:---|:---|:---|:---|
1047
- |`400`|`BadRequestError: Missing personalisation: [PERSONALISATION FIELD]`|`BadRequestError`|Check that the personalisation arguments in the method match the placeholder fields in the template|
1048
- |`400`|`NoResultFound: No result found`|`BadRequestError`|Check the [template ID](#generate-a-preview-template-arguments-id-required)|
1049
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
1050
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
1051
-
1052
- ## Get received text messages
1053
-
1054
- 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.
1055
-
1056
- You can only get the status of messages that are 7 days old or newer.
1057
-
1058
- You can also set up [callbacks](#callbacks) for received text messages.
1059
-
1060
- ### Enable received text messages
1061
-
1062
- Contact the GOV.UK Notify team using the [support page](https://www.notifications.service.gov.uk/support) or [chat to us on Slack](https://ukgovernmentdigital.slack.com/messages/C0E1ADVPC) to request a unique number for text message replies.
1063
-
1064
- ### Get a page of received text messages
1065
-
1066
- #### Method
1067
-
1068
- ```ruby
1069
- args = {
1070
- older_than: 'e194efd1-c34d-49c9-9915-e4267e01e92e'
1071
- }
1072
- response = client.get_received_texts(args)
1073
- ```
1074
-
1075
- To get older messages, pass the ID of an older notification into the `older_than` argument. This returns the next oldest messages from the specified notification ID.
1076
-
1077
- If you leave out the `older_than` argument, the client returns the most recent 250 notifications.
1078
-
1079
- #### Arguments
1080
-
1081
- ##### older_than (optional)
1082
-
1083
- Input the ID of a received text message into this argument. If you use this argument, the client returns the next 250 received text messages older than the given ID. For example:
1084
-
1085
- ```ruby
1086
- older_than: '8e222534-7f05-4972-86e3-17c5d9f894e2'
1087
- ```
1088
-
1089
- If you leave out the `older_than` argument, the client returns the most recent 250 notifications.
1090
-
1091
- 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.
1092
-
1093
- #### Response
1094
-
1095
- 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-a-page-of-received-text-messages-method), the object is named `response`.
1096
-
1097
- You must then call either the `.links` method or the `.collection` method on this object.
1098
-
1099
- |Method|Information|
1100
- |:---|:---|
1101
- |#`response.links`|Returns a hash linking to the requested texts (limited to 250)|
1102
- |#`response.collection`|Returns an array of the required texts|
1103
-
1104
- If you call the `collection` method on this object to return an array, you must then call the following methods on the received texts in this array to return information on those texts:
1105
-
1106
- |Method|Information|Type|
1107
- |:---|:---|:---|
1108
- |#`response.id`|Received text UUID|String|
1109
- |#`response.created_at`|Date and time of received text|String|
1110
- |#`response.content`|Received text content|String|
1111
- |#`response.notify_number`|Number that received text was sent to|String|
1112
- |#`response.service_id`|Received text service ID|String|
1113
- |#`response.user_number`|Number that received text was sent from|String|
1114
-
1115
- If the notification specified in the `older_than` argument is older than 7 days, the client returns an empty `collection` response.
1116
-
1117
- #### Error codes
1118
-
1119
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
1120
-
1121
- |error.code|error.message|class|How to fix|
1122
- |:---|:---|:---|:---|
1123
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
1124
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|