gds-api-adapters 52.4.0 → 52.5.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: f25de033dd0924ac2e17348a1c1a8358aa7deb30c502a1ae6483595e997837ed
4
- data.tar.gz: 7f0dee4ad67cd1cbbb7e97cb924b96210f6d31480abf713032cdf604fa9a8f6f
3
+ metadata.gz: aec33b725938e09035043960dd0f4571f712bc71930eb93bd2684888730529af
4
+ data.tar.gz: ac1f9bd79d271352d0896f6997bdf5a6609afc33016d422bf0b66993bf31f566
5
5
  SHA512:
6
- metadata.gz: 44f54f5b8cf0a657ee42e4c876fc067397aba75f8319eef8b43aa48d4d8ba6a095f3e20965d38505ba18a64bbc9f22fc993f45014c990e28b74da933012e37b8
7
- data.tar.gz: 82f2662c2972eed87740a126c900f748cf44740443d30040ba05599324caf2b5324f21d9984ea382a01d86b9685aa1ab10de1aa24d2625757d5106d05c190d76
6
+ metadata.gz: 62ffe96af3f95e88ba37096f5eebef3ccaca181ab86e87cae1319f1eed8eedeee4ee4b4cf7eb65e8df201cc54980d9106a378207bbece98e55bce83503a3e205
7
+ data.tar.gz: e5acd2473f6c23bdf629f113bdd2cbfa6ef14e3cdd68bab07ef9bfa1895cebedcc3a7b6c79642add884c31cc730f85126a57baf2deebf926305bce45301fa472
@@ -69,19 +69,19 @@ class GdsApi::EmailAlertApi < GdsApi::Base
69
69
  end
70
70
 
71
71
  # Unsubscribe subscriber from subscription
72
- # #
73
- # @param uuid Subscription uuid
74
72
  #
75
- # @return null
73
+ # @param [string] Subscription uuid
74
+ #
75
+ # @return [nil]
76
76
  def unsubscribe(uuid)
77
77
  post_json("#{endpoint}/unsubscribe/#{uuid}")
78
78
  end
79
79
 
80
80
  # Unsubscribe subscriber from everything
81
- # #
82
- # @param integer Subscriber id
83
81
  #
84
- # @return null
82
+ # @param [integer] Subscriber id
83
+ #
84
+ # @return [nil]
85
85
  def unsubscribe_subscriber(id)
86
86
  delete_json("#{endpoint}/subscribers/#{id}")
87
87
  end
@@ -135,8 +135,8 @@ class GdsApi::EmailAlertApi < GdsApi::Base
135
135
  end
136
136
 
137
137
  # Get Subscriptions for a Subscriber
138
- # #
139
- # @param integer Subscriber id
138
+ #
139
+ # @param [integer] Subscriber id
140
140
  #
141
141
  # @return [Hash] subscriber, subscriptions
142
142
  def get_subscriptions(id:)
@@ -144,9 +144,9 @@ class GdsApi::EmailAlertApi < GdsApi::Base
144
144
  end
145
145
 
146
146
  # Patch a Subscriber
147
- # #
148
- # @param integer Subscriber id
149
- # @param string Subscriber new_address
147
+ #
148
+ # @param [integer] Subscriber id
149
+ # @param [string] Subscriber new_address
150
150
  #
151
151
  # @return [Hash] subscriber
152
152
  def change_subscriber(id:, new_address:)
@@ -157,9 +157,9 @@ class GdsApi::EmailAlertApi < GdsApi::Base
157
157
  end
158
158
 
159
159
  # Patch a Subscription
160
- # #
161
- # @param string Subscription id
162
- # @param string Subscription frequency
160
+ #
161
+ # @param [string] Subscription id
162
+ # @param [string] Subscription frequency
163
163
  #
164
164
  # @return [Hash] subscription
165
165
  def change_subscription(id:, frequency:)
@@ -169,6 +169,23 @@ class GdsApi::EmailAlertApi < GdsApi::Base
169
169
  )
170
170
  end
171
171
 
172
+ # Create an authentication token for a subscriber
173
+ #
174
+ # @param [string] address Email address of subscriber to create token for
175
+ # @param [string] destination Path on GOV.UK that subscriber will be emailed
176
+ # @param [string, nil] redirect Path on GOV.UK to be encoded into the token for redirecting
177
+ #
178
+ # @return [Hash] subscriber
179
+ #
180
+ def create_auth_token(address:, destination:, redirect: nil)
181
+ post_json(
182
+ "#{endpoint}/subscribers/auth-token",
183
+ address: address,
184
+ destination: destination,
185
+ redirect: redirect,
186
+ )
187
+ end
188
+
172
189
  private
173
190
 
174
191
  def nested_query_string(params)
@@ -7,7 +7,7 @@ module GdsApi
7
7
  EMAIL_ALERT_API_ENDPOINT = Plek.find("email-alert-api")
8
8
 
9
9
  def email_alert_api_has_updated_subscriber(id, new_address)
10
- stub_request(:patch, subscriber_url(id))
10
+ stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/#{id}")
11
11
  .to_return(
12
12
  status: 200,
13
13
  body: get_subscriber_response(id, new_address).to_json,
@@ -15,12 +15,12 @@ module GdsApi
15
15
  end
16
16
 
17
17
  def email_alert_api_does_not_have_updated_subscriber(id)
18
- stub_request(:patch, subscriber_url(id))
18
+ stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/#{id}")
19
19
  .to_return(status: 404)
20
20
  end
21
21
 
22
22
  def email_alert_api_has_updated_subscription(subscription_id, frequency)
23
- stub_request(:patch, subscription_url(subscription_id))
23
+ stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions/#{subscription_id}")
24
24
  .to_return(
25
25
  status: 200,
26
26
  body: get_subscription_response(subscription_id, frequency).to_json,
@@ -28,12 +28,12 @@ module GdsApi
28
28
  end
29
29
 
30
30
  def email_alert_api_does_not_have_updated_subscription(subscription_id)
31
- stub_request(:patch, subscription_url(subscription_id))
31
+ stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions/#{subscription_id}")
32
32
  .to_return(status: 404)
33
33
  end
34
34
 
35
35
  def email_alert_api_has_subscriber_subscriptions(id, address)
36
- stub_request(:get, subscriber_subscriptions_url(id))
36
+ stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/#{id}/subscriptions")
37
37
  .to_return(
38
38
  status: 200,
39
39
  body: get_subscriber_subscriptions_response(id, address).to_json,
@@ -41,12 +41,12 @@ module GdsApi
41
41
  end
42
42
 
43
43
  def email_alert_api_does_not_have_subscriber_subscriptions(id)
44
- stub_request(:get, subscriber_subscriptions_url(id))
44
+ stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/#{id}/subscriptions")
45
45
  .to_return(status: 404)
46
46
  end
47
47
 
48
48
  def email_alert_api_has_subscription(id, frequency, title: "Some title")
49
- stub_request(:get, subscription_url(id))
49
+ stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions/#{id}")
50
50
  .to_return(
51
51
  status: 200,
52
52
  body: get_subscription_response(id, frequency, title).to_json,
@@ -54,7 +54,7 @@ module GdsApi
54
54
  end
55
55
 
56
56
  def email_alert_api_has_subscriber_list(attributes)
57
- stub_request(:get, subscriber_lists_url(attributes))
57
+ stub_request(:get, build_subscriber_lists_url(attributes))
58
58
  .to_return(
59
59
  status: 200,
60
60
  body: get_subscriber_list_response(attributes).to_json,
@@ -62,12 +62,12 @@ module GdsApi
62
62
  end
63
63
 
64
64
  def email_alert_api_does_not_have_subscriber_list(attributes)
65
- stub_request(:get, subscriber_lists_url(attributes))
65
+ stub_request(:get, build_subscriber_lists_url(attributes))
66
66
  .to_return(status: 404)
67
67
  end
68
68
 
69
69
  def email_alert_api_creates_subscriber_list(attributes)
70
- stub_request(:post, subscriber_lists_url)
70
+ stub_request(:post, build_subscriber_lists_url)
71
71
  .to_return(
72
72
  status: 201,
73
73
  body: get_subscriber_list_response(attributes).to_json,
@@ -75,77 +75,13 @@ module GdsApi
75
75
  end
76
76
 
77
77
  def email_alert_api_refuses_to_create_subscriber_list
78
- stub_request(:post, subscriber_lists_url)
79
- .to_return(
80
- status: 422,
81
- )
82
- end
83
-
84
- def get_subscriber_response(id, address)
85
- {
86
- "subscriber" => {
87
- "id" => id,
88
- "address" => address
89
- }
90
- }
91
- end
92
-
93
- def get_subscription_response(id, frequency, title = "Some title")
94
- {
95
- "subscription" => {
96
- "subscriber_id" => 1,
97
- "subscriber_list_id" => 1000,
98
- "frequency" => frequency,
99
- "id" => id,
100
- "subscriber_list" => {
101
- "id" => 1000,
102
- "slug" => "some-thing",
103
- "title" => title,
104
- }
105
- }
106
- }
107
- end
108
-
109
- def get_subscriber_subscriptions_response(id, address)
110
- {
111
- "subscriber" => {
112
- "id" => id,
113
- "address" => address
114
- },
115
- "subscriptions" => [
116
- {
117
- "subscriber_id" => 1,
118
- "subscriber_list_id" => 1000,
119
- "frequency" => "daily",
120
- "id" => "447135c3-07d6-4c3a-8a3b-efa49ef70e52",
121
- "subscriber_list" => {
122
- "id" => 1000,
123
- "slug" => "some-thing"
124
- }
125
- }
126
- ]
127
- }
128
- end
129
-
130
- def get_subscriber_list_response(attributes)
131
- {
132
- "subscriber_list" => {
133
- "id" => "447135c3-07d6-4c3a-8a3b-efa49ef70e52",
134
- "title" => "Some title",
135
- }.merge(attributes)
136
- }
78
+ stub_request(:post, build_subscriber_lists_url)
79
+ .to_return(status: 422)
137
80
  end
138
81
 
139
82
  def email_alert_api_accepts_alert
140
- stub_request(:post, notifications_url)
141
- .to_return(
142
- status: 202,
143
- body: {}.to_json,
144
- )
145
- end
146
-
147
- def post_alert_response
148
- {}
83
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/notifications")
84
+ .to_return(status: 202, body: {}.to_json)
149
85
  end
150
86
 
151
87
  def stub_any_email_alert_api_call
@@ -160,11 +96,11 @@ module GdsApi
160
96
  end
161
97
  end
162
98
 
163
- assert_requested(:post, notifications_url, times: 1, &matcher)
99
+ assert_requested(:post, "#{EMAIL_ALERT_API_ENDPOINT}/notifications", times: 1, &matcher)
164
100
  end
165
101
 
166
102
  def email_alert_api_has_notifications(notifications, start_at = nil)
167
- url = notifications_url
103
+ url = "#{EMAIL_ALERT_API_ENDPOINT}/notifications"
168
104
  url += "?start_at=#{start_at}" if start_at
169
105
  url_regexp = Regexp.new("^#{Regexp.escape(url)}$")
170
106
 
@@ -176,7 +112,7 @@ module GdsApi
176
112
  end
177
113
 
178
114
  def email_alert_api_has_notification(notification)
179
- url = "#{notifications_url}/#{notification['web_service_bulletin']['to_param']}"
115
+ url = "#{EMAIL_ALERT_API_ENDPOINT}/notifications/#{notification['web_service_bulletin']['to_param']}"
180
116
 
181
117
  stub_request(:get, url).to_return(
182
118
  status: 200,
@@ -185,54 +121,62 @@ module GdsApi
185
121
  end
186
122
 
187
123
  def email_alert_api_unsubscribes_a_subscription(uuid)
188
- stub_request(:post, unsubscribe_url(uuid))
124
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/unsubscribe/#{uuid}")
189
125
  .with(body: "{}")
190
126
  .to_return(status: 204)
191
127
  end
192
128
 
193
129
  def email_alert_api_has_no_subscription_for_uuid(uuid)
194
- stub_request(:post, unsubscribe_url(uuid))
130
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/unsubscribe/#{uuid}")
195
131
  .with(body: "{}")
196
132
  .to_return(status: 404)
197
133
  end
198
134
 
199
135
  def email_alert_api_unsubscribes_a_subscriber(subscriber_id)
200
- stub_request(:delete, unsubscribe_subscriber_url(subscriber_id))
136
+ stub_request(:delete, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/#{subscriber_id}")
201
137
  .to_return(status: 204)
202
138
  end
203
139
 
204
140
  def email_alert_api_has_no_subscriber(subscriber_id)
205
- stub_request(:delete, unsubscribe_subscriber_url(subscriber_id))
141
+ stub_request(:delete, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/#{subscriber_id}")
206
142
  .to_return(status: 404)
207
143
  end
208
144
 
209
145
  def email_alert_api_creates_a_subscription(subscribable_id, address, frequency, returned_subscription_id)
210
- stub_request(:post, subscribe_url)
146
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions")
211
147
  .with(
212
148
  body: { subscribable_id: subscribable_id, address: address, frequency: frequency }.to_json
213
149
  ).to_return(status: 201, body: { subscription_id: returned_subscription_id }.to_json)
214
150
  end
215
151
 
216
152
  def email_alert_api_creates_an_existing_subscription(subscribable_id, address, frequency, returned_subscription_id)
217
- stub_request(:post, subscribe_url)
153
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions")
218
154
  .with(
219
155
  body: { subscribable_id: subscribable_id, address: address, frequency: frequency }.to_json
220
156
  ).to_return(status: 200, body: { subscription_id: returned_subscription_id }.to_json)
221
157
  end
222
158
 
223
159
  def email_alert_api_refuses_to_create_subscription(subscribable_id, address, frequency)
224
- stub_request(:post, subscribe_url)
160
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions")
225
161
  .with(
226
162
  body: { subscribable_id: subscribable_id, address: address, frequency: frequency }.to_json
227
163
  ).to_return(status: 422)
228
164
  end
229
165
 
166
+ def email_alert_api_creates_an_auth_token(subscriber_id, address)
167
+ stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/auth-token")
168
+ .to_return(
169
+ status: 201,
170
+ body: get_subscriber_response(subscriber_id, address).to_json
171
+ )
172
+ end
173
+
230
174
  def assert_unsubscribed(uuid)
231
- assert_requested(:post, unsubscribe_url(uuid), times: 1)
175
+ assert_requested(:post, "#{EMAIL_ALERT_API_ENDPOINT}/unsubscribe/#{uuid}", times: 1)
232
176
  end
233
177
 
234
178
  def assert_subscribed(subscribable_id, address, frequency = "immediately")
235
- assert_requested(:post, subscribe_url) do |req|
179
+ assert_requested(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions") do |req|
236
180
  JSON.parse(req.body).symbolize_keys == {
237
181
  subscribable_id: subscribable_id,
238
182
  address: address,
@@ -242,7 +186,7 @@ module GdsApi
242
186
  end
243
187
 
244
188
  def email_alert_api_has_subscribable(reference:, returned_attributes:)
245
- stub_request(:get, subscribable_url(reference))
189
+ stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscribables/#{reference}")
246
190
  .to_return(
247
191
  status: 200,
248
192
  body: {
@@ -252,13 +196,72 @@ module GdsApi
252
196
  end
253
197
 
254
198
  def email_alert_api_does_not_have_subscribable(reference:)
255
- stub_request(:get, subscribable_url(reference))
199
+ stub_request(:get, "#{EMAIL_ALERT_API_ENDPOINT}/subscribables/#{reference}")
256
200
  .to_return(status: 404)
257
201
  end
258
202
 
259
203
  private
260
204
 
261
- def subscriber_lists_url(attributes = nil)
205
+ def get_subscriber_response(id, address)
206
+ {
207
+ "subscriber" => {
208
+ "id" => id,
209
+ "address" => address
210
+ }
211
+ }
212
+ end
213
+
214
+ def get_subscription_response(id, frequency, title = "Some title")
215
+ {
216
+ "subscription" => {
217
+ "subscriber_id" => 1,
218
+ "subscriber_list_id" => 1000,
219
+ "frequency" => frequency,
220
+ "id" => id,
221
+ "subscriber_list" => {
222
+ "id" => 1000,
223
+ "slug" => "some-thing",
224
+ "title" => title,
225
+ }
226
+ }
227
+ }
228
+ end
229
+
230
+ def get_subscriber_subscriptions_response(id, address)
231
+ {
232
+ "subscriber" => {
233
+ "id" => id,
234
+ "address" => address
235
+ },
236
+ "subscriptions" => [
237
+ {
238
+ "subscriber_id" => 1,
239
+ "subscriber_list_id" => 1000,
240
+ "frequency" => "daily",
241
+ "id" => "447135c3-07d6-4c3a-8a3b-efa49ef70e52",
242
+ "subscriber_list" => {
243
+ "id" => 1000,
244
+ "slug" => "some-thing"
245
+ }
246
+ }
247
+ ]
248
+ }
249
+ end
250
+
251
+ def get_subscriber_list_response(attributes)
252
+ {
253
+ "subscriber_list" => {
254
+ "id" => "447135c3-07d6-4c3a-8a3b-efa49ef70e52",
255
+ "title" => "Some title",
256
+ }.merge(attributes)
257
+ }
258
+ end
259
+
260
+ def post_alert_response
261
+ {}
262
+ end
263
+
264
+ def build_subscriber_lists_url(attributes = nil)
262
265
  if attributes
263
266
  tags = attributes["tags"]
264
267
  links = attributes["links"]
@@ -278,41 +281,9 @@ module GdsApi
278
281
  query = Rack::Utils.build_nested_query(params)
279
282
  end
280
283
 
281
- url = EMAIL_ALERT_API_ENDPOINT + "/subscriber-lists"
284
+ url = "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists"
282
285
  query ? "#{url}?#{query}" : url
283
286
  end
284
-
285
- def notifications_url
286
- EMAIL_ALERT_API_ENDPOINT + "/notifications"
287
- end
288
-
289
- def unsubscribe_url(uuid)
290
- EMAIL_ALERT_API_ENDPOINT + "/unsubscribe/#{uuid}"
291
- end
292
-
293
- def unsubscribe_subscriber_url(id)
294
- EMAIL_ALERT_API_ENDPOINT + "/subscribers/#{id}"
295
- end
296
-
297
- def subscribe_url
298
- EMAIL_ALERT_API_ENDPOINT + "/subscriptions"
299
- end
300
-
301
- def subscription_url(id)
302
- EMAIL_ALERT_API_ENDPOINT + "/subscriptions/#{id}"
303
- end
304
-
305
- def subscribable_url(reference)
306
- EMAIL_ALERT_API_ENDPOINT + "/subscribables/#{reference}"
307
- end
308
-
309
- def subscriber_url(id)
310
- EMAIL_ALERT_API_ENDPOINT + "/subscribers/#{id}"
311
- end
312
-
313
- def subscriber_subscriptions_url(id)
314
- EMAIL_ALERT_API_ENDPOINT + "/subscribers/#{id}/subscriptions"
315
- end
316
287
  end
317
288
  end
318
289
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '52.4.0'.freeze
2
+ VERSION = '52.5.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 52.4.0
4
+ version: 52.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-23 00:00:00.000000000 Z
11
+ date: 2018-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plek