gds-api-adapters 84.0.0 → 85.0.1

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: ebd8c9876a6c89de5d0fdae4fcee5466c37e79e64d6841b02bb52ec581876166
4
- data.tar.gz: 64702ddd905480c111b7da1da758825d15d79d351dc9c4c14fd62308f16ab374
3
+ metadata.gz: 2b0dc3a7a3430d48165ca6e1b8720675dc9a1e5a94e8180d881d10f55af0c3a1
4
+ data.tar.gz: d12927fcfda065d8f8e9a51fbf01bcca3a4a8dd9e8b77550ed7cba34cb3b5145
5
5
  SHA512:
6
- metadata.gz: 177b9edcbb43ea4b9c5b0bd3df452e69a14458af851cb7339524a10c6f5a6d8439db588a9725350a9424ea336dfd2f464763be036112790be9d15ce48d98bde7
7
- data.tar.gz: c0ed5d8e02c058ca2c848ccf0e9235f664e7e263a0df3d5fa242a07b4c47953d28f3651e1f64567d07cfbd8286dc96a27695862fb13a0ed5577305a62874a9a4
6
+ metadata.gz: 7d3833134e981234ae2b3a9abc1c433b1f7e51c96fbc0b733f0e0ec325b515dea0513ae9fabcb7767c9a4a93117066429061aecd1a25a4d3ff50777655bfdaf7
7
+ data.tar.gz: d0774cdaa3d94aa927aa54c451434eb6036e2c4973864ee770186943f7fb106bbbf21e98756f11a274147c5e7568f22193781263fa20423876a3fb680ec983bd
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"
@@ -11,8 +11,8 @@ class GdsApi::EmailAlertApi < GdsApi::Base
11
11
  # @param attributes [Hash] document_type, links, tags used to search existing subscriber lists
12
12
  def find_or_create_subscriber_list(attributes)
13
13
  present_fields = [attributes["content_id"], attributes["links"], attributes["tags"]].compact.count
14
- if present_fields > 1
15
- message = "please provide content_id, tags, or links (or none), but not more than one of them"
14
+ if (present_fields > 1) && (attributes["tags"])
15
+ message = "Invalid attributes provided. Valid attributes are content_id only, tags only, links only, content_id AND links, or none."
16
16
  raise ArgumentError, message
17
17
  end
18
18
 
@@ -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.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
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "84.0.0".freeze
2
+ VERSION = "85.0.1".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
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: 84.0.0
4
+ version: 85.0.1
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-21 00:00:00.000000000 Z
11
+ date: 2023-01-30 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.4.5
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