gds-api-adapters 79.0.0 → 79.1.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/locations_api.rb +28 -0
- data/lib/gds_api/test_helpers/locations_api.rb +38 -0
- data/lib/gds_api/version.rb +1 -1
- data/lib/gds_api.rb +8 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be2d6d94c4da753ae82eabe4728e9e21d385c8d7332baa5682eed54ee4d41d37
|
4
|
+
data.tar.gz: c0435733dd835d528ae596002542aa426030b494bcb7c839ba80b8020322e089
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f731412f3b2172d700bae052a934b30051213c28dd8b6217154196193b5c6c246efeac1b682b199cce2f8f1d38974c7864fb3aca682219492da8ccf92f41b2b0
|
7
|
+
data.tar.gz: 4e61e4360f445fa5c37e364303893874eedc3004e8e53d6dc0df3ffffbb08e1f0316882860bf9c389bdc12a425cbd2e93aa6ef7823aaa8ed300ae60dc28446f8
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
require_relative "exceptions"
|
3
|
+
|
4
|
+
class GdsApi::LocationsApi < GdsApi::Base
|
5
|
+
# Get a list of local custodian codes for a postcode
|
6
|
+
#
|
7
|
+
# @param [String, nil] postcode The postcode for which the custodian codes are requested
|
8
|
+
#
|
9
|
+
# @return [Array] All local custodian codes for a specific postcode
|
10
|
+
def local_custodian_code_for_postcode(postcode)
|
11
|
+
response = get_json("#{endpoint}/locations?postcode=#{postcode}.json")
|
12
|
+
|
13
|
+
return [] if response["results"].nil?
|
14
|
+
|
15
|
+
response["results"].map { |r| r["local_custodian_code"] }.uniq
|
16
|
+
end
|
17
|
+
|
18
|
+
# Get the average coordinates for a postcode
|
19
|
+
#
|
20
|
+
# @param [String, nil] postcode The postcode for which the coordinates are requested
|
21
|
+
#
|
22
|
+
# @return [Hash] The average coordinates (two fields, "latitude" and "longitude") for a specific postcode
|
23
|
+
def coordinates_for_postcode(postcode)
|
24
|
+
response = get_json("#{endpoint}/locations?postcode=#{postcode}.json")
|
25
|
+
|
26
|
+
{ "latitude" => response["average_latitude"], "longitude" => response["average_longitude"] } unless response["results"].nil?
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module GdsApi
|
2
|
+
module TestHelpers
|
3
|
+
module LocationsApi
|
4
|
+
LOCATIONS_API_ENDPOINT = Plek.current.find("locations-api")
|
5
|
+
|
6
|
+
def stub_locations_api_has_location(postcode, locations)
|
7
|
+
results = []
|
8
|
+
locations.each do |l|
|
9
|
+
results << {
|
10
|
+
"latitude" => l["latitude"],
|
11
|
+
"longitude" => l["longitude"],
|
12
|
+
"postcode" => postcode,
|
13
|
+
"local_custodian_code" => l["local_custodian_code"],
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
response = {
|
18
|
+
"average_latitude" => results.sum { |r| r["latitude"] } / results.size.to_f,
|
19
|
+
"average_longitude" => results.sum { |r| r["longitude"] } / results.size.to_f,
|
20
|
+
"results" => results,
|
21
|
+
}
|
22
|
+
|
23
|
+
stub_request(:get, "#{LOCATIONS_API_ENDPOINT}/locations?postcode=#{postcode}.json")
|
24
|
+
.to_return(body: response.to_json, status: 200)
|
25
|
+
end
|
26
|
+
|
27
|
+
def stub_locations_api_has_no_location(postcode)
|
28
|
+
stub_request(:get, "#{LOCATIONS_API_ENDPOINT}/locations?postcode=#{postcode}.json")
|
29
|
+
.to_return(body: { "results" => nil }.to_json, status: 200)
|
30
|
+
end
|
31
|
+
|
32
|
+
def stub_locations_api_does_not_have_a_bad_postcode(postcode)
|
33
|
+
stub_request(:get, "#{LOCATIONS_API_ENDPOINT}/locations?postcode=#{postcode}.json")
|
34
|
+
.to_return(body: { "code" => 400, "error" => "Postcode '#{postcode}' is not valid." }.to_json, status: 400)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/gds_api/version.rb
CHANGED
data/lib/gds_api.rb
CHANGED
@@ -10,6 +10,7 @@ require "gds_api/imminence"
|
|
10
10
|
require "gds_api/licence_application"
|
11
11
|
require "gds_api/link_checker_api"
|
12
12
|
require "gds_api/local_links_manager"
|
13
|
+
require "gds_api/locations_api"
|
13
14
|
require "gds_api/mapit"
|
14
15
|
require "gds_api/maslow"
|
15
16
|
require "gds_api/organisations"
|
@@ -201,4 +202,11 @@ module GdsApi
|
|
201
202
|
def self.worldwide(options = {})
|
202
203
|
GdsApi::Worldwide.new(Plek.new.website_root, options)
|
203
204
|
end
|
205
|
+
|
206
|
+
# Creates a GdsApi::LocationsApi adapter
|
207
|
+
#
|
208
|
+
# @return [GdsApi::LocationsApi]
|
209
|
+
def self.locations_api(options = {})
|
210
|
+
GdsApi::LocationsApi.new(Plek.find("locations-api"), options)
|
211
|
+
end
|
204
212
|
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: 79.
|
4
|
+
version: 79.1.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-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -385,6 +385,7 @@ files:
|
|
385
385
|
- lib/gds_api/link_checker_api.rb
|
386
386
|
- lib/gds_api/list_response.rb
|
387
387
|
- lib/gds_api/local_links_manager.rb
|
388
|
+
- lib/gds_api/locations_api.rb
|
388
389
|
- lib/gds_api/mapit.rb
|
389
390
|
- lib/gds_api/maslow.rb
|
390
391
|
- lib/gds_api/middleware/govuk_header_sniffer.rb
|
@@ -409,6 +410,7 @@ files:
|
|
409
410
|
- lib/gds_api/test_helpers/licence_application.rb
|
410
411
|
- lib/gds_api/test_helpers/link_checker_api.rb
|
411
412
|
- lib/gds_api/test_helpers/local_links_manager.rb
|
413
|
+
- lib/gds_api/test_helpers/locations_api.rb
|
412
414
|
- lib/gds_api/test_helpers/mapit.rb
|
413
415
|
- lib/gds_api/test_helpers/organisations.rb
|
414
416
|
- lib/gds_api/test_helpers/publishing_api.rb
|