gds-api-adapters 68.0.0 → 69.2.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/asset_manager.rb +9 -10
- data/lib/gds_api/email_alert_api.rb +6 -48
- 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 +8 -13
- 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: 294f4287f0eb5a9fad08a2732fba69502b5622e5a8ebbc8bef4acc54a98b5c71
|
4
|
+
data.tar.gz: a9ecd5e2dbaf5e0fe31f678330300256b629e9ecd7b53c6f25b7c0e5ddaa4180
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76d12236b2395137708802139460673ef5cb8e2634e84dfb29066dc69cfa2dbba08c049554cc74f363e2e9c22ce7b4d924b06e498704666c3c8fd60a4a0adfc4
|
7
|
+
data.tar.gz: c1186893c71cd5daa83f62d52c0849954f1fc3395e224b934372bba08696691478553ce2c0a5ec25f2ba53ff7b5a7f08b936aee7bdf5160ad13604d3e09d19a8
|
@@ -7,12 +7,13 @@ class GdsApi::AssetManager < GdsApi::Base
|
|
7
7
|
#
|
8
8
|
# Makes a +POST+ request to the asset manager api to create an asset.
|
9
9
|
#
|
10
|
-
# The asset must be provided as a +Hash+ with a
|
10
|
+
# The asset must be provided as a +Hash+ with a +file+ attribute that
|
11
11
|
# behaves like a +File+ object. The +content-type+ that the asset manager will
|
12
|
-
# subsequently serve will be based
|
13
|
-
#
|
12
|
+
# subsequently serve will be based on the file's extension (derived from
|
13
|
+
# +#path+). If you supply a +content-type+ via, for example
|
14
14
|
# +ActionDispatch::Http::UploadedFile+ or another multipart wrapper, it will
|
15
|
-
# be ignored.
|
15
|
+
# be ignored. To provide a +content-type+ directly you must be specify it
|
16
|
+
# as a +content_type+ attribute of the hash.
|
16
17
|
#
|
17
18
|
# @param asset [Hash] The attributes for the asset to send to the api. Must
|
18
19
|
# contain +file+, which behaves like a +File+. All other attributes will be
|
@@ -143,12 +144,10 @@ class GdsApi::AssetManager < GdsApi::Base
|
|
143
144
|
#
|
144
145
|
# Makes a +PUT+ request to the asset manager api to update an asset.
|
145
146
|
#
|
146
|
-
# The asset must be provided as a +Hash+ with a
|
147
|
-
# behaves like a +File+ object. The +content-type+
|
148
|
-
#
|
149
|
-
#
|
150
|
-
# +ActionDispatch::Http::UploadedFile+ or another multipart wrapper, it will
|
151
|
-
# be ignored.
|
147
|
+
# The asset must be provided as a +Hash+ with a +file+ attribute that
|
148
|
+
# behaves like a +File+ object. The +content-type+ of the file will be based
|
149
|
+
# on the files extension unless you specify a +content_type+ attribute of
|
150
|
+
# the hash to set it.
|
152
151
|
#
|
153
152
|
# @param id [String] The asset identifier (a UUID).
|
154
153
|
# @param asset [Hash] The attributes for the asset to send to the api. Must
|
@@ -10,44 +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
|
-
combine_mode = attributes["combine_mode"]
|
28
|
-
|
29
|
-
if tags && links
|
13
|
+
if attributes["tags"] && attributes["links"]
|
30
14
|
message = "please provide either tags or links (or neither), but not both"
|
31
15
|
raise ArgumentError, message
|
32
16
|
end
|
33
17
|
|
34
|
-
|
35
|
-
params[:tags] = tags if tags
|
36
|
-
params[:links] = links if links
|
37
|
-
params[:document_type] = document_type if document_type
|
38
|
-
params[:email_document_supertype] = email_document_supertype if email_document_supertype
|
39
|
-
params[:government_document_supertype] = government_document_supertype if government_document_supertype
|
40
|
-
params[:combine_mode] = combine_mode if combine_mode
|
41
|
-
|
42
|
-
query_string = nested_query_string(params)
|
43
|
-
get_json("#{endpoint}/subscriber-lists?" + query_string)
|
18
|
+
post_json("#{endpoint}/subscriber-lists", attributes)
|
44
19
|
end
|
45
20
|
|
46
|
-
#
|
21
|
+
# Get a subscriber list
|
47
22
|
#
|
48
23
|
# @param attributes [Hash] document_type, links, tags used to search existing subscriber lists
|
49
|
-
def
|
50
|
-
|
24
|
+
def find_subscriber_list(attributes)
|
25
|
+
query_string = nested_query_string(attributes)
|
26
|
+
get_json("#{endpoint}/subscriber-lists?" + query_string)
|
51
27
|
end
|
52
28
|
|
53
29
|
# Post a content change
|
@@ -64,24 +40,6 @@ class GdsApi::EmailAlertApi < GdsApi::Base
|
|
64
40
|
post_json("#{endpoint}/messages", message, headers)
|
65
41
|
end
|
66
42
|
|
67
|
-
# Send email
|
68
|
-
#
|
69
|
-
# @param email_params [Hash] address, subject, body
|
70
|
-
def create_email(email_params)
|
71
|
-
post_json("#{endpoint}/emails", email_params)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Unpublishing alert
|
75
|
-
#
|
76
|
-
# @param message [Hash] content_id
|
77
|
-
#
|
78
|
-
# Used by email-alert-service to send a message to email-alert-api
|
79
|
-
# when an unpublishing message is put on the Rabbitmq queue by
|
80
|
-
# publishing-api
|
81
|
-
def send_unpublish_message(message)
|
82
|
-
post_json("#{endpoint}/unpublish-messages", message)
|
83
|
-
end
|
84
|
-
|
85
43
|
# Get topic matches
|
86
44
|
#
|
87
45
|
# @param attributes [Hash] tags, links, 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,24 +145,11 @@ 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)
|
151
151
|
end
|
152
152
|
|
153
|
-
def stub_email_alert_api_accepts_unpublishing_message
|
154
|
-
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/unpublish-messages")
|
155
|
-
.to_return(status: 202, body: {}.to_json)
|
156
|
-
end
|
157
|
-
|
158
153
|
def stub_email_alert_api_accepts_content_change
|
159
154
|
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/content-changes")
|
160
155
|
.to_return(status: 202, body: {}.to_json)
|
@@ -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.2.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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|