gds-api-adapters 67.2.1 → 69.1.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 +6 -40
- data/lib/gds_api/exceptions.rb +3 -0
- data/lib/gds_api/mapit.rb +4 -0
- data/lib/gds_api/test_helpers/email_alert_api.rb +31 -29
- 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: 30536128d763109b2965438ade68ca08a7bc60782f3ad29f4f874ee051d687ef
|
4
|
+
data.tar.gz: 18db0bcda095594ec145e1ab54a6d80b68aa62df2d4348789931b2298d80b9ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f488b6b0512fd5a2ae41bad2116c225b2f39446f3d01fe4e493a1d4f0e4673176561dc0a1a79a68f349fc68f92c3b4d14e3cf8a506ffd81a014f22e3a6ad5480
|
7
|
+
data.tar.gz: 8cb30f4f8c075c4674a792a9647112268be2a52a77c14c7d20c2ee65f5f2fbcf082e4c6211a6603984426e887a240b0910d4d894575a0f267ba156600e1ed2b5
|
@@ -10,46 +10,20 @@ 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
|
+
post_json("#{endpoint}/subscriber-lists", attributes)
|
46
19
|
end
|
47
20
|
|
48
|
-
#
|
21
|
+
# Get a subscriber list
|
49
22
|
#
|
50
23
|
# @param attributes [Hash] document_type, links, tags used to search existing subscriber lists
|
51
|
-
def
|
52
|
-
|
24
|
+
def find_subscriber_list(attributes)
|
25
|
+
query_string = nested_query_string(attributes)
|
26
|
+
get_json("#{endpoint}/subscriber-lists?" + query_string)
|
53
27
|
end
|
54
28
|
|
55
29
|
# Post a content change
|
@@ -66,13 +40,6 @@ class GdsApi::EmailAlertApi < GdsApi::Base
|
|
66
40
|
post_json("#{endpoint}/messages", message, headers)
|
67
41
|
end
|
68
42
|
|
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
43
|
# Unpublishing alert
|
77
44
|
#
|
78
45
|
# @param message [Hash] content_id
|
@@ -131,7 +98,6 @@ class GdsApi::EmailAlertApi < GdsApi::Base
|
|
131
98
|
# @return [Hash] subscriber_list: {
|
132
99
|
# id
|
133
100
|
# title
|
134
|
-
# gov_delivery_id
|
135
101
|
# created_at
|
136
102
|
# updated_at
|
137
103
|
# 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
@@ -124,6 +124,14 @@ module GdsApi
|
|
124
124
|
matching.last
|
125
125
|
end
|
126
126
|
|
127
|
+
def stub_email_alert_api_creates_subscriber_list(attributes)
|
128
|
+
stub_request(:post, build_subscriber_lists_url)
|
129
|
+
.to_return(
|
130
|
+
status: 201,
|
131
|
+
body: get_subscriber_list_response(attributes).to_json,
|
132
|
+
)
|
133
|
+
end
|
134
|
+
|
127
135
|
def stub_email_alert_api_has_subscriber_list(attributes)
|
128
136
|
stub_request(:get, build_subscriber_lists_url(attributes))
|
129
137
|
.to_return(
|
@@ -137,14 +145,6 @@ module GdsApi
|
|
137
145
|
.to_return(status: 404)
|
138
146
|
end
|
139
147
|
|
140
|
-
def stub_email_alert_api_creates_subscriber_list(attributes)
|
141
|
-
stub_request(:post, build_subscriber_lists_url)
|
142
|
-
.to_return(
|
143
|
-
status: 201,
|
144
|
-
body: get_subscriber_list_response(attributes).to_json,
|
145
|
-
)
|
146
|
-
end
|
147
|
-
|
148
148
|
def stub_email_alert_api_refuses_to_create_subscriber_list
|
149
149
|
stub_request(:post, build_subscriber_lists_url)
|
150
150
|
.to_return(status: 422)
|
@@ -218,27 +218,31 @@ module GdsApi
|
|
218
218
|
.to_return(status: 404)
|
219
219
|
end
|
220
220
|
|
221
|
-
def stub_email_alert_api_creates_a_subscription(
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
221
|
+
def stub_email_alert_api_creates_a_subscription(
|
222
|
+
subscriber_list_id: nil,
|
223
|
+
address: nil,
|
224
|
+
frequency: nil,
|
225
|
+
returned_subscription_id: nil,
|
226
|
+
skip_confirmation_email: false,
|
227
|
+
subscriber_id: nil
|
228
|
+
)
|
229
|
+
response = get_subscription_response(
|
230
|
+
returned_subscription_id,
|
231
|
+
frequency: frequency,
|
232
|
+
subscriber_list_id: subscriber_list_id,
|
233
|
+
subscriber_id: subscriber_id,
|
234
|
+
)
|
235
|
+
|
236
|
+
request_params = {
|
237
|
+
subscriber_list_id: subscriber_list_id,
|
238
|
+
address: address,
|
239
|
+
frequency: frequency,
|
240
|
+
skip_confirmation_email: skip_confirmation_email,
|
241
|
+
}
|
232
242
|
|
233
|
-
def stub_email_alert_api_creates_an_existing_subscription(subscriber_list_id, address, frequency, returned_subscription_id)
|
234
243
|
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)
|
244
|
+
.with(body: hash_including(request_params.compact))
|
245
|
+
.to_return(status: 200, body: response.to_json)
|
242
246
|
end
|
243
247
|
|
244
248
|
def stub_email_alert_api_refuses_to_create_subscription(subscriber_list_id, address, frequency)
|
@@ -394,7 +398,6 @@ module GdsApi
|
|
394
398
|
document_type = attributes["document_type"]
|
395
399
|
email_document_supertype = attributes["email_document_supertype"]
|
396
400
|
government_document_supertype = attributes["government_document_supertype"]
|
397
|
-
gov_delivery_id = attributes["gov_delivery_id"]
|
398
401
|
content_purpose_supergroup = attributes["content_purpose_supergroup"]
|
399
402
|
combine_mode = attributes["combine_mode"]
|
400
403
|
|
@@ -404,7 +407,6 @@ module GdsApi
|
|
404
407
|
params[:document_type] = document_type if document_type
|
405
408
|
params[:email_document_supertype] = email_document_supertype if email_document_supertype
|
406
409
|
params[:government_document_supertype] = government_document_supertype if government_document_supertype
|
407
|
-
params[:gov_delivery_id] = gov_delivery_id if gov_delivery_id
|
408
410
|
params[:content_purpose_supergroup] = content_purpose_supergroup if content_purpose_supergroup
|
409
411
|
params[:combine_mode] = combine_mode if combine_mode
|
410
412
|
|
@@ -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.1.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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|