gds-api-adapters 88.1.0 → 89.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/asset_manager.rb +13 -2
- data/lib/gds_api/json_client.rb +1 -1
- data/lib/gds_api/test_helpers/asset_manager.rb +3 -0
- data/lib/gds_api/test_helpers/worldwide.rb +33 -107
- data/lib/gds_api/version.rb +1 -1
- data/lib/gds_api/worldwide.rb +39 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3eb40035b5fa647944d596304bd5ae025bafef25b92e642e6a5d8480f4f928c
|
4
|
+
data.tar.gz: 01d7a039b547736315c2d67974e3408b566a176a93bd4d912ae47fbedca97039
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2759dda02d68912b14e7a918846b98dda7d439be7b352f1499dda2f9131eff75aa26e952931b836553be86c603e90ca7ae2ff5e3a1e3df7934596fc7adf2be0a
|
7
|
+
data.tar.gz: 5aae0a77fafc975e667966f859d4f9e96b50c669c8460f1e5debec6254258d0ef9cdcb0b9b8586ef289334f93a563d3e76cdb2a6f2de623fc234834552bc2b73
|
@@ -128,7 +128,7 @@ class GdsApi::AssetManager < GdsApi::Base
|
|
128
128
|
post_multipart("#{base_url}/whitehall_assets", asset: asset)
|
129
129
|
end
|
130
130
|
|
131
|
-
# Fetches a Whitehall asset given the legacy URL path
|
131
|
+
# Fetches a Whitehall asset's metadata given the legacy URL path
|
132
132
|
#
|
133
133
|
# @param legacy_url_path [String] The Whitehall asset identifier.
|
134
134
|
# @return [GdsApi::Response] A response object containing the parsed JSON
|
@@ -171,7 +171,7 @@ class GdsApi::AssetManager < GdsApi::Base
|
|
171
171
|
put_multipart("#{base_url}/assets/#{id}", asset: asset)
|
172
172
|
end
|
173
173
|
|
174
|
-
# Fetches an asset given the id
|
174
|
+
# Fetches an asset's metadata given the id
|
175
175
|
#
|
176
176
|
# @param id [String] The asset identifier (a UUID).
|
177
177
|
# @return [GdsApi::Response, nil] A response object containing the parsed JSON response. If
|
@@ -228,6 +228,17 @@ class GdsApi::AssetManager < GdsApi::Base
|
|
228
228
|
post_json("#{base_url}/assets/#{id}/restore")
|
229
229
|
end
|
230
230
|
|
231
|
+
# Fetches a Whitehall asset given the legacy URL path
|
232
|
+
#
|
233
|
+
# @param legacy_url_path [String] The Whitehall asset identifier.
|
234
|
+
# @return [GdsApi::Response] A response object containing the raw asset.
|
235
|
+
# If the asset cannot be found, +GdsApi::HTTPNotFound+ will be raised.
|
236
|
+
#
|
237
|
+
# @raise [HTTPErrorResponse] if the request returns an error
|
238
|
+
def whitehall_media(legacy_url_path)
|
239
|
+
get_raw("#{base_url}/#{uri_encode(legacy_url_path)}")
|
240
|
+
end
|
241
|
+
|
231
242
|
private
|
232
243
|
|
233
244
|
def base_url
|
data/lib/gds_api/json_client.rb
CHANGED
@@ -157,7 +157,7 @@ module GdsApi
|
|
157
157
|
end
|
158
158
|
|
159
159
|
def do_request(method, url, params = nil, additional_headers = {})
|
160
|
-
loggable = { request_uri: url, start_time: Time.now.to_f }
|
160
|
+
loggable = { request_uri: url, start_time: Time.now.to_f, govuk_request_id: GdsApi::GovukHeaders.headers[:govuk_request_id] }.compact
|
161
161
|
start_logging = loggable.merge(action: "start")
|
162
162
|
logger.debug start_logging.to_json
|
163
163
|
|
@@ -33,6 +33,9 @@ module GdsApi
|
|
33
33
|
|
34
34
|
stub_request(:get, "#{ASSET_MANAGER_ENDPOINT}/whitehall_assets/#{legacy_url_path}")
|
35
35
|
.to_return(body: response.to_json, status: 200)
|
36
|
+
|
37
|
+
stub_request(:get, "#{ASSET_MANAGER_ENDPOINT}/#{legacy_url_path}")
|
38
|
+
.to_return(body: "Some file content", status: 200)
|
36
39
|
end
|
37
40
|
|
38
41
|
def stub_asset_manager_does_not_have_an_asset(id)
|
@@ -8,95 +8,48 @@ module GdsApi
|
|
8
8
|
|
9
9
|
WORLDWIDE_API_ENDPOINT = Plek.new.website_root
|
10
10
|
|
11
|
-
# Sets up the index endpoints for the given country slugs
|
12
|
-
# The stubs are setup to paginate in chunks of 20
|
13
|
-
#
|
14
|
-
# This also sets up the individual endpoints for each slug
|
15
|
-
# by calling stub_worldwide_api_has_location below
|
16
11
|
def stub_worldwide_api_has_locations(location_slugs)
|
17
|
-
location_slugs.
|
18
|
-
|
19
|
-
location_slugs.each_slice(20) do |slugs|
|
20
|
-
pages << slugs.map { |s| world_location_details_for_slug(s) }
|
12
|
+
international_delegation_slugs = location_slugs.select do |slug|
|
13
|
+
slug =~ /(delegation|mission)/
|
21
14
|
end
|
22
15
|
|
23
|
-
|
24
|
-
|
25
|
-
"
|
26
|
-
"
|
27
|
-
"
|
28
|
-
"
|
29
|
-
"
|
30
|
-
"
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
links[:next] = "#{WORLDWIDE_API_ENDPOINT}/api/world-locations?page=#{i + 2}" if pages[i + 1]
|
35
|
-
links[:previous] = "#{WORLDWIDE_API_ENDPOINT}/api/world-locations?page=#{i}" unless i.zero?
|
36
|
-
page_details["_response_info"]["links"] = []
|
37
|
-
link_headers = []
|
38
|
-
links.each do |rel, href|
|
39
|
-
page_details["_response_info"]["links"] << { "rel" => rel, "href" => href }
|
40
|
-
link_headers << "<#{href}>; rel=\"#{rel}\""
|
41
|
-
end
|
42
|
-
|
43
|
-
stub_request(:get, links[:self])
|
44
|
-
.to_return(status: 200, body: page_details.to_json, headers: { "Link" => link_headers.join(", ") })
|
45
|
-
|
46
|
-
next unless i.zero?
|
16
|
+
international_delegations = international_delegation_slugs.map do |slug|
|
17
|
+
{
|
18
|
+
"active": true,
|
19
|
+
"analytics_identifier": "WL1",
|
20
|
+
"content_id": "content_id_for_#{slug}",
|
21
|
+
"iso2": slug[0..1].upcase,
|
22
|
+
"name": titleize_slug(slug, title_case: true),
|
23
|
+
"slug": slug,
|
24
|
+
"updated_at": "2013-03-25T13:06:42+00:00",
|
25
|
+
}
|
26
|
+
end
|
47
27
|
|
48
|
-
|
49
|
-
|
50
|
-
|
28
|
+
world_locations = (location_slugs - international_delegation_slugs).map do |slug|
|
29
|
+
{
|
30
|
+
"active": true,
|
31
|
+
"analytics_identifier": "WL1",
|
32
|
+
"content_id": "content_id_for_#{slug}",
|
33
|
+
"iso2": slug[0..1].upcase,
|
34
|
+
"name": titleize_slug(slug, title_case: true),
|
35
|
+
"slug": slug,
|
36
|
+
"updated_at": "2013-03-25T13:06:42+00:00",
|
37
|
+
}
|
51
38
|
end
|
52
|
-
end
|
53
39
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
belarus
|
61
|
-
brazil
|
62
|
-
brunei
|
63
|
-
cambodia
|
64
|
-
chad
|
65
|
-
croatia
|
66
|
-
denmark
|
67
|
-
eritrea
|
68
|
-
france
|
69
|
-
ghana
|
70
|
-
iceland
|
71
|
-
japan
|
72
|
-
laos
|
73
|
-
luxembourg
|
74
|
-
malta
|
75
|
-
micronesia
|
76
|
-
mozambique
|
77
|
-
nicaragua
|
78
|
-
panama
|
79
|
-
portugal
|
80
|
-
sao-tome-and-principe
|
81
|
-
singapore
|
82
|
-
south-korea
|
83
|
-
sri-lanka
|
84
|
-
uk-delegation-to-council-of-europe
|
85
|
-
uk-delegation-to-organization-for-security-and-co-operation-in-europe
|
86
|
-
united-kingdom
|
87
|
-
venezuela
|
88
|
-
vietnam
|
89
|
-
]
|
90
|
-
end
|
40
|
+
content_item = {
|
41
|
+
"details": {
|
42
|
+
"international_delegation": international_delegations,
|
43
|
+
"world_locations": world_locations,
|
44
|
+
},
|
45
|
+
}
|
91
46
|
|
92
|
-
|
93
|
-
|
94
|
-
stub_request(:get, "#{WORLDWIDE_API_ENDPOINT}/api/world-locations/#{location_slug}")
|
95
|
-
.to_return(status: 200, body: details.to_json)
|
47
|
+
stub_request(:get, "#{WORLDWIDE_API_ENDPOINT}/api/content/world")
|
48
|
+
.to_return(status: 200, body: content_item.to_json)
|
96
49
|
end
|
97
50
|
|
98
|
-
def
|
99
|
-
|
51
|
+
def stub_worldwide_api_has_location(location_slug)
|
52
|
+
stub_worldwide_api_has_locations([location_slug])
|
100
53
|
end
|
101
54
|
|
102
55
|
def stub_worldwide_api_has_organisations_for_location(location_slug, json_or_hash)
|
@@ -112,33 +65,6 @@ module GdsApi
|
|
112
65
|
stub_request(:get, url)
|
113
66
|
.to_return(status: 200, body: details.to_json, headers: { "Link" => "<#{url}; rel\"self\"" })
|
114
67
|
end
|
115
|
-
|
116
|
-
def world_location_for_slug(slug)
|
117
|
-
singular_response_base.merge(world_location_details_for_slug(slug))
|
118
|
-
end
|
119
|
-
|
120
|
-
# Constructs a sample world_location
|
121
|
-
#
|
122
|
-
# if the slug contains 'delegation' or 'mission' the format will be set to 'International delegation'
|
123
|
-
# othersiwe it will be set to 'World location'
|
124
|
-
def world_location_details_for_slug(slug)
|
125
|
-
{
|
126
|
-
"id" => "https://www.gov.uk/api/world-locations/#{slug}",
|
127
|
-
"title" => titleize_slug(slug, title_case: true),
|
128
|
-
"format" => (slug =~ /(delegation|mission)/ ? "International delegation" : "World location"),
|
129
|
-
"updated_at" => "2013-03-25T13:06:42+00:00",
|
130
|
-
"web_url" => "https://www.gov.uk/government/world/#{slug}",
|
131
|
-
"details" => {
|
132
|
-
"slug" => slug,
|
133
|
-
"iso2" => slug[0..1].upcase,
|
134
|
-
},
|
135
|
-
"organisations" => {
|
136
|
-
"id" => "https://www.gov.uk/api/world-locations/#{slug}/organisations",
|
137
|
-
"web_url" => "https://www.gov.uk/government/world/#{slug}#organisations",
|
138
|
-
},
|
139
|
-
"content_id" => "content_id_for_#{slug}",
|
140
|
-
}
|
141
|
-
end
|
142
68
|
end
|
143
69
|
end
|
144
70
|
end
|
data/lib/gds_api/version.rb
CHANGED
data/lib/gds_api/worldwide.rb
CHANGED
@@ -2,11 +2,17 @@ require_relative "base"
|
|
2
2
|
|
3
3
|
class GdsApi::Worldwide < GdsApi::Base
|
4
4
|
def world_locations
|
5
|
-
|
5
|
+
all_world_locations
|
6
6
|
end
|
7
7
|
|
8
8
|
def world_location(location_slug)
|
9
|
-
|
9
|
+
world_location = all_world_locations.find do |location|
|
10
|
+
location.dig("details", "slug") == location_slug
|
11
|
+
end
|
12
|
+
|
13
|
+
raise GdsApi::HTTPNotFound, 404 unless world_location
|
14
|
+
|
15
|
+
world_location
|
10
16
|
end
|
11
17
|
|
12
18
|
def organisations_for_world_location(location_slug)
|
@@ -18,4 +24,35 @@ private
|
|
18
24
|
def base_url
|
19
25
|
"#{endpoint}/api"
|
20
26
|
end
|
27
|
+
|
28
|
+
def all_world_locations
|
29
|
+
content_item = JSON.parse(get_raw("#{base_url}/content/world"))
|
30
|
+
|
31
|
+
world_locations = format_locations(content_item.dig("details", "world_locations"), "World location")
|
32
|
+
international_delegations = format_locations(content_item.dig("details", "international_delegations"), "International delegation")
|
33
|
+
|
34
|
+
Array(world_locations) + Array(international_delegations)
|
35
|
+
end
|
36
|
+
|
37
|
+
def format_locations(locations, type)
|
38
|
+
locations&.map do |location|
|
39
|
+
{
|
40
|
+
"id" => "#{Plek.new.website_root}/world/#{location['slug']}",
|
41
|
+
"title" => location["name"],
|
42
|
+
"format" => type,
|
43
|
+
"updated_at" => location["updated_at"],
|
44
|
+
"web_url" => "#{Plek.new.website_root}/world/#{location['slug']}",
|
45
|
+
"analytics_identifier" => location["analytics_identifier"],
|
46
|
+
"details" => {
|
47
|
+
"slug" => location["slug"],
|
48
|
+
"iso2" => location["iso2"],
|
49
|
+
},
|
50
|
+
"organisations" => {
|
51
|
+
"id" => "#{Plek.new.website_root}/world/#{location['slug']}#organisations",
|
52
|
+
"web_url" => "#{Plek.new.website_root}/world/#{location['slug']}#organisations",
|
53
|
+
},
|
54
|
+
"content_id" => location["content_id"],
|
55
|
+
}
|
56
|
+
end
|
57
|
+
end
|
21
58
|
end
|
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: 89.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: 2023-
|
11
|
+
date: 2023-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -268,14 +268,14 @@ dependencies:
|
|
268
268
|
requirements:
|
269
269
|
- - '='
|
270
270
|
- !ruby/object:Gem::Version
|
271
|
-
version: 4.
|
271
|
+
version: 4.11.0
|
272
272
|
type: :development
|
273
273
|
prerelease: false
|
274
274
|
version_requirements: !ruby/object:Gem::Requirement
|
275
275
|
requirements:
|
276
276
|
- - '='
|
277
277
|
- !ruby/object:Gem::Version
|
278
|
-
version: 4.
|
278
|
+
version: 4.11.0
|
279
279
|
- !ruby/object:Gem::Dependency
|
280
280
|
name: simplecov
|
281
281
|
requirement: !ruby/object:Gem::Requirement
|
@@ -417,7 +417,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
417
417
|
- !ruby/object:Gem::Version
|
418
418
|
version: '0'
|
419
419
|
requirements: []
|
420
|
-
rubygems_version: 3.4.
|
420
|
+
rubygems_version: 3.4.17
|
421
421
|
signing_key:
|
422
422
|
specification_version: 4
|
423
423
|
summary: Adapters to work with GDS APIs
|