gds-api-adapters 79.2.0 → 81.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +28 -0
- data/lib/gds_api/email_alert_api.rb +1 -1
- data/lib/gds_api/local_links_manager.rb +10 -0
- data/lib/gds_api/publishing_api.rb +0 -17
- data/lib/gds_api/test_helpers/email_alert_api.rb +16 -16
- data/lib/gds_api/test_helpers/local_links_manager.rb +64 -18
- data/lib/gds_api/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b05bc427e1871e4a8b4d0abbd4a0f33bede6a2e2abd1dc9538d734d19bcd7715
|
4
|
+
data.tar.gz: 3a824dc05509ad151471dcec3e5d536b4036af83d64ce93d614b6a6ff22deda7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a289fa007a4da3cb78bb31f8647aa43bf3e49fd43c1a2bb6e63f00fd60b03448b1fbf4e5ee7e1881cce8bbc9011db5d75478dc0c6833d42813aa7a010e60f52d
|
7
|
+
data.tar.gz: d1680c586b6443e1a1a95d4ea1195664de2f9ca971d8d3b764d5767813b41cd82f91704ff6c4d63a4a71de2a2ff13292d5ba09ea0d3954f6c3061576b1714451
|
data/README.md
CHANGED
@@ -82,6 +82,34 @@ There are also test helpers for stubbing various requests in other apps.
|
|
82
82
|
|
83
83
|
See [all the test helpers in lib/gds_api/test_helpers](/lib/gds_api/test_helpers).
|
84
84
|
|
85
|
+
|
86
|
+
## Pact Verification During CI
|
87
|
+
|
88
|
+
During the CI test suite, Jenkins downloads and runs the pact:verify tasks for
|
89
|
+
each provider app. It's run directly on the Jenkins machine rather than in
|
90
|
+
docker containers for each app. For this reason the email-alert-api app
|
91
|
+
requires a specific setup on the CI machine - on db creation it copies the
|
92
|
+
database from the template1 db (this is the usual PG behaviour, but for some
|
93
|
+
reason rails needs to be told to do this explicitly). This template1 db has
|
94
|
+
to have the uuid-ossp extension installed by superuser, because the jenkins
|
95
|
+
user that CI runs under cannot create this extension. If this test stops
|
96
|
+
working with errors like:
|
97
|
+
|
98
|
+
```
|
99
|
+
Caused by:
|
100
|
+
PG::InsufficientPrivilege: ERROR: permission denied to create extension "uuid-ossp"
|
101
|
+
HINT: Must be superuser to create this extension.
|
102
|
+
```
|
103
|
+
|
104
|
+
...the template may have been deleted or changed. Log in to the relevant CI
|
105
|
+
agent and run:
|
106
|
+
|
107
|
+
`> sudo -u postgres psql -d template1`
|
108
|
+
|
109
|
+
Then at the PSQL command line:
|
110
|
+
|
111
|
+
`template1=# CREATE EXTENSION IF NOT EXISTS "uuid-ossp";`
|
112
|
+
|
85
113
|
## Licence
|
86
114
|
|
87
115
|
Released under the MIT Licence, a copy of which can be found in the file
|
@@ -252,7 +252,7 @@ class GdsApi::EmailAlertApi < GdsApi::Base
|
|
252
252
|
# optionally send a notification email explaining the reason
|
253
253
|
#
|
254
254
|
# @param [string] slug Identifier for the subscription list
|
255
|
-
# @param [string] (optional) govuk_request_id An ID allowing us to trace requests across our infra. Required if you want to send an email.
|
255
|
+
# @param [string] (optional) govuk_request_id An ID allowing us to trace requests across our infra. Required if you want to send an email by running out-of-band processes via asynchronous workers.
|
256
256
|
# @param [string] (optional) body Optional email body to send to alert users they are being unsubscribed. Required if you want to send an email
|
257
257
|
# @param [string] (optional) sender_message_id A UUID to prevent multiple emails for the same event. Required if you want to send an email.
|
258
258
|
def bulk_unsubscribe(slug:, govuk_request_id: nil, body: nil, sender_message_id: nil)
|
@@ -6,8 +6,18 @@ class GdsApi::LocalLinksManager < GdsApi::Base
|
|
6
6
|
get_json(url)
|
7
7
|
end
|
8
8
|
|
9
|
+
def local_link_by_custodian_code(local_custodian_code, lgsl, lgil)
|
10
|
+
url = "#{endpoint}/api/link?local_custodian_code=#{local_custodian_code}&lgsl=#{lgsl}&lgil=#{lgil}"
|
11
|
+
get_json(url)
|
12
|
+
end
|
13
|
+
|
9
14
|
def local_authority(authority_slug)
|
10
15
|
url = "#{endpoint}/api/local-authority?authority_slug=#{authority_slug}"
|
11
16
|
get_json(url)
|
12
17
|
end
|
18
|
+
|
19
|
+
def local_authority_by_custodian_code(local_custodian_code)
|
20
|
+
url = "#{endpoint}/api/local-authority?local_custodian_code=#{local_custodian_code}"
|
21
|
+
get_json(url)
|
22
|
+
end
|
13
23
|
end
|
@@ -150,23 +150,6 @@ class GdsApi::PublishingApi < GdsApi::Base
|
|
150
150
|
post_json(republish_url(content_id), params)
|
151
151
|
end
|
152
152
|
|
153
|
-
# Import content into the publishing API
|
154
|
-
#
|
155
|
-
# The publishing-api will delete any content which has the content
|
156
|
-
# id provided, and then import the data given.
|
157
|
-
#
|
158
|
-
# @param content_id [UUID]
|
159
|
-
# @param content_items [Array]
|
160
|
-
#
|
161
|
-
# @see https://github.com/alphagov/publishing-api/blob/main/docs/api.md#post-v2contentcontent_idimport
|
162
|
-
def import(content_id, locale, content_items)
|
163
|
-
params = {
|
164
|
-
history: content_items,
|
165
|
-
}
|
166
|
-
|
167
|
-
post_json("#{endpoint}/v2/content/#{content_id}/import?locale=#{locale}", params)
|
168
|
-
end
|
169
|
-
|
170
153
|
# Unpublish a content item
|
171
154
|
#
|
172
155
|
# The publishing API will "unpublish" a live item, to remove it from the public
|
@@ -413,15 +413,15 @@ module GdsApi
|
|
413
413
|
.to_return(status: 202)
|
414
414
|
end
|
415
415
|
|
416
|
-
def stub_email_alert_api_bulk_unsubscribe_with_message(slug:,
|
416
|
+
def stub_email_alert_api_bulk_unsubscribe_with_message(slug:, body:, sender_message_id:, govuk_request_id: nil)
|
417
417
|
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
|
418
|
-
.with(
|
418
|
+
.with({
|
419
419
|
body: {
|
420
420
|
body: body,
|
421
421
|
sender_message_id: sender_message_id,
|
422
422
|
}.to_json,
|
423
|
-
|
424
|
-
|
423
|
+
}.tap { |attr| attr[:headers] = { "Govuk-Request-Id" => govuk_request_id } if govuk_request_id })
|
424
|
+
.to_return(status: 202)
|
425
425
|
end
|
426
426
|
|
427
427
|
def stub_email_alert_api_bulk_unsubscribe_not_found(slug:)
|
@@ -429,15 +429,15 @@ module GdsApi
|
|
429
429
|
.to_return(status: 404)
|
430
430
|
end
|
431
431
|
|
432
|
-
def stub_email_alert_api_bulk_unsubscribe_not_found_with_message(slug:,
|
432
|
+
def stub_email_alert_api_bulk_unsubscribe_not_found_with_message(slug:, body:, sender_message_id:, govuk_request_id: nil)
|
433
433
|
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
|
434
|
-
.with(
|
434
|
+
.with({
|
435
435
|
body: {
|
436
436
|
body: body,
|
437
437
|
sender_message_id: sender_message_id,
|
438
438
|
}.to_json,
|
439
|
-
|
440
|
-
|
439
|
+
}.tap { |attr| attr[:headers] = { "Govuk-Request-Id" => govuk_request_id } if govuk_request_id })
|
440
|
+
.to_return(status: 404)
|
441
441
|
end
|
442
442
|
|
443
443
|
def stub_email_alert_api_bulk_unsubscribe_conflict(slug:)
|
@@ -445,15 +445,15 @@ module GdsApi
|
|
445
445
|
.to_return(status: 409)
|
446
446
|
end
|
447
447
|
|
448
|
-
def stub_email_alert_api_bulk_unsubscribe_conflict_with_message(slug:,
|
448
|
+
def stub_email_alert_api_bulk_unsubscribe_conflict_with_message(slug:, body:, sender_message_id:, govuk_request_id: nil)
|
449
449
|
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
|
450
|
-
.with(
|
450
|
+
.with({
|
451
451
|
body: {
|
452
452
|
body: body,
|
453
453
|
sender_message_id: sender_message_id,
|
454
454
|
}.to_json,
|
455
|
-
|
456
|
-
|
455
|
+
}.tap { |attr| attr[:headers] = { "Govuk-Request-Id" => govuk_request_id } if govuk_request_id })
|
456
|
+
.to_return(status: 409)
|
457
457
|
end
|
458
458
|
|
459
459
|
def stub_email_alert_api_bulk_unsubscribe_bad_request(slug:)
|
@@ -461,15 +461,15 @@ module GdsApi
|
|
461
461
|
.to_return(status: 422)
|
462
462
|
end
|
463
463
|
|
464
|
-
def stub_email_alert_api_bulk_unsubscribe_bad_request_with_message(slug:,
|
464
|
+
def stub_email_alert_api_bulk_unsubscribe_bad_request_with_message(slug:, body:, sender_message_id:, govuk_request_id: nil)
|
465
465
|
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
|
466
|
-
.with(
|
466
|
+
.with({
|
467
467
|
body: {
|
468
468
|
body: body,
|
469
469
|
sender_message_id: sender_message_id,
|
470
470
|
}.to_json,
|
471
|
-
|
472
|
-
|
471
|
+
}.tap { |attr| attr[:headers] = { "Govuk-Request-Id" => govuk_request_id } if govuk_request_id })
|
472
|
+
.to_return(status: 422)
|
473
473
|
end
|
474
474
|
|
475
475
|
def stub_update_subscriber_list_details(slug:, params:)
|
@@ -5,7 +5,7 @@ module GdsApi
|
|
5
5
|
module LocalLinksManager
|
6
6
|
LOCAL_LINKS_MANAGER_ENDPOINT = Plek.current.find("local-links-manager")
|
7
7
|
|
8
|
-
def stub_local_links_manager_has_a_link(authority_slug:, lgsl:, lgil:, url:, country_name: "England", status: "ok")
|
8
|
+
def stub_local_links_manager_has_a_link(authority_slug:, lgsl:, lgil:, url:, country_name: "England", status: "ok", local_custodian_code: nil)
|
9
9
|
response = {
|
10
10
|
"local_authority" => {
|
11
11
|
"name" => authority_slug.capitalize,
|
@@ -13,6 +13,7 @@ module GdsApi
|
|
13
13
|
"tier" => "unitary",
|
14
14
|
"homepage_url" => "http://#{authority_slug}.example.com",
|
15
15
|
"country_name" => country_name,
|
16
|
+
"slug" => authority_slug,
|
16
17
|
},
|
17
18
|
"local_interaction" => {
|
18
19
|
"lgsl_code" => lgsl,
|
@@ -25,9 +26,15 @@ module GdsApi
|
|
25
26
|
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
|
26
27
|
.with(query: { authority_slug: authority_slug, lgsl: lgsl, lgil: lgil })
|
27
28
|
.to_return(body: response.to_json, status: 200)
|
29
|
+
|
30
|
+
unless local_custodian_code.nil?
|
31
|
+
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
|
32
|
+
.with(query: { local_custodian_code: local_custodian_code, lgsl: lgsl, lgil: lgil })
|
33
|
+
.to_return(body: response.to_json, status: 200)
|
34
|
+
end
|
28
35
|
end
|
29
36
|
|
30
|
-
def stub_local_links_manager_has_no_link(authority_slug:, lgsl:, lgil:, country_name: "England")
|
37
|
+
def stub_local_links_manager_has_no_link(authority_slug:, lgsl:, lgil:, country_name: "England", local_custodian_code: nil)
|
31
38
|
response = {
|
32
39
|
"local_authority" => {
|
33
40
|
"name" => authority_slug.capitalize,
|
@@ -35,15 +42,22 @@ module GdsApi
|
|
35
42
|
"tier" => "unitary",
|
36
43
|
"homepage_url" => "http://#{authority_slug}.example.com",
|
37
44
|
"country_name" => country_name,
|
45
|
+
"slug" => authority_slug,
|
38
46
|
},
|
39
47
|
}
|
40
48
|
|
41
49
|
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
|
42
50
|
.with(query: { authority_slug: authority_slug, lgsl: lgsl, lgil: lgil })
|
43
51
|
.to_return(body: response.to_json, status: 200)
|
52
|
+
|
53
|
+
unless local_custodian_code.nil?
|
54
|
+
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
|
55
|
+
.with(query: { local_custodian_code: local_custodian_code, lgsl: lgsl, lgil: lgil })
|
56
|
+
.to_return(body: response.to_json, status: 200)
|
57
|
+
end
|
44
58
|
end
|
45
59
|
|
46
|
-
def stub_local_links_manager_has_no_link_and_no_homepage_url(authority_slug:, lgsl:, lgil:, country_name: "England")
|
60
|
+
def stub_local_links_manager_has_no_link_and_no_homepage_url(authority_slug:, lgsl:, lgil:, country_name: "England", local_custodian_code: nil)
|
47
61
|
response = {
|
48
62
|
"local_authority" => {
|
49
63
|
"name" => authority_slug.capitalize,
|
@@ -51,36 +65,40 @@ module GdsApi
|
|
51
65
|
"tier" => "unitary",
|
52
66
|
"homepage_url" => nil,
|
53
67
|
"country_name" => country_name,
|
68
|
+
"slug" => authority_slug,
|
54
69
|
},
|
55
70
|
}
|
56
71
|
|
57
72
|
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
|
58
73
|
.with(query: { authority_slug: authority_slug, lgsl: lgsl, lgil: lgil })
|
59
74
|
.to_return(body: response.to_json, status: 200)
|
60
|
-
end
|
61
75
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
}
|
76
|
+
unless local_custodian_code.nil?
|
77
|
+
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
|
78
|
+
.with(query: { local_custodian_code: local_custodian_code, lgsl: lgsl, lgil: lgil })
|
79
|
+
.to_return(body: response.to_json, status: 200)
|
80
|
+
end
|
81
|
+
end
|
69
82
|
|
83
|
+
def stub_local_links_manager_request_with_missing_parameters(**parameters)
|
70
84
|
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
|
71
|
-
.with(query:
|
85
|
+
.with(query: convert_to_query_string_params(parameters))
|
72
86
|
.to_return(body: {}.to_json, status: 400)
|
73
87
|
end
|
74
88
|
|
75
|
-
def
|
76
|
-
params = { authority_slug: authority_slug, lgsl: lgsl, lgil: lgil }
|
77
|
-
|
89
|
+
def stub_local_links_manager_request_with_invalid_parameters(**parameters)
|
78
90
|
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/link")
|
79
|
-
.with(query:
|
91
|
+
.with(query: convert_to_query_string_params(parameters))
|
80
92
|
.to_return(body: {}.to_json, status: 404)
|
81
93
|
end
|
82
94
|
|
83
|
-
def
|
95
|
+
def convert_to_query_string_params(parameters)
|
96
|
+
# convert nil to an empty string, otherwise query param is not expressed correctly
|
97
|
+
parameters.each { |key, _value| parameters[key] = "" if parameters[key].nil? }
|
98
|
+
parameters
|
99
|
+
end
|
100
|
+
|
101
|
+
def stub_local_links_manager_has_a_local_authority(authority_slug, local_custodian_code: nil)
|
84
102
|
response = {
|
85
103
|
"local_authorities" => [
|
86
104
|
{
|
@@ -88,6 +106,7 @@ module GdsApi
|
|
88
106
|
"homepage_url" => "http://#{authority_slug}.example.com",
|
89
107
|
"country_name" => "England",
|
90
108
|
"tier" => "unitary",
|
109
|
+
"slug" => authority_slug,
|
91
110
|
},
|
92
111
|
],
|
93
112
|
}
|
@@ -95,9 +114,15 @@ module GdsApi
|
|
95
114
|
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
|
96
115
|
.with(query: { authority_slug: authority_slug })
|
97
116
|
.to_return(body: response.to_json, status: 200)
|
117
|
+
|
118
|
+
unless local_custodian_code.nil?
|
119
|
+
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
|
120
|
+
.with(query: { local_custodian_code: local_custodian_code })
|
121
|
+
.to_return(body: response.to_json, status: 200)
|
122
|
+
end
|
98
123
|
end
|
99
124
|
|
100
|
-
def stub_local_links_manager_has_a_district_and_county_local_authority(district_slug, county_slug)
|
125
|
+
def stub_local_links_manager_has_a_district_and_county_local_authority(district_slug, county_slug, local_custodian_code: nil)
|
101
126
|
response = {
|
102
127
|
"local_authorities" => [
|
103
128
|
{
|
@@ -105,12 +130,14 @@ module GdsApi
|
|
105
130
|
"homepage_url" => "http://#{district_slug}.example.com",
|
106
131
|
"country_name" => "England",
|
107
132
|
"tier" => "district",
|
133
|
+
"slug" => district_slug,
|
108
134
|
},
|
109
135
|
{
|
110
136
|
"name" => county_slug.capitalize,
|
111
137
|
"homepage_url" => "http://#{county_slug}.example.com",
|
112
138
|
"country_name" => "England",
|
113
139
|
"tier" => "county",
|
140
|
+
"slug" => county_slug,
|
114
141
|
},
|
115
142
|
],
|
116
143
|
}
|
@@ -118,6 +145,12 @@ module GdsApi
|
|
118
145
|
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
|
119
146
|
.with(query: { authority_slug: district_slug })
|
120
147
|
.to_return(body: response.to_json, status: 200)
|
148
|
+
|
149
|
+
unless local_custodian_code.nil?
|
150
|
+
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
|
151
|
+
.with(query: { local_custodian_code: local_custodian_code })
|
152
|
+
.to_return(body: response.to_json, status: 200)
|
153
|
+
end
|
121
154
|
end
|
122
155
|
|
123
156
|
def stub_local_links_manager_request_without_local_authority_slug
|
@@ -126,12 +159,24 @@ module GdsApi
|
|
126
159
|
.to_return(body: {}.to_json, status: 400)
|
127
160
|
end
|
128
161
|
|
162
|
+
def stub_local_links_manager_request_without_local_custodian_code
|
163
|
+
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
|
164
|
+
.with(query: { local_custodian_code: "" })
|
165
|
+
.to_return(body: {}.to_json, status: 400)
|
166
|
+
end
|
167
|
+
|
129
168
|
def stub_local_links_manager_does_not_have_an_authority(authority_slug)
|
130
169
|
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
|
131
170
|
.with(query: { authority_slug: authority_slug })
|
132
171
|
.to_return(body: {}.to_json, status: 404)
|
133
172
|
end
|
134
173
|
|
174
|
+
def stub_local_links_manager_does_not_have_a_custodian_code(local_custodian_code)
|
175
|
+
stub_request(:get, "#{LOCAL_LINKS_MANAGER_ENDPOINT}/api/local-authority")
|
176
|
+
.with(query: { local_custodian_code: local_custodian_code })
|
177
|
+
.to_return(body: {}.to_json, status: 404)
|
178
|
+
end
|
179
|
+
|
135
180
|
def stub_local_links_manager_has_a_local_authority_without_homepage(authority_slug)
|
136
181
|
response = {
|
137
182
|
"local_authorities" => [
|
@@ -140,6 +185,7 @@ module GdsApi
|
|
140
185
|
"homepage_url" => "",
|
141
186
|
"country_name" => "England",
|
142
187
|
"tier" => "unitary",
|
188
|
+
"slug" => authority_slug,
|
143
189
|
},
|
144
190
|
],
|
145
191
|
}
|
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:
|
4
|
+
version: 81.0.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: 2022-
|
11
|
+
date: 2022-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -440,14 +440,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
440
440
|
requirements:
|
441
441
|
- - ">="
|
442
442
|
- !ruby/object:Gem::Version
|
443
|
-
version: 2.
|
443
|
+
version: 2.7.0
|
444
444
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
445
445
|
requirements:
|
446
446
|
- - ">="
|
447
447
|
- !ruby/object:Gem::Version
|
448
448
|
version: '0'
|
449
449
|
requirements: []
|
450
|
-
rubygems_version: 3.
|
450
|
+
rubygems_version: 3.1.6
|
451
451
|
signing_key:
|
452
452
|
specification_version: 4
|
453
453
|
summary: Adapters to work with GDS APIs
|