notifications-ruby-client 1.1.2 → 2.0.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: c878b94e8c21c7ab8709764b27e242de18dccc1e
4
- data.tar.gz: 4a3a9fad24a4b0685841bf7bfceadb05efe8339b
3
+ metadata.gz: 24ed09fc74d72afa42d20c723df34402b6d4d50d
4
+ data.tar.gz: f99c8a7ee09d01734af27f95c32d76cecd416be8
5
5
  SHA512:
6
- metadata.gz: f03bef489bf792cf544f05c457a07066fd93cdb4a80be7fa8a83fc9ecda165f19a7ddacac5095fad24b93db92d5d62bc2c31c33fbd02e536f25caa3b5bad49d7
7
- data.tar.gz: 6702179d9bb960e7935060b87185dcc1f6eeaf77b4887e52acee009715807d0a00282fc2f52bb6cb1bfab8f3e4b2bcaecd9e55c9f756e656a493d626e78aa17b
6
+ metadata.gz: a2d80bf886dc3b2a846e23842e49401d28d06595eb7f734ec9849b67e8c9be0fee81ce1f88409eede2ba4dd43baced5381f29dbce59bd8bc0c859966d4f8a5f2
7
+ data.tar.gz: 289479f21c94313ff77e24c5bc2e1906a9c7b71a8f7d02cc222593c8f6a872b51fdbf4039dd98fc1b3edd11baaa0c1420c9f0818f92e892242464e2118a923b4
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ ##2.0.0
2
+
3
+ ###Changed
4
+ * Using version 2 of the notification-api.
5
+ * A new `Notifications::Client` no longer requires the `service_id`, only the `api_key` is required.
6
+ * `Notifications::Client.send_sms()` input parameters and the response object has changed, see the README for more information.
7
+ ```ruby
8
+ client.sendSms(phone_number, template_id, personalisation, reference)
9
+ ```
10
+ * `Notifications::Client.send_email()` input parameters has changed and the response object, see the README for more information.
11
+ ```ruby
12
+ client.sendSms(phone_number, template_id, personalisation, reference)
13
+ ```
14
+ * `reference` is a new optional argument of the send methods. The `reference` can be used as a unique reference for the notification. Because Notify does not require this reference to be unique you could also use this reference to identify a batch or group of notifications.
15
+ * `Notifications::Client.get_all_notifications()` => the response object has changed.
16
+ * You can also filter the collection of `Notifications` by `reference`. See the README for more information.
17
+ * `Notifications::Client.get_notification(id)` => the response object has changed. See the README for more information.
18
+ * Initializing a client only requires the api key.
data/README.md CHANGED
@@ -28,43 +28,224 @@ 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
- sms = client.send_sms(to: number,
32
- template: template_id,
33
- personalisation: {
34
- name: "name",
35
- year: "2016"
36
- }
37
- )
31
+ require 'notifications/client/response_notification'
32
+ sms = client.send_sms(phone_number: number,
33
+ template_id: template_id,
34
+ personalisation: Hash[name: "name",
35
+ year: "2016",
36
+ ],
37
+ reference: "your_reference_string"
38
+ ) # => Notifications::Client::ResponseNotification
39
+ ```
40
+
41
+ <details>
42
+ <summary>
43
+ Response
44
+ </summary>
45
+
46
+ If the request is successful, a `Notifications::Client:ResponseNotification` is returned
38
47
 
48
+ ```ruby
49
+ sms => Notifications::Client::ResponseNotification
50
+
51
+ sms.id # => uuid for the notification
52
+ sms.reference # => Reference string you supplied in the request
53
+ sms.type # => sms
54
+ sms.status # => status of the message "created|pending|sent|delivered|permanent-failure|temporary-failure"
55
+ content # => Hash containing body => the message sent to the recipient, with placeholders replaced.
56
+ # from_number => the sms sender number of your service found **Settings** page
57
+ template # => Hash containing id => id of the template
58
+ # version => version of the template
59
+ # uri => url of the template
60
+ uri # => URL of the notification
39
61
  ```
40
62
 
63
+ Otherwise the client will raise a `Notifications::Client::RequestError`:
64
+ <table>
65
+ <thead>
66
+ <tr>
67
+ <th>error.code</th>
68
+ <th>error.message</th>
69
+ </tr>
70
+ </thead>
71
+ <tbody>
72
+ <tr>
73
+ <td>
74
+ <pre>429</pre>
75
+ </td>
76
+ <td>
77
+ <pre>
78
+ [{
79
+ "error": "TooManyRequestsError",
80
+ "message": "Exceeded send limits (50) for today"
81
+ }]
82
+ </pre>
83
+ </td>
84
+ </tr>
85
+ <tr>
86
+ <td>
87
+ <pre>400</pre>
88
+ </td>
89
+ <td>
90
+ <pre>
91
+ [{
92
+ "error": "BadRequestError",
93
+ "message": "Can"t send to this recipient using a team-only API key"
94
+ ]}
95
+ </pre>
96
+ </td>
97
+ </tr>
98
+ <tr>
99
+ <td>
100
+ <pre>400</pre>
101
+ </td>
102
+ <td>
103
+ <pre>
104
+ [{
105
+ "error": "BadRequestError",
106
+ "message": "Can"t send to this recipient when service is in trial mode
107
+ - see https://www.notifications.service.gov.uk/trial-mode"
108
+ }]
109
+ </pre>
110
+ </td>
111
+ </tr>
112
+ </tbody>
113
+ </table>
114
+ </details>
115
+
116
+
41
117
  Email:
118
+
42
119
  ```ruby
43
- email = client.send_email(
44
- to: email_address,
45
- template: template_id,
46
- personalisation: {
47
- name: "name",
48
- year: "2016"
49
- }
50
- ) # => Notifications::Client::ResponseNotification
120
+ require 'notifications/client/response_notification'
121
+ email = client.send_email(email_address: email_address,
122
+ template: template_id,
123
+ personalisation: Hash[name: "name",
124
+ year: "2016"
125
+ ],
126
+ reference: "your_reference_string"
127
+ ) # => Notifications::Client::ResponseNotification
51
128
  ```
52
129
 
53
- Find `template_id` by clicking **API info** for the template you want to send.
130
+ <details>
131
+ <summary>
132
+ Response
133
+ </summary>
134
+
135
+ If the request is successful, a `Notifications::Client:ResponseNotification` is returned
136
+
137
+ ```ruby
138
+ email => Notifications::Client::ResponseNotification
139
+
140
+ email.id # => uuid for the notification
141
+ email.reference # => Reference string you supplied in the request
142
+ email.type # => sms
143
+ email.status # => status of the message "created|pending|sent|delivered|permanent-failure|temporary-failure"
144
+ email.content # => Hash containing body => the message sent to the recipient, with placeholders replaced.
145
+ # subject => subject of the message sent to the recipient, with placeholders replaced.
146
+ # from_email => the from email of your service found **Settings** page
147
+ email.template # => Hash containing id => id of the template
148
+ # version => version of the template
149
+ # uri => url of the template
150
+ email.uri # => URL of the notification
151
+ ```
152
+
153
+ Otherwise the client will raise a `Notifications::Client::RequestError`:
154
+ <table>
155
+ <thead>
156
+ <tr>
157
+ <th>error.code</th>
158
+ <th>error.message</th>
159
+ </tr>
160
+ </thead>
161
+ <tbody>
162
+ <tr>
163
+ <td>
164
+ <pre>429</pre>
165
+ </td>
166
+ <td>
167
+ <pre>
168
+ [{
169
+ "error": "TooManyRequestsError",
170
+ "message": "Exceeded send limits (50) for today"
171
+ }]
172
+ </pre>
173
+ </td>
174
+ </tr>
175
+ <tr>
176
+ <td>
177
+ <pre>400</pre>
178
+ </td>
179
+ <td>
180
+ <pre>
181
+ [{
182
+ "error": "BadRequestError",
183
+ "message": "Can"t send to this recipient using a team-only API key"
184
+ ]}
185
+ </pre>
186
+ </td>
187
+ </tr>
188
+ <tr>
189
+ <td>
190
+ <pre>400</pre>
191
+ </td>
192
+ <td>
193
+ <pre>
194
+ [{
195
+ "error": "BadRequestError",
196
+ "message": "Can"t send to this recipient when service is in trial mode
197
+ - see https://www.notifications.service.gov.uk/trial-mode"
198
+ }]
199
+ </pre>
200
+ </td>
201
+ </tr>
202
+ </tbody>
203
+ </table>
204
+ </details>
205
+
206
+ ### Arguments
207
+ #### `phone_number`
208
+ The phone number of the recipient, only required when using `client.send_sms`.
209
+
210
+ #### `email_address`
211
+ The email address of the recipient, only required when using `client.send_email`.
212
+
213
+ #### `template_id`
214
+ Find by clicking **API info** for the template you want to send.
54
215
 
55
- If a template has placeholders, you need to provide their values in `personalisation`. Otherwise do not pass in `personalisation`
216
+ #### `reference`
217
+ An optional identifier you generate. The `reference` can be used as a unique reference for the notification. Because Notify does not require this reference to be unique you could also use this reference to identify a batch or group of notifications.
56
218
 
57
- If successful the response is a `Notifications::Client::ResponseNotification`, which has the notification id.
58
- Otherwise a Notifications::Client::RequestError is returned.
219
+ You can omit this argument if you do not require a reference for the notification.
59
220
 
221
+ #### `personalisation`
222
+ If the template has placeholders you need to provide their values as a Hash, for example:
223
+
224
+ ```ruby
225
+ personalisation=Hash[
226
+ 'first_name': 'Amala',
227
+ 'reference_number': '300241',
228
+ ]
229
+ ```
230
+
231
+ You can omit this argument if the template does not contain placeholders.
60
232
 
61
233
  ### Get the status of one message
62
234
 
63
235
  ```ruby
64
236
  notification = client.get_notification(id) # => Notifications::Client::Notification
237
+ ```
238
+
239
+ <details>
240
+ <summary>
241
+ Response
242
+ </summary>
243
+ If successful a `Notifications::Client::Notification is returned.
244
+
245
+ ```ruby
65
246
  notification.id # => uuid for the notification
66
247
  notification.to # => recipient email address or mobile number
67
- notification.status # => status of the message "created|pending|sent|delivered|permanent-failure|temporary-failure"
248
+ notification.status # => status of the message "created|pending|sent|delivered|permanent-failure|temporary-failure"
68
249
  notification.created_at # => Date time the message was created
69
250
  notification.api_key # => uuid for the api key (not the actual api key)
70
251
  notification.billable_units # => units billable or nil for email
@@ -80,69 +261,141 @@ notification.template_version # Template version number
80
261
  notification.reference # => reference of the email or nil for sms
81
262
  notification.updated_at # => Date time that the notification was last updated
82
263
  ```
264
+ Otherwise a `Notification::Client::RequestError` is raised
265
+
266
+ <table>
267
+ <thead>
268
+ <tr>
269
+ <th>`error.code`</th>
270
+ <th>`error.message`</th>
271
+ </tr>
272
+ </thead>
273
+ <tbody>
274
+ <tr>
275
+ <td>
276
+ <pre>404</pre>
277
+ </td>
278
+ <td>
279
+ <pre>
280
+ [{
281
+ "error": "NoResultFound",
282
+ "message": "No result found"
283
+ }]
284
+ </pre>
285
+ </td>
286
+ </tr>
287
+ <tr>
288
+ <td>
289
+ <pre>400</pre>
290
+ </td>
291
+ <td>
292
+ <pre>
293
+ [{
294
+ "error": "ValidationError",
295
+ "message": "id is not a valid UUID"
296
+ }]
297
+ </pre>
298
+ </td>
299
+ </tr>
300
+ </tbody>
301
+ </table>
302
+ </details>
83
303
 
304
+ </details>
84
305
  ### Get the status of all messages
85
306
 
86
307
  ```ruby
87
- notifications = client.get_notifications
88
- notifications.links # => {"last"=>"/notifications?page=4", "next"=>"/notifications?page=2"}
89
- notifications.total # => 202
90
- notifications.page_size # => 50
91
- notifications.collection # => [] (array of notification objects)
92
-
308
+ # See section below for a description of the arguments.
309
+ args = Hash[
310
+ 'template_type', 'sms',
311
+ 'status', 'failed',
312
+ 'reference', 'your reference string'
313
+ 'olderThanId', 'e194efd1-c34d-49c9-9915-e4267e01e92e' # => Notifications::Client::Notification
314
+ ]
315
+ notifications = client.get_notifications(args)
93
316
  ```
94
-
95
- Query parameters are also supported
317
+ <details>
318
+ <summary>
319
+ Response
320
+ </summary>
321
+ If the request is successful a `Notifications::Client::NotificationsCollection` is returned.
96
322
 
97
323
  ```ruby
98
- client.get_notifications(
99
- page: 2,
100
- limit_days: 3,
101
- page_size: 20,
102
- status: "delivered",
103
- template_type: "sms"
104
- )
324
+ notifications.links # => Hash containing current=>"/notifications?template_type=sms&status=delivered"
325
+ next=>"/notifications?other_than=last_id_in_list&template_type=sms&status=delivered"}
326
+ notifications.collection # => [] (array of notification objects)
105
327
  ```
328
+ Otherwise the client will raise a `Notifications::Client::RequestError`:
329
+ <table>
330
+ <thead>
331
+ <tr>
332
+ <th>error.status_code</th>
333
+ <th>error.message</th>
334
+ </tr>
335
+ </thead>
336
+ <tbody>
337
+ <tr>
338
+ <td>
339
+ <pre>400</pre>
340
+ </td>
341
+ <td>
342
+ <pre>
343
+ [{
344
+ 'error': 'ValidationError',
345
+ 'message': 'bad status is not one of [created, sending, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure]'
346
+ }]
347
+ </pre>
348
+ </td>
349
+ </tr>
350
+ <tr>
351
+ <td>
352
+ <pre>400</pre>
353
+ </td>
354
+ <td>
355
+ <pre>
356
+ [{
357
+ "error": "ValidationError",
358
+ "message": "Apple is not one of [sms, email, letter]"
359
+ }]
360
+ </pre>
361
+ </td>
362
+ </tr>
363
+ </tbody>
364
+ </table>
365
+ </details>
106
366
 
107
- ### Exceptions
367
+ ### Arguments
368
+ Omit the argument Hash if you do not want to filter the results.
369
+ #### `template_type`
108
370
 
109
- Raised exceptions will contain error message and response status code
371
+ You can filter by:
110
372
 
111
- ```ruby
112
- client = Notifications::Client.new(base_url, invalid, invalid)
113
- rescue Notifications::Client::RequestError => e
114
- e.code # => 403
115
- e.message # => Invalid credentials
116
- ```
117
- <table>
118
- <thead>
119
- <tr>
120
- <td> Code </td>
121
- <td> Message </td>
122
- </tr>
123
- </thead>
124
- <tbdoy>
125
- <tr>
126
- <td> 403 </td>
127
- <td> {"token"=>["Invalid token: signature"]} </td>
128
- </tr>
129
- <tr>
130
- <td> 403 </td>
131
- <td> {"token"=>["Invalid token: expired"]} </td>
132
- </tr>
133
- <tr>
134
- <td> 429 </td>
135
- <td> Exceeded send limits (50) for today </td>
136
- </tr>
137
- <tr>
138
- <td> 400 </td>
139
- <td> Can’t send to this recipient using a team-only API key </td>
140
- </tr>
141
- <tr>
142
- <td> 400 </td>
143
- <td> Can’t send to this recipient when service is in trial
144
- mode - see https://www.notifications.service.gov.uk/trial-mode
145
- </td>
146
- </tr>
147
- </tbody>
148
- </table>
373
+ * `email`
374
+ * `sms`
375
+ * `letter`
376
+
377
+ You can omit this argument to ignore the filter.
378
+
379
+ #### `status`
380
+
381
+ You can filter by:
382
+
383
+ * `sending` - the message is queued to be sent by the provider.
384
+ * `delivered` - the message was successfully delivered.
385
+ * `failed` - this will return all failure statuses `permanent-failure`, `temporary-failure` and `technical-failure`.
386
+ * `permanent-failure` - the provider was unable to deliver message, email or phone number does not exist; remove this recipient from your list.
387
+ * `temporary-failure` - the provider was unable to deliver message, email box was full or the phone was turned off; you can try to send the message again.
388
+ * `technical-failure` - Notify had a technical failure; you can try to send the message again.
389
+
390
+ You can omit this argument to ignore the filter.
391
+
392
+ ### `reference`
393
+
394
+ This is the `reference` you gave at the time of sending the notification. The `reference` can be a unique identifier for the notification or an identifier for a batch of notifications.
395
+
396
+ You can omit this argument to ignore the filter.
397
+
398
+
399
+ #### `olderThanId`
400
+ You can get the notifications older than a given `Notification.id`.
401
+ You can omit this argument to ignore this filter.
data/bin/test_client.rb CHANGED
@@ -5,7 +5,7 @@ require 'notifications/client/response_notification'
5
5
  require 'notifications/client/notification'
6
6
 
7
7
  def main
8
- client = Notifications::Client.new(ENV['SERVICE_ID'], ENV['API_KEY'], ENV['NOTIFY_API_URL'])
8
+ client = Notifications::Client.new(ENV['API_KEY'], ENV['NOTIFY_API_URL'])
9
9
  email_notification = test_send_email_endpoint(client)
10
10
  sms_notification = test_send_sms_endpoint(client)
11
11
  test_get_notification_by_id_endpoint(client, email_notification.id, 'email')
@@ -16,15 +16,17 @@ def main
16
16
  end
17
17
 
18
18
  def test_send_email_endpoint(client)
19
- email_resp = client.send_email(to: ENV['FUNCTIONAL_TEST_EMAIL'], template: ENV['EMAIL_TEMPLATE_ID'],
20
- personalisation:Hash["name", "some name"])
19
+ email_resp = client.send_email(email_address: ENV['FUNCTIONAL_TEST_EMAIL'], template_id: ENV['EMAIL_TEMPLATE_ID'],
20
+ personalisation:Hash["name", "some name"],
21
+ reference: "some reference")
21
22
  test_notification_response_data_type(email_resp, 'email')
22
23
  email_resp
23
24
  end
24
25
 
25
26
  def test_send_sms_endpoint(client)
26
- sms_resp = client.send_sms(to: ENV['FUNCTIONAL_TEST_NUMBER'], template: ENV['SMS_TEMPLATE_ID'],
27
- personalisation:Hash["name", "some name"])
27
+ sms_resp = client.send_sms(phone_number: ENV['FUNCTIONAL_TEST_NUMBER'], template_id: ENV['SMS_TEMPLATE_ID'],
28
+ personalisation:Hash["name", "some name"],
29
+ reference: "some reference")
28
30
  test_notification_response_data_type(sms_resp, 'sms')
29
31
  sms_resp
30
32
  end
@@ -38,6 +40,15 @@ def test_notification_response_data_type(notification, message_type)
38
40
  p 'failed '+ message_type + 'id is not a String'
39
41
  exit 1
40
42
  end
43
+ field_should_not_be_nil(expected_fields_in_notification_response, notification, 'send_'+message_type)
44
+ hash_key_should_not_be_nil(expected_fields_in_template, notification.send('template'), 'send_'+message_type+'.template')
45
+ if message_type == 'email' then
46
+ hash_key_should_not_be_nil(expected_fields_in_email_content, notification.send('content'), 'send_'+message_type+'.content')
47
+ end
48
+ if message_type == 'sms' then
49
+ hash_key_should_not_be_nil(expected_fields_in_sms_content, notification.send('content'),'send_'+message_type+'.content')
50
+ end
51
+
41
52
  end
42
53
 
43
54
  def test_get_notification_by_id_endpoint(client, id, message_type)
@@ -47,13 +58,16 @@ def test_get_notification_by_id_endpoint(client, id, message_type)
47
58
  exit 1
48
59
  end
49
60
  if message_type == 'email' then
50
- field_should_not_be_nil(expected_fields_in_email_resp, get_notification_response, 'send_email')
51
- field_should_be_nil(expected_fields_in_email_resp_that_are_nil, get_notification_response, 'send_email')
61
+ field_should_not_be_nil(expected_fields_in_email_notification, get_notification_response, 'Notifications::Client::Notification for type email')
62
+ field_should_be_nil(expected_fields_in_email_notification_that_are_nil, get_notification_response, 'Notifications::Client::Notification for type email')
63
+ hash_key_should_not_be_nil(expected_fields_in_template, get_notification_response.send('template'), 'Notifications::Client::Notification.template for type email')
52
64
  end
53
65
  if message_type == 'sms' then
54
- field_should_not_be_nil(expected_fields_in_sms_resp, get_notification_response, 'send_sms')
55
- field_should_be_nil(expected_fields_in_sms_resp_that_are_nil, get_notification_response, 'send_sms')
66
+ field_should_not_be_nil(expected_fields_in_sms_notification, get_notification_response, 'Notifications::Client::Notification for type sms')
67
+ field_should_be_nil(expected_fields_in_sms_notification_that_are_nil, get_notification_response, 'Notifications::Client::Notification for type sms')
68
+ hash_key_should_not_be_nil(expected_fields_in_template, get_notification_response.send('template'), 'Notifications::Client::Notification.template for type sms')
56
69
  end
70
+
57
71
  end
58
72
 
59
73
 
@@ -86,6 +100,15 @@ def get_notification_for_id(client, id, message_type)
86
100
  get_notification_response
87
101
  end
88
102
 
103
+ def hash_key_should_not_be_nil(fields, obj, method_name)
104
+ fields.each do |field|
105
+ if obj.has_value?(:"#{field}") then
106
+ p 'contract test failed because ' + field + ' should not be nil for ' + method_name + ' response'
107
+ exit 1
108
+ end
109
+ end
110
+ end
111
+
89
112
  def field_should_not_be_nil(fields, obj, method_name)
90
113
  fields.each do |field|
91
114
  if obj.send(:"#{field}") == nil then
@@ -104,51 +127,84 @@ def field_should_be_nil(fields, obj, method_name)
104
127
  end
105
128
  end
106
129
 
107
- def expected_fields_in_email_resp
130
+
131
+ def expected_fields_in_notification_response
108
132
  %w(id
109
- api_key
110
- billable_units
111
- to
112
- subject
133
+ reference
134
+ content
135
+ template
136
+ uri
137
+ )
138
+ end
139
+
140
+ def expected_fields_in_email_content
141
+ %w(from_email
113
142
  body
114
- notification_type
143
+ subject
144
+ )
145
+ end
146
+
147
+ def expected_fields_in_sms_content
148
+ %w(body
149
+ )
150
+ end
151
+
152
+ def expected_fields_in_email_notification
153
+ %w(id
154
+ reference
155
+ email_address
156
+ type
115
157
  status
116
- service
117
158
  sent_at
118
- sent_by
119
159
  template
120
- template_version
160
+ body
161
+ subject
121
162
  created_at
122
- updated_at
123
163
  )
124
164
  end
125
165
 
126
- def expected_fields_in_email_resp_that_are_nil
127
- %w(job)
166
+ def expected_fields_in_email_notification_that_are_nil
167
+ %w(phone_number
168
+ line_1
169
+ line_2
170
+ line_3
171
+ line_4
172
+ line_5
173
+ line_5
174
+ line_6
175
+ postcode
176
+ )
128
177
  end
129
178
 
130
- def expected_fields_in_sms_resp
179
+ def expected_fields_in_sms_notification
131
180
  %w(id
132
- api_key
133
- billable_units
134
- to
135
- body
136
- notification_type
137
- status
138
- service
139
- sent_at
140
- sent_by
141
- template
142
- template_version
143
- created_at
144
- updated_at
181
+ phone_number
182
+ type
183
+ status
184
+ sent_at
185
+ template
186
+ body
187
+ created_at
145
188
  )
146
189
  end
147
190
 
148
- def expected_fields_in_sms_resp_that_are_nil
149
- %w(job
150
- subject
151
- reference)
191
+ def expected_fields_in_sms_notification_that_are_nil
192
+ %w(email_address
193
+ line_1
194
+ line_2
195
+ line_3
196
+ line_4
197
+ line_5
198
+ line_5
199
+ line_6
200
+ postcode
201
+ subject)
202
+ end
203
+
204
+ def expected_fields_in_template
205
+ %w(id
206
+ version
207
+ uri)
152
208
  end
153
209
 
154
210
  def test_get_all_notifications(client, first_id, second_id)
@@ -173,8 +229,6 @@ end
173
229
 
174
230
  def expected_fields_for_get_all_notifications
175
231
  %W(links
176
- total
177
- page_size
178
232
  collection
179
233
  )
180
234
  end
data/docker/Dockerfile CHANGED
@@ -1,10 +1,12 @@
1
1
  FROM ruby:2.3.1-slim
2
2
 
3
- ARG APT_HTTP_PROXY
3
+ ARG HTTP_PROXY
4
+ ARG HTTPS_PROXY
5
+ ARG NO_PROXY
4
6
 
5
7
  RUN \
6
8
  echo "Install Debian packages" \
7
- && ([ -z "$APT_HTTP_PROXY" ] || echo "Acquire::http::Proxy \"${APT_HTTP_PROXY}\";\n" > /etc/apt/apt.conf.d/99HttpProxy) \
9
+ && ([ -z "$HTTP_PROXY" ] || echo "Acquire::http::Proxy \"${HTTP_PROXY}\";" > /etc/apt/apt.conf.d/99HttpProxy) \
8
10
  && apt-get update \
9
11
  && apt-get install -y --no-install-recommends \
10
12
  make \
data/docker/Makefile CHANGED
@@ -7,4 +7,10 @@ help:
7
7
 
8
8
  .PHONY: build
9
9
  build:
10
- docker build --pull -t govuk/notify-ruby-client-builder --build-arg APT_HTTP_PROXY="${HTTP_PROXY}" .
10
+ docker build \
11
+ --pull \
12
+ --build-arg HTTP_PROXY="${HTTP_PROXY}" \
13
+ --build-arg HTTPS_PROXY="${HTTP_PROXY}" \
14
+ --build-arg NO_PROXY="${NO_PROXY}" \
15
+ -t govuk/notify-ruby-client-builder \
16
+ .
@@ -55,9 +55,10 @@ module Notifications
55
55
  # @option options [String] :status
56
56
  # sending, delivered, permanently failed,
57
57
  # temporarily failed, or technical failure
58
- # @option options [String] :page
59
- # @option options [String] :page_size
60
- # @option options [String] :limit_days
58
+ # @option options [String] :reference
59
+ # your reference for the notification
60
+ # @option options [String] :olderThanId
61
+ # notification id to return notificaitons that are older than this id.
61
62
  # @see Notifications::Client::Speaker#get
62
63
  # @return [NotificationsCollection]
63
64
  def get_notifications(options = {})
@@ -3,28 +3,29 @@ module Notifications
3
3
  class Notification
4
4
  FIELDS = [
5
5
  :id,
6
- :api_key,
7
- :billable_units,
8
- :to,
9
- :subject,
10
- :body,
11
- :job,
12
- :notification_type,
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,
13
17
  :status,
14
- :service,
15
- :sent_at,
16
- :sent_by,
17
18
  :template,
18
- :template_version,
19
- :reference,
19
+ :body,
20
+ :subject,
21
+ :sent_at,
20
22
  :created_at,
21
- :updated_at
23
+ :completed_at
22
24
  ].freeze
23
25
 
24
26
  attr_reader(*FIELDS)
25
27
 
26
28
  def initialize(notification)
27
- notification = normalize(notification)
28
29
 
29
30
  FIELDS.each do |field|
30
31
  instance_variable_set(:"@#{field}", notification.fetch(field.to_s, nil)
@@ -35,7 +36,7 @@ module Notifications
35
36
  [
36
37
  :sent_at,
37
38
  :created_at,
38
- :updated_at
39
+ :completed_at
39
40
  ].each do |field|
40
41
  define_method field do
41
42
  begin
@@ -47,11 +48,6 @@ module Notifications
47
48
  end
48
49
  end
49
50
 
50
- private
51
-
52
- def normalize(notification)
53
- notification.key?('data') ? notification['data']['notification'] : notification
54
- end
55
51
  end
56
52
  end
57
53
  end
@@ -2,14 +2,10 @@ module Notifications
2
2
  class Client
3
3
  class NotificationsCollection
4
4
  attr_reader :links,
5
- :total,
6
- :page_size,
7
5
  :collection
8
6
 
9
7
  def initialize(response)
10
8
  @links = response["links"]
11
- @total = response["total"]
12
- @page_size = response["page_size"]
13
9
  @collection = collection_from(response["notifications"])
14
10
  end
15
11
 
@@ -13,7 +13,7 @@ module Notifications
13
13
  end
14
14
 
15
15
  def message_from(body)
16
- JSON.parse(body).fetch("message")
16
+ JSON.parse(body).fetch('errors')
17
17
  rescue JSON::ParserError
18
18
  body
19
19
  end
@@ -1,11 +1,25 @@
1
1
  module Notifications
2
2
  class Client
3
3
  class ResponseNotification
4
- attr_reader :id
4
+ FIELDS = [
5
+ :id,
6
+ :reference,
7
+ :content,
8
+ :template,
9
+ :uri
10
+ ].freeze
5
11
 
6
- def initialize(response)
7
- @id = response["data"]["notification"]["id"]
12
+
13
+ attr_reader(*FIELDS)
14
+
15
+ def initialize(notification)
16
+
17
+ FIELDS.each do |field|
18
+ instance_variable_set(:"@#{field}", notification.fetch(field.to_s, nil)
19
+ )
20
+ end
8
21
  end
22
+
9
23
  end
10
24
  end
11
25
  end
@@ -10,41 +10,34 @@ module Notifications
10
10
  attr_reader :service_id
11
11
  attr_reader :secret_token
12
12
 
13
- BASE_PATH = "/notifications".freeze
13
+ BASE_PATH = "/v2/notifications".freeze
14
14
  USER_AGENT = "NOTIFY-API-RUBY-CLIENT/#{Notifications::Client::VERSION}".freeze
15
15
 
16
16
  ##
17
- # @param service_id [String] your service
18
- # API identifier
19
- # @param secret [String] your service API
20
- # secret
21
- # @param base_url [String] host URL. This is
22
- # the address to perform the requests
23
- def initialize(service_id, secret_token = nil, base_url = nil)
24
- if secret_token == nil and base_url == nil
25
- @service_id = service_id[service_id.length - 73..service_id.length - 38]
26
- @secret_token = service_id[service_id.length - 36..service_id.length]
27
- @base_url = PRODUCTION_BASE_URL
28
- elsif secret_token.start_with?("http") and base_url == nil
29
- @service_id = service_id[service_id.length - 73..service_id.length - 38]
30
- @secret_token = service_id[service_id.length - 36..service_id.length]
31
- @base_url = secret_token
32
- else
33
- @service_id = service_id
34
- @secret_token = secret_token[secret_token.length - 36..secret_token.length]
35
- @base_url = base_url || PRODUCTION_BASE_URL
36
- end
17
+ # @param secret [String] your service API secret
18
+ # @param base_url [String] host URL. This is the address to perform the requests.
19
+ # If left nil the production url is used.
20
+ def initialize(secret_token = nil, base_url = nil)
21
+ @service_id = secret_token[secret_token.length - 73..secret_token.length - 38]
22
+ @secret_token = secret_token[secret_token.length - 36..secret_token.length]
23
+ @base_url = base_url || PRODUCTION_BASE_URL
37
24
  end
38
25
 
39
26
  ##
40
27
  # @param kind [String] 'email' or 'sms'
41
28
  # @param form_data [Hash]
42
- # @option form_data [String] :to recipient
43
- # to notify (sms or email)
29
+ # @option form_data [String] :phone_number
30
+ # phone number of the sms recipient
31
+ # @option form_data [String] :email_address
32
+ # email address of the email recipent
44
33
  # @option form_data [String] :template
45
34
  # template to render in notification
46
35
  # @option form_data [Hash] :personalisation
47
36
  # fields to use in the template
37
+ # @option form_data [String] :reference
38
+ # A reference specified by the service for the notification. Get all notifications can be filtered by this reference.
39
+ # This reference can be unique or used used to refer to a batch of notifications.
40
+ # Can be an empty string or nil, when you do not require a reference for the notifications.
48
41
  # @see #perform_request!
49
42
  def post(kind, form_data)
50
43
  request = Net::HTTP::Post.new(
@@ -1,5 +1,5 @@
1
1
  module Notifications
2
2
  class Client
3
- VERSION = "1.1.2".freeze
3
+ VERSION = "2.0.0".freeze
4
4
  end
5
5
  end
@@ -7,11 +7,10 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "notifications-ruby-client"
8
8
  spec.version = Notifications::Client::VERSION
9
9
  spec.authors = [
10
- "bitzesty",
11
- "dazahern"
10
+ "Government Digital Service"
12
11
  ]
13
12
 
14
- spec.email = ["info@bitzesty.com", "daz.ahern@digital.cabinet-office.gov.uk"]
13
+ spec.email = ["notify@digital.cabinet-office.gov.uk"]
15
14
 
16
15
  spec.summary = "Ruby client for GOV.UK Notifications API"
17
16
  spec.homepage = "https://github.com/alphagov/notifications-ruby-client"
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifications-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - bitzesty
8
- - dazahern
7
+ - Government Digital Service
9
8
  autorequire:
10
9
  bindir: exe
11
10
  cert_chain: []
12
- date: 2016-12-02 00:00:00.000000000 Z
11
+ date: 2017-01-06 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: jwt
@@ -111,14 +110,14 @@ dependencies:
111
110
  version: 1.1.0
112
111
  description:
113
112
  email:
114
- - info@bitzesty.com
115
- - daz.ahern@digital.cabinet-office.gov.uk
113
+ - notify@digital.cabinet-office.gov.uk
116
114
  executables: []
117
115
  extensions: []
118
116
  extra_rdoc_files: []
119
117
  files:
120
118
  - ".gitignore"
121
119
  - ".rspec"
120
+ - CHANGELOG.md
122
121
  - Gemfile
123
122
  - LICENSE
124
123
  - Makefile