gds-api-adapters 67.2.0 → 69.0.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 +2 -37
- data/lib/gds_api/exceptions.rb +3 -0
- data/lib/gds_api/mapit.rb +4 -0
- data/lib/gds_api/publishing_api/special_route_publisher.rb +6 -3
- data/lib/gds_api/test_helpers/email_alert_api.rb +23 -34
- data/lib/gds_api/test_helpers/local_links_manager.rb +10 -3
- data/lib/gds_api/test_helpers/mapit.rb +14 -0
- 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: b5de255ce4237b87f433deb2306447f9bda4534d3d85cad5b2ea3053b8d2dda1
|
4
|
+
data.tar.gz: 2144a904a6f4b3eeb6d0ec0c14b11d680d844f37c432d8c2909f843ce67a6927
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d045fefa180fd19839f9f10db2f6743bfe6e70f916434d486dd1745c8457b2874870f4fbd7f3f46eca5ee010afe9fc01b3b63e625694684d36feae3b69febb4b
|
7
|
+
data.tar.gz: 812e40c01ab8876121451782fbf6103facfe9dd97f2e1b246a047ef3ec628f116dda681f7de2bdd36dfdc8fafd8ae8ba450bfed00da3b9100a02abd8ee51c78e
|
@@ -10,39 +10,12 @@ class GdsApi::EmailAlertApi < GdsApi::Base
|
|
10
10
|
#
|
11
11
|
# @param attributes [Hash] document_type, links, tags used to search existing subscriber lists
|
12
12
|
def find_or_create_subscriber_list(attributes)
|
13
|
-
|
14
|
-
rescue GdsApi::HTTPNotFound
|
15
|
-
create_subscriber_list(attributes)
|
16
|
-
end
|
17
|
-
|
18
|
-
# Get a subscriber list
|
19
|
-
#
|
20
|
-
# @param attributes [Hash] document_type, links, tags used to search existing subscriber lists
|
21
|
-
def find_subscriber_list(attributes)
|
22
|
-
tags = attributes["tags"]
|
23
|
-
links = attributes["links"]
|
24
|
-
document_type = attributes["document_type"]
|
25
|
-
email_document_supertype = attributes["email_document_supertype"]
|
26
|
-
government_document_supertype = attributes["government_document_supertype"]
|
27
|
-
gov_delivery_id = attributes["gov_delivery_id"]
|
28
|
-
combine_mode = attributes["combine_mode"]
|
29
|
-
|
30
|
-
if tags && links
|
13
|
+
if attributes["tags"] && attributes["links"]
|
31
14
|
message = "please provide either tags or links (or neither), but not both"
|
32
15
|
raise ArgumentError, message
|
33
16
|
end
|
34
17
|
|
35
|
-
|
36
|
-
params[:tags] = tags if tags
|
37
|
-
params[:links] = links if links
|
38
|
-
params[:document_type] = document_type if document_type
|
39
|
-
params[:email_document_supertype] = email_document_supertype if email_document_supertype
|
40
|
-
params[:government_document_supertype] = government_document_supertype if government_document_supertype
|
41
|
-
params[:gov_delivery_id] = gov_delivery_id if gov_delivery_id
|
42
|
-
params[:combine_mode] = combine_mode if combine_mode
|
43
|
-
|
44
|
-
query_string = nested_query_string(params)
|
45
|
-
get_json("#{endpoint}/subscriber-lists?" + query_string)
|
18
|
+
create_subscriber_list(attributes)
|
46
19
|
end
|
47
20
|
|
48
21
|
# Post a subscriber list
|
@@ -66,13 +39,6 @@ class GdsApi::EmailAlertApi < GdsApi::Base
|
|
66
39
|
post_json("#{endpoint}/messages", message, headers)
|
67
40
|
end
|
68
41
|
|
69
|
-
# Send email
|
70
|
-
#
|
71
|
-
# @param email_params [Hash] address, subject, body
|
72
|
-
def create_email(email_params)
|
73
|
-
post_json("#{endpoint}/emails", email_params)
|
74
|
-
end
|
75
|
-
|
76
42
|
# Unpublishing alert
|
77
43
|
#
|
78
44
|
# @param message [Hash] content_id
|
@@ -131,7 +97,6 @@ class GdsApi::EmailAlertApi < GdsApi::Base
|
|
131
97
|
# @return [Hash] subscriber_list: {
|
132
98
|
# id
|
133
99
|
# title
|
134
|
-
# gov_delivery_id
|
135
100
|
# created_at
|
136
101
|
# updated_at
|
137
102
|
# document_type
|
data/lib/gds_api/exceptions.rb
CHANGED
@@ -40,6 +40,7 @@ module GdsApi
|
|
40
40
|
class HTTPForbidden < HTTPClientError; end
|
41
41
|
class HTTPConflict < HTTPClientError; end
|
42
42
|
class HTTPUnprocessableEntity < HTTPClientError; end
|
43
|
+
class HTTPBadRequest < HTTPClientError; end
|
43
44
|
class HTTPTooManyRequests < HTTPIntermittentClientError; end
|
44
45
|
|
45
46
|
# Superclass & fallback for all 5XX errors
|
@@ -60,6 +61,8 @@ module GdsApi
|
|
60
61
|
|
61
62
|
def error_class_for_code(code)
|
62
63
|
case code
|
64
|
+
when 400
|
65
|
+
GdsApi::HTTPBadRequest
|
63
66
|
when 401
|
64
67
|
GdsApi::HTTPUnauthorized
|
65
68
|
when 403
|
data/lib/gds_api/mapit.rb
CHANGED
@@ -12,6 +12,9 @@ module GdsApi
|
|
12
12
|
def publish(options)
|
13
13
|
logger.info("Publishing #{options.fetch(:type)} route #{options.fetch(:base_path)}, routing to #{options.fetch(:rendering_app)}")
|
14
14
|
|
15
|
+
update_type = options.fetch(:update_type, "major")
|
16
|
+
locale = options.fetch(:locale, "en")
|
17
|
+
|
15
18
|
put_content_response = publishing_api.put_content(
|
16
19
|
options.fetch(:content_id),
|
17
20
|
base_path: options.fetch(:base_path),
|
@@ -19,7 +22,7 @@ module GdsApi
|
|
19
22
|
schema_name: options.fetch(:schema_name, "special_route"),
|
20
23
|
title: options.fetch(:title),
|
21
24
|
description: options.fetch(:description, ""),
|
22
|
-
locale:
|
25
|
+
locale: locale,
|
23
26
|
details: {},
|
24
27
|
routes: [
|
25
28
|
{
|
@@ -30,11 +33,11 @@ module GdsApi
|
|
30
33
|
publishing_app: options.fetch(:publishing_app),
|
31
34
|
rendering_app: options.fetch(:rendering_app),
|
32
35
|
public_updated_at: time.now.iso8601,
|
33
|
-
update_type:
|
36
|
+
update_type: update_type,
|
34
37
|
)
|
35
38
|
|
36
39
|
publishing_api.patch_links(options.fetch(:content_id), links: options[:links]) if options[:links]
|
37
|
-
publishing_api.publish(options.fetch(:content_id))
|
40
|
+
publishing_api.publish(options.fetch(:content_id), update_type, locale: locale)
|
38
41
|
put_content_response
|
39
42
|
end
|
40
43
|
|
@@ -124,19 +124,6 @@ module GdsApi
|
|
124
124
|
matching.last
|
125
125
|
end
|
126
126
|
|
127
|
-
def stub_email_alert_api_has_subscriber_list(attributes)
|
128
|
-
stub_request(:get, build_subscriber_lists_url(attributes))
|
129
|
-
.to_return(
|
130
|
-
status: 200,
|
131
|
-
body: get_subscriber_list_response(attributes).to_json,
|
132
|
-
)
|
133
|
-
end
|
134
|
-
|
135
|
-
def stub_email_alert_api_does_not_have_subscriber_list(attributes)
|
136
|
-
stub_request(:get, build_subscriber_lists_url(attributes))
|
137
|
-
.to_return(status: 404)
|
138
|
-
end
|
139
|
-
|
140
127
|
def stub_email_alert_api_creates_subscriber_list(attributes)
|
141
128
|
stub_request(:post, build_subscriber_lists_url)
|
142
129
|
.to_return(
|
@@ -218,27 +205,31 @@ module GdsApi
|
|
218
205
|
.to_return(status: 404)
|
219
206
|
end
|
220
207
|
|
221
|
-
def stub_email_alert_api_creates_a_subscription(
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
208
|
+
def stub_email_alert_api_creates_a_subscription(
|
209
|
+
subscriber_list_id: nil,
|
210
|
+
address: nil,
|
211
|
+
frequency: nil,
|
212
|
+
returned_subscription_id: nil,
|
213
|
+
skip_confirmation_email: false,
|
214
|
+
subscriber_id: nil
|
215
|
+
)
|
216
|
+
response = get_subscription_response(
|
217
|
+
returned_subscription_id,
|
218
|
+
frequency: frequency,
|
219
|
+
subscriber_list_id: subscriber_list_id,
|
220
|
+
subscriber_id: subscriber_id,
|
221
|
+
)
|
222
|
+
|
223
|
+
request_params = {
|
224
|
+
subscriber_list_id: subscriber_list_id,
|
225
|
+
address: address,
|
226
|
+
frequency: frequency,
|
227
|
+
skip_confirmation_email: skip_confirmation_email,
|
228
|
+
}
|
232
229
|
|
233
|
-
def stub_email_alert_api_creates_an_existing_subscription(subscriber_list_id, address, frequency, returned_subscription_id)
|
234
230
|
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriptions")
|
235
|
-
.with(
|
236
|
-
|
237
|
-
subscriber_list_id: subscriber_list_id,
|
238
|
-
address: address,
|
239
|
-
frequency: frequency,
|
240
|
-
),
|
241
|
-
).to_return(status: 200, body: { id: returned_subscription_id }.to_json)
|
231
|
+
.with(body: hash_including(request_params.compact))
|
232
|
+
.to_return(status: 200, body: response.to_json)
|
242
233
|
end
|
243
234
|
|
244
235
|
def stub_email_alert_api_refuses_to_create_subscription(subscriber_list_id, address, frequency)
|
@@ -394,7 +385,6 @@ module GdsApi
|
|
394
385
|
document_type = attributes["document_type"]
|
395
386
|
email_document_supertype = attributes["email_document_supertype"]
|
396
387
|
government_document_supertype = attributes["government_document_supertype"]
|
397
|
-
gov_delivery_id = attributes["gov_delivery_id"]
|
398
388
|
content_purpose_supergroup = attributes["content_purpose_supergroup"]
|
399
389
|
combine_mode = attributes["combine_mode"]
|
400
390
|
|
@@ -404,7 +394,6 @@ module GdsApi
|
|
404
394
|
params[:document_type] = document_type if document_type
|
405
395
|
params[:email_document_supertype] = email_document_supertype if email_document_supertype
|
406
396
|
params[:government_document_supertype] = government_document_supertype if government_document_supertype
|
407
|
-
params[:gov_delivery_id] = gov_delivery_id if gov_delivery_id
|
408
397
|
params[:content_purpose_supergroup] = content_purpose_supergroup if content_purpose_supergroup
|
409
398
|
params[:combine_mode] = combine_mode if combine_mode
|
410
399
|
|
@@ -5,13 +5,14 @@ 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:)
|
8
|
+
def stub_local_links_manager_has_a_link(authority_slug:, lgsl:, lgil:, url:, country_name: "England")
|
9
9
|
response = {
|
10
10
|
"local_authority" => {
|
11
11
|
"name" => authority_slug.capitalize,
|
12
12
|
"snac" => "00AG",
|
13
13
|
"tier" => "unitary",
|
14
14
|
"homepage_url" => "http://#{authority_slug}.example.com",
|
15
|
+
"country_name" => country_name,
|
15
16
|
},
|
16
17
|
"local_interaction" => {
|
17
18
|
"lgsl_code" => lgsl,
|
@@ -25,13 +26,14 @@ module GdsApi
|
|
25
26
|
.to_return(body: response.to_json, status: 200)
|
26
27
|
end
|
27
28
|
|
28
|
-
def stub_local_links_manager_has_no_link(authority_slug:, lgsl:, lgil:)
|
29
|
+
def stub_local_links_manager_has_no_link(authority_slug:, lgsl:, lgil:, country_name: "England")
|
29
30
|
response = {
|
30
31
|
"local_authority" => {
|
31
32
|
"name" => authority_slug.capitalize,
|
32
33
|
"snac" => "00AG",
|
33
34
|
"tier" => "unitary",
|
34
35
|
"homepage_url" => "http://#{authority_slug}.example.com",
|
36
|
+
"country_name" => country_name,
|
35
37
|
},
|
36
38
|
}
|
37
39
|
|
@@ -40,13 +42,14 @@ module GdsApi
|
|
40
42
|
.to_return(body: response.to_json, status: 200)
|
41
43
|
end
|
42
44
|
|
43
|
-
def stub_local_links_manager_has_no_link_and_no_homepage_url(authority_slug:, lgsl:, lgil:)
|
45
|
+
def stub_local_links_manager_has_no_link_and_no_homepage_url(authority_slug:, lgsl:, lgil:, country_name: "England")
|
44
46
|
response = {
|
45
47
|
"local_authority" => {
|
46
48
|
"name" => authority_slug.capitalize,
|
47
49
|
"snac" => "00AG",
|
48
50
|
"tier" => "unitary",
|
49
51
|
"homepage_url" => nil,
|
52
|
+
"country_name" => country_name,
|
50
53
|
},
|
51
54
|
}
|
52
55
|
|
@@ -82,6 +85,7 @@ module GdsApi
|
|
82
85
|
{
|
83
86
|
"name" => authority_slug.capitalize,
|
84
87
|
"homepage_url" => "http://#{authority_slug}.example.com",
|
88
|
+
"country_name" => "England",
|
85
89
|
"tier" => "unitary",
|
86
90
|
},
|
87
91
|
],
|
@@ -98,11 +102,13 @@ module GdsApi
|
|
98
102
|
{
|
99
103
|
"name" => district_slug.capitalize,
|
100
104
|
"homepage_url" => "http://#{district_slug}.example.com",
|
105
|
+
"country_name" => "England",
|
101
106
|
"tier" => "district",
|
102
107
|
},
|
103
108
|
{
|
104
109
|
"name" => county_slug.capitalize,
|
105
110
|
"homepage_url" => "http://#{county_slug}.example.com",
|
111
|
+
"country_name" => "England",
|
106
112
|
"tier" => "county",
|
107
113
|
},
|
108
114
|
],
|
@@ -131,6 +137,7 @@ module GdsApi
|
|
131
137
|
{
|
132
138
|
"name" => authority_slug.capitalize,
|
133
139
|
"homepage_url" => "",
|
140
|
+
"country_name" => "England",
|
134
141
|
"tier" => "unitary",
|
135
142
|
},
|
136
143
|
],
|
@@ -43,6 +43,20 @@ module GdsApi
|
|
43
43
|
.to_return(body: response.to_json, status: 200)
|
44
44
|
end
|
45
45
|
|
46
|
+
def stub_mapit_has_a_postcode_and_country_name(postcode, coords, country_name)
|
47
|
+
response = {
|
48
|
+
"wgs84_lat" => coords.first,
|
49
|
+
"wgs84_lon" => coords.last,
|
50
|
+
"postcode" => postcode,
|
51
|
+
"country_name" => country_name,
|
52
|
+
}
|
53
|
+
|
54
|
+
stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.tr(" ", "+") + ".json")
|
55
|
+
.to_return(body: response.to_json, status: 200)
|
56
|
+
stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/partial/" + postcode.split(" ").first + ".json")
|
57
|
+
.to_return(body: response.to_json, status: 200)
|
58
|
+
end
|
59
|
+
|
46
60
|
def stub_mapit_does_not_have_a_postcode(postcode)
|
47
61
|
stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.tr(" ", "+") + ".json")
|
48
62
|
.to_return(body: { "code" => 404, "error" => "No Postcode matches the given query." }.to_json, status: 404)
|
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: 69.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:
|
11
|
+
date: 2021-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|