defra_ruby_area 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/defra_ruby/area.rb +13 -0
- data/lib/defra_ruby/area/configuration.rb +13 -0
- data/lib/defra_ruby/area/services/base_area_service.rb +5 -1
- data/lib/defra_ruby/area/version.rb +1 -1
- data/spec/cassettes/public_face_area_invalid_blank.yml +2 -2
- data/spec/cassettes/public_face_area_valid.yml +2 -2
- data/spec/defra_ruby/area/configuration_spec.rb +15 -0
- data/spec/defra_ruby/area/services/public_face_area_service_spec.rb +2 -0
- data/spec/defra_ruby/area/services/water_management_area_service_spec.rb +2 -0
- data/spec/defra_ruby/area_spec.rb +18 -0
- data/spec/examples.txt +20 -13
- data/spec/support/shared_examples/handle_request_errors.rb +36 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f427f04ac61c560c18dc91548c45c1843097f1a
|
4
|
+
data.tar.gz: 8f4a923e04b6861a168e867c302ed7ff583f1997
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1def8fe471daa1dc45d2741e6509b3b4c84af6e49160e6635ba300f3b93c2e303c2e72513e94f91fbe475e4e1d18982ad9a2146469c0a49b7a2066ae13119825
|
7
|
+
data.tar.gz: b9c1eff78d8e407afff6ed9534fefa0287962cc414ba3155458f65e26aec5529c56f7db85b1844bdc998a28c94ecddfa337780eec0578d758037e9811b575879
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
[![Maintainability](https://api.codeclimate.com/v1/badges/7aeffed0588d86a5e553/maintainability)](https://codeclimate.com/github/DEFRA/defra-ruby-area/maintainability)
|
5
5
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/7aeffed0588d86a5e553/test_coverage)](https://codeclimate.com/github/DEFRA/defra-ruby-area/test_coverage)
|
6
6
|
[![security](https://hakiri.io/github/DEFRA/defra-ruby-area/master.svg)](https://hakiri.io/github/DEFRA/defra-ruby-area/master)
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/defra_ruby_area.svg)](https://badge.fury.io/rb/defra_ruby_area)
|
7
8
|
[![Licence](https://img.shields.io/badge/Licence-OGLv3-blue.svg)](http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3)
|
8
9
|
|
9
10
|
This ruby gem provides a means of looking up an Environment Agency Administrative boundary from a GIS Web Feature Service (WFS). Provided with a valid [easting and northing](https://en.wikipedia.org/wiki/Easting_and_northing) it will query the WFS and return the long name for the area if a match is found.
|
data/lib/defra_ruby/area.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "area/configuration"
|
3
4
|
require_relative "area/no_match_error"
|
4
5
|
require_relative "area/response"
|
5
6
|
|
@@ -9,5 +10,17 @@ require_relative "area/services/water_management_area_service"
|
|
9
10
|
|
10
11
|
module DefraRuby
|
11
12
|
module Area
|
13
|
+
class << self
|
14
|
+
# attr_accessor :configuration
|
15
|
+
|
16
|
+
def configure
|
17
|
+
yield(configuration)
|
18
|
+
end
|
19
|
+
|
20
|
+
def configuration
|
21
|
+
@configuration ||= Configuration.new
|
22
|
+
@configuration
|
23
|
+
end
|
24
|
+
end
|
12
25
|
end
|
13
26
|
end
|
@@ -27,7 +27,11 @@ module DefraRuby
|
|
27
27
|
def response_exe
|
28
28
|
lambda do
|
29
29
|
begin
|
30
|
-
response = RestClient::Request.execute(
|
30
|
+
response = RestClient::Request.execute(
|
31
|
+
method: :get,
|
32
|
+
url: url,
|
33
|
+
timeout: DefraRuby::Area.configuration.timeout
|
34
|
+
)
|
31
35
|
area = parse_xml(response)
|
32
36
|
raise NoMatchError if area.nil? || area == ""
|
33
37
|
rescue StandardError => e
|
@@ -131,7 +131,7 @@ http_interactions:
|
|
131
131
|
Server:
|
132
132
|
- nginx
|
133
133
|
Date:
|
134
|
-
-
|
134
|
+
- Sun, 04 Aug 2019 10:30:09 GMT
|
135
135
|
Content-Type:
|
136
136
|
- application/xml
|
137
137
|
Content-Length:
|
@@ -153,5 +153,5 @@ http_interactions:
|
|
153
153
|
<ogc:ServiceException><![CDATA[Operator 'Intersects' can't parse geometry.]]></ogc:ServiceException>
|
154
154
|
</ogc:ServiceExceptionReport>
|
155
155
|
http_version:
|
156
|
-
recorded_at:
|
156
|
+
recorded_at: Sun, 04 Aug 2019 10:30:09 GMT
|
157
157
|
recorded_with: VCR 4.0.0
|
@@ -128,7 +128,7 @@ http_interactions:
|
|
128
128
|
Server:
|
129
129
|
- nginx
|
130
130
|
Date:
|
131
|
-
-
|
131
|
+
- Sun, 04 Aug 2019 10:30:09 GMT
|
132
132
|
Content-Type:
|
133
133
|
- application/xml
|
134
134
|
Content-Length:
|
@@ -161,5 +161,5 @@ http_interactions:
|
|
161
161
|
</gml:featureMember>
|
162
162
|
</wfs:FeatureCollection>
|
163
163
|
http_version:
|
164
|
-
recorded_at:
|
164
|
+
recorded_at: Sun, 04 Aug 2019 10:30:09 GMT
|
165
165
|
recorded_with: VCR 4.0.0
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
module DefraRuby
|
6
|
+
module Area
|
7
|
+
RSpec.describe Configuration do
|
8
|
+
it "sets the appropriate default config settings" do
|
9
|
+
fresh_config = described_class.new
|
10
|
+
|
11
|
+
expect(fresh_config.timeout).to eq(3)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -9,4 +9,22 @@ RSpec.describe DefraRuby::Area do
|
|
9
9
|
expect(DefraRuby::Area::VERSION).to match(/\d+\.\d+\.\d+/)
|
10
10
|
end
|
11
11
|
end
|
12
|
+
|
13
|
+
describe "#configuration" do
|
14
|
+
context "when the host app has not provided configuration" do
|
15
|
+
it "returns a DefraRuby::Area::Configuration instance" do
|
16
|
+
expect(described_class.configuration).to be_an_instance_of(DefraRuby::Area::Configuration)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when the host app has provided configuration" do
|
21
|
+
let(:timeout) { 10 }
|
22
|
+
|
23
|
+
it "returns an DefraRuby::Area::Configuration instance with a matching timeout" do
|
24
|
+
described_class.configure { |config| config.timeout = timeout }
|
25
|
+
|
26
|
+
expect(described_class.configuration.timeout).to eq(timeout)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
12
30
|
end
|
data/spec/examples.txt
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
example_id | status | run_time |
|
2
2
|
-------------------------------------------------------------------------------- | ------ | --------------- |
|
3
|
-
./spec/defra_ruby/area/
|
4
|
-
./spec/defra_ruby/area/response_spec.rb[1:1:
|
5
|
-
./spec/defra_ruby/area/response_spec.rb[1:2:1
|
6
|
-
./spec/defra_ruby/area/response_spec.rb[1:2:
|
7
|
-
./spec/defra_ruby/area/response_spec.rb[1:
|
8
|
-
./spec/defra_ruby/area/response_spec.rb[1:3:
|
9
|
-
./spec/defra_ruby/area/
|
10
|
-
./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:
|
11
|
-
./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:2:
|
12
|
-
./spec/defra_ruby/area/services/
|
13
|
-
./spec/defra_ruby/area/services/
|
14
|
-
./spec/defra_ruby/area/services/
|
15
|
-
./spec/defra_ruby/
|
3
|
+
./spec/defra_ruby/area/configuration_spec.rb[1:1] | passed | 0.0001 seconds |
|
4
|
+
./spec/defra_ruby/area/response_spec.rb[1:1:1:1] | passed | 0.00017 seconds |
|
5
|
+
./spec/defra_ruby/area/response_spec.rb[1:1:2:1] | passed | 0.00013 seconds |
|
6
|
+
./spec/defra_ruby/area/response_spec.rb[1:2:1:1] | passed | 0.00013 seconds |
|
7
|
+
./spec/defra_ruby/area/response_spec.rb[1:2:2:1] | passed | 0.00013 seconds |
|
8
|
+
./spec/defra_ruby/area/response_spec.rb[1:3:1:1] | passed | 0.00011 seconds |
|
9
|
+
./spec/defra_ruby/area/response_spec.rb[1:3:2:1] | passed | 0.00012 seconds |
|
10
|
+
./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:1:1] | passed | 0.37074 seconds |
|
11
|
+
./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:2:1:1] | passed | 0.33628 seconds |
|
12
|
+
./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:2:2:1] | passed | 0.03231 seconds |
|
13
|
+
./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:3:1:1] | passed | 0.03391 seconds |
|
14
|
+
./spec/defra_ruby/area/services/public_face_area_service_spec.rb[1:1:3:2:1] | passed | 0.02614 seconds |
|
15
|
+
./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:1:1] | passed | 0.0305 seconds |
|
16
|
+
./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:2:1:1] | passed | 0.02802 seconds |
|
17
|
+
./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:2:2:1] | passed | 0.02484 seconds |
|
18
|
+
./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:3:1:1] | passed | 0.01976 seconds |
|
19
|
+
./spec/defra_ruby/area/services/water_management_area_service_spec.rb[1:1:3:2:1] | passed | 0.02365 seconds |
|
20
|
+
./spec/defra_ruby/area_spec.rb[1:1:1] | passed | 0.00131 seconds |
|
21
|
+
./spec/defra_ruby/area_spec.rb[1:2:1:1] | passed | 0.00057 seconds |
|
22
|
+
./spec/defra_ruby/area_spec.rb[1:2:2:1] | passed | 0.0013 seconds |
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.shared_examples "handle request errors" do
|
4
|
+
context "when there is a problem with the Web Feature Service" do
|
5
|
+
before(:each) { VCR.turn_off! }
|
6
|
+
after(:each) { VCR.turn_on! }
|
7
|
+
|
8
|
+
let(:host) { "https://environment.data.gov.uk/" }
|
9
|
+
let(:easting) { 408_602.61 }
|
10
|
+
let(:northing) { 257_535.31 }
|
11
|
+
|
12
|
+
context "and the request times out" do
|
13
|
+
before(:each) { stub_request(:any, /.*#{host}.*/).to_timeout }
|
14
|
+
|
15
|
+
it "returns a failed response" do
|
16
|
+
response = described_class.run(easting, northing)
|
17
|
+
expect(response).to be_a(DefraRuby::Area::Response)
|
18
|
+
expect(response).to_not be_successful
|
19
|
+
expect(response.area).to be_nil
|
20
|
+
expect(response.error).to_not be_nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "and the request returns an error" do
|
25
|
+
before(:each) { stub_request(:any, /.*#{host}.*/).to_raise(SocketError) }
|
26
|
+
|
27
|
+
it "returns a failed response" do
|
28
|
+
response = described_class.run(easting, northing)
|
29
|
+
expect(response).to be_a(DefraRuby::Area::Response)
|
30
|
+
expect(response).to_not be_successful
|
31
|
+
expect(response.area).to be_nil
|
32
|
+
expect(response.error).to_not be_nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: defra_ruby_area
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Defra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -193,6 +193,7 @@ files:
|
|
193
193
|
- bin/setup
|
194
194
|
- lib/defra_ruby.rb
|
195
195
|
- lib/defra_ruby/area.rb
|
196
|
+
- lib/defra_ruby/area/configuration.rb
|
196
197
|
- lib/defra_ruby/area/no_match_error.rb
|
197
198
|
- lib/defra_ruby/area/response.rb
|
198
199
|
- lib/defra_ruby/area/services/base_area_service.rb
|
@@ -205,6 +206,7 @@ files:
|
|
205
206
|
- spec/cassettes/water_management_area_invalid_blank.yml
|
206
207
|
- spec/cassettes/water_management_area_invalid_coords.yml
|
207
208
|
- spec/cassettes/water_management_area_valid.yml
|
209
|
+
- spec/defra_ruby/area/configuration_spec.rb
|
208
210
|
- spec/defra_ruby/area/response_spec.rb
|
209
211
|
- spec/defra_ruby/area/services/public_face_area_service_spec.rb
|
210
212
|
- spec/defra_ruby/area/services/water_management_area_service_spec.rb
|
@@ -214,6 +216,7 @@ files:
|
|
214
216
|
- spec/support/defra_ruby_area.rb
|
215
217
|
- spec/support/dotenv.rb
|
216
218
|
- spec/support/pry.rb
|
219
|
+
- spec/support/shared_examples/handle_request_errors.rb
|
217
220
|
- spec/support/simplecov.rb
|
218
221
|
- spec/support/vcr.rb
|
219
222
|
homepage: https://github.com/DEFRA/defra-ruby-area
|
@@ -243,6 +246,7 @@ specification_version: 4
|
|
243
246
|
summary: Defra ruby on rails EA administrative area lookup
|
244
247
|
test_files:
|
245
248
|
- spec/spec_helper.rb
|
249
|
+
- spec/defra_ruby/area/configuration_spec.rb
|
246
250
|
- spec/defra_ruby/area/response_spec.rb
|
247
251
|
- spec/defra_ruby/area/services/water_management_area_service_spec.rb
|
248
252
|
- spec/defra_ruby/area/services/public_face_area_service_spec.rb
|
@@ -259,3 +263,4 @@ test_files:
|
|
259
263
|
- spec/support/vcr.rb
|
260
264
|
- spec/support/pry.rb
|
261
265
|
- spec/support/dotenv.rb
|
266
|
+
- spec/support/shared_examples/handle_request_errors.rb
|