notifications-ruby-client 2.10.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 323f2b6f8d75d806a1a9cc63d33f21432791cb3bb806db047376071f819eacc7
4
- data.tar.gz: 1bd9804348d562a43370f56b1dc00461b99dc5abe21fa5a73c74c8f8fe5cd684
3
+ metadata.gz: 3aa0a6d3a19753534e19441bc9bd6ac3e0dc1913d1a5dee660d629367ea85dd4
4
+ data.tar.gz: b760674b646a232fa7a0d6e6c844fef4488cd4fd582496f6380c3eaee861e520
5
5
  SHA512:
6
- metadata.gz: e6640fb0a6781b566e55951f7d1a8cddf2b9d950780467404a57895f94e8d6c504e4b8883d6e424d9b7a85269a22caf535f05281c605f32cd4aa2ab490a1845b
7
- data.tar.gz: f0c5ee819a5d1868a4055d19a1af026e2338a7b2bb1ca19478814d5bf18be2b09f8943cd0b02b839a3ee85f070a7e07afd3a2ba0dbc2e3ce3398d74157d3bdca
6
+ metadata.gz: 10593571a7496c3669361bc56bcdab4fe2e7075ab2a743b08e860894721b288c31d042a9c8f433122385373523a948b8cd53d78fc8cf374f314868708dbfef9e
7
+ data.tar.gz: 10ab2c60a4f94ce96e8da05a0b1d71205051c9655005948a7cf9b4ec08e9a42e775cbb2ce3dbebd440f4c4542754dd41ffa818a50c824d5d4314777589ea69e9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 3.0.0
2
+
3
+ * Changed response class for `send_precompiled_letter` request from `ResponseNotification` to a new response class: `ResponsePrecompiledLetter`. This may affect users sending precompiled letters.
4
+ * Added an optional `postage` argument to `send_precompiled_letter` method, so users can specify postage when sending
5
+ a precompiled letter via API.
6
+ * Added postage to `Notification` class on the client.
7
+
1
8
  ## 2.10.0
2
9
 
3
10
  * Added subclasses of the `RequestError` class to handle specific types of errors.
data/DOCUMENTATION.md CHANGED
@@ -215,7 +215,7 @@ This is an invitation-only feature. [Contact the GOV.UK Notify team](https://www
215
215
 
216
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.
217
217
 
218
- #### Add a placeholder field to the template
218
+ ### Add a placeholder field to the template
219
219
 
220
220
  1. Sign in to [GOV.UK Notify](https://www.notifications.service.gov.uk/).
221
221
  1. Go to the __Templates__ page and select the relevant email template.
@@ -223,7 +223,7 @@ To send a document by email, add a placeholder field to the template then upload
223
223
 
224
224
  "Download your document at: ((link_to_document))"
225
225
 
226
- #### Upload your document
226
+ ### Upload your document
227
227
 
228
228
  The document you upload must be a PDF file smaller than 2MB.
229
229
 
@@ -401,9 +401,14 @@ File.open("path/to/pdf_file", "rb") do |pdf_file|
401
401
  end
402
402
  ```
403
403
 
404
+ #### postage (optional)
405
+
406
+ 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.
407
+
408
+
404
409
  ### Response
405
410
 
406
- If the request to the client is successful, the client returns a `Notifications::Client:ResponseNotification` object. In the example shown in the [Method section](/ruby.html#send-a-pre-compiled-letter-method), the object is named `precompiled_letter`.
411
+ If the request to the client is successful, the client returns a `Notifications::Client:ResponsePrecompiledLetter` object. In the example shown in the [Method section](/ruby.html#send-a-pre-compiled-letter-method), the object is named `precompiled_letter`.
407
412
 
408
413
  You can then call different methods on this object to return the requested information.
409
414
 
@@ -411,9 +416,8 @@ You can then call different methods on this object to return the requested infor
411
416
  |:---|:---|:---|
412
417
  |`precompiled_letter.id`|Notification UUID|String|
413
418
  |`precompiled_letter.reference`|`reference` argument|String|
414
- |`precompiled_letter.content`|Always `nil`|nil|
415
- |`precompiled_letter.template`|Always `nil`|nil|
416
- |`precompiled_letter.uri`|Always `nil`|nil|
419
+ |`precompiled_letter.postage`|`postage` argument|String|
420
+
417
421
 
418
422
  ### Error codes
419
423
 
@@ -426,6 +430,7 @@ If the request is not successful, the client returns a `Notifications::Client::R
426
430
  |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Letter content is not a valid PDF"`<br>`]}`|`BadRequestError`|PDF file format is required|
427
431
  |`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
432
  |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "reference is a required property"`<br>`}]`|`BadRequestError`|Add a `reference` argument to the method call|
433
+ |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "postage invalid. It must be either first or second."`<br>`}]`|`BadRequestError`|Change the value of `postage` argument in the method call to either 'first' or 'second'|
429
434
  |`400`|`[{`<br>`"error": "BadRequestError",`<br>`"message": "Service is not allowed to send precompiled letters"`<br>`}]`|`BadRequestError`|Contact the GOV.UK Notify team|
430
435
  |`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
436
  |`429`|`[{`<br>`"error": "TooManyRequestsError",`<br>`"message": "Exceeded send limits (50) for today"`<br>`}]`|`RateLimitError`|Refer to [service limits](#service-limits) for the limit number|
@@ -509,6 +514,7 @@ You can then call different methods on this object to return the requested infor
509
514
  |`response.line_5`|Recipient address line 5 of the address (letter only)|String|
510
515
  |`response.line_6`|Recipient address line 6 of the address (letter only)|String|
511
516
  |`response.postcode`|Recipient postcode (letter only)|String|
517
+ |`response.postage`|Postage class of the notification sent (letter only)|String|
512
518
  |`response.type`|Type of notification sent (sms, email or letter)|String|
513
519
  |`response.status`|Notification status (sending / delivered / permanent-failure / temporary-failure / technical-failure)|String|
514
520
  |`response.template`|Template UUID|String|
@@ -694,7 +700,7 @@ You can then call different methods on this object to return the requested infor
694
700
  If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code:
695
701
 
696
702
  |error.code|error.message|class|How to fix|
697
- |:---|:---|:---|
703
+ |:---|:---|:---|:---|
698
704
  |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "id is not a valid UUID"`<br>`}]`|`BadRequestError`|Check the notification ID|
699
705
  |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|`AuthError`|Check your system clock|
700
706
  |`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|
@@ -745,7 +751,7 @@ You can then call different methods on this object to return the requested infor
745
751
  If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code:
746
752
 
747
753
  |error.code|error.message|class|How to fix|
748
- |:---|:---|:---|
754
+ |:---|:---|:---|:---|
749
755
  |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "id is not a valid UUID"`<br>`}]`|`BadRequestError`|Check the notification ID|
750
756
  |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|`AuthError`|Check your system clock|
751
757
  |`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|
@@ -801,7 +807,7 @@ If no templates exist for a template type or there no templates for a service, t
801
807
  If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code:
802
808
 
803
809
  |error.code|error.message|class|How to fix|
804
- |:---|:---|:---|
810
+ |:---|:---|:---|:---|
805
811
  |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "Template type is not one of [sms, email, letter]"`<br>`}]`|`BadRequestError`|Contact the Notify team|
806
812
 
807
813
  ## Generate a preview template
@@ -858,7 +864,7 @@ You can then call different methods on this object to return the requested infor
858
864
  If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code:
859
865
 
860
866
  |error.code|error.message|class|How to fix|
861
- |:---|:---|:---|
867
+ |:---|:---|:---|:---|
862
868
  |`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
869
  |`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
870
  |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|`AuthError`|Check your system clock|
@@ -870,6 +876,14 @@ This API call returns one page of up to 250 received text messages. You can get
870
876
 
871
877
  You can only get the status of messages that are 7 days old or newer.
872
878
 
879
+ You can also set up [callbacks](/ruby.html#callbacks) for received text messages.
880
+
881
+ ## Enable received text messages
882
+
883
+ 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) to enable receiving text messages for your service.
884
+
885
+ ## Get a page of received text messages
886
+
873
887
  ### Method
874
888
 
875
889
  ```ruby
@@ -926,6 +940,6 @@ If the notification specified in the `older_than` argument is older than 7 days,
926
940
  If the request is not successful, the client returns a `Notifications::Client::RequestError` and an error code.
927
941
 
928
942
  |error.code|error.message|class|How to fix|
929
- |:---|:---|:---|
943
+ |:---|:---|:---|:---|
930
944
  |`403`|`[{`<br>`"error": "AuthError",`<br>`"message": "Error: Your system clock must be accurate to within 30 seconds"`<br>`}]`|`AuthError`|Check your system clock|
931
945
  |`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|
data/bin/test_client.rb CHANGED
@@ -139,7 +139,7 @@ end
139
139
 
140
140
  def test_send_precompiled_letter_endpoint(client)
141
141
  precompiled_letter_resp = File.open('spec/test_files/test_pdf.pdf', 'rb') do |file|
142
- client.send_precompiled_letter("some reference", file)
142
+ client.send_precompiled_letter("some reference", file, "first")
143
143
  end
144
144
 
145
145
  test_notification_response_data_type(precompiled_letter_resp, 'precompiled_letter')
@@ -148,7 +148,7 @@ def test_send_precompiled_letter_endpoint(client)
148
148
  end
149
149
 
150
150
  def test_notification_response_data_type(notification, message_type)
151
- unless notification.is_a?(Notifications::Client::ResponseNotification)
151
+ unless notification.is_a?(Notifications::Client::ResponseNotification) || (notification.is_a?(Notifications::Client::ResponsePrecompiledLetter) && message_type == "precompiled_letter")
152
152
  p 'failed ' + message_type + ' response is not a Notifications::Client::ResponseNotification'
153
153
  exit 1
154
154
  end
@@ -159,6 +159,10 @@ def test_notification_response_data_type(notification, message_type)
159
159
 
160
160
  if message_type == 'precompiled_letter'
161
161
  field_should_not_be_nil(expected_fields_in_precompiled_letter_response, notification, 'send_precompiled_letter')
162
+ if notification.postage != "first"
163
+ p "Postage should be set to 'first' for precompiled letter sending test. Right now it is set to #{notification.postage}"
164
+ exit 1
165
+ end
162
166
  return
163
167
  end
164
168
 
@@ -255,7 +259,8 @@ end
255
259
 
256
260
  def expected_fields_in_precompiled_letter_response
257
261
  %w(id
258
- reference)
262
+ reference
263
+ postage)
259
264
  end
260
265
 
261
266
  def expected_fields_in_email_content
@@ -297,7 +302,8 @@ def expected_fields_in_email_notification_that_are_nil
297
302
  line_5
298
303
  line_6
299
304
  postcode
300
- created_by_name)
305
+ created_by_name
306
+ postage)
301
307
  end
302
308
 
303
309
  def expected_fields_in_sms_notification
@@ -321,7 +327,8 @@ def expected_fields_in_sms_notification_that_are_nil
321
327
  line_6
322
328
  postcode
323
329
  subject
324
- created_by_name)
330
+ created_by_name
331
+ postage)
325
332
  end
326
333
 
327
334
  def expected_fields_in_letter_notification
@@ -336,6 +343,7 @@ def expected_fields_in_letter_notification
336
343
  line_2
337
344
  postcode
338
345
  created_at
346
+ postage
339
347
  )
340
348
  end
341
349
 
@@ -363,6 +371,7 @@ def expected_fields_in_precompiled_letter_notification
363
371
  subject
364
372
  template
365
373
  type
374
+ postage
366
375
  )
367
376
  end
368
377
 
@@ -2,6 +2,7 @@ require_relative "client/version"
2
2
  require_relative "client/speaker"
3
3
  require_relative "client/notification"
4
4
  require_relative "client/response_notification"
5
+ require_relative "client/response_precompiled_letter"
5
6
  require_relative "client/notifications_collection"
6
7
  require_relative "client/received_text"
7
8
  require_relative "client/received_text_collection"
@@ -59,10 +60,10 @@ module Notifications
59
60
  # @param reference [String]
60
61
  # @param pdf_file [File]
61
62
  # @see Notifications::Client::Speaker#post_precompiled_letter
62
- # @return [ResponseNotification]
63
- def send_precompiled_letter(reference, pdf_file)
64
- ResponseNotification.new(
65
- speaker.post_precompiled_letter(reference, pdf_file)
63
+ # @return [ResponsePrecompiledLetter]
64
+ def send_precompiled_letter(reference, pdf_file, postage = nil)
65
+ ResponsePrecompiledLetter.new(
66
+ speaker.post_precompiled_letter(reference, pdf_file, postage)
66
67
  )
67
68
  end
68
69
 
@@ -15,6 +15,7 @@ module Notifications
15
15
  line_5
16
16
  line_6
17
17
  postcode
18
+ postage
18
19
  type
19
20
  status
20
21
  template
@@ -0,0 +1,19 @@
1
+ module Notifications
2
+ class Client
3
+ class ResponsePrecompiledLetter
4
+ FIELDS = %i(
5
+ id
6
+ reference
7
+ postage
8
+ ).freeze
9
+
10
+ attr_reader(*FIELDS)
11
+
12
+ def initialize(notification)
13
+ FIELDS.each do |field|
14
+ instance_variable_set(:"@#{field}", notification.fetch(field.to_s, nil))
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -102,10 +102,14 @@ module Notifications
102
102
  # @param reference [String] reference of the notification
103
103
  # @param pdf_file [File] PDF file opened for reading
104
104
  # @see #perform_request!
105
- def post_precompiled_letter(reference, pdf_file)
105
+ def post_precompiled_letter(reference, pdf_file, postage = nil)
106
106
  content = Base64.strict_encode64(pdf_file.read)
107
107
  form_data = { reference: reference, content: content }
108
108
 
109
+ if postage != nil
110
+ form_data[:postage] = postage
111
+ end
112
+
109
113
  request = Net::HTTP::Post.new(
110
114
  "#{BASE_PATH}/letter",
111
115
  headers
@@ -9,6 +9,6 @@
9
9
 
10
10
  module Notifications
11
11
  class Client
12
- VERSION = "2.10.0".freeze
12
+ VERSION = "3.0.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.10.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-09 00:00:00.000000000 Z
11
+ date: 2019-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -147,6 +147,7 @@ files:
147
147
  - lib/notifications/client/received_text_collection.rb
148
148
  - lib/notifications/client/request_error.rb
149
149
  - lib/notifications/client/response_notification.rb
150
+ - lib/notifications/client/response_precompiled_letter.rb
150
151
  - lib/notifications/client/response_template.rb
151
152
  - lib/notifications/client/speaker.rb
152
153
  - lib/notifications/client/template_collection.rb