gds-api-adapters 84.0.0 → 85.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +6 -0
- data/lib/gds_api/locations_api.rb +18 -0
- data/lib/gds_api/test_helpers/locations_api.rb +2 -2
- data/lib/gds_api/version.rb +1 -1
- data/lib/gds_api.rb +0 -8
- metadata +7 -9
- data/lib/gds_api/mapit.rb +0 -51
- data/lib/gds_api/test_helpers/mapit.rb +0 -91
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0e7c159e27c8d969ceda2b447b8fcf1fe39528236bd924ee7dd33c97e27b6ea
|
4
|
+
data.tar.gz: c19e0660b7cf3e5ea2bd59ea39b940d45cd475230f45805f6f886606ab039e76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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"
|
@@ -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
|
@@ -5,11 +5,11 @@ module GdsApi
|
|
5
5
|
|
6
6
|
def stub_locations_api_has_location(postcode, locations)
|
7
7
|
results = []
|
8
|
-
locations.
|
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
|
data/lib/gds_api/version.rb
CHANGED
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
|
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: 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-
|
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: '
|
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: '
|
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.
|
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.
|
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.
|
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
|