gds-api-adapters 88.2.0 → 89.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7adeea7abfc8234541609b17eca719cd8d39be01991cc68ca285bda907f9a96a
4
- data.tar.gz: 3e75818f4bf1a56e94089e94e341a5d8adb8f9a8e3b6faa5a8592f929355a0d9
3
+ metadata.gz: d3eb40035b5fa647944d596304bd5ae025bafef25b92e642e6a5d8480f4f928c
4
+ data.tar.gz: 01d7a039b547736315c2d67974e3408b566a176a93bd4d912ae47fbedca97039
5
5
  SHA512:
6
- metadata.gz: a4ae5ac10341ba1c29872cf3772be25db3cbbba4a567a09da807b6b0909c1b7dc8d5bf0acdef4dd93fc07596ea7aa5bb299709f1a11a75d062bbeeb7f1910c12
7
- data.tar.gz: b4cc259326d27d9c80b5bcf3ec25759ada42ff3f5440013e4056ff01cc44f2140b2c0d82862017ac72bcded2dd65802ca988a6261b5c7866bf5a389ce0edcc43
6
+ metadata.gz: 2759dda02d68912b14e7a918846b98dda7d439be7b352f1499dda2f9131eff75aa26e952931b836553be86c603e90ca7ae2ff5e3a1e3df7934596fc7adf2be0a
7
+ data.tar.gz: 5aae0a77fafc975e667966f859d4f9e96b50c669c8460f1e5debec6254258d0ef9cdcb0b9b8586ef289334f93a563d3e76cdb2a6f2de623fc234834552bc2b73
@@ -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
 
@@ -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.each { |s| stub_worldwide_api_has_location(s) }
18
- pages = []
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
- pages.each_with_index do |page, i|
24
- page_details = plural_response_base.merge(
25
- "results" => page,
26
- "total" => location_slugs.size,
27
- "pages" => pages.size,
28
- "current_page" => i + 1,
29
- "page_size" => 20,
30
- "start_index" => i * 20 + 1,
31
- )
32
-
33
- links = { self: "#{WORLDWIDE_API_ENDPOINT}/api/world-locations?page=#{i + 1}" }
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
- # First page exists at URL with and without page param
49
- stub_request(:get, links[:self].sub(/\?page=1/, ""))
50
- .to_return(status: 200, body: page_details.to_json, headers: { "Link" => link_headers.join(", ") })
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
- def stub_worldwide_api_has_selection_of_locations
55
- stub_worldwide_api_has_locations %w[
56
- afghanistan
57
- angola
58
- australia
59
- bahamas
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
- def stub_worldwide_api_has_location(location_slug, details = nil)
93
- details ||= world_location_for_slug(location_slug)
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 stub_worldwide_api_does_not_have_location(location_slug)
99
- stub_request(:get, "#{WORLDWIDE_API_ENDPOINT}/api/world-locations/#{location_slug}").to_return(status: 404)
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
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "88.2.0".freeze
2
+ VERSION = "89.0.0".freeze
3
3
  end
@@ -2,11 +2,17 @@ require_relative "base"
2
2
 
3
3
  class GdsApi::Worldwide < GdsApi::Base
4
4
  def world_locations
5
- get_list("#{base_url}/world-locations")
5
+ all_world_locations
6
6
  end
7
7
 
8
8
  def world_location(location_slug)
9
- get_json("#{base_url}/world-locations/#{location_slug}")
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: 88.2.0
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-06-06 00:00:00.000000000 Z
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.10.0
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.10.0
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.13
420
+ rubygems_version: 3.4.17
421
421
  signing_key:
422
422
  specification_version: 4
423
423
  summary: Adapters to work with GDS APIs