gds-api-adapters 79.0.0 → 79.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e10a938b3148397b6c9a4ff3a06a6105f4d07ad02a80b4103440cd065b92d4ba
4
- data.tar.gz: e246e963aa42bcb62dc1479a076713ce4fefbcac40ca00e07b7f492a54396517
3
+ metadata.gz: be2d6d94c4da753ae82eabe4728e9e21d385c8d7332baa5682eed54ee4d41d37
4
+ data.tar.gz: c0435733dd835d528ae596002542aa426030b494bcb7c839ba80b8020322e089
5
5
  SHA512:
6
- metadata.gz: b2ee8e777bac9cbefe10b5497c5ec6cd48e4f7566cb07eff82bfa35a800c1fa28c99c3bfcd93c2dfa20fc63205c65142ddc4bc4e649ab1fa312565ea03bb324c
7
- data.tar.gz: 5764cc76a32646d8162f37d76098540acfe10e10d2c27f91504cf72c3a9abc3d8802f01c9d4cd64df920a503184e605ce718c1e0229a96aad52c2fda8e29f5cc
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
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "79.0.0".freeze
2
+ VERSION = "79.1.0".freeze
3
3
  end
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.0.0
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-01-25 00:00:00.000000000 Z
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