notifications-ruby-client 2.1.0 → 2.2.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
  SHA1:
3
- metadata.gz: 2e9bb7eef63e23bb6ffd7f6f35c9659791a6501c
4
- data.tar.gz: 540c6b9214bccc51b8c0e1ada26562b30103870d
3
+ metadata.gz: 1cacbc8bf726eac5dfde61a8b0f9bad26ece23e6
4
+ data.tar.gz: 62f6050ebcab00e662124c17bb5f5b32c7b25505
5
5
  SHA512:
6
- metadata.gz: e297db99fcb11ecb4f7d88fe9670230c83fd92f891a30b3498407eb7b305d9a3333cabeec5b1413bf257d3df8e014cc035e2683b714411b0ca0ea526e8f13afe
7
- data.tar.gz: c76a4aecc6513919f80895d45ecb8124f7c47d379120db61981059108b5cb9075ddb53f7c951a50813d7a15c2449d03e99f26b9b208957cfa743af5e77eedf88
6
+ metadata.gz: 01ccf7949dc273065b7a5324f72b0080879d89c7136e5d10fdd13e4e51c92a88e4346378527216e1c7a624666853df1f745895b1d7db3ed03d1c0d3e59c73f3a
7
+ data.tar.gz: 449bcdb891547ec90f0f026036ad801b213e60288c22ef8a65ab53f76721a2403a3f35dc83a6a1b4c73bd2a401ac7d3bf4dc3aed395dd199b1b7754d4565868c
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
- ##2.1.0
1
+ ## 2.2.0
2
2
 
3
- ###Changed
3
+ ### Changed
4
+ * Added a new `send_letter` method
5
+ * Removed 'govuk-lint' gem as a development dependency
6
+
7
+
8
+ ## 2.1.0
9
+
10
+ ### Changed
4
11
  * Added methods to get templates and generate a preview of a template.
5
12
  * `get_template_by_id` - get the latest version of a template by id.
6
13
  * `get_template_version` - get the template by id and version.
@@ -9,9 +16,9 @@
9
16
  * See the README for more information about the new template methods.
10
17
 
11
18
 
12
- ##2.0.0
19
+ ## 2.0.0
13
20
 
14
- ###Changed
21
+ ### Changed
15
22
  * Using version 2 of the notification-api.
16
23
  * A new `Notifications::Client` no longer requires the `service_id`, only the `api_key` is required.
17
24
  * `Notifications::Client.send_sms()` input parameters and the response object has changed, see the README for more information.
data/README.md CHANGED
@@ -28,7 +28,6 @@ Generate an API key by logging in to GOV.UK Notify [GOV.UK Notify](https://www.n
28
28
  Text message:
29
29
 
30
30
  ```ruby
31
- require 'notifications/client/response_notification'
32
31
  sms = client.send_sms(
33
32
  phone_number: number,
34
33
  template_id: template_id,
@@ -52,14 +51,12 @@ sms => Notifications::Client::ResponseNotification
52
51
 
53
52
  sms.id # => uuid for the notification
54
53
  sms.reference # => Reference string you supplied in the request
55
- sms.type # => sms
56
- sms.status # => status of the message "created|pending|sent|delivered|permanent-failure|temporary-failure"
57
- content # => Hash containing body => the message sent to the recipient, with placeholders replaced.
54
+ sms.content # => Hash containing body => the message sent to the recipient, with placeholders replaced.
58
55
  # from_number => the sms sender number of your service found **Settings** page
59
- template # => Hash containing id => id of the template
56
+ sms.template # => Hash containing id => id of the template
60
57
  # version => version of the template
61
- # uri => url of the template
62
- uri # => URL of the notification
58
+ # uri => url of the template
59
+ sms.uri # => URL of the notification
63
60
  ```
64
61
 
65
62
  Otherwise the client will raise a `Notifications::Client::RequestError`:
@@ -71,6 +68,19 @@ Otherwise the client will raise a `Notifications::Client::RequestError`:
71
68
  </tr>
72
69
  </thead>
73
70
  <tbody>
71
+ <tr>
72
+ <td>
73
+ <pre>429</pre>
74
+ </td>
75
+ <td>
76
+ <pre>
77
+ [{
78
+ "error": "RateLimitError",
79
+ "message": "Exceeded rate limit for key type TEAM of 10 requests per 10 seconds"
80
+ }]
81
+ </pre>
82
+ </td>
83
+ </tr>
74
84
  <tr>
75
85
  <td>
76
86
  <pre>429</pre>
@@ -119,7 +129,6 @@ Otherwise the client will raise a `Notifications::Client::RequestError`:
119
129
  Email:
120
130
 
121
131
  ```ruby
122
- require 'notifications/client/response_notification'
123
132
  email = client.send_email(
124
133
  email_address: email_address,
125
134
  template_id: template_id,
@@ -143,14 +152,12 @@ email => Notifications::Client::ResponseNotification
143
152
 
144
153
  email.id # => uuid for the notification
145
154
  email.reference # => Reference string you supplied in the request
146
- email.type # => email
147
- email.status # => status of the message "created|pending|sent|delivered|permanent-failure|temporary-failure"
148
155
  email.content # => Hash containing body => the message sent to the recipient, with placeholders replaced.
149
156
  # subject => subject of the message sent to the recipient, with placeholders replaced.
150
157
  # from_email => the from email of your service found **Settings** page
151
158
  email.template # => Hash containing id => id of the template
152
159
  # version => version of the template
153
- # uri => url of the template
160
+ # uri => url of the template
154
161
  email.uri # => URL of the notification
155
162
  ```
156
163
 
@@ -163,6 +170,19 @@ Otherwise the client will raise a `Notifications::Client::RequestError`:
163
170
  </tr>
164
171
  </thead>
165
172
  <tbody>
173
+ <tr>
174
+ <td>
175
+ <pre>429</pre>
176
+ </td>
177
+ <td>
178
+ <pre>
179
+ [{
180
+ "error": "RateLimitError",
181
+ "message": "Exceeded rate limit for key type TEAM of 10 requests per 10 seconds"
182
+ }]
183
+ </pre>
184
+ </td>
185
+ </tr>
166
186
  <tr>
167
187
  <td>
168
188
  <pre>429</pre>
@@ -207,6 +227,122 @@ Otherwise the client will raise a `Notifications::Client::RequestError`:
207
227
  </table>
208
228
  </details>
209
229
 
230
+ Letter:
231
+
232
+ ```ruby
233
+ letter = client.send_letter(
234
+ template_id: template_id,
235
+ personalisation: {
236
+ address_line_1: 'Her Majesty The Queen', # required
237
+ address_line_2: 'Buckingham Palace', # required
238
+ address_line_3: 'London',
239
+ postcode: 'SW1 1AA', # required
240
+
241
+ ... # any other personalisation found in your template
242
+ },
243
+ reference: "your_reference_string"
244
+ ) # => Notifications::Client::ResponseNotification
245
+ ```
246
+
247
+ <details>
248
+ <summary>
249
+ Response
250
+ </summary>
251
+
252
+ If the request is successful, a `Notifications::Client:ResponseNotification` is returned
253
+
254
+ ```ruby
255
+ letter => Notifications::Client::ResponseNotification
256
+
257
+ letter.id # => uuid for the notification
258
+ letter.reference # => Reference string you supplied in the request
259
+ letter.content # => Hash containing body => the body of the letter sent to the recipient, with placeholders replaced
260
+ # subject => the main heading of the letter
261
+ letter.template # => Hash containing id => id of the template
262
+ # version => version of the template
263
+ # uri => url of the template
264
+ letter.uri # => URL of the notification
265
+ ```
266
+
267
+ Otherwise the client will raise a `Notifications::Client::RequestError`:
268
+ <table>
269
+ <thead>
270
+ <tr>
271
+ <th>error.code</th>
272
+ <th>error.message</th>
273
+ </tr>
274
+ </thead>
275
+ <tbody>
276
+ <tr>
277
+ <td>
278
+ <pre>429</pre>
279
+ </td>
280
+ <td>
281
+ <pre>
282
+ [{
283
+ "error": "RateLimitError",
284
+ "message": "Exceeded rate limit for key type TEAM of 10 requests per 10 seconds"
285
+ }]
286
+ </pre>
287
+ </td>
288
+ </tr>
289
+ <tr>
290
+ <td>
291
+ <pre>429</pre>
292
+ </td>
293
+ <td>
294
+ <pre>
295
+ [{
296
+ "error": "TooManyRequestsError",
297
+ "message": "Exceeded send limits (50) for today"
298
+ }]
299
+ </pre>
300
+ </td>
301
+ </tr>
302
+ <tr>
303
+ <td>
304
+ <pre>400</pre>
305
+ </td>
306
+ <td>
307
+ <pre>
308
+ [{
309
+ "error": "BadRequestError",
310
+ "message": "Can"t send to this recipient using a team-only API key"
311
+ ]}
312
+ </pre>
313
+ </td>
314
+ </tr>
315
+ <tr>
316
+ <td>
317
+ <pre>400</pre>
318
+ </td>
319
+ <td>
320
+ <pre>
321
+ [{
322
+ "error": "BadRequestError",
323
+ "message": "Can"t send to this recipient when service is in trial mode
324
+ - see https://www.notifications.service.gov.uk/trial-mode"
325
+ }]
326
+ </pre>
327
+ </td>
328
+ </tr>
329
+ <tr>
330
+ <td>
331
+ <pre>400</pre>
332
+ </td>
333
+ <td>
334
+ <pre>
335
+ [{
336
+ "error": "ValidationError",
337
+ "message": "personalisation address_line_1 is a required property"
338
+ }]
339
+ </pre>
340
+ </td>
341
+ </tr>
342
+ </tbody>
343
+ </table>
344
+ </details>
345
+
210
346
  ### Arguments
211
347
  #### `phone_number`
212
348
  The phone number of the recipient, only required when using `client.send_sms`.
@@ -232,7 +368,24 @@ If the template has placeholders you need to provide their values as a Hash, for
232
368
  }
233
369
  ```
234
370
 
235
- You can omit this argument if the template does not contain placeholders.
371
+ You can omit this argument if the template does not contain placeholders and is for email or sms.
372
+
373
+ #### `personalisation` (for letters)
374
+
375
+ If you are sending a letter, you will need to provide the letter fields in the format `"address_line_#"`, for example:
376
+
377
+ ```ruby
378
+ personalisation: {
379
+ 'address_line_1' => 'The Occupier',
380
+ 'address_line_2' => '123 High Street',
381
+ 'address_line_3' => 'London',
382
+ 'postcode' => 'SW14 6BH',
383
+ 'first_name' => 'Amala',
384
+ 'reference_number' => '300241',
385
+ }
386
+ ```
387
+
388
+ The fields `address_line_1`, `address_line_2` and `postcode` are required.
236
389
 
237
390
  ### Get the status of one message
238
391
 
@@ -306,6 +459,7 @@ Otherwise a `Notification::Client::RequestError` is raised
306
459
  </details>
307
460
 
308
461
  </details>
462
+
309
463
  ### Get the status of all messages
310
464
 
311
465
  ```ruby
data/Rakefile CHANGED
@@ -4,9 +4,3 @@ require "rspec/core/rake_task"
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task :default => :spec
7
-
8
-
9
- desc "Run govuk-lint with similar params to CI"
10
- task "lint" do
11
- sh "bundle exec govuk-lint-ruby --format clang spec lib"
12
- end
@@ -17,6 +17,7 @@ env_vars=(
17
17
  FUNCTIONAL_TEST_NUMBER
18
18
  EMAIL_TEMPLATE_ID
19
19
  SMS_TEMPLATE_ID
20
+ LETTER_TEMPLATE_ID
20
21
  )
21
22
 
22
23
  for env_var in "${env_vars[@]}"; do
data/bin/test_client.rb CHANGED
@@ -15,8 +15,10 @@ def main
15
15
  test_generate_template_preview(client, ENV['EMAIL_TEMPLATE_ID'])
16
16
  email_notification = test_send_email_endpoint(client)
17
17
  sms_notification = test_send_sms_endpoint(client)
18
+ letter_notification = test_send_letter_endpoint(client)
18
19
  test_get_notification_by_id_endpoint(client, email_notification.id, 'email')
19
20
  test_get_notification_by_id_endpoint(client, sms_notification.id, 'sms')
21
+ test_get_notification_by_id_endpoint(client, letter_notification.id, 'letter')
20
22
  test_get_all_notifications(client)
21
23
  p 'ruby client integration tests pass'
22
24
  exit 0
@@ -34,25 +36,26 @@ end
34
36
 
35
37
  def test_get_all_templates(client)
36
38
  response = client.get_all_templates()
37
- unless response.is_a?(Notifications::Client::TemplateCollection) then
39
+ unless response.is_a?(Notifications::Client::TemplateCollection)
38
40
  p 'failed test_get_all_templates response is not a Notifications::Client::TemplateCollection'
39
41
  exit 1
40
42
  end
41
- unless response.collection.length >= 2 then
42
- p 'failed test_get_all_templates, expected at least 2 templates returned.'
43
+ unless response.collection.length >= 3
44
+ p 'failed test_get_all_templates, expected at least 3 templates returned.'
43
45
  exit 1
44
46
  end
45
47
  test_template_response(response.collection[0], 'test_get_all_templates')
46
48
  test_template_response(response.collection[1], 'test_get_all_templates')
49
+ test_template_response(response.collection[2], 'test_get_all_templates')
47
50
  end
48
51
 
49
52
  def test_get_all_templates_filter_by_type(client)
50
53
  response = client.get_all_templates({'type' => 'sms'})
51
- unless response.is_a?(Notifications::Client::TemplateCollection) then
54
+ unless response.is_a?(Notifications::Client::TemplateCollection)
52
55
  p 'failed test_get_all_templates response is not a Notifications::Client::TemplateCollection'
53
56
  exit 1
54
57
  end
55
- unless response.collection.length >= 1 then
58
+ unless response.collection.length >= 1
56
59
  p 'failed test_get_all_templates, expected at least 2 templates returned.'
57
60
  exit 1
58
61
  end
@@ -66,11 +69,11 @@ def test_generate_template_preview(client, id)
66
69
  end
67
70
 
68
71
  def test_template_response(response, test_method)
69
- unless response.is_a?(Notifications::Client::Template) then
72
+ unless response.is_a?(Notifications::Client::Template)
70
73
  p 'failed test_get_template_by_id response is not a Notifications::Client::Template'
71
74
  exit 1
72
75
  end
73
- unless response.id.is_a?(String) then
76
+ unless response.id.is_a?(String)
74
77
  p 'failed template id is not a String'
75
78
  exit 1
76
79
  end
@@ -78,11 +81,11 @@ def test_template_response(response, test_method)
78
81
  end
79
82
 
80
83
  def test_template_preview(response)
81
- unless response.is_a?(Notifications::Client::TemplatePreview) then
84
+ unless response.is_a?(Notifications::Client::TemplatePreview)
82
85
  p 'failed test_generate_template_preview response is not a Notifications::Client::TemplatePreview'
83
86
  exit 1
84
87
  end
85
- unless response.id.is_a?(String) then
88
+ unless response.id.is_a?(String)
86
89
  p 'failed template id is not a String'
87
90
  exit 1
88
91
  end
@@ -105,50 +108,67 @@ def test_send_sms_endpoint(client)
105
108
  sms_resp
106
109
  end
107
110
 
111
+ def test_send_letter_endpoint(client)
112
+ letter_resp = client.send_letter(
113
+ template_id: ENV['LETTER_TEMPLATE_ID'],
114
+ personalisation: {
115
+ address_line_1: "Her Majesty The Queen",
116
+ address_line_2: "Buckingham Palace",
117
+ postcode: "SW1 1AA"
118
+ },
119
+ reference: "some reference"
120
+ )
121
+ test_notification_response_data_type(letter_resp, 'letter')
122
+ letter_resp
123
+ end
124
+
108
125
  def test_notification_response_data_type(notification, message_type)
109
- unless notification.is_a?(Notifications::Client::ResponseNotification) then
126
+ unless notification.is_a?(Notifications::Client::ResponseNotification)
110
127
  p 'failed ' + message_type +' response is not a Notifications::Client::ResponseNotification'
111
128
  exit 1
112
129
  end
113
- unless notification.id.is_a?(String) then
130
+ unless notification.id.is_a?(String)
114
131
  p 'failed '+ message_type + 'id is not a String'
115
132
  exit 1
116
133
  end
117
134
  field_should_not_be_nil(expected_fields_in_notification_response, notification, 'send_'+message_type)
118
135
  hash_key_should_not_be_nil(expected_fields_in_template, notification.send('template'), 'send_'+message_type+'.template')
119
- if message_type == 'email' then
136
+
137
+ if message_type == 'email'
120
138
  hash_key_should_not_be_nil(expected_fields_in_email_content, notification.send('content'), 'send_'+message_type+'.content')
121
- end
122
- if message_type == 'sms' then
139
+ elsif message_type == 'sms'
123
140
  hash_key_should_not_be_nil(expected_fields_in_sms_content, notification.send('content'),'send_'+message_type+'.content')
141
+ elsif message_type == 'letter'
142
+ hash_key_should_not_be_nil(expected_fields_in_letter_content, notification.send('content'),'send_'+message_type+'.content')
124
143
  end
125
-
126
144
  end
127
145
 
128
146
  def test_get_notification_by_id_endpoint(client, id, message_type)
129
147
  get_notification_response = client.get_notification(id)
130
148
 
131
- unless get_notification_response.is_a?(Notifications::Client::Notification) then
149
+ unless get_notification_response.is_a?(Notifications::Client::Notification)
132
150
  p 'get notification is not a Notifications::Client::Notification for id ' + id
133
151
  exit 1
134
152
  end
135
- if message_type == 'email' then
153
+
154
+ if message_type == 'email'
136
155
  field_should_not_be_nil(expected_fields_in_email_notification, get_notification_response, 'Notifications::Client::Notification for type email')
137
156
  field_should_be_nil(expected_fields_in_email_notification_that_are_nil, get_notification_response, 'Notifications::Client::Notification for type email')
138
157
  hash_key_should_not_be_nil(expected_fields_in_template, get_notification_response.send('template'), 'Notifications::Client::Notification.template for type email')
139
- end
140
- if message_type == 'sms' then
158
+ elsif message_type == 'sms'
141
159
  field_should_not_be_nil(expected_fields_in_sms_notification, get_notification_response, 'Notifications::Client::Notification for type sms')
142
160
  field_should_be_nil(expected_fields_in_sms_notification_that_are_nil, get_notification_response, 'Notifications::Client::Notification for type sms')
143
161
  hash_key_should_not_be_nil(expected_fields_in_template, get_notification_response.send('template'), 'Notifications::Client::Notification.template for type sms')
162
+ elsif message_type == 'letter'
163
+ field_should_not_be_nil(expected_fields_in_letter_notification, get_notification_response, 'Notifications::Client::Notification for type letter')
164
+ field_should_be_nil(expected_fields_in_letter_notification_that_are_nil, get_notification_response, 'Notifications::Client::Notification for type letter')
165
+ hash_key_should_not_be_nil(expected_fields_in_template, get_notification_response.send('template'), 'Notifications::Client::Notification.template for type letter')
144
166
  end
145
-
146
167
  end
147
168
 
148
-
149
169
  def hash_key_should_not_be_nil(fields, obj, method_name)
150
170
  fields.each do |field|
151
- if obj.has_value?(:"#{field}") then
171
+ if obj.has_value?(:"#{field}")
152
172
  p 'contract test failed because ' + field + ' should not be nil for ' + method_name + ' response'
153
173
  exit 1
154
174
  end
@@ -157,7 +177,7 @@ end
157
177
 
158
178
  def field_should_not_be_nil(fields, obj, method_name)
159
179
  fields.each do |field|
160
- if obj.send(:"#{field}") == nil then
180
+ if obj.send(:"#{field}") == nil
161
181
  p 'contract test failed because ' + field + ' should not be nil for ' + method_name + ' response'
162
182
  exit 1
163
183
  end
@@ -166,7 +186,7 @@ end
166
186
 
167
187
  def field_should_be_nil(fields, obj, method_name)
168
188
  fields.each do |field|
169
- if obj.send(:"#{field}") != nil then
189
+ if obj.send(:"#{field}") != nil
170
190
  p 'contract test failed because ' + field + ' should be nil for ' + method_name + ' response'
171
191
  exit 1
172
192
  end
@@ -212,6 +232,13 @@ def expected_fields_in_sms_content
212
232
  )
213
233
  end
214
234
 
235
+ def expected_fields_in_letter_content
236
+ %w(
237
+ body
238
+ subject
239
+ )
240
+ end
241
+
215
242
  def expected_fields_in_email_notification
216
243
  %w(id
217
244
  email_address
@@ -261,6 +288,33 @@ def expected_fields_in_sms_notification_that_are_nil
261
288
  subject)
262
289
  end
263
290
 
291
+ def expected_fields_in_letter_notification
292
+ %w(
293
+ id
294
+ type
295
+ status
296
+ template
297
+ body
298
+ subject
299
+ line_1
300
+ line_2
301
+ postcode
302
+ created_at
303
+ )
304
+ end
305
+
306
+ def expected_fields_in_letter_notification_that_are_nil
307
+ %w(
308
+ phone_number
309
+ email_address
310
+ line_3
311
+ line_4
312
+ line_5
313
+ line_5
314
+ line_6
315
+ )
316
+ end
317
+
264
318
  def expected_fields_in_template
265
319
  %w(id
266
320
  version
@@ -269,7 +323,7 @@ end
269
323
 
270
324
  def test_get_all_notifications(client)
271
325
  notifications = client.get_notifications()
272
- unless notifications.is_a?(Notifications::Client::NotificationsCollection) then
326
+ unless notifications.is_a?(Notifications::Client::NotificationsCollection)
273
327
  p 'get all notifications is not Notifications::Client::NotificationsCollection'
274
328
  exit 1
275
329
  end
@@ -1,43 +1,41 @@
1
1
  module Notifications
2
2
  class Client
3
3
  class Notification
4
- FIELDS = [
5
- :id,
6
- :reference,
7
- :email_address,
8
- :phone_number,
9
- :line_1,
10
- :line_2,
11
- :line_3,
12
- :line_4,
13
- :line_5,
14
- :line_6,
15
- :postcode,
16
- :type,
17
- :status,
18
- :template,
19
- :body,
20
- :subject,
21
- :sent_at,
22
- :created_at,
23
- :completed_at
24
- ].freeze
4
+ FIELDS = %i(
5
+ id
6
+ reference
7
+ email_address
8
+ phone_number
9
+ line_1
10
+ line_2
11
+ line_3
12
+ line_4
13
+ line_5
14
+ line_6
15
+ postcode
16
+ type
17
+ status
18
+ template
19
+ body
20
+ subject
21
+ sent_at
22
+ created_at
23
+ completed_at
24
+ ).freeze
25
25
 
26
26
  attr_reader(*FIELDS)
27
27
 
28
28
  def initialize(notification)
29
-
30
29
  FIELDS.each do |field|
31
- instance_variable_set(:"@#{field}", notification.fetch(field.to_s, nil)
32
- )
30
+ instance_variable_set(:"@#{field}", notification.fetch(field.to_s, nil))
33
31
  end
34
32
  end
35
33
 
36
- [
37
- :sent_at,
38
- :created_at,
39
- :completed_at
40
- ].each do |field|
34
+ %i(
35
+ sent_at
36
+ created_at
37
+ completed_at
38
+ ).each do |field|
41
39
  define_method field do
42
40
  begin
43
41
  value = instance_variable_get(:"@#{field}")
@@ -47,7 +45,6 @@ module Notifications
47
45
  end
48
46
  end
49
47
  end
50
-
51
48
  end
52
49
  end
53
50
  end
@@ -1,25 +1,21 @@
1
1
  module Notifications
2
2
  class Client
3
3
  class ResponseNotification
4
- FIELDS = [
5
- :id,
6
- :reference,
7
- :content,
8
- :template,
9
- :uri
10
- ].freeze
11
-
4
+ FIELDS = %i(
5
+ id
6
+ reference
7
+ content
8
+ template
9
+ uri
10
+ ).freeze
12
11
 
13
12
  attr_reader(*FIELDS)
14
13
 
15
14
  def initialize(notification)
16
-
17
15
  FIELDS.each do |field|
18
- instance_variable_set(:"@#{field}", notification.fetch(field.to_s, nil)
19
- )
16
+ instance_variable_set(:"@#{field}", notification.fetch(field.to_s, nil))
20
17
  end
21
18
  end
22
-
23
19
  end
24
20
  end
25
21
  end
@@ -1,41 +1,38 @@
1
1
  module Notifications
2
2
  class Client
3
3
  class Template
4
- FIELDS = [
5
- :id,
6
- :type,
7
- :created_at,
8
- :updated_at,
9
- :created_by,
10
- :version,
11
- :body,
12
- :subject
13
- ].freeze
4
+ FIELDS = %i(
5
+ id
6
+ type
7
+ created_at
8
+ updated_at
9
+ created_by
10
+ version
11
+ body
12
+ subject
13
+ ).freeze
14
14
 
15
- attr_reader(*FIELDS)
15
+ attr_reader(*FIELDS)
16
16
 
17
- def initialize(notification)
18
-
19
- FIELDS.each do |field|
20
- instance_variable_set(:"@#{field}", notification.fetch(field.to_s, nil)
21
- )
22
- end
23
- end
24
-
25
- [
26
- :created_at,
27
- :updated_at
28
- ].each do |field|
29
- define_method field do
30
- begin
31
- value = instance_variable_get(:"@#{field}")
32
- Time.parse value
33
- rescue
34
- value
35
- end
36
- end
37
- end
17
+ def initialize(notification)
18
+ FIELDS.each do |field|
19
+ instance_variable_set(:"@#{field}", notification.fetch(field.to_s, nil))
20
+ end
21
+ end
38
22
 
23
+ %i(
24
+ created_at
25
+ updated_at
26
+ ).each do |field|
27
+ define_method field do
28
+ begin
29
+ value = instance_variable_get(:"@#{field}")
30
+ Time.parse value
31
+ rescue
32
+ value
39
33
  end
40
34
  end
41
35
  end
36
+ end
37
+ end
38
+ end
@@ -24,7 +24,7 @@ module Notifications
24
24
  end
25
25
 
26
26
  ##
27
- # @param kind [String] 'email' or 'sms'
27
+ # @param kind [String] 'email', 'sms' or 'letter'
28
28
  # @param form_data [Hash]
29
29
  # @option form_data [String] :phone_number
30
30
  # phone number of the sms recipient
@@ -89,7 +89,7 @@ module Notifications
89
89
  perform_request!(request)
90
90
  end
91
91
 
92
- private
92
+ private
93
93
 
94
94
  ##
95
95
  # @return [Hash] JSON parsed response
@@ -12,5 +12,5 @@ module Notifications
12
12
  end
13
13
  end
14
14
  end
15
- end
16
- end
15
+ end
16
+ end
@@ -1,23 +1,21 @@
1
1
  module Notifications
2
2
  class Client
3
3
  class TemplatePreview
4
- FIELDS = [
5
- :id,
6
- :version,
7
- :body,
8
- :subject,
9
- :type
10
- ].freeze
4
+ FIELDS = %i(
5
+ id
6
+ version
7
+ body
8
+ subject
9
+ type
10
+ ).freeze
11
11
 
12
- attr_reader(*FIELDS)
12
+ attr_reader(*FIELDS)
13
13
 
14
- def initialize(notification)
15
-
16
- FIELDS.each do |field|
17
- instance_variable_set(:"@#{field}", notification.fetch(field.to_s, nil)
18
- )
19
- end
20
- end
14
+ def initialize(notification)
15
+ FIELDS.each do |field|
16
+ instance_variable_set(:"@#{field}", notification.fetch(field.to_s, nil))
17
+ end
18
+ end
21
19
  end
22
20
  end
23
21
  end
@@ -1,5 +1,5 @@
1
1
  module Notifications
2
2
  class Client
3
- VERSION = "2.1.0".freeze
3
+ VERSION = "2.2.0".freeze
4
4
  end
5
5
  end
@@ -41,6 +41,15 @@ module Notifications
41
41
  )
42
42
  end
43
43
 
44
+ ##
45
+ # @see Notifications::Client::Speaker#post
46
+ # @return [ResponseNotification]
47
+ def send_letter(args)
48
+ ResponseNotification.new(
49
+ speaker.post("letter", args)
50
+ )
51
+ end
52
+
44
53
  ##
45
54
  # @param id [String]
46
55
  # @see Notifications::Client::Speaker#get
@@ -112,6 +121,5 @@ module Notifications
112
121
  speaker.post_with_url(path, options)
113
122
  )
114
123
  end
115
-
116
124
  end
117
125
  end
@@ -27,5 +27,4 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "rspec", "~> 3.0"
28
28
  spec.add_development_dependency "webmock", "~> 2.0"
29
29
  spec.add_development_dependency "factory_girl", "~> 4.7"
30
- spec.add_development_dependency "govuk-lint", "~> 1.1.0"
31
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: 2.1.0
4
+ version: 2.2.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: 2017-05-09 00:00:00.000000000 Z
11
+ date: 2017-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -94,20 +94,6 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '4.7'
97
- - !ruby/object:Gem::Dependency
98
- name: govuk-lint
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: 1.1.0
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: 1.1.0
111
97
  description:
112
98
  email:
113
99
  - notify@digital.cabinet-office.gov.uk
@@ -159,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
145
  version: '0'
160
146
  requirements: []
161
147
  rubyforge_project:
162
- rubygems_version: 2.6.7
148
+ rubygems_version: 2.5.1
163
149
  signing_key:
164
150
  specification_version: 4
165
151
  summary: Ruby client for GOV.UK Notifications API