gds-api-adapters 52.4.0 → 52.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gds_api/email_alert_api.rb +31 -14
- data/lib/gds_api/test_helpers/email_alert_api.rb +97 -126
- data/lib/gds_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aec33b725938e09035043960dd0f4571f712bc71930eb93bd2684888730529af
|
4
|
+
data.tar.gz: ac1f9bd79d271352d0896f6997bdf5a6609afc33016d422bf0b66993bf31f566
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
# @
|
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
|
-
# @
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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 =
|
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 = "#{
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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
|
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
|
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
|
data/lib/gds_api/version.rb
CHANGED
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
|
+
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-
|
11
|
+
date: 2018-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plek
|