gds-api-adapters 83.0.0 → 85.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: 921ed76df07dc2083415048acc0ddff80db26c5f3295691d81f7560f5d55d458
4
- data.tar.gz: 21c0741d4e870e768a95b129c09a77d35cdd1f47c9bbdc9684d12192ebc3d5e5
3
+ metadata.gz: d0e7c159e27c8d969ceda2b447b8fcf1fe39528236bd924ee7dd33c97e27b6ea
4
+ data.tar.gz: c19e0660b7cf3e5ea2bd59ea39b940d45cd475230f45805f6f886606ab039e76
5
5
  SHA512:
6
- metadata.gz: c94e219206c289f6ee340ed3c4384c936201fb93d867547546f4ca984f7fdafa6c69e3b677870b8c0d5003c50aaaa44da8e729bdc57820ef47b1a7a68eed0f7b
7
- data.tar.gz: 600b41211a2911bcde2d6d9e0f218b015f66e02322a608b02bc19dc4a12b049837e20baf230c12bb6d58ac65e72fc9be75d1dd1910196d8092fd29b4420fb55b
6
+ metadata.gz: 765fd1eda340f5b5f38935d7502ef13429c69794044176e282e4884d7c5623a60d3b98c5931205ad198d490c5f42d9ee3b2fe17c68664cf819e617dfc68c9af3
7
+ data.tar.gz: 1f57b304c744502c45f6c4640bc294c42d33c20034204b27dd260aa277711163ada24e28ce7a843a6f97efa35f298fa6e5582e3b9e338f13501e5d1b17ad8a9e
data/Rakefile CHANGED
@@ -12,6 +12,12 @@ Rake::TestTask.new("test") do |t|
12
12
  t.warning = false
13
13
  end
14
14
 
15
+ Rake::TestTask.new("pact_test") do |t|
16
+ t.libs << "test"
17
+ t.test_files = FileList["test/pacts/**/*_test.rb"]
18
+ t.warning = false
19
+ end
20
+
15
21
  task default: %i[lint test]
16
22
 
17
23
  require "pact_broker/client/tasks"
@@ -30,11 +30,6 @@ class GdsApi::Imminence < GdsApi::Base
30
30
  get_raw("#{@endpoint}/places/#{type}.kml").body
31
31
  end
32
32
 
33
- def areas_for_postcode(postcode)
34
- url = "#{@endpoint}/areas/#{uri_encode(postcode)}.json"
35
- get_json(url)
36
- end
37
-
38
33
  # @private
39
34
  def self.extract_location_hash(location)
40
35
  # Deal with all known location formats:
@@ -25,4 +25,22 @@ class GdsApi::LocationsApi < GdsApi::Base
25
25
 
26
26
  { "latitude" => response["average_latitude"], "longitude" => response["average_longitude"] } unless response["results"].nil?
27
27
  end
28
+
29
+ # Get all results for a postcode
30
+ #
31
+ # @param [String, nil] postcode The postcode for which results are requested
32
+ #
33
+ # @return [Hash] The fulls results as returned from Locations API, with the average latitude
34
+ # and longitude, and an array of results for individual addresses with lat/long/lcc, eg:
35
+ # {
36
+ # "average_latitude"=>51.43122412857143,
37
+ # "average_longitude"=>-0.37395367142857144,
38
+ # "results"=>
39
+ # [{"address"=>"29, DEAN ROAD, HAMPTON, TW12 1AQ",
40
+ # "latitude"=>51.4303819,
41
+ # "longitude"=>-0.3745976,
42
+ # "local_custodian_code"=>5810}, ETC...
43
+ def results_for_postcode(postcode)
44
+ get_json("#{endpoint}/v1/locations?postcode=#{postcode}")
45
+ end
28
46
  end
@@ -12,21 +12,6 @@ module GdsApi
12
12
  stub_imminence_places_request(details["slug"], query_hash, details["details"])
13
13
  end
14
14
 
15
- def stub_imminence_has_areas_for_postcode(postcode, areas)
16
- results = {
17
- "_response_info" => { "status" => "ok" },
18
- "total" => areas.size,
19
- "startIndex" => 1,
20
- "pageSize" => areas.size,
21
- "currentPage" => 1,
22
- "pages" => 1,
23
- "results" => areas,
24
- }
25
-
26
- stub_request(:get, %r{\A#{IMMINENCE_API_ENDPOINT}/areas/#{postcode}\.json})
27
- .to_return(body: results.to_json)
28
- end
29
-
30
15
  def stub_imminence_has_places_for_postcode(places, slug, postcode, limit)
31
16
  query_hash = { "postcode" => postcode, "limit" => limit }
32
17
  stub_imminence_places_request(slug, query_hash, places)
@@ -5,11 +5,11 @@ module GdsApi
5
5
 
6
6
  def stub_locations_api_has_location(postcode, locations)
7
7
  results = []
8
- locations.each do |l|
8
+ locations.each_with_index do |l, i|
9
9
  results << {
10
+ "address" => l["address"] || "Empty Address #{i}",
10
11
  "latitude" => l["latitude"] || 0,
11
12
  "longitude" => l["longitude"] || 0,
12
- "postcode" => postcode,
13
13
  "local_custodian_code" => l["local_custodian_code"],
14
14
  }
15
15
  end
@@ -4,7 +4,7 @@ require "gds_api/test_helpers/json_client_helper"
4
4
  module GdsApi
5
5
  module TestHelpers
6
6
  module Search
7
- SEARCH_ENDPOINT = Plek.find("search")
7
+ SEARCH_ENDPOINT = Plek.find("search-api")
8
8
 
9
9
  def stub_any_search_post(index: nil)
10
10
  if index
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "83.0.0".freeze
2
+ VERSION = "85.0.0".freeze
3
3
  end
data/lib/gds_api.rb CHANGED
@@ -11,7 +11,6 @@ require "gds_api/licence_application"
11
11
  require "gds_api/link_checker_api"
12
12
  require "gds_api/local_links_manager"
13
13
  require "gds_api/locations_api"
14
- require "gds_api/mapit"
15
14
  require "gds_api/maslow"
16
15
  require "gds_api/organisations"
17
16
  require "gds_api/publishing_api"
@@ -123,13 +122,6 @@ module GdsApi
123
122
  GdsApi::LocationsApi.new(Plek.find("locations-api"), options)
124
123
  end
125
124
 
126
- # Creates a GdsApi::Mapit adapter
127
- #
128
- # @return [GdsApi::Mapit]
129
- def self.mapit(options = {})
130
- GdsApi::Mapit.new(Plek.find("mapit"), options)
131
- end
132
-
133
125
  # Creates a GdsApi::Maslow adapter
134
126
  #
135
127
  # It's set to use an external url as an endpoint as the Maslow adapter is
@@ -179,7 +171,7 @@ module GdsApi
179
171
  #
180
172
  # @return [GdsApi::Search]
181
173
  def self.search(options = {})
182
- GdsApi::Search.new(Plek.find("search"), options)
174
+ GdsApi::Search.new(Plek.find("search-api"), options)
183
175
  end
184
176
 
185
177
  # Creates a GdsApi::Support adapter
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: 83.0.0
4
+ version: 85.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: 2022-10-03 00:00:00.000000000 Z
11
+ date: 2022-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '1.14'
159
+ version: '2.0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '1.14'
166
+ version: '2.0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: pact
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -268,14 +268,14 @@ dependencies:
268
268
  requirements:
269
269
  - - '='
270
270
  - !ruby/object:Gem::Version
271
- version: 4.7.0
271
+ version: 4.9.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.7.0
278
+ version: 4.9.0
279
279
  - !ruby/object:Gem::Dependency
280
280
  name: simplecov
281
281
  requirement: !ruby/object:Gem::Requirement
@@ -358,7 +358,6 @@ files:
358
358
  - lib/gds_api/list_response.rb
359
359
  - lib/gds_api/local_links_manager.rb
360
360
  - lib/gds_api/locations_api.rb
361
- - lib/gds_api/mapit.rb
362
361
  - lib/gds_api/maslow.rb
363
362
  - lib/gds_api/middleware/govuk_header_sniffer.rb
364
363
  - lib/gds_api/organisations.rb
@@ -383,7 +382,6 @@ files:
383
382
  - lib/gds_api/test_helpers/link_checker_api.rb
384
383
  - lib/gds_api/test_helpers/local_links_manager.rb
385
384
  - lib/gds_api/test_helpers/locations_api.rb
386
- - lib/gds_api/test_helpers/mapit.rb
387
385
  - lib/gds_api/test_helpers/organisations.rb
388
386
  - lib/gds_api/test_helpers/publishing_api.rb
389
387
  - lib/gds_api/test_helpers/router.rb
@@ -419,7 +417,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
419
417
  - !ruby/object:Gem::Version
420
418
  version: '0'
421
419
  requirements: []
422
- rubygems_version: 3.1.6
420
+ rubygems_version: 3.3.26
423
421
  signing_key:
424
422
  specification_version: 4
425
423
  summary: Adapters to work with GDS APIs
data/lib/gds_api/mapit.rb DELETED
@@ -1,51 +0,0 @@
1
- require_relative "base"
2
- require_relative "exceptions"
3
-
4
- class GdsApi::Mapit < GdsApi::Base
5
- def location_for_postcode(postcode)
6
- response = get_json("#{base_url}/postcode/#{CGI.escape postcode}.json")
7
- Location.new(response) unless response.nil?
8
- end
9
-
10
- def areas_for_type(type)
11
- get_json("#{base_url}/areas/#{type}.json")
12
- end
13
-
14
- def area_for_code(code_type, code)
15
- get_json("#{base_url}/code/#{code_type}/#{code}.json")
16
- end
17
-
18
- class Location
19
- attr_reader :response
20
-
21
- def initialize(response)
22
- @response = response
23
- end
24
-
25
- def lat
26
- @response["wgs84_lat"]
27
- end
28
-
29
- def lon
30
- @response["wgs84_lon"]
31
- end
32
-
33
- def areas
34
- @response["areas"].map { |_i, area| OpenStruct.new(area) }
35
- end
36
-
37
- def postcode
38
- @response["postcode"]
39
- end
40
-
41
- def country_name
42
- @response["country_name"]
43
- end
44
- end
45
-
46
- private
47
-
48
- def base_url
49
- endpoint
50
- end
51
- end
@@ -1,91 +0,0 @@
1
- module GdsApi
2
- module TestHelpers
3
- module Mapit
4
- MAPIT_ENDPOINT = Plek.find("mapit")
5
-
6
- def stub_mapit_has_a_postcode(postcode, coords)
7
- response = {
8
- "wgs84_lat" => coords.first,
9
- "wgs84_lon" => coords.last,
10
- "postcode" => postcode,
11
- }
12
-
13
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/#{postcode.tr(' ', '+')}.json")
14
- .to_return(body: response.to_json, status: 200)
15
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/partial/#{postcode.split(' ').first}.json")
16
- .to_return(body: response.to_json, status: 200)
17
- end
18
-
19
- def stub_mapit_has_a_postcode_and_areas(postcode, coords, areas)
20
- response = {
21
- "wgs84_lat" => coords.first,
22
- "wgs84_lon" => coords.last,
23
- "postcode" => postcode,
24
- }
25
-
26
- area_response = Hash[areas.map.with_index do |area, i|
27
- [i,
28
- {
29
- "codes" => {
30
- "ons" => area["ons"],
31
- "gss" => area["gss"],
32
- "govuk_slug" => area["govuk_slug"],
33
- },
34
- "name" => area["name"],
35
- "type" => area["type"],
36
- "country_name" => area["country_name"],
37
- }]
38
- end]
39
-
40
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/#{postcode.tr(' ', '+')}.json")
41
- .to_return(body: response.merge("areas" => area_response).to_json, status: 200)
42
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/partial/#{postcode.split(' ').first}.json")
43
- .to_return(body: response.to_json, status: 200)
44
- end
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
-
60
- def stub_mapit_does_not_have_a_postcode(postcode)
61
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/#{postcode.tr(' ', '+')}.json")
62
- .to_return(body: { "code" => 404, "error" => "No Postcode matches the given query." }.to_json, status: 404)
63
- end
64
-
65
- def stub_mapit_does_not_have_a_bad_postcode(postcode)
66
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/#{postcode.tr(' ', '+')}.json")
67
- .to_return(body: { "code" => 400, "error" => "Postcode '#{postcode}' is not valid." }.to_json, status: 400)
68
- end
69
-
70
- def stub_mapit_has_areas(area_type, areas)
71
- stub_request(:get, "#{MAPIT_ENDPOINT}/areas/#{area_type}.json")
72
- .to_return(body: areas.to_json, status: 200)
73
- end
74
-
75
- def stub_mapit_does_not_have_areas(area_type)
76
- stub_request(:get, "#{MAPIT_ENDPOINT}/areas/#{area_type}.json")
77
- .to_return(body: [].to_json, status: 200)
78
- end
79
-
80
- def stub_mapit_has_area_for_code(code_type, code, area)
81
- stub_request(:get, "#{MAPIT_ENDPOINT}/code/#{code_type}/#{code}.json")
82
- .to_return(body: area.to_json, status: 200)
83
- end
84
-
85
- def stub_mapit_does_not_have_area_for_code(code_type, code)
86
- stub_request(:get, "#{MAPIT_ENDPOINT}/code/#{code_type}/#{code}.json")
87
- .to_return(body: { "code" => 404, "error" => "No areas were found that matched code #{code_type} = #{code}." }.to_json, status: 404)
88
- end
89
- end
90
- end
91
- end