defra_ruby_address 0.1.0 → 0.4.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.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +82 -6
  3. data/Rakefile +2 -2
  4. data/bin/console +2 -6
  5. data/lib/defra_ruby/address/helmert_transformation.rb +102 -0
  6. data/lib/defra_ruby/address/response.rb +1 -2
  7. data/lib/defra_ruby/address/services/base_service.rb +2 -2
  8. data/lib/defra_ruby/address/services/easting_northing_to_lat_lon_service.rb +18 -0
  9. data/lib/defra_ruby/address/services/lat_lon_to_easting_northing_service.rb +20 -0
  10. data/lib/defra_ruby/address/services/os_api_address_lookup_v1_service.rb +100 -0
  11. data/lib/defra_ruby/address/services/os_places_address_lookup_service.rb +11 -14
  12. data/lib/defra_ruby/address/transverse_mercator_projection.rb +151 -0
  13. data/lib/defra_ruby/address/version.rb +1 -1
  14. data/lib/defra_ruby/address.rb +5 -0
  15. metadata +11 -181
  16. data/spec/defra_ruby/address/configuration_spec.rb +0 -18
  17. data/spec/defra_ruby/address/response_spec.rb +0 -70
  18. data/spec/defra_ruby/address/services/ea_address_facade_v1_1_service_spec.rb +0 -73
  19. data/spec/defra_ruby/address/services/ea_address_facade_v1_service_spec.rb +0 -73
  20. data/spec/defra_ruby/address/services/os_places_address_lookup_service_spec.rb +0 -72
  21. data/spec/defra_ruby/address_spec.rb +0 -30
  22. data/spec/examples.txt +0 -27
  23. data/spec/fixtures/ea_address_facade_v1_1_blank.json +0 -8
  24. data/spec/fixtures/ea_address_facade_v1_1_not_found.json +0 -14
  25. data/spec/fixtures/ea_address_facade_v1_1_valid.json +0 -83
  26. data/spec/fixtures/ea_address_facade_v1_blank.json +0 -13
  27. data/spec/fixtures/ea_address_facade_v1_not_found.json +0 -8
  28. data/spec/fixtures/ea_address_facade_v1_valid.json +0 -45
  29. data/spec/fixtures/os_places_address_lookup_blank.json +0 -5
  30. data/spec/fixtures/os_places_address_lookup_not_found.json +0 -6
  31. data/spec/fixtures/os_places_address_lookup_valid.json +0 -56
  32. data/spec/spec_helper.rb +0 -83
  33. data/spec/support/defra_ruby_address.rb +0 -4
  34. data/spec/support/dotenv.rb +0 -4
  35. data/spec/support/pry.rb +0 -7
  36. data/spec/support/shared_examples/handle_request_errors.rb +0 -32
  37. data/spec/support/simplecov.rb +0 -17
  38. data/spec/support/webmock.rb +0 -4
@@ -1,83 +0,0 @@
1
- {
2
- "header": {
3
- "totalMatches": 2,
4
- "startMatch": 1,
5
- "endMatch": 2,
6
- "query": "postcode=BS1 5AH",
7
- "language": "EN",
8
- "dataset": "DPA",
9
- "epoch": "70",
10
- "uriToSupplier": "https://api.ordnancesurvey.co.uk/places/v1/addresses/postcode?lr=EN&postcode=BS1%205AH&fq=logical_status_code%3A1&dataset=DPA",
11
- "uriFromClient": ""
12
- },
13
- "results": [
14
- {
15
- "uprn": 340116,
16
- "address": "ENVIRONMENT AGENCY, HORIZON HOUSE, DEANERY ROAD, BRISTOL, BS1 5AH",
17
- "organisation": "ENVIRONMENT AGENCY",
18
- "premises": "HORIZON HOUSE",
19
- "street_address": "DEANERY ROAD",
20
- "locality": null,
21
- "city": "BRISTOL",
22
- "postcode": "BS1 5AH",
23
- "country": "United Kingdom",
24
- "x": 358205.03,
25
- "y": 172708.06,
26
- "coordinate_system": null,
27
- "blpu_state_date": "12/10/2009",
28
- "blpu_state_code": 2,
29
- "postal_address_code": "D",
30
- "logical_status_code": 1,
31
- "source_data_type": "dpa",
32
- "blpu_state_code_description": "In use",
33
- "classification_code": "CO01",
34
- "classification_code_description": "Office / Work Studio",
35
- "lpi_logical_status_code": null,
36
- "lpi_logical_status_code_description": null,
37
- "match": 1.0,
38
- "match_description": "EXACT",
39
- "topography_layer_toid": "osgb1000002529079737",
40
- "parent_uprn": null,
41
- "last_update_date": "10/02/2016",
42
- "status": "APPROVED",
43
- "entry_date": "12/10/2009",
44
- "postal_address_code_description": "A record which is linked to PAF",
45
- "usrn": null,
46
- "language": "EN"
47
- },
48
- {
49
- "uprn": 340117,
50
- "address": "THRIVE RENEWABLES PLC, DEANERY ROAD, BRISTOL, BS1 5AH",
51
- "organisation": "THRIVE RENEWABLES PLC",
52
- "premises": null,
53
- "street_address": "DEANERY ROAD",
54
- "locality": null,
55
- "city": "BRISTOL",
56
- "postcode": "BS1 5AH",
57
- "country": "United Kingdom",
58
- "x": 358130.1,
59
- "y": 172687.88,
60
- "coordinate_system": null,
61
- "blpu_state_date": "12/10/2009",
62
- "blpu_state_code": 2,
63
- "postal_address_code": "D",
64
- "logical_status_code": 1,
65
- "source_data_type": "dpa",
66
- "blpu_state_code_description": "In use",
67
- "classification_code": "CO01",
68
- "classification_code_description": "Office / Work Studio",
69
- "lpi_logical_status_code": null,
70
- "lpi_logical_status_code_description": null,
71
- "match": 1.0,
72
- "match_description": "EXACT",
73
- "topography_layer_toid": "osgb1000002529079753",
74
- "parent_uprn": null,
75
- "last_update_date": "14/03/2019",
76
- "status": "APPROVED",
77
- "entry_date": "12/10/2009",
78
- "postal_address_code_description": "A record which is linked to PAF",
79
- "usrn": null,
80
- "language": "EN"
81
- }
82
- ]
83
- }
@@ -1,13 +0,0 @@
1
- {
2
- "facade_status_code": 400,
3
- "facade_error_message": "bad request to supplier service",
4
- "facade_error_code": "address_service_error_1",
5
- "supplier_was_called": true,
6
- "supplier_status_code": 400,
7
- "supplier_response": {
8
- "error": {
9
- "statuscode": 400,
10
- "message": "Parameter postcode cannot be empty."
11
- }
12
- }
13
- }
@@ -1,8 +0,0 @@
1
- {
2
- "totalMatches": 0,
3
- "startMatch": null,
4
- "endMatch": null,
5
- "uri_to_supplier": "https://api.ordnancesurvey.co.uk/places/v1/addresses/postcode?lr=EN&postcode=bs19xx&maxresults=100&dataset=DPA",
6
- "uri_from_client": "stub",
7
- "results": []
8
- }
@@ -1,45 +0,0 @@
1
- {
2
- "totalMatches": 2,
3
- "startMatch": 1,
4
- "endMatch": 2,
5
- "uri_to_supplier": "https://api.ordnancesurvey.co.uk/places/v1/addresses/postcode?lr=EN&postcode=bs15ah&maxresults=100&dataset=DPA",
6
- "uri_from_client": "stub",
7
- "results": [
8
- {
9
- "uprn": 340116,
10
- "address": "ENVIRONMENT AGENCY, HORIZON HOUSE, DEANERY ROAD, BRISTOL, BS1 5AH",
11
- "organisation": "ENVIRONMENT AGENCY",
12
- "premises": "HORIZON HOUSE",
13
- "street_address": "DEANERY ROAD",
14
- "locality": null,
15
- "city": "BRISTOL",
16
- "postcode": "BS1 5AH",
17
- "x": "358205.03",
18
- "y": "172708.07",
19
- "coordinate_system": null,
20
- "state_date": "12/10/2009",
21
- "blpu_state_code": null,
22
- "postal_address_code": null,
23
- "logical_status_code": null,
24
- "source_data_type": "dpa"
25
- },
26
- {
27
- "uprn": 340117,
28
- "address": "THRIVE RENEWABLES PLC, DEANERY ROAD, BRISTOL, BS1 5AH",
29
- "organisation": "THRIVE RENEWABLES PLC",
30
- "premises": null,
31
- "street_address": "DEANERY ROAD",
32
- "locality": null,
33
- "city": "BRISTOL",
34
- "postcode": "BS1 5AH",
35
- "x": "358130.1",
36
- "y": "172687.87",
37
- "coordinate_system": null,
38
- "state_date": "12/10/2009",
39
- "blpu_state_code": null,
40
- "postal_address_code": null,
41
- "logical_status_code": null,
42
- "source_data_type": "dpa"
43
- }
44
- ]
45
- }
@@ -1,5 +0,0 @@
1
- {
2
- "errors": [
3
- "query param postcode may not be empty"
4
- ]
5
- }
@@ -1,6 +0,0 @@
1
- {
2
- "error": {
3
- "statuscode": 400,
4
- "message": "Parameters are not valid"
5
- }
6
- }
@@ -1,56 +0,0 @@
1
- [
2
- {
3
- "moniker": "340116",
4
- "uprn": "340116",
5
- "lines": [
6
- "ENVIRONMENT AGENCY",
7
- "DEANERY ROAD"
8
- ],
9
- "town": "BRISTOL",
10
- "postcode": "BS1 5AH",
11
- "easting": "358205",
12
- "northing": "172708",
13
- "country": "",
14
- "dependentLocality": "",
15
- "dependentThroughfare": "",
16
- "administrativeArea": "BRISTOL",
17
- "localAuthorityUpdateDate": "",
18
- "royalMailUpdateDate": "",
19
- "partial": "ENVIRONMENT AGENCY, HORIZON HOUSE, DEANERY ROAD, BRISTOL, BS1 5AH",
20
- "subBuildingName": "",
21
- "buildingName": "HORIZON HOUSE",
22
- "thoroughfareName": "DEANERY ROAD",
23
- "organisationName": "ENVIRONMENT AGENCY",
24
- "buildingNumber": "",
25
- "postOfficeBoxNumber": "",
26
- "departmentName": "",
27
- "doubleDependentLocality": ""
28
- },
29
- {
30
- "moniker": "340117",
31
- "uprn": "340117",
32
- "lines": [
33
- "THRIVE RENEWABLES PLC",
34
- "DEANERY ROAD"
35
- ],
36
- "town": "BRISTOL",
37
- "postcode": "BS1 5AH",
38
- "easting": "358130",
39
- "northing": "172687",
40
- "country": "",
41
- "dependentLocality": "",
42
- "dependentThroughfare": "",
43
- "administrativeArea": "BRISTOL",
44
- "localAuthorityUpdateDate": "",
45
- "royalMailUpdateDate": "",
46
- "partial": "THRIVE RENEWABLES PLC, DEANERY ROAD, BRISTOL, BS1 5AH",
47
- "subBuildingName": "",
48
- "buildingName": "",
49
- "thoroughfareName": "DEANERY ROAD",
50
- "organisationName": "THRIVE RENEWABLES PLC",
51
- "buildingNumber": "",
52
- "postOfficeBoxNumber": "",
53
- "departmentName": "",
54
- "doubleDependentLocality": ""
55
- }
56
- ]
data/spec/spec_helper.rb DELETED
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/setup"
4
-
5
- # Require and run our simplecov initializer as the very first thing we do.
6
- # This is as per its docs https://github.com/colszowka/simplecov#getting-started
7
- require "./spec/support/simplecov"
8
-
9
- # Requires supporting ruby files with custom matchers and macros, etc, in
10
- # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
11
- # run as spec files by default. This means that files in spec/support that end
12
- # in _spec.rb will both be required and run as specs, causing the specs to be
13
- # run twice. It is recommended that you do not name files matching this glob to
14
- # end with _spec.rb. You can configure this pattern with the --pattern
15
- # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
16
- #
17
- # We make an exception for simplecov because that will already have been
18
- # required and run at the very top of spec_helper.rb
19
- support_files = Dir["./spec/support/**/*.rb"].reject { |file| file == "./spec/support/simplecov.rb" }
20
- support_files.each { |f| require f }
21
-
22
- RSpec.configure do |config|
23
- # rspec-expectations config goes here. You can use an alternate
24
- # assertion/expectation library such as wrong or the stdlib/minitest
25
- # assertions if you prefer.
26
- config.expect_with :rspec do |expectations|
27
- # This option will default to `true` in RSpec 4. It makes the `description`
28
- # and `failure_message` of custom matchers include text for helper methods
29
- # defined using `chain`, e.g.:
30
- # be_bigger_than(2).and_smaller_than(4).description
31
- # # => "be bigger than 2 and smaller than 4"
32
- # ...rather than:
33
- # # => "be bigger than 2"
34
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
- end
36
-
37
- # rspec-mocks config goes here. You can use an alternate test double
38
- # library (such as bogus or mocha) by changing the `mock_with` option here.
39
- config.mock_with :rspec do |mocks|
40
- # Prevents you from mocking or stubbing a method that does not exist on
41
- # a real object. This is generally recommended, and will default to
42
- # `true` in RSpec 4.
43
- mocks.verify_partial_doubles = true
44
- end
45
-
46
- # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
47
- # have no way to turn it off -- the option exists only for backwards
48
- # compatibility in RSpec 3). It causes shared context metadata to be
49
- # inherited by the metadata hash of host groups and examples, rather than
50
- # triggering implicit auto-inclusion in groups with matching metadata.
51
- config.shared_context_metadata_behavior = :apply_to_host_groups
52
-
53
- # This allows you to limit a spec run to individual examples or groups
54
- # you care about by tagging them with `:focus` metadata. When nothing
55
- # is tagged with `:focus`, all examples get run. RSpec also provides
56
- # aliases for `it`, `describe`, and `context` that include `:focus`
57
- # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
58
- config.filter_run_when_matching :focus
59
-
60
- # Allows RSpec to persist some state between runs in order to support
61
- # the `--only-failures` and `--next-failure` CLI options. We recommend
62
- # you configure your source control system to ignore this file.
63
- config.example_status_persistence_file_path = "spec/examples.txt"
64
-
65
- # Limits the available syntax to the non-monkey patched syntax that is
66
- # recommended. For more details, see:
67
- # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
68
- # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
69
- # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
70
- config.disable_monkey_patching!
71
-
72
- # Run specs in random order to surface order dependencies. If you find an
73
- # order dependency and want to debug it, you can fix the order by providing
74
- # the seed, which is printed after each run.
75
- # --seed 1234
76
- config.order = :random
77
-
78
- # Seed global randomization in this process using the `--seed` CLI option.
79
- # Setting this allows you to use `--seed` to deterministically reproduce
80
- # test failures related to randomization by passing the same `--seed` value
81
- # as the one that triggered the failure.
82
- Kernel.srand config.seed
83
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Need to require our actual code files.
4
- require "defra_ruby/address"
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Load env vars from a text file
4
- require "dotenv/load"
data/spec/support/pry.rb DELETED
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Support debugging in the tests. Add `binding.pry` wherever you want execution
4
- # to stop and the debugger to kick in.
5
- # Details on the debugging commands can be found here
6
- # https://github.com/deivid-rodriguez/pry-byebug#commands
7
- require "pry-byebug"
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.shared_examples "handle request errors" do
4
- context "when there is a problem with the address lookup" do
5
-
6
- context "and the request times out" do
7
- before { stub_request(:get, url).to_timeout }
8
-
9
- it "returns a failed response" do
10
- response = described_class.run(postcode)
11
-
12
- expect(response).to be_a(DefraRuby::Address::Response)
13
- expect(response).to_not be_successful
14
- expect(response.results).to be_empty
15
- expect(response.error).to_not be_nil
16
- end
17
- end
18
-
19
- context "and the request returns an error" do
20
- before { stub_request(:get, url).to_raise(SocketError) }
21
-
22
- it "returns a failed response" do
23
- response = described_class.run(postcode)
24
-
25
- expect(response).to be_a(DefraRuby::Address::Response)
26
- expect(response).to_not be_successful
27
- expect(response.results).to be_empty
28
- expect(response.error).to_not be_nil
29
- end
30
- end
31
- end
32
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "simplecov"
4
-
5
- # We start it with the rails param to ensure it includes coverage for all code
6
- # started by the rails app, and not just the files touched by our unit tests.
7
- # This gives us the most accurate assessment of our unit test coverage
8
- # https://github.com/colszowka/simplecov#getting-started
9
- SimpleCov.start do
10
- # We filter the spec folder, mainly to ensure that any dummy apps don't get
11
- # included in the coverage report. However our intent is that nothing in the
12
- # spec folder should be included
13
- add_filter "/spec/"
14
- # The version file is simply just that, so we do not feel the need to ensure
15
- # we have a test for it
16
- add_filter "lib/defra_ruby/validators/version"
17
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Stubbing HTTP requests
4
- require "webmock/rspec"