From 650add809d3e252c899255cafe186759e2189714 Mon Sep 17 00:00:00 2001 From: Abe Voelker Date: Tue, 2 Jan 2018 12:05:52 -0600 Subject: [PATCH 001/248] Handle IPv6 addresses when removing port numbers in request.location --- lib/geocoder/request.rb | 13 ++++++++++++- test/unit/request_test.rb | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/geocoder/request.rb b/lib/geocoder/request.rb index 5e2eb6c99..0180cf958 100644 --- a/lib/geocoder/request.rb +++ b/lib/geocoder/request.rb @@ -81,7 +81,18 @@ def geocoder_reject_trusted_ip_addresses(ip_addresses) end def geocoder_remove_port_from_addresses(ip_addresses) - ip_addresses.map { |ip| ip.split(':').first } + ip_addresses.map do |ip| + # IPv4 + if ip.count('.') > 0 + ip.split(':').first + # IPv6 bracket notation + elsif match = ip.match(/\[(\S+)\]/) + match.captures.first + # IPv6 bare notation + else + ip + end + end end def geocoder_reject_non_ipv4_addresses(ip_addresses) diff --git a/test/unit/request_test.rb b/test/unit/request_test.rb index 127f5f4f3..09e8ac9ac 100644 --- a/test/unit/request_test.rb +++ b/test/unit/request_test.rb @@ -72,6 +72,12 @@ def test_geocoder_remove_port_from_addresses_with_port req = MockRequest.new() assert_equal expected_ips, req.send(:geocoder_remove_port_from_addresses, ips) end + def test_geocoder_remove_port_from_ipv6_addresses_with_port + expected_ips = ['2600:1008:b16e:26da:ecb3:22f7:6be4:2137', '2600:1901:0:2df5::', '2001:db8:1f70::999:de8:7648:6e8', '10.128.0.2'] + ips = ['2600:1008:b16e:26da:ecb3:22f7:6be4:2137', '2600:1901:0:2df5::', '[2001:db8:1f70::999:de8:7648:6e8]:100', '10.128.0.2'] + req = MockRequest.new() + assert_equal expected_ips, req.send(:geocoder_remove_port_from_addresses, ips) + end def test_geocoder_remove_port_from_addresses_without_port expected_ips = ['127.0.0.1', '127.0.0.2', '127.0.0.3'] ips = ['127.0.0.1', '127.0.0.2', '127.0.0.3'] From 0b7a1abfdc4d42237f9dfa751c9f5bca71c5e190 Mon Sep 17 00:00:00 2001 From: Robert Schaefer Date: Mon, 8 Jan 2018 03:08:50 +0100 Subject: [PATCH 002/248] Provide ipdata.co as a lookup --- lib/geocoder/lookup.rb | 1 + lib/geocoder/lookups/ipdata_co.rb | 51 +++++++++++++++++++++++++++ lib/geocoder/results/ipdata_co.rb | 45 +++++++++++++++++++++++ test/fixtures/ipdata_co_74_200_247_59 | 24 +++++++++++++ test/fixtures/ipdata_co_no_results | 1 + test/test_helper.rb | 8 +++++ test/unit/error_handling_test.rb | 4 +-- test/unit/lookup_test.rb | 2 +- test/unit/lookups/ipdata_co_test.rb | 19 ++++++++++ 9 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 lib/geocoder/lookups/ipdata_co.rb create mode 100644 lib/geocoder/results/ipdata_co.rb create mode 100644 test/fixtures/ipdata_co_74_200_247_59 create mode 100644 test/fixtures/ipdata_co_no_results create mode 100644 test/unit/lookups/ipdata_co_test.rb diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index 2d7104190..b756f768f 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -71,6 +71,7 @@ def ip_services :maxmind_geoip2, :ipinfo_io, :ipapi_com, + :ipdata_co, :db_ip_com ] end diff --git a/lib/geocoder/lookups/ipdata_co.rb b/lib/geocoder/lookups/ipdata_co.rb new file mode 100644 index 000000000..f1322a2c8 --- /dev/null +++ b/lib/geocoder/lookups/ipdata_co.rb @@ -0,0 +1,51 @@ +require 'geocoder/lookups/base' +require 'geocoder/results/ipdata_co' + +module Geocoder::Lookup + class IpdataCo < Base + + def name + "ipdata.co" + end + + def supported_protocols + [:https] + end + + def query_url(query) + "#{protocol}://#{host}/#{query.sanitized_text}" + end + + private # --------------------------------------------------------------- + + def parse_raw_data(raw_data) + raw_data.match(/^404/) ? nil : super(raw_data) + end + + def results(query) + # don't look up a loopback address, just return the stored result + return [reserved_result(query.text)] if query.loopback_ip_address? + # note: Ipdata.co returns plain text on bad request + (doc = fetch_data(query)) ? [doc] : [] + end + + def reserved_result(ip) + { + "ip" => ip, + "city" => "", + "region_code" => "", + "region_name" => "", + "metrocode" => "", + "zipcode" => "", + "latitude" => "0", + "longitude" => "0", + "country_name" => "Reserved", + "country_code" => "RD" + } + end + + def host + "api.ipdata.co" + end + end +end diff --git a/lib/geocoder/results/ipdata_co.rb b/lib/geocoder/results/ipdata_co.rb new file mode 100644 index 000000000..497ac156d --- /dev/null +++ b/lib/geocoder/results/ipdata_co.rb @@ -0,0 +1,45 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class IpdataCo < Base + + def address(format = :full) + s = state_code.to_s == "" ? "" : ", #{state_code}" + "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "") + end + + def city + @data['city'] + end + + def state + @data['region'] + end + + def state_code + @data['region_code'] + end + + def country + @data['country_name'] + end + + def country_code + @data['country_code'] + end + + def postal_code + @data['postal'] + end + + def self.response_attributes + %w[ip asn organisation currency currency_symbol calling_code flag time_zone is_eu] + end + + response_attributes.each do |a| + define_method a do + @data[a] + end + end + end +end diff --git a/test/fixtures/ipdata_co_74_200_247_59 b/test/fixtures/ipdata_co_74_200_247_59 new file mode 100644 index 000000000..a2da12b53 --- /dev/null +++ b/test/fixtures/ipdata_co_74_200_247_59 @@ -0,0 +1,24 @@ +{ + "ip": "74.200.247.59", + "city": "Jersey City", + "region": "New Jersey", + "region_code": "NJ", + "country_name": "United States", + "country_code": "US", + "continent_name": "North America", + "continent_code": "NA", + "latitude": 40.7209, + "longitude": -74.0468, + "asn": "AS22576", + "organisation": "DataPipe, Inc.", + "postal": "07302", + "currency": "USD", + "currency_symbol": "$", + "calling_code": "1", + "flag": "https://ipdata.co/flags/us.png", + "time_zone": "America/New_York", + "is_eu": false, + "suspicious_factors": { + "is_tor": false + } +} \ No newline at end of file diff --git a/test/fixtures/ipdata_co_no_results b/test/fixtures/ipdata_co_no_results new file mode 100644 index 000000000..896eaf563 --- /dev/null +++ b/test/fixtures/ipdata_co_no_results @@ -0,0 +1 @@ +0.0.0 does not appear to be an IPv4 or IPv6 address \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 87e11da44..4857dfed7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -373,6 +373,14 @@ def default_fixture_filename end end + require 'geocoder/lookups/ipdata_co' + class IpdataCo + private + def default_fixture_filename + "ipdata_co_74_200_247_59" + end + end + require 'geocoder/lookups/ban_data_gouv_fr' class BanDataGouvFr private diff --git a/test/unit/error_handling_test.rb b/test/unit/error_handling_test.rb index ca20f3e5e..689d1fe56 100644 --- a/test/unit/error_handling_test.rb +++ b/test/unit/error_handling_test.rb @@ -19,7 +19,7 @@ def test_does_not_choke_on_timeout def test_always_raise_response_parse_error Geocoder.configure(:always_raise => [Geocoder::ResponseParseError]) - [:freegeoip, :google, :okf].each do |l| + [:freegeoip, :google, :ipdata_co, :okf].each do |l| lookup = Geocoder::Lookup.get(l) set_api_key!(l) assert_raises Geocoder::ResponseParseError do @@ -29,7 +29,7 @@ def test_always_raise_response_parse_error end def test_never_raise_response_parse_error - [:freegeoip, :google, :okf].each do |l| + [:freegeoip, :google, :ipdata_co, :okf].each do |l| lookup = Geocoder::Lookup.get(l) set_api_key!(l) silence_warnings do diff --git a/test/unit/lookup_test.rb b/test/unit/lookup_test.rb index 8dcaf8047..7f21877f7 100644 --- a/test/unit/lookup_test.rb +++ b/test/unit/lookup_test.rb @@ -24,7 +24,7 @@ def test_search_returns_empty_array_when_no_results def test_query_url_contains_values_in_params_hash Geocoder::Lookup.all_services_except_test.each do |l| - next if [:freegeoip, :maxmind_local, :telize, :pointpin, :geoip2, :maxmind_geoip2, :mapbox, :ipinfo_io, :ipapi_com].include? l # does not use query string + next if [:freegeoip, :maxmind_local, :telize, :pointpin, :geoip2, :maxmind_geoip2, :mapbox, :ipdata_co, :ipinfo_io, :ipapi_com].include? l # does not use query string set_api_key!(l) url = Geocoder::Lookup.get(l).query_url(Geocoder::Query.new( "test", :params => {:one_in_the_hand => "two in the bush"} diff --git a/test/unit/lookups/ipdata_co_test.rb b/test/unit/lookups/ipdata_co_test.rb new file mode 100644 index 000000000..fcd98f80b --- /dev/null +++ b/test/unit/lookups/ipdata_co_test.rb @@ -0,0 +1,19 @@ +# encoding: utf-8 +require 'test_helper' + +class IpdataCoTest < GeocoderTestCase + + def setup + Geocoder.configure(ip_lookup: :ipdata_co) + end + + def test_result_on_ip_address_search + result = Geocoder.search("74.200.247.59").first + assert result.is_a?(Geocoder::Result::IpdataCo) + end + + def test_result_components + result = Geocoder.search("74.200.247.59").first + assert_equal "Jersey City, NJ 07302, United States", result.address + end +end From 9e37488756c6b808af48ed87c8400e390816a700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= <roschaefer@users.noreply.github.com> Date: Wed, 10 Jan 2018 15:51:07 +0100 Subject: [PATCH 003/248] Add :ipdata_co to README --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 232a2dd61..0697d8559 100644 --- a/README.md +++ b/README.md @@ -856,6 +856,18 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Documentation**: https://db-ip.com/api/doc.php * **Terms of Service**: https://db-ip.com/tos.php +#### Ipdata.co (`:ipdata_co`) + +* **API key**: optional, see: https://ipdata.co/pricing.html +* **Quota**: 1500/day (up to 600k with paid API keys) +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://ipdata.co/docs.html +* **Terms of Service**: https://ipdata.co/terms.html +* **Limitations**: ? + + ### IP Address Local Database Services #### MaxMind Local (`:maxmind_local`) - EXPERIMENTAL From 3cfd2a20191cb87281061d14ad2b5aa1d7e29058 Mon Sep 17 00:00:00 2001 From: Robert Schaefer <robert.schaefer@student.hpi.de> Date: Wed, 10 Jan 2018 23:30:48 +0100 Subject: [PATCH 004/248] Proper error handling Remove silly check for HTML tags Add test case for invalid json --- lib/geocoder/lookups/ipdata_co.rb | 4 ---- test/fixtures/ipdata_co_8_8_8 | 1 + test/unit/lookups/ipdata_co_test.rb | 8 ++++++++ 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/ipdata_co_8_8_8 diff --git a/lib/geocoder/lookups/ipdata_co.rb b/lib/geocoder/lookups/ipdata_co.rb index f1322a2c8..a5fa295c1 100644 --- a/lib/geocoder/lookups/ipdata_co.rb +++ b/lib/geocoder/lookups/ipdata_co.rb @@ -18,10 +18,6 @@ def query_url(query) private # --------------------------------------------------------------- - def parse_raw_data(raw_data) - raw_data.match(/^<html><title>404/) ? nil : super(raw_data) - end - def results(query) # don't look up a loopback address, just return the stored result return [reserved_result(query.text)] if query.loopback_ip_address? diff --git a/test/fixtures/ipdata_co_8_8_8 b/test/fixtures/ipdata_co_8_8_8 new file mode 100644 index 000000000..2462e1270 --- /dev/null +++ b/test/fixtures/ipdata_co_8_8_8 @@ -0,0 +1 @@ +8.8.8 does not appear to be an IPv4 or IPv6 address \ No newline at end of file diff --git a/test/unit/lookups/ipdata_co_test.rb b/test/unit/lookups/ipdata_co_test.rb index fcd98f80b..3811a13c1 100644 --- a/test/unit/lookups/ipdata_co_test.rb +++ b/test/unit/lookups/ipdata_co_test.rb @@ -12,8 +12,16 @@ def test_result_on_ip_address_search assert result.is_a?(Geocoder::Result::IpdataCo) end + def test_invalid_json + Geocoder.configure(:always_raise => [Geocoder::ResponseParseError]) + assert_raise Geocoder::ResponseParseError do + Geocoder.search("8.8.8", ip_address: true) + end + end + def test_result_components result = Geocoder.search("74.200.247.59").first assert_equal "Jersey City, NJ 07302, United States", result.address end + end From eed78751a1d6816cca09a36ec63465cfc1de5e73 Mon Sep 17 00:00:00 2001 From: Abe Voelker <abe@abevoelker.com> Date: Wed, 10 Jan 2018 20:03:56 -0600 Subject: [PATCH 005/248] Fix Travis CI build errors --- .travis.yml | 2 ++ Gemfile | 4 ++-- Rakefile | 4 ++-- gemfiles/Gemfile.rails3.2 | 4 ++-- gemfiles/Gemfile.rails4.1 | 4 ++-- gemfiles/Gemfile.rails5.0 | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index bb325f3f9..d8587bf5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,8 @@ gemfile: - gemfiles/Gemfile.rails3.2 - gemfiles/Gemfile.rails4.1 - gemfiles/Gemfile.rails5.0 +before_install: + - which bundle >/dev/null 2>&1 || gem install bundler matrix: exclude: - rvm: 1.9.3 diff --git a/Gemfile b/Gemfile index 128b94fda..b52115ad5 100644 --- a/Gemfile +++ b/Gemfile @@ -31,14 +31,14 @@ group :test do gem 'webmock' platforms :ruby do - gem 'pg' + gem 'pg', '~> 0.11' gem 'mysql2', '~> 0.3.11' end platforms :jruby do gem 'jdbc-mysql' gem 'jdbc-sqlite3' - gem 'activerecord-jdbcpostgresql-adapter' + gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.0' end end diff --git a/Rakefile b/Rakefile index c7d106326..83de4cdd5 100644 --- a/Rakefile +++ b/Rakefile @@ -32,7 +32,7 @@ namespace :db do desc 'Drop the MySQL test databases' task :drop do - `mysqladmin --user=#{config['mysql']['username']} -f drop #{config['mysql']['database']}` + `mysql --user=#{config['mysql']['username']} -e "DROP DATABASE IF EXISTS #{config['mysql']['database']}"` end end @@ -44,7 +44,7 @@ namespace :db do desc 'Drop the PostgreSQL test databases' task :drop do - `dropdb #{config['postgres']['database']}` + `dropdb --if-exists #{config['postgres']['database']}` end end diff --git a/gemfiles/Gemfile.rails3.2 b/gemfiles/Gemfile.rails3.2 index da838d6ab..8eed6ddc6 100644 --- a/gemfiles/Gemfile.rails3.2 +++ b/gemfiles/Gemfile.rails3.2 @@ -31,13 +31,13 @@ group :test do gem 'webmock' platforms :ruby do - gem 'pg' + gem 'pg', '~> 0.11' gem 'mysql2', '~> 0.3.11' end platforms :jruby do gem 'jdbc-mysql' gem 'jdbc-sqlite3' - gem 'activerecord-jdbcpostgresql-adapter' + gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.0' end end diff --git a/gemfiles/Gemfile.rails4.1 b/gemfiles/Gemfile.rails4.1 index 34f96168b..b9b0a9448 100644 --- a/gemfiles/Gemfile.rails4.1 +++ b/gemfiles/Gemfile.rails4.1 @@ -31,13 +31,13 @@ group :test do gem 'webmock' platforms :ruby do - gem 'pg' + gem 'pg', '~> 0.11' gem 'mysql2', '~> 0.3.11' end platforms :jruby do gem 'jdbc-mysql' gem 'jdbc-sqlite3' - gem 'activerecord-jdbcpostgresql-adapter' + gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.0' end end diff --git a/gemfiles/Gemfile.rails5.0 b/gemfiles/Gemfile.rails5.0 index 07a4aaa87..21370903a 100644 --- a/gemfiles/Gemfile.rails5.0 +++ b/gemfiles/Gemfile.rails5.0 @@ -31,7 +31,7 @@ group :test do gem 'webmock' platforms :ruby do - gem 'pg' + gem 'pg', '~> 0.18' gem 'mysql2', '~> 0.3.11' end From 9ea50a86a1ef762269f4c8d09e5934afd5acd93c Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Thu, 11 Jan 2018 12:41:39 -0500 Subject: [PATCH 006/248] Add note about limitations of Test lookup results. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 232a2dd61..21b0012ab 100644 --- a/README.md +++ b/README.md @@ -1067,6 +1067,7 @@ Notes: - Keys must be strings not symbols when calling `add_stub` or `set_default_stub`. For example `'latitude' =>` not `:latitude =>`. - To clear stubs (e.g. prior to another spec), use `Geocoder::Lookup::Test.reset`. This will clear all stubs _including the default stub_. +- The stubbed result objects returned by the Test lookup do not support all the methods real result objects do. If you need to test interaction with real results it may be better to use an external stubbing tool and something like WebMock or VCR to prevent network calls. Command Line Interface From 5e5dfcd523b4cd99f22ef67208e31bba5a8dcdea Mon Sep 17 00:00:00 2001 From: Robert Schaefer <robert.schaefer@student.hpi.de> Date: Thu, 11 Jan 2018 23:46:46 +0100 Subject: [PATCH 007/248] Check HTTP 403 error on missing api keys --- lib/geocoder/lookups/ipdata_co.rb | 9 +++++++++ test/unit/lookups/ipdata_co_test.rb | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/geocoder/lookups/ipdata_co.rb b/lib/geocoder/lookups/ipdata_co.rb index a5fa295c1..04e38fa41 100644 --- a/lib/geocoder/lookups/ipdata_co.rb +++ b/lib/geocoder/lookups/ipdata_co.rb @@ -43,5 +43,14 @@ def reserved_result(ip) def host "api.ipdata.co" end + + def check_response_for_errors!(response) + if response.code.to_i == 403 + raise_error(Geocoder::RequestDenied) || + Geocoder.log(:warn, "Geocoding API error: 403 API key does not exist") + else + super(response) + end + end end end diff --git a/test/unit/lookups/ipdata_co_test.rb b/test/unit/lookups/ipdata_co_test.rb index 3811a13c1..5acdcf72e 100644 --- a/test/unit/lookups/ipdata_co_test.rb +++ b/test/unit/lookups/ipdata_co_test.rb @@ -24,4 +24,12 @@ def test_result_components assert_equal "Jersey City, NJ 07302, United States", result.address end + def test_not_authorized + Geocoder.configure(always_raise: [Geocoder::RequestDenied]) + lookup = Geocoder::Lookup.get(:ipdata_co) + assert_raises Geocoder::RequestDenied do + response = MockHttpResponse.new(code: 403) + lookup.send(:check_response_for_errors!, response) + end + end end From b05df568c732236b1ab68164c2a51c93cf0d8fb5 Mon Sep 17 00:00:00 2001 From: Robert Schaefer <robert.schaefer@student.hpi.de> Date: Fri, 12 Jan 2018 00:26:57 +0100 Subject: [PATCH 008/248] Add api-key to http request headers if given --- lib/geocoder/lookups/ipdata_co.rb | 1 + test/unit/lookups/ipdata_co_test.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/geocoder/lookups/ipdata_co.rb b/lib/geocoder/lookups/ipdata_co.rb index 04e38fa41..a8e0bf00d 100644 --- a/lib/geocoder/lookups/ipdata_co.rb +++ b/lib/geocoder/lookups/ipdata_co.rb @@ -19,6 +19,7 @@ def query_url(query) private # --------------------------------------------------------------- def results(query) + Geocoder.configure(:http_headers => { "api-key" => configuration.api_key }) if configuration.api_key # don't look up a loopback address, just return the stored result return [reserved_result(query.text)] if query.loopback_ip_address? # note: Ipdata.co returns plain text on bad request diff --git a/test/unit/lookups/ipdata_co_test.rb b/test/unit/lookups/ipdata_co_test.rb index 5acdcf72e..88a4d16c1 100644 --- a/test/unit/lookups/ipdata_co_test.rb +++ b/test/unit/lookups/ipdata_co_test.rb @@ -32,4 +32,23 @@ def test_not_authorized lookup.send(:check_response_for_errors!, response) end end + + def test_api_key + Geocoder.configure(:api_key => 'XXXX') + + # HACK: run the code once to add the api key to the HTTP request headers + Geocoder.search('8.8.8.8') + # It's really hard to 'un-monkey-patch' the base lookup class here + + require 'webmock/test_unit' + WebMock.enable! + stubbed_request = WebMock.stub_request(:get, "https://api.ipdata.co/8.8.8.8").with(headers: {'api-key' => 'XXXX'}).to_return(status: 200) + + g = Geocoder::Lookup::IpdataCo.new + g.send(:actual_make_api_request, Geocoder::Query.new('8.8.8.8')) + assert_requested(stubbed_request) + + WebMock.reset! + WebMock.disable! + end end From 4dc3b36e054b328ba2b15bcda3db239c6e9c72c6 Mon Sep 17 00:00:00 2001 From: German Velasco <germsvel@gmail.com> Date: Tue, 16 Jan 2018 16:03:50 -0500 Subject: [PATCH 009/248] Raise bing errors for statuses 403, 500, 503 Bing returns the status codes within the json response. When a request is forbidden, it will return a 403. If there is an internal server error, it will return a 500. And if the service is unavailable for some other reason, it will return a 503. That information was obtained from bing's [Status Codes and Error Handling](https://msdn.microsoft.com/en-us/library/ff701703.aspx) documentation. We handle those three status codes here to raise `Geocoder::RequestDenied` (for 403) and `Geocoder::ServiceUnavailable` (for 500 and 503). This allows for the users of the Geocoder to handle those errors in their applications. --- lib/geocoder/lookups/bing.rb | 5 +++++ test/fixtures/bing_forbidden_request | 16 ++++++++++++++++ test/fixtures/bing_internal_server_error | 16 ++++++++++++++++ test/unit/lookups/bing_test.rb | 14 ++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 test/fixtures/bing_forbidden_request create mode 100644 test/fixtures/bing_internal_server_error diff --git a/lib/geocoder/lookups/bing.rb b/lib/geocoder/lookups/bing.rb index 53aaadf57..5d46f3a83 100644 --- a/lib/geocoder/lookups/bing.rb +++ b/lib/geocoder/lookups/bing.rb @@ -44,6 +44,11 @@ def results(query) return doc['resourceSets'].first['estimatedTotal'] > 0 ? doc['resourceSets'].first['resources'] : [] elsif doc['statusCode'] == 401 and doc["authenticationResultCode"] == "InvalidCredentials" raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "Invalid Bing API key.") + elsif doc['statusCode'] == 403 + raise_error(Geocoder::RequestDenied) || Geocoder.log(:warn, "Bing Geocoding API error: Forbidden Request") + elsif [500, 503].include?(doc['statusCode']) + raise_error(Geocoder::ServiceUnavailable) || + Geocoder.log(:warn, "Bing Geocoding API error: Service Unavailable") else Geocoder.log(:warn, "Bing Geocoding API error: #{doc['statusCode']} (#{doc['statusDescription']}).") end diff --git a/test/fixtures/bing_forbidden_request b/test/fixtures/bing_forbidden_request new file mode 100644 index 000000000..6736e6abf --- /dev/null +++ b/test/fixtures/bing_forbidden_request @@ -0,0 +1,16 @@ +{ + "authenticationResultCode":"ValidCredentials", + "brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png", + "copyright":"Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.", + "resourceSets":[ + { + "estimatedTotal":0, + "resources":[ + + ] + } + ], + "statusCode":403, + "statusDescription":"OK", + "traceId":"907b76a307bc49129a489de3d4c992ea|CH1M001463|02.00.82.2800|CH1MSNVM001383, CH1MSNVM001358, CH1MSNVM001397" +} diff --git a/test/fixtures/bing_internal_server_error b/test/fixtures/bing_internal_server_error new file mode 100644 index 000000000..8abd2c4d6 --- /dev/null +++ b/test/fixtures/bing_internal_server_error @@ -0,0 +1,16 @@ +{ + "authenticationResultCode":"ValidCredentials", + "brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png", + "copyright":"Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.", + "resourceSets":[ + { + "estimatedTotal":0, + "resources":[ + + ] + } + ], + "statusCode":500, + "statusDescription":"OK", + "traceId":"907b76a307bc49129a489de3d4c992ea|CH1M001463|02.00.82.2800|CH1MSNVM001383, CH1MSNVM001358, CH1MSNVM001397" +} diff --git a/test/unit/lookups/bing_test.rb b/test/unit/lookups/bing_test.rb index db9457b91..028f84107 100644 --- a/test/unit/lookups/bing_test.rb +++ b/test/unit/lookups/bing_test.rb @@ -82,4 +82,18 @@ def test_raises_exception_when_service_unavailable l.send(:results, Geocoder::Query.new("service unavailable")) end end + + def test_raises_exception_when_bing_returns_forbidden_request + Geocoder.configure(:always_raise => [Geocoder::RequestDenied]) + assert_raises Geocoder::RequestDenied do + Geocoder.search("forbidden request") + end + end + + def test_raises_exception_when_bing_returns_internal_server_error + Geocoder.configure(:always_raise => [Geocoder::ServiceUnavailable]) + assert_raises Geocoder::ServiceUnavailable do + Geocoder.search("internal server error") + end + end end From 491a30148fecb91999685a23d3d8a5de858c0d16 Mon Sep 17 00:00:00 2001 From: Robert Schaefer <robert.schaefer@student.hpi.de> Date: Sun, 4 Feb 2018 12:16:46 +0100 Subject: [PATCH 010/248] Avoid ipdata lookup headers at root level suggested by @alexreisner --- lib/geocoder/lookups/ipdata_co.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/ipdata_co.rb b/lib/geocoder/lookups/ipdata_co.rb index a8e0bf00d..0e18fd836 100644 --- a/lib/geocoder/lookups/ipdata_co.rb +++ b/lib/geocoder/lookups/ipdata_co.rb @@ -19,7 +19,7 @@ def query_url(query) private # --------------------------------------------------------------- def results(query) - Geocoder.configure(:http_headers => { "api-key" => configuration.api_key }) if configuration.api_key + Geocoder.configure(:ipdata_co => {:http_headers => { "api-key" => configuration.api_key }}) if configuration.api_key # don't look up a loopback address, just return the stored result return [reserved_result(query.text)] if query.loopback_ip_address? # note: Ipdata.co returns plain text on bad request From 385aafa01c273d492a7fd185ba1c2c8333db2037 Mon Sep 17 00:00:00 2001 From: Robert Schaefer <robert.schaefer@student.hpi.de> Date: Sun, 4 Feb 2018 12:18:43 +0100 Subject: [PATCH 011/248] Remove ipdata test case for api keys see: https://github.com/alexreisner/geocoder/pull/1254#issuecomment-359118927 --- test/unit/lookups/ipdata_co_test.rb | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/test/unit/lookups/ipdata_co_test.rb b/test/unit/lookups/ipdata_co_test.rb index 88a4d16c1..5acdcf72e 100644 --- a/test/unit/lookups/ipdata_co_test.rb +++ b/test/unit/lookups/ipdata_co_test.rb @@ -32,23 +32,4 @@ def test_not_authorized lookup.send(:check_response_for_errors!, response) end end - - def test_api_key - Geocoder.configure(:api_key => 'XXXX') - - # HACK: run the code once to add the api key to the HTTP request headers - Geocoder.search('8.8.8.8') - # It's really hard to 'un-monkey-patch' the base lookup class here - - require 'webmock/test_unit' - WebMock.enable! - stubbed_request = WebMock.stub_request(:get, "https://api.ipdata.co/8.8.8.8").with(headers: {'api-key' => 'XXXX'}).to_return(status: 200) - - g = Geocoder::Lookup::IpdataCo.new - g.send(:actual_make_api_request, Geocoder::Query.new('8.8.8.8')) - assert_requested(stubbed_request) - - WebMock.reset! - WebMock.disable! - end end From d70f8d5329331e7afb0709dc7f00330ef7b89d02 Mon Sep 17 00:00:00 2001 From: Joe Francis <joe@lostapathy.com> Date: Tue, 16 Jan 2018 09:01:21 -0600 Subject: [PATCH 012/248] add ruby 2.4 and 2.5 to travis --- .travis.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.travis.yml b/.travis.yml index d8587bf5d..af9ff5337 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,8 @@ rvm: - 2.1.2 - 2.2.2 - 2.3.0 + - 2.4.3 + - 2.5.0 - jruby-19mode gemfile: - Gemfile @@ -54,6 +56,14 @@ matrix: gemfile: gemfiles/Gemfile.ruby1.9.3 - rvm: 2.3.0 gemfile: gemfiles/Gemfile.ruby1.9.3 + - rvm: 2.4.3 + gemfile: gemfiles/Gemfile.ruby1.9.3 + - rvm: 2.5.0 + gemfile: gemfiles/Gemfile.ruby1.9.3 + - rvm: 2.4.3 + gemfile: gemfiles/Gemfile.rails3.2 + - rvm: 2.5.0 + gemfile: gemfiles/Gemfile.rails3.2 - rvm: jruby-19mode gemfile: gemfiles/Gemfile.rails5.0 - env: DB=sqlite USE_SQLITE_EXT=1 From e3d301076bffa6846db44662e3af0f39f6a8562f Mon Sep 17 00:00:00 2001 From: Joe Francis <joe@lostapathy.com> Date: Tue, 13 Feb 2018 10:33:48 -0600 Subject: [PATCH 013/248] update rubygems per https://github.com/travis-ci/travis-ci/issues/8978 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index af9ff5337..53e1045f8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,7 @@ gemfile: - gemfiles/Gemfile.rails5.0 before_install: - which bundle >/dev/null 2>&1 || gem install bundler + - gem update --system matrix: exclude: - rvm: 1.9.3 From a666cfd173739bf0814ca695755a4bb97a4b8214 Mon Sep 17 00:00:00 2001 From: Joe Francis <joe@lostapathy.com> Date: Tue, 13 Feb 2018 12:18:06 -0600 Subject: [PATCH 014/248] ruby 2.5 changes behavior of CGI.escape See https://github.com/ruby/ruby/commit/e1b432754553423008a14d39d0901eabc99e7ddb --- test/unit/lookups/yandex_test.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/unit/lookups/yandex_test.rb b/test/unit/lookups/yandex_test.rb index 45c4c26cb..b4ca20941 100644 --- a/test/unit/lookups/yandex_test.rb +++ b/test/unit/lookups/yandex_test.rb @@ -26,6 +26,10 @@ def test_yandex_query_url_contains_bbox "Some Intersection", :bounds => [[40.0, -120.0], [39.0, -121.0]] )) - assert_match(/bbox=40.0+%2C-120.0+%7E39.0+%2C-121.0+/, url) + if RUBY_VERSION < '2.5.0' + assert_match(/bbox=40.0+%2C-120.0+%7E39.0+%2C-121.0+/, url) + else + assert_match(/bbox=40.0+%2C-120.0+~39.0+%2C-121.0+/, url) + end end end From 6d88e398beb941c9185ef8d2b81c4bda03b7a180 Mon Sep 17 00:00:00 2001 From: Joe Francis <joe@lostapathy.com> Date: Tue, 13 Feb 2018 12:21:45 -0600 Subject: [PATCH 015/248] rails 4.1 has a bug with our tests on ruby 2.4 and 2.5 --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 53e1045f8..bd126ce7e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,6 +57,10 @@ matrix: gemfile: gemfiles/Gemfile.ruby1.9.3 - rvm: 2.3.0 gemfile: gemfiles/Gemfile.ruby1.9.3 + - rvm: 2.4.3 + gemfile: gemfiles/Gemfile.rails4.1 + - rvm: 2.5.0 + gemfile: gemfiles/Gemfile.rails4.1 - rvm: 2.4.3 gemfile: gemfiles/Gemfile.ruby1.9.3 - rvm: 2.5.0 From c8214e0975d3aeaeea0136fb7ce1a1584e907b20 Mon Sep 17 00:00:00 2001 From: Mathias Hansen <me@codemonkey.io> Date: Thu, 15 Feb 2018 21:36:54 -0500 Subject: [PATCH 016/248] Update geocod.io to use most recent API version --- lib/geocoder/lookups/geocodio.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/geocodio.rb b/lib/geocoder/lookups/geocodio.rb index 60c15957c..532490a46 100644 --- a/lib/geocoder/lookups/geocodio.rb +++ b/lib/geocoder/lookups/geocodio.rb @@ -10,7 +10,7 @@ def name def query_url(query) path = query.reverse_geocode? ? "reverse" : "geocode" - "#{protocol}://api.geocod.io/v1/#{path}?#{url_query_string(query)}" + "#{protocol}://api.geocod.io/v1.2/#{path}?#{url_query_string(query)}" end def results(query) From bfc9741fb5c813e74c93fe65fdc591f8909df495 Mon Sep 17 00:00:00 2001 From: Mathias Hansen <me@codemonkey.io> Date: Thu, 15 Feb 2018 21:40:31 -0500 Subject: [PATCH 017/248] Updated geocod.io description to reflect that it also supports Canada --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 21b0012ab..68e8a7990 100644 --- a/README.md +++ b/README.md @@ -662,11 +662,11 @@ Data Science Toolkit provides an API whose response format is like Google's but * **API key**: required * **Quota**: 2,500 free requests/day then purchase $0.0005 for each, also has volume pricing and plans. -* **Region**: US +* **Region**: USA & Canada * **SSL support**: yes * **Languages**: en -* **Documentation**: http://geocod.io/docs -* **Terms of Service**: http://geocod.io/terms-of-use +* **Documentation**: https://geocod.io/docs/ +* **Terms of Service**: https://geocod.io/terms-of-use/ * **Limitations**: No restrictions on use #### SmartyStreets (`:smarty_streets`) From ece06b87143ea1c1df17cb6a2c7e52dceefdcf6d Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Tue, 20 Feb 2018 14:43:01 -0500 Subject: [PATCH 018/248] Don't require client and channel for Google Premier. No longer required, according to this page: https://developers.google.com/maps/premium/overview Fixes #1268 --- lib/geocoder/lookups/google_premier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/google_premier.rb b/lib/geocoder/lookups/google_premier.rb index 2867ede0b..0a1a93c4e 100644 --- a/lib/geocoder/lookups/google_premier.rb +++ b/lib/geocoder/lookups/google_premier.rb @@ -11,7 +11,7 @@ def name end def required_api_key_parts - ["private key", "client", "channel"] + ["private key"] end def query_url(query) From 7cb0acc985ccb49c65c0529dab1d111165e8a1b9 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Tue, 20 Feb 2018 14:48:28 -0500 Subject: [PATCH 019/248] Use HTTPS for all Nominatim requests. HTTP support will be discontinued according to this: https://lists.openstreetmap.org/pipermail/geocoding/2018-January/001918.html Fixes #1267 --- lib/geocoder/lookups/nominatim.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/nominatim.rb b/lib/geocoder/lookups/nominatim.rb index bb37c41fa..18a203001 100644 --- a/lib/geocoder/lookups/nominatim.rb +++ b/lib/geocoder/lookups/nominatim.rb @@ -9,7 +9,7 @@ def name end def map_link_url(coordinates) - "http://www.openstreetmap.org/?lat=#{coordinates[0]}&lon=#{coordinates[1]}&zoom=15&layers=M" + "https://www.openstreetmap.org/?lat=#{coordinates[0]}&lon=#{coordinates[1]}&zoom=15&layers=M" end def query_url(query) @@ -18,6 +18,10 @@ def query_url(query) "#{protocol}://#{host}/#{method}?" + url_query_string(query) end + def supported_protocols + [:https] + end + private # --------------------------------------------------------------- def results(query) From e4bc9ee23b9b98a1a51de85e143147797092375f Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Tue, 20 Feb 2018 16:23:56 -0500 Subject: [PATCH 020/248] Fix broken test. Should have been part of 7cb0acc985ccb49c65c0529dab1d111165e8a1b9 --- test/unit/lookups/nominatim_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/lookups/nominatim_test.rb b/test/unit/lookups/nominatim_test.rb index 27d2d1d70..c75cf4589 100644 --- a/test/unit/lookups/nominatim_test.rb +++ b/test/unit/lookups/nominatim_test.rb @@ -37,7 +37,7 @@ def test_neighbourhood def test_host_configuration Geocoder.configure(nominatim: {host: "local.com"}) query = Geocoder::Query.new("Bluffton, SC") - assert_match %r(http://local\.com), query.url + assert_match %r(https://local\.com), query.url end def test_raises_exception_when_over_query_limit From 379c6c9ac2fdca048349cdc9c0d6a7a2f4fbc185 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Tue, 20 Feb 2018 16:24:17 -0500 Subject: [PATCH 021/248] Restore HTTP support for LocationIQ. Should have been part of 7cb0acc985ccb49c65c0529dab1d111165e8a1b9 --- lib/geocoder/lookups/location_iq.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/geocoder/lookups/location_iq.rb b/lib/geocoder/lookups/location_iq.rb index 197e7696a..3773d4063 100644 --- a/lib/geocoder/lookups/location_iq.rb +++ b/lib/geocoder/lookups/location_iq.rb @@ -16,6 +16,10 @@ def query_url(query) "#{protocol}://locationiq.org/v1/#{method}.php?key=#{configuration.api_key}&" + url_query_string(query) end + def supported_protocols + [:http, :https] + end + private def results(query) From 81c97590b3c6096d889b557013c2e5c4792b57f6 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 26 Feb 2018 21:42:16 -0500 Subject: [PATCH 022/248] Revert "Remove ipdata test case for api keys" This reverts commit 385aafa01c273d492a7fd185ba1c2c8333db2037. --- test/unit/lookups/ipdata_co_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/unit/lookups/ipdata_co_test.rb b/test/unit/lookups/ipdata_co_test.rb index 5acdcf72e..88a4d16c1 100644 --- a/test/unit/lookups/ipdata_co_test.rb +++ b/test/unit/lookups/ipdata_co_test.rb @@ -32,4 +32,23 @@ def test_not_authorized lookup.send(:check_response_for_errors!, response) end end + + def test_api_key + Geocoder.configure(:api_key => 'XXXX') + + # HACK: run the code once to add the api key to the HTTP request headers + Geocoder.search('8.8.8.8') + # It's really hard to 'un-monkey-patch' the base lookup class here + + require 'webmock/test_unit' + WebMock.enable! + stubbed_request = WebMock.stub_request(:get, "https://api.ipdata.co/8.8.8.8").with(headers: {'api-key' => 'XXXX'}).to_return(status: 200) + + g = Geocoder::Lookup::IpdataCo.new + g.send(:actual_make_api_request, Geocoder::Query.new('8.8.8.8')) + assert_requested(stubbed_request) + + WebMock.reset! + WebMock.disable! + end end From 0ab4800615f8c8539389427265c0a037e6814c18 Mon Sep 17 00:00:00 2001 From: Steven Harman <steven@harmanly.com> Date: Tue, 27 Feb 2018 14:47:41 -0500 Subject: [PATCH 023/248] Make #near_scope_options public for Rails 5.2 Rails 5.2 changed the receiver within a scope from `klass` to `relation`. With that, we no longer have private access to Geocoder::Store::ActiveRecord#near_scope_options, and so must make it public. see: https://github.com/rails/rails/pull/29301 --- lib/geocoder/stores/active_record.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/geocoder/stores/active_record.rb b/lib/geocoder/stores/active_record.rb index 0f2187a07..e7c423a9f 100644 --- a/lib/geocoder/stores/active_record.rb +++ b/lib/geocoder/stores/active_record.rb @@ -87,8 +87,6 @@ def distance_from_sql(location, *args) end end - private # ---------------------------------------------------------------- - ## # Get options hash suitable for passing to ActiveRecord.find to get # records within a radius (in kilometers) of the given point. @@ -168,6 +166,8 @@ def near_scope_options(latitude, longitude, radius = 20, options = {}) } end + private # ---------------------------------------------------------------- + ## # SQL for calculating distance based on the current database's # capabilities (trig functions?). From bbebcf364be5615d2ab5e68bd3791ff884763257 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 28 Feb 2018 11:07:21 -0500 Subject: [PATCH 024/248] Prepare for release of gem version 1.4.6. --- CHANGELOG.md | 5 +++++ lib/geocoder/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45f2b21a4..9181e3966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ Changelog Major changes to Geocoder for each release. Please see the Git log for complete list of changes. +1.4.6 (2018 Feb 28) +------------------- +* Add support for :ipdata_co lookup (thanks github.com/roschaefer). +* Update for Rails 5.2 compatibility (thanks github.com/stevenharman). + 1.4.5 (2017 Nov 29) ------------------- * Add support for :pickpoint lookup (thanks github.com/cylon-v). diff --git a/lib/geocoder/version.rb b/lib/geocoder/version.rb index 29ea0404a..ca0fa5e98 100644 --- a/lib/geocoder/version.rb +++ b/lib/geocoder/version.rb @@ -1,3 +1,3 @@ module Geocoder - VERSION = "1.4.5" + VERSION = "1.4.6" end From 858d3e6638c02d09c844dbb54cda3db3d0903060 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 28 Feb 2018 13:45:52 -0500 Subject: [PATCH 025/248] Lock dependencies for Ruby 2.0 compatibility. --- gemfiles/Gemfile.rails4.1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gemfiles/Gemfile.rails4.1 b/gemfiles/Gemfile.rails4.1 index b9b0a9448..d20f0941a 100644 --- a/gemfiles/Gemfile.rails4.1 +++ b/gemfiles/Gemfile.rails4.1 @@ -28,7 +28,9 @@ group :test do gem 'sqlite_ext', '~> 1.5.0' end - gem 'webmock' + gem 'public_suffix', '2.0.5' # webmock dependency + gem 'addressable', '2.5.2' # webmock dependency + gem 'webmock', '3.3.0' platforms :ruby do gem 'pg', '~> 0.11' From 327c169a7dd4d65b24b601578fa3deddc573209e Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 28 Feb 2018 16:40:47 -0500 Subject: [PATCH 026/248] Lock dependencies for Ruby 2.0 compatibility. --- gemfiles/Gemfile.rails3.2 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gemfiles/Gemfile.rails3.2 b/gemfiles/Gemfile.rails3.2 index 8eed6ddc6..994d0cbb5 100644 --- a/gemfiles/Gemfile.rails3.2 +++ b/gemfiles/Gemfile.rails3.2 @@ -28,7 +28,9 @@ group :test do gem 'sqlite_ext', '~> 1.5.0' end - gem 'webmock' + gem 'public_suffix', '2.0.5' # webmock dependency + gem 'addressable', '2.5.2' # webmock dependency + gem 'webmock', '3.3.0' platforms :ruby do gem 'pg', '~> 0.11' From bfa34249497c584d1d5e920347c70fa584720019 Mon Sep 17 00:00:00 2001 From: Kris Khaira <kris.khaira@gmail.com> Date: Fri, 9 Mar 2018 23:30:22 +0800 Subject: [PATCH 027/248] Explain that 20 is default radius for near() (#1272) There's no documentation that 20 is the default value for the radius when using near. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d4db141b7..fa12ef91f 100644 --- a/README.md +++ b/README.md @@ -156,10 +156,10 @@ Please use MongoDB's [geospatial query language](https://docs.mongodb.org/manual To find objects by location, use the following scopes: - Venue.near('Omaha, NE, US', 20) # venues within 20 miles of Omaha - Venue.near([40.71, -100.23], 20) # venues within 20 miles of a point - Venue.near([40.71, -100.23], 20, :units => :km) - # venues within 20 kilometres of a point + Venue.near('Omaha, NE, US') # venues within 20 (default) miles of Omaha + Venue.near([40.71, -100.23], 50) # venues within 50 miles of a point + Venue.near([40.71, -100.23], 50, :units => :km) + # venues within 50 kilometres of a point Venue.geocoded # venues with coordinates Venue.not_geocoded # venues without coordinates From 26d57fd35f6815ea2140602293f6732e1807aa18 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 12 Mar 2018 20:19:22 -0700 Subject: [PATCH 028/248] Allow HTTP protocol for Nominatim lookup but default to HTTPS (custom hosts may not support HTTPS). This partially reverts 7cb0acc985ccb49c65c0529dab1d111165e8a1b9. --- lib/geocoder/lookups/location_iq.rb | 10 +++++----- lib/geocoder/lookups/nominatim.rb | 18 +++++++++++++----- test/unit/lookups/nominatim_test.rb | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/geocoder/lookups/location_iq.rb b/lib/geocoder/lookups/location_iq.rb index 3773d4063..d9fb0659b 100644 --- a/lib/geocoder/lookups/location_iq.rb +++ b/lib/geocoder/lookups/location_iq.rb @@ -13,15 +13,15 @@ def required_api_key_parts def query_url(query) method = query.reverse_geocode? ? "reverse" : "search" - "#{protocol}://locationiq.org/v1/#{method}.php?key=#{configuration.api_key}&" + url_query_string(query) - end - - def supported_protocols - [:http, :https] + "#{protocol}://#{configured_host}/v1/#{method}.php?key=#{configuration.api_key}&" + url_query_string(query) end private + def configured_host + configuration[:host] || "locationiq.org" + end + def results(query) return [] unless doc = fetch_data(query) diff --git a/lib/geocoder/lookups/nominatim.rb b/lib/geocoder/lookups/nominatim.rb index 18a203001..cee363a53 100644 --- a/lib/geocoder/lookups/nominatim.rb +++ b/lib/geocoder/lookups/nominatim.rb @@ -14,15 +14,23 @@ def map_link_url(coordinates) def query_url(query) method = query.reverse_geocode? ? "reverse" : "search" - host = configuration[:host] || "nominatim.openstreetmap.org" - "#{protocol}://#{host}/#{method}?" + url_query_string(query) + "#{protocol}://#{configured_host}/#{method}?" + url_query_string(query) end - def supported_protocols - [:https] + private # --------------------------------------------------------------- + + def configured_host + configuration[:host] || "nominatim.openstreetmap.org" end - private # --------------------------------------------------------------- + def use_ssl? + # nominatim.openstreetmap.org redirects HTTP requests to HTTPS + if configured_host == "nominatim.openstreetmap.org" + true + else + super + end + end def results(query) return [] unless doc = fetch_data(query) diff --git a/test/unit/lookups/nominatim_test.rb b/test/unit/lookups/nominatim_test.rb index c75cf4589..27d2d1d70 100644 --- a/test/unit/lookups/nominatim_test.rb +++ b/test/unit/lookups/nominatim_test.rb @@ -37,7 +37,7 @@ def test_neighbourhood def test_host_configuration Geocoder.configure(nominatim: {host: "local.com"}) query = Geocoder::Query.new("Bluffton, SC") - assert_match %r(https://local\.com), query.url + assert_match %r(http://local\.com), query.url end def test_raises_exception_when_over_query_limit From dcfd6e36fe050f1832b45b233ee6c261af15a90c Mon Sep 17 00:00:00 2001 From: Jordan Moncharmont <jormon@gmail.com> Date: Mon, 12 Mar 2018 20:25:24 -0700 Subject: [PATCH 029/248] add bounds detection for google results (#1196) some google geocoding requests have bounds within the result. add a helper to extract these. * Add tests to cover results with no bounds In this case, calling .bounds should return nil. Oddly, calling viewport on a result with no viewport causes the current code to `fail`. I have preserved this behavior even though I think it to be a little odd. --- lib/geocoder/results/google.rb | 21 ++++++++--- test/fixtures/google_new_york | 64 ++++++++++++++++++++++++++++++++ test/unit/lookups/google_test.rb | 11 ++++++ 3 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/google_new_york diff --git a/lib/geocoder/results/google.rb b/lib/geocoder/results/google.rb index 804e4ea58..e1215ff41 100644 --- a/lib/geocoder/results/google.rb +++ b/lib/geocoder/results/google.rb @@ -120,19 +120,30 @@ def geometry def precision geometry['location_type'] if geometry end - + def partial_match @data['partial_match'] end - + def place_id @data['place_id'] - end + end def viewport viewport = geometry['viewport'] || fail - south, west = %w(lat lng).map { |c| viewport['southwest'][c] } - north, east = %w(lat lng).map { |c| viewport['northeast'][c] } + bounding_box_from viewport + end + + def bounds + bounding_box_from geometry['bounds'] + end + + private + + def bounding_box_from(box) + return nil unless box + south, west = %w(lat lng).map { |c| box['southwest'][c] } + north, east = %w(lat lng).map { |c| box['northeast'][c] } [south, west, north, east] end end diff --git a/test/fixtures/google_new_york b/test/fixtures/google_new_york new file mode 100644 index 000000000..0de608f16 --- /dev/null +++ b/test/fixtures/google_new_york @@ -0,0 +1,64 @@ +{ + "status": "OK", + "results": [ { + "address_components": [ + { + "long_name": "New York", + "short_name": "New York", + "types": [ + "locality", + "political" + ] + }, + { + "long_name": "New York", + "short_name": "NY", + "types": [ + "administrative_area_level_1", + "political" + ] + }, + { + "long_name": "United States", + "short_name": "US", + "types": [ + "country", + "political" + ] + } + ], + "formatted_address": "New York, NY, USA", + "geometry": { + "bounds": { + "northeast": { + "lat": 40.9175771, + "lng": -73.7002721 + }, + "southwest": { + "lat": 40.4773991, + "lng": -74.2590899 + } + }, + "location": { + "lat": 40.7127837, + "lng": -74.0059413 + }, + "location_type": "APPROXIMATE", + "viewport": { + "northeast": { + "lat": 40.9152555, + "lng": -73.7002721 + }, + "southwest": { + "lat": 40.4960439, + "lng": -74.2557349 + } + } + }, + "place_id": "ChIJOwg_06VPwokRYv534QaPC8g", + "types": [ + "locality", + "political" + ] + } ] +} diff --git a/test/unit/lookups/google_test.rb b/test/unit/lookups/google_test.rb index 32f147e97..7fe6a4847 100644 --- a/test/unit/lookups/google_test.rb +++ b/test/unit/lookups/google_test.rb @@ -48,6 +48,17 @@ def test_google_viewport result.viewport end + def test_google_bounds + result = Geocoder.search("new york").first + assert_equal [40.4773991, -74.2590899, 40.9175771, -73.7002721], + result.bounds + end + + def test_google_no_bounds + result = Geocoder.search("Madison Square Garden, New York, NY").first + assert_equal nil, result.bounds + end + def test_google_query_url_contains_bounds lookup = Geocoder::Lookup::Google.new url = lookup.query_url(Geocoder::Query.new( From 518a14983e94902f08834bcc4a07e1e1491daecd Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Tue, 13 Mar 2018 08:25:34 -0700 Subject: [PATCH 030/248] Prepare for release of gem version 1.4.7. --- CHANGELOG.md | 4 ++++ lib/geocoder/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9181e3966..3305072ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ Changelog Major changes to Geocoder for each release. Please see the Git log for complete list of changes. +1.4.7 (2018 Mar 13) +------------------- +* Allow HTTP protocol for Nominatim. + 1.4.6 (2018 Feb 28) ------------------- * Add support for :ipdata_co lookup (thanks github.com/roschaefer). diff --git a/lib/geocoder/version.rb b/lib/geocoder/version.rb index ca0fa5e98..71cfe2adb 100644 --- a/lib/geocoder/version.rb +++ b/lib/geocoder/version.rb @@ -1,3 +1,3 @@ module Geocoder - VERSION = "1.4.6" + VERSION = "1.4.7" end From d94b987931c979da21de868c038e26dad86e7e31 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Thu, 22 Mar 2018 13:37:28 -0400 Subject: [PATCH 031/248] Include custom :params in query options. Fixes #1273. --- lib/geocoder/stores/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/stores/base.rb b/lib/geocoder/stores/base.rb index 9e49d48dd..048b62e12 100644 --- a/lib/geocoder/stores/base.rb +++ b/lib/geocoder/stores/base.rb @@ -90,7 +90,7 @@ def do_lookup(reverse = false) return end - query_options = [:lookup, :ip_lookup, :language].inject({}) do |hash, key| + query_options = [:lookup, :ip_lookup, :language, :params].inject({}) do |hash, key| if options.has_key?(key) val = options[key] hash[key] = val.respond_to?(:call) ? val.call(self) : val From fa54d4ddc30662f819287d7d194347319198a4e3 Mon Sep 17 00:00:00 2001 From: Michael Holroyd <meekohi@gmail.com> Date: Thu, 22 Mar 2018 13:51:07 -0400 Subject: [PATCH 032/248] Update Geocodio to v1.3 (#1276) Update Geocodio to v1.3 --- lib/geocoder/lookups/geocodio.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/geocodio.rb b/lib/geocoder/lookups/geocodio.rb index 532490a46..c4c88e5a1 100644 --- a/lib/geocoder/lookups/geocodio.rb +++ b/lib/geocoder/lookups/geocodio.rb @@ -10,7 +10,7 @@ def name def query_url(query) path = query.reverse_geocode? ? "reverse" : "geocode" - "#{protocol}://api.geocod.io/v1.2/#{path}?#{url_query_string(query)}" + "#{protocol}://api.geocod.io/v1.3/#{path}?#{url_query_string(query)}" end def results(query) From c74356b448be992dc4aaa2ba0e932260cdbbf5e0 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 28 Mar 2018 14:16:13 -0400 Subject: [PATCH 033/248] Update based on changes to redis-rb gem v4.0. [] and []= methods were removed. --- examples/autoexpire_cache_redis.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/autoexpire_cache_redis.rb b/examples/autoexpire_cache_redis.rb index 1b67a9eee..395a71e5e 100644 --- a/examples/autoexpire_cache_redis.rb +++ b/examples/autoexpire_cache_redis.rb @@ -8,11 +8,11 @@ def initialize(store, ttl = 86400) end def [](url) - @store.[](url) + @store.get(url) end def []=(url, value) - @store.[]=(url, value) + @store.set(url, value) @store.expire(url, @ttl) end @@ -25,4 +25,4 @@ def del(url) end end -Geocoder.configure(:cache => AutoexpireCacheRedis.new(Redis.new)) \ No newline at end of file +Geocoder.configure(:cache => AutoexpireCacheRedis.new(Redis.new)) From 34c1a99ff1266b542050abf7f4169eef0d882370 Mon Sep 17 00:00:00 2001 From: David <dmchoull@gmail.com> Date: Wed, 4 Apr 2018 17:08:43 -0400 Subject: [PATCH 034/248] Use Telize 2.0.0 /location endpoint instead of the deprecated /geoip --- lib/geocoder/lookups/telize.rb | 6 +++--- test/fixtures/telize_74_200_247_59 | 18 +++++++++++++++++- test/unit/lookups/telize_test.rb | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/geocoder/lookups/telize.rb b/lib/geocoder/lookups/telize.rb index 0609ab938..ded98c1af 100644 --- a/lib/geocoder/lookups/telize.rb +++ b/lib/geocoder/lookups/telize.rb @@ -14,9 +14,9 @@ def required_api_key_parts def query_url(query) if configuration[:host] - "#{protocol}://#{configuration[:host]}/geoip/#{query.sanitized_text}" + "#{protocol}://#{configuration[:host]}/location/#{query.sanitized_text}" else - "#{protocol}://telize-v1.p.mashape.com/geoip/#{query.sanitized_text}?mashape-key=#{api_key}" + "#{protocol}://telize-v1.p.mashape.com/location/#{query.sanitized_text}?mashape-key=#{api_key}" end end @@ -50,6 +50,6 @@ def reserved_result(ip) def api_key configuration.api_key end - + end end diff --git a/test/fixtures/telize_74_200_247_59 b/test/fixtures/telize_74_200_247_59 index a8c64d324..522e013bc 100644 --- a/test/fixtures/telize_74_200_247_59 +++ b/test/fixtures/telize_74_200_247_59 @@ -1 +1,17 @@ -{"timezone":"America\/Chicago","isp":"Layered Technologies, Inc.","region_code":"TX","country":"United States","dma_code":"0","area_code":"0","region":"Texas","ip":"74.200.247.59","asn":"AS22576","continent_code":"NA","city":"Plano","postal_code":"75093","longitude":-96.8134,"latitude":33.0347,"country_code":"US","country_code3":"USA"} +{ + "longitude": -74.0468, + "city": "Jersey City", + "timezone": "America/New_York", + "latitude": 40.7209, + "asn": 22576, + "region": "New Jersey", + "offset": -14400, + "organization": "DataPipe, Inc.", + "country_code": "US", + "ip": "74.200.247.59", + "country_code3": "USA", + "postal_code": "07302", + "continent_code": "NA", + "country": "United States", + "region_code": "NJ" +} diff --git a/test/unit/lookups/telize_test.rb b/test/unit/lookups/telize_test.rb index aa6e4dbe5..36abe4aab 100644 --- a/test/unit/lookups/telize_test.rb +++ b/test/unit/lookups/telize_test.rb @@ -14,7 +14,7 @@ def test_result_on_ip_address_search def test_result_components result = Geocoder.search("74.200.247.59").first - assert_equal "Plano, TX 75093, United States", result.address + assert_equal "Jersey City, NJ 07302, United States", result.address end def test_no_results From 49140748283fd8bcec9ff50629dad96a605b5a19 Mon Sep 17 00:00:00 2001 From: David <dmchoull@gmail.com> Date: Thu, 5 Apr 2018 09:47:44 -0400 Subject: [PATCH 035/248] Added more tests for Telize lookup --- test/unit/lookups/telize_test.rb | 38 +++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/test/unit/lookups/telize_test.rb b/test/unit/lookups/telize_test.rb index 36abe4aab..751161771 100644 --- a/test/unit/lookups/telize_test.rb +++ b/test/unit/lookups/telize_test.rb @@ -4,7 +4,41 @@ class TelizeTest < GeocoderTestCase def setup - Geocoder.configure(ip_lookup: :telize) + Geocoder.configure(ip_lookup: :telize, telize: {host: nil}) + end + + def test_query_url + lookup = Geocoder::Lookup::Telize.new + query = Geocoder::Query.new("74.200.247.59") + assert_match %r{^https://telize-v1\.p\.mashape\.com/location/74\.200\.247\.59}, lookup.query_url(query) + end + + def test_includes_api_key_when_set + Geocoder.configure(api_key: "api_key") + lookup = Geocoder::Lookup::Telize.new + query = Geocoder::Query.new("74.200.247.59") + assert_match %r{/location/74\.200\.247\.59\?mashape-key=api_key}, lookup.query_url(query) + end + + def test_uses_custom_host_when_set + Geocoder.configure(telize: {host: "example.com"}) + lookup = Geocoder::Lookup::Telize.new + query = Geocoder::Query.new("74.200.247.59") + assert_match %r{^http://example\.com/location/74\.200\.247\.59$}, lookup.query_url(query) + end + + def test_allows_https_when_custom_host + Geocoder.configure(use_https: true, telize: {host: "example.com"}) + lookup = Geocoder::Lookup::Telize.new + query = Geocoder::Query.new("74.200.247.59") + assert_match %r{^https://example\.com}, lookup.query_url(query) + end + + def test_requires_https_when_not_custom_host + Geocoder.configure(use_https: false) + lookup = Geocoder::Lookup::Telize.new + query = Geocoder::Query.new("74.200.247.59") + assert_match %r{^https://telize-v1\.p\.mashape\.com}, lookup.query_url(query) end def test_result_on_ip_address_search @@ -15,6 +49,8 @@ def test_result_on_ip_address_search def test_result_components result = Geocoder.search("74.200.247.59").first assert_equal "Jersey City, NJ 07302, United States", result.address + assert_equal "US", result.country_code + assert_equal [40.7209, -74.0468], result.coordinates end def test_no_results From 378774022426de335a53cdbbbd7d1348048c78b4 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 9 Apr 2018 11:02:16 +0300 Subject: [PATCH 036/248] Change default IP address lookup to IPinfo.io Freegeoip/IPstack no longer provides keyless service. --- README.md | 2 +- lib/geocoder/configuration.rb | 2 +- test/unit/request_test.rb | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fa12ef91f..64d190708 100644 --- a/README.md +++ b/README.md @@ -327,7 +327,7 @@ If you're familiar with the results returned by the geocoding service you're usi Geocoding Service ("Lookup") Configuration ------------------------------------------ -Geocoder supports a variety of street and IP address geocoding services. The default lookups are `:google` for street addresses and `:freegeoip` for IP addresses. Please see the listing and comparison below for details on specific geocoding services (not all settings are supported by all services). +Geocoder supports a variety of street and IP address geocoding services. The default lookups are `:google` for street addresses and `:ipinfo_io` for IP addresses. Please see the listing and comparison below for details on specific geocoding services (not all settings are supported by all services). To create a Rails initializer with an example configuration: diff --git a/lib/geocoder/configuration.rb b/lib/geocoder/configuration.rb index 8a53e9817..f2fbccf92 100644 --- a/lib/geocoder/configuration.rb +++ b/lib/geocoder/configuration.rb @@ -98,7 +98,7 @@ def set_defaults # geocoding options @data[:timeout] = 3 # geocoding service timeout (secs) @data[:lookup] = :google # name of street address geocoding service (symbol) - @data[:ip_lookup] = :freegeoip # name of IP address geocoding service (symbol) + @data[:ip_lookup] = :ipinfo_io # name of IP address geocoding service (symbol) @data[:language] = :en # ISO-639 language code @data[:http_headers] = {} # HTTP headers for lookup @data[:use_https] = false # use HTTPS for lookup requests? (if supported) diff --git a/test/unit/request_test.rb b/test/unit/request_test.rb index 09e8ac9ac..8db88b1ea 100644 --- a/test/unit/request_test.rb +++ b/test/unit/request_test.rb @@ -10,6 +10,11 @@ def initialize(headers={}, ip="") super(super_env) end end + + def setup + Geocoder.configure(ip_lookup: :freegeoip) + end + def test_http_x_real_ip req = MockRequest.new({"HTTP_X_REAL_IP" => "74.200.247.59"}) assert req.location.is_a?(Geocoder::Result::Freegeoip) @@ -96,4 +101,4 @@ def test_geocoder_reject_non_ipv4_addresses_with_bad_ips req = MockRequest.new() assert_equal expected_ips, req.send(:geocoder_reject_non_ipv4_addresses, ips) end -end \ No newline at end of file +end From c5b308b6fdf6d92c436b1331404d5f733de4e909 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 9 Apr 2018 11:04:31 +0300 Subject: [PATCH 037/248] Update readme: Nominatim does support SSL. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 64d190708..3356f44d2 100644 --- a/README.md +++ b/README.md @@ -477,7 +477,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **API key**: none * **Quota**: 1 request/second * **Region**: world -* **SSL support**: no +* **SSL support**: yes * **Languages**: ? * **Documentation**: http://wiki.openstreetmap.org/wiki/Nominatim * **Terms of Service**: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy From 95c06732322f589cb1b53d552db45b87c1205de4 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 9 Apr 2018 12:09:27 +0300 Subject: [PATCH 038/248] Omit test, temporarily. --- test/unit/rake_task_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/rake_task_test.rb b/test/unit/rake_task_test.rb index 0818b3f3b..426e8523a 100644 --- a/test/unit/rake_task_test.rb +++ b/test/unit/rake_task_test.rb @@ -8,6 +8,7 @@ def setup end def test_rake_task_geocode_raise_specify_class_message + omit("Errors on Travis") if ENV['TRAVIS'] # TODO: figure out why assert_raise(RuntimeError, "Please specify a CLASS (model)") do Rake.application.invoke_task("geocode:all") end From 23a1075bc3aae9d6495723e5406ce8a5a0913a9b Mon Sep 17 00:00:00 2001 From: Scott Wenborne <scott@initfothe.com> Date: Tue, 10 Apr 2018 16:02:23 +0100 Subject: [PATCH 039/248] WIP setup for Postcodes.io --- lib/geocoder/lookup.rb | 1 + lib/geocoder/lookups/postcodes_io.rb | 28 +++++++++++++++++ lib/geocoder/results/postcodes_io.rb | 38 ++++++++++++++++++++++++ test/fixtures/postcodes_io_malvern_hills | 36 ++++++++++++++++++++++ test/fixtures/postcodes_io_no_results | 4 +++ test/test_helper.rb | 12 ++++++++ test/unit/lookup_test.rb | 2 +- test/unit/lookups/postcodes_io_test.rb | 21 +++++++++++++ 8 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 lib/geocoder/lookups/postcodes_io.rb create mode 100644 lib/geocoder/results/postcodes_io.rb create mode 100644 test/fixtures/postcodes_io_malvern_hills create mode 100644 test/fixtures/postcodes_io_no_results create mode 100644 test/unit/lookups/postcodes_io_test.rb diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index b756f768f..73cf81e1a 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -48,6 +48,7 @@ def street_services :smarty_streets, :okf, :postcode_anywhere_uk, + :postcodes_io, :geoportail_lu, :ban_data_gouv_fr, :test, diff --git a/lib/geocoder/lookups/postcodes_io.rb b/lib/geocoder/lookups/postcodes_io.rb new file mode 100644 index 000000000..169571327 --- /dev/null +++ b/lib/geocoder/lookups/postcodes_io.rb @@ -0,0 +1,28 @@ +require 'geocoder/lookups/base' +require 'geocoder/results/postcodes_io' + +module Geocoder::Lookup + class PostcodesIo < Base + def name + 'Postcodes.io' + end + + def query_url(query) + str = query.sanitized_text.gsub(/\s/, '') + format('%s://%s/%s', protocol, 'api.postcodes.io/postcodes', str) + end + + def supported_protocols + [:https] + end + + private + + def results(query) + response = fetch_data(query) + return [] if response.nil? || response['status'] != 200 || response.empty? + + [response['result']] + end + end +end diff --git a/lib/geocoder/results/postcodes_io.rb b/lib/geocoder/results/postcodes_io.rb new file mode 100644 index 000000000..a9d1194ff --- /dev/null +++ b/lib/geocoder/results/postcodes_io.rb @@ -0,0 +1,38 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class PostcodesIo < Base + def coordinates + [latitude, longitude] + end + + def latitude + @data['latitude'].to_f + end + + def longitude + @data['longitude'].to_f + end + + def quality + @data['quality'] + end + + def postcode + @data['postcode'] + end + + def county + @data['admin_county'] + end + alias state county + + def country + 'United Kingdom' + end + + def country_code + 'UK' + end + end +end diff --git a/test/fixtures/postcodes_io_malvern_hills b/test/fixtures/postcodes_io_malvern_hills new file mode 100644 index 000000000..7a43cfc10 --- /dev/null +++ b/test/fixtures/postcodes_io_malvern_hills @@ -0,0 +1,36 @@ +{ + "status": 200, + "result": { + "postcode": "WR2 6NJ", + "quality": 1, + "eastings": 381676, + "northings": 259425, + "country": "England", + "nhs_ha": "West Midlands", + "longitude": -2.26972239639173, + "latitude": 52.2327158260535, + "european_electoral_region": "West Midlands", + "primary_care_trust": "Worcestershire", + "region": "West Midlands", + "lsoa": "Malvern Hills 002B", + "msoa": "Malvern Hills 002", + "incode": "6NJ", + "outcode": "WR2", + "parliamentary_constituency": "West Worcestershire", + "admin_district": "Malvern Hills", + "parish": "Hallow", + "admin_county": "Worcestershire", + "admin_ward": "Hallow", + "ccg": "NHS South Worcestershire", + "nuts": "Worcestershire", + "codes": { + "admin_district": "E07000235", + "admin_county": "E10000034", + "admin_ward": "E05007851", + "parish": "E04010305", + "parliamentary_constituency": "E14001035", + "ccg": "E38000166", + "nuts": "UKG12" + } + } +} diff --git a/test/fixtures/postcodes_io_no_results b/test/fixtures/postcodes_io_no_results new file mode 100644 index 000000000..0c929cda7 --- /dev/null +++ b/test/fixtures/postcodes_io_no_results @@ -0,0 +1,4 @@ +{ + "status": 404, + "error": "Postcode not found" +} diff --git a/test/test_helper.rb b/test/test_helper.rb index 4857dfed7..961216d6a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -330,6 +330,18 @@ def default_fixture_filename end end + require 'geocoder/lookups/postcodes_io' + class PostcodesIo + private + def fixture_prefix + 'postcodes_io' + end + + def default_fixture_filename + "#{fixture_prefix}_malvern_hills" + end + end + require 'geocoder/lookups/geoportail_lu' class GeoportailLu private diff --git a/test/unit/lookup_test.rb b/test/unit/lookup_test.rb index 7f21877f7..1b8a13bd2 100644 --- a/test/unit/lookup_test.rb +++ b/test/unit/lookup_test.rb @@ -24,7 +24,7 @@ def test_search_returns_empty_array_when_no_results def test_query_url_contains_values_in_params_hash Geocoder::Lookup.all_services_except_test.each do |l| - next if [:freegeoip, :maxmind_local, :telize, :pointpin, :geoip2, :maxmind_geoip2, :mapbox, :ipdata_co, :ipinfo_io, :ipapi_com].include? l # does not use query string + next if [:freegeoip, :maxmind_local, :telize, :pointpin, :geoip2, :maxmind_geoip2, :mapbox, :ipdata_co, :ipinfo_io, :ipapi_com, :postcodes_io].include? l # does not use query string set_api_key!(l) url = Geocoder::Lookup.get(l).query_url(Geocoder::Query.new( "test", :params => {:one_in_the_hand => "two in the bush"} diff --git a/test/unit/lookups/postcodes_io_test.rb b/test/unit/lookups/postcodes_io_test.rb new file mode 100644 index 000000000..30fd73785 --- /dev/null +++ b/test/unit/lookups/postcodes_io_test.rb @@ -0,0 +1,21 @@ +# encoding: utf-8 +require 'test_helper' + +class PostcodesIoTest < GeocoderTestCase + + def setup + Geocoder.configure(lookup: :postcodes_io) + end + + def test_result_on_postcode_search + results = Geocoder.search('WR26NJ') + + assert_equal 1, results.size + assert_equal 'Worcestershire', results.first.county + assert_equal [52.2327158260535, -2.26972239639173], results.first.coordinates + end + + def test_no_results + assert_equal [], Geocoder.search('no results') + end +end From 43fa9f3ac315c32247f5ec42240e7642b8d6a48b Mon Sep 17 00:00:00 2001 From: Scott Wenborne <scott@initfothe.com> Date: Tue, 10 Apr 2018 16:07:26 +0100 Subject: [PATCH 040/248] Ensure tests pass --- lib/geocoder/results/postcodes_io.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/geocoder/results/postcodes_io.rb b/lib/geocoder/results/postcodes_io.rb index a9d1194ff..82c97d626 100644 --- a/lib/geocoder/results/postcodes_io.rb +++ b/lib/geocoder/results/postcodes_io.rb @@ -18,15 +18,24 @@ def quality @data['quality'] end - def postcode + def postal_code @data['postcode'] end + alias address postal_code + + def city + @data['admin_ward'] + end def county @data['admin_county'] end alias state county + def state_code + @data['codes']['admin_county'] + end + def country 'United Kingdom' end From d36f36fd825b089d0afb9905bcbbbf910544f7a9 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Thu, 19 Apr 2018 22:26:19 +0300 Subject: [PATCH 041/248] Omit test, temporarily. --- test/unit/rake_task_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/rake_task_test.rb b/test/unit/rake_task_test.rb index 426e8523a..25b46e0f1 100644 --- a/test/unit/rake_task_test.rb +++ b/test/unit/rake_task_test.rb @@ -15,6 +15,7 @@ def test_rake_task_geocode_raise_specify_class_message end def test_rake_task_geocode_specify_class + omit("Errors on Travis") if ENV['TRAVIS'] # TODO: figure out why ENV['CLASS'] = 'Place' assert_nil Rake.application.invoke_task("geocode:all") end From c87dbf6ebdc499edbbf0565b25dce752d9b20f88 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 25 Apr 2018 07:34:37 +0300 Subject: [PATCH 042/248] Call accessor rather than cache store. Fixes #1286. --- lib/geocoder/cache.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/cache.rb b/lib/geocoder/cache.rb index defb25612..9eb032a3a 100644 --- a/lib/geocoder/cache.rb +++ b/lib/geocoder/cache.rb @@ -68,7 +68,7 @@ def key_for(url) # that have non-nil values. # def keys - store.keys.select{ |k| k.match(/^#{prefix}/) and interpret(store[k]) } + store.keys.select{ |k| k.match(/^#{prefix}/) and self[k] } end ## From f4fe1477f55bea1ff2c89bde35ce6faa51643f9f Mon Sep 17 00:00:00 2001 From: Alex Reisner <alexreisner@users.noreply.github.com> Date: Wed, 25 Apr 2018 07:38:49 +0300 Subject: [PATCH 043/248] Add lookup to issue template. --- ISSUE_TEMPLATE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 013f2faf8..59fa0ffc8 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -17,3 +17,4 @@ BEFORE POSTING AN ISSUE, PLEASE MAKE SURE THE PROBLEM IS NOT ADDRESSED IN THE RE * Geocoder version: * Rails version: * Database (if applicable): +* Lookup (if applicable): From d3a0f0a3d524be7dc8c38e7c91845b4a9f88f833 Mon Sep 17 00:00:00 2001 From: "Cayo Medeiros (yogodoshi)" <yogodoshi@gmail.com> Date: Fri, 11 May 2018 23:46:41 +0700 Subject: [PATCH 044/248] Remove Geocoder::Results::Geoip2#data --- lib/geocoder/results/geoip2.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/geocoder/results/geoip2.rb b/lib/geocoder/results/geoip2.rb index 5e8b00884..cf0f758a7 100644 --- a/lib/geocoder/results/geoip2.rb +++ b/lib/geocoder/results/geoip2.rb @@ -64,10 +64,6 @@ def language private - def data - @data.to_hash - end - def default_language @default_language = Geocoder.config[:language].to_s end From c51c6eb07b969c17e025f33e518b5f428fd59934 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 11 May 2018 14:27:50 -0400 Subject: [PATCH 045/248] Lock rake to version 12.2.1 with Ruby 1.9.3. --- gemfiles/Gemfile.ruby1.9.3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gemfiles/Gemfile.ruby1.9.3 b/gemfiles/Gemfile.ruby1.9.3 index 05148196a..cc5ca1449 100644 --- a/gemfiles/Gemfile.ruby1.9.3 +++ b/gemfiles/Gemfile.ruby1.9.3 @@ -1,7 +1,7 @@ source "https://rubygems.org" group :development, :test do - gem 'rake' + gem 'rake', '12.2.1' gem 'mongoid', '2.6.0' gem 'bson_ext', :platforms => :ruby gem 'geoip' From 08264baf45d49cf50d023a7ac111e02307ecbaaf Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 11 May 2018 15:10:39 -0400 Subject: [PATCH 046/248] Lock byebug to version 9.0.6 with Rails 4.1. --- gemfiles/Gemfile.rails4.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gemfiles/Gemfile.rails4.1 b/gemfiles/Gemfile.rails4.1 index d20f0941a..5e5005937 100644 --- a/gemfiles/Gemfile.rails4.1 +++ b/gemfiles/Gemfile.rails4.1 @@ -9,7 +9,7 @@ group :development, :test do gem 'rails', '~> 4.1.13' gem 'test-unit' # needed for Ruby >=2.2.0 - gem 'byebug', platforms: :mri + gem 'byebug', '9.0.6', platforms: :mri platforms :jruby do gem 'jruby-openssl' From e7b9373492d3cead0c4c78ba4e5149f5adfe90ce Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 11 May 2018 15:12:02 -0400 Subject: [PATCH 047/248] Lock rack-cache to version 1.7.1 with Ruby 1.9.3. --- gemfiles/Gemfile.ruby1.9.3 | 1 + 1 file changed, 1 insertion(+) diff --git a/gemfiles/Gemfile.ruby1.9.3 b/gemfiles/Gemfile.ruby1.9.3 index cc5ca1449..cc8f66197 100644 --- a/gemfiles/Gemfile.ruby1.9.3 +++ b/gemfiles/Gemfile.ruby1.9.3 @@ -6,6 +6,7 @@ group :development, :test do gem 'bson_ext', :platforms => :ruby gem 'geoip' gem 'rubyzip' + gem 'rack-cache', '1.7.1' gem 'rails' gem 'sqlite3' gem 'sqlite_ext', '~> 1.5.0' From 0f5758212b69efb9da115b8731a27a94e05458e9 Mon Sep 17 00:00:00 2001 From: Heath Attig <heath.attig@gmail.com> Date: Mon, 14 May 2018 15:54:02 -0600 Subject: [PATCH 048/248] Deprecate Freegeoip and Implement Ipstack (#1289) * Update initializer template to use ipinfo_io * Implement ipstack lookup * Add Ipstack readme documentation * Add post-install message * Remove DSL from ipstack lookup * Remove unnecessary logging * Update post-install message --- README.md | 26 +- geocoder.gemspec | 11 + .../geocoder/config/templates/initializer.rb | 2 +- lib/geocoder/lookup.rb | 3 +- lib/geocoder/lookups/ipstack.rb | 64 ++++ lib/geocoder/results/ipstack.rb | 60 ++++ test/fixtures/freegeoip_74_200_247_59 | 4 +- test/fixtures/ipstack_134_201_250_155 | 49 +++ test/fixtures/ipstack_access_restricted | 8 + test/fixtures/ipstack_batch_not_supported | 8 + test/fixtures/ipstack_inactive_user | 8 + test/fixtures/ipstack_invalid_access_key | 8 + test/fixtures/ipstack_invalid_api_function | 8 + test/fixtures/ipstack_invalid_fields | 8 + test/fixtures/ipstack_missing_access_key | 8 + test/fixtures/ipstack_no_results | 0 test/fixtures/ipstack_not_found | 8 + .../ipstack_protocol_access_restricted | 8 + test/fixtures/ipstack_too_many_ips | 8 + test/fixtures/ipstack_usage_limit | 8 + test/test_helper.rb | 8 + test/unit/lookup_test.rb | 2 +- test/unit/lookups/ipstack_test.rb | 285 ++++++++++++++++++ 23 files changed, 596 insertions(+), 6 deletions(-) create mode 100644 lib/geocoder/lookups/ipstack.rb create mode 100644 lib/geocoder/results/ipstack.rb create mode 100644 test/fixtures/ipstack_134_201_250_155 create mode 100644 test/fixtures/ipstack_access_restricted create mode 100644 test/fixtures/ipstack_batch_not_supported create mode 100644 test/fixtures/ipstack_inactive_user create mode 100644 test/fixtures/ipstack_invalid_access_key create mode 100644 test/fixtures/ipstack_invalid_api_function create mode 100644 test/fixtures/ipstack_invalid_fields create mode 100644 test/fixtures/ipstack_missing_access_key create mode 100644 test/fixtures/ipstack_no_results create mode 100644 test/fixtures/ipstack_not_found create mode 100644 test/fixtures/ipstack_protocol_access_restricted create mode 100644 test/fixtures/ipstack_too_many_ips create mode 100644 test/fixtures/ipstack_usage_limit create mode 100644 test/unit/lookups/ipstack_test.rb diff --git a/README.md b/README.md index 3356f44d2..67fb58f7b 100644 --- a/README.md +++ b/README.md @@ -753,7 +753,31 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string ### IP Address Services -#### FreeGeoIP (`:freegeoip`) +#### Ipstack (`:ipstack`) + +* **API key**: required - see https://ipstack.com/product +* **Quota**: 10,000 requests per month (with free API Key, 50,000/day and up for paid plans) +* **Region**: world +* **SSL support**: yes ( only with paid plan ) +* **Languages**: English, German, Spanish, French, Japanese, Portugues (Brazil), Russian, Chinese +* **Documentation**: https://ipstack.com/documentation +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: To use Ipstack set `Geocoder.configure(:ip_lookup => :ipstack, :api_key => "your_ipstack_api_key")`. Support for the ipstack JSONP, batch lookup, and requester lookup features has not been implemented yet. This lookup does support the params shown below: +* ```ruby + # Search Options Examples + + Geocoder.search('0.0.0.0', { + params: { + hostname: '1', + security: '1', + fields: 'country_code,location.capital,...', # see ipstack documentation + language: 'en' + } + }) + ``` + +#### FreeGeoIP (`:freegeoip`) - DEPRECATED ( [ more information](https://github.com/alexreisner/geocoder/wiki/Freegeoip-Discontinuation) ) * **API key**: none * **Quota**: 15,000 requests per hour. After reaching the hourly quota, all of your requests will result in HTTP 403 (Forbidden) until it clears up on the next roll over. diff --git a/geocoder.gemspec b/geocoder.gemspec index 8bb7462e6..7488885ca 100644 --- a/geocoder.gemspec +++ b/geocoder.gemspec @@ -19,6 +19,17 @@ Gem::Specification.new do |s| s.executables = ["geocode"] s.license = 'MIT' + s.post_install_message = %q{ + +IMPORTANT: Geocoder has recently switched its default ip lookup. If you have specified :freegeoip +in your configuration, you must choose a different ip lookup by July 1, 2018, which is when +the Freegeoip API will be discontinued. + +For more information visit: +https://github.com/alexreisner/geocoder/wiki/Freegeoip-Discontinuation + +} + s.metadata = { 'source_code_uri' => 'https://github.com/alexreisner/geocoder', 'changelog_uri' => 'https://github.com/alexreisner/geocoder/blob/master/CHANGELOG.md' diff --git a/lib/generators/geocoder/config/templates/initializer.rb b/lib/generators/geocoder/config/templates/initializer.rb index 41d682f2f..88c64890c 100644 --- a/lib/generators/geocoder/config/templates/initializer.rb +++ b/lib/generators/geocoder/config/templates/initializer.rb @@ -2,7 +2,7 @@ # Geocoding options # timeout: 3, # geocoding service timeout (secs) # lookup: :google, # name of geocoding service (symbol) - # ip_lookup: :freegeoip, # name of IP address geocoding service (symbol) + # ip_lookup: :ipinfo_io, # name of IP address geocoding service (symbol) # language: :en, # ISO-639 language code # use_https: false, # use HTTPS for lookup requests? (if supported) # http_proxy: nil, # HTTP proxy server (user:pass@host:port) diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index b756f768f..d439c7d23 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -72,7 +72,8 @@ def ip_services :ipinfo_io, :ipapi_com, :ipdata_co, - :db_ip_com + :db_ip_com, + :ipstack, ] end diff --git a/lib/geocoder/lookups/ipstack.rb b/lib/geocoder/lookups/ipstack.rb new file mode 100644 index 000000000..2d8d3c328 --- /dev/null +++ b/lib/geocoder/lookups/ipstack.rb @@ -0,0 +1,64 @@ +require 'geocoder/lookups/base' +require 'geocoder/results/ipstack' + +module Geocoder::Lookup + class Ipstack < Base + + ERROR_CODES = { + 404 => Geocoder::InvalidRequest, + 101 => Geocoder::InvalidApiKey, + 102 => Geocoder::Error, + 103 => Geocoder::InvalidRequest, + 104 => Geocoder::OverQueryLimitError, + 105 => Geocoder::RequestDenied, + 301 => Geocoder::InvalidRequest, + 302 => Geocoder::InvalidRequest, + 303 => Geocoder::RequestDenied, + } + ERROR_CODES.default = Geocoder::Error + + def name + "Ipstack" + end + + def query_url(query) + extra_params = url_query_string(query) + url = "#{protocol}://#{host}/#{query.sanitized_text}?access_key=#{api_key}" + url << "&#{extra_params}" unless extra_params.empty? + url + end + + private + + def results(query) + # don't look up a loopback address, just return the stored result + return [reserved_result(query.text)] if query.loopback_ip_address? + + return [] unless doc = fetch_data(query) + + if error = doc['error'] + code = error['code'] + msg = error['info'] + raise_error(ERROR_CODES[code], msg ) || Geocoder.log(:warn, "Ipstack Geocoding API error: #{msg}") + return [] + end + [doc] + end + + def reserved_result(ip) + { + "ip" => ip, + "country_name" => "Reserved", + "country_code" => "RD" + } + end + + def host + configuration[:host] || "api.ipstack.com" + end + + def api_key + configuration.api_key + end + end +end diff --git a/lib/geocoder/results/ipstack.rb b/lib/geocoder/results/ipstack.rb new file mode 100644 index 000000000..af1099fb8 --- /dev/null +++ b/lib/geocoder/results/ipstack.rb @@ -0,0 +1,60 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class Ipstack < Base + + def address(format = :full) + s = region_code.empty? ? "" : ", #{region_code}" + "#{city}#{s} #{zip}, #{country_name}".sub(/^[ ,]*/, "") + end + + def state + @data['region_name'] + end + + def state_code + @data['region_code'] + end + + def country + @data['country_name'] + end + + def postal_code + @data['zip'] || @data['zipcode'] || @data['zip_code'] + end + + def self.response_attributes + [ + ['ip', ''], + ['hostname', ''], + ['continent_code', ''], + ['continent_name', ''], + ['country_code', ''], + ['country_name', ''], + ['region_code', ''], + ['region_name', ''], + ['city', ''], + ['zip', ''], + ['latitude', 0], + ['longitude', 0], + ['location', {}], + ['time_zone', {}], + ['currency', {}], + ['connection', {}], + ['security', {}], + ] + end + + response_attributes.each do |attr, default| + define_method attr do + @data[attr] || default + end + end + + def metro_code + Geocoder.log(:warn, "Ipstack does not implement `metro_code` in api results. Please discontinue use.") + 0 # no longer implemented by ipstack + end + end +end diff --git a/test/fixtures/freegeoip_74_200_247_59 b/test/fixtures/freegeoip_74_200_247_59 index e187b40bd..defc4ace5 100644 --- a/test/fixtures/freegeoip_74_200_247_59 +++ b/test/fixtures/freegeoip_74_200_247_59 @@ -4,9 +4,9 @@ "region_name": "Texas", "metro_code": "623", "zipcode": "75093", - "longitude": "-96.8134", + "longitude": -96.8134, "country_name": "United States", "country_code": "US", "ip": "74.200.247.59", - "latitude": "33.0347" + "latitude": 33.0347 } diff --git a/test/fixtures/ipstack_134_201_250_155 b/test/fixtures/ipstack_134_201_250_155 new file mode 100644 index 000000000..cff0568d2 --- /dev/null +++ b/test/fixtures/ipstack_134_201_250_155 @@ -0,0 +1,49 @@ +{ + "ip": "134.201.250.155", + "hostname": "134.201.250.155", + "type": "ipv4", + "continent_code": "NA", + "continent_name": "North America", + "country_code": "US", + "country_name": "United States", + "region_code": "CA", + "region_name": "California", + "city": "Los Angeles", + "zip": "90013", + "latitude": 34.0453, + "longitude": -118.2413, + "location": { + "geoname_id": 5368361, + "capital": "Washington D.C.", + "languages": [ + { + "code": "en", + "name": "English", + "native": "English" + } + ], + "country_flag": "https://assets.ipstack.com/images/assets/flags_svg/us.svg", + "country_flag_emoji": "🇺🇸", + "country_flag_emoji_unicode": "U+1F1FA U+1F1F8", + "calling_code": "1", + "is_eu": false + }, + "time_zone": { + "id": "America/Los_Angeles", + "current_time": "2018-03-29T07:35:08-07:00", + "gmt_offset": -25200, + "code": "PDT", + "is_daylight_saving": true + }, + "currency": { + "code": "USD", + "name": "US Dollar", + "plural": "US dollars", + "symbol": "$", + "symbol_native": "$" + }, + "connection": { + "asn": 25876, + "isp": "Los Angeles Department of Water & Power" + } +} diff --git a/test/fixtures/ipstack_access_restricted b/test/fixtures/ipstack_access_restricted new file mode 100644 index 000000000..652e1cb9c --- /dev/null +++ b/test/fixtures/ipstack_access_restricted @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 105, + "type": "function_access_restricted", + "info": "The current subscription plan does not support this API endpoint." + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_batch_not_supported b/test/fixtures/ipstack_batch_not_supported new file mode 100644 index 000000000..b60a245f3 --- /dev/null +++ b/test/fixtures/ipstack_batch_not_supported @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 303, + "type": "batch_not_supported_on_plan", + "info": "The Bulk Lookup Endpoint is not supported on the current subscription plan" + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_inactive_user b/test/fixtures/ipstack_inactive_user new file mode 100644 index 000000000..1ead8fa9e --- /dev/null +++ b/test/fixtures/ipstack_inactive_user @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 102, + "type": "inactive_user", + "info": "The current user account is not active. User will be prompted to get in touch with Customer Support." + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_invalid_access_key b/test/fixtures/ipstack_invalid_access_key new file mode 100644 index 000000000..f119c8521 --- /dev/null +++ b/test/fixtures/ipstack_invalid_access_key @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 101, + "type": "invalid_access_key", + "info": "No API Key was specified or an invalid API Key was specified." + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_invalid_api_function b/test/fixtures/ipstack_invalid_api_function new file mode 100644 index 000000000..e58000501 --- /dev/null +++ b/test/fixtures/ipstack_invalid_api_function @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 103, + "type": "invalid_api_function", + "info": "The requested API endpoint does not exist." + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_invalid_fields b/test/fixtures/ipstack_invalid_fields new file mode 100644 index 000000000..105f54119 --- /dev/null +++ b/test/fixtures/ipstack_invalid_fields @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 301, + "type": "invalid_fields", + "info": "One or more invalid fields were specified using the fields parameter." + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_missing_access_key b/test/fixtures/ipstack_missing_access_key new file mode 100644 index 000000000..358e5c8e0 --- /dev/null +++ b/test/fixtures/ipstack_missing_access_key @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 101, + "type": "missing_access_key", + "info": "No API Key was specified." + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_no_results b/test/fixtures/ipstack_no_results new file mode 100644 index 000000000..e69de29bb diff --git a/test/fixtures/ipstack_not_found b/test/fixtures/ipstack_not_found new file mode 100644 index 000000000..f644fa30a --- /dev/null +++ b/test/fixtures/ipstack_not_found @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 404, + "type": "404_not_found", + "info": "The requested resource does not exist." + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_protocol_access_restricted b/test/fixtures/ipstack_protocol_access_restricted new file mode 100644 index 000000000..7c915afaf --- /dev/null +++ b/test/fixtures/ipstack_protocol_access_restricted @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 105, + "type": "https_access_restricted", + "info": "The user's current subscription plan does not support HTTPS Encryption." + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_too_many_ips b/test/fixtures/ipstack_too_many_ips new file mode 100644 index 000000000..b85c5e5d1 --- /dev/null +++ b/test/fixtures/ipstack_too_many_ips @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 302, + "type": "too_many_ips", + "info": "Too many IPs have been specified for the Bulk Lookup Endpoint. (max. 50)" + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_usage_limit b/test/fixtures/ipstack_usage_limit new file mode 100644 index 000000000..d3753f02a --- /dev/null +++ b/test/fixtures/ipstack_usage_limit @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 104, + "type": "usage_limit_reached", + "info": "The maximum allowed amount of monthly API requests has been reached." + } +} \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 4857dfed7..5698e49ef 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -217,6 +217,14 @@ def default_fixture_filename end end + require 'geocoder/lookups/ipstack' + class Ipstack + private + def default_fixture_filename + "ipstack_134_201_250_155" + end + end + require 'geocoder/lookups/geoip2' class Geoip2 private diff --git a/test/unit/lookup_test.rb b/test/unit/lookup_test.rb index 7f21877f7..2afa95474 100644 --- a/test/unit/lookup_test.rb +++ b/test/unit/lookup_test.rb @@ -24,7 +24,7 @@ def test_search_returns_empty_array_when_no_results def test_query_url_contains_values_in_params_hash Geocoder::Lookup.all_services_except_test.each do |l| - next if [:freegeoip, :maxmind_local, :telize, :pointpin, :geoip2, :maxmind_geoip2, :mapbox, :ipdata_co, :ipinfo_io, :ipapi_com].include? l # does not use query string + next if [:freegeoip, :maxmind_local, :telize, :pointpin, :geoip2, :maxmind_geoip2, :mapbox, :ipdata_co, :ipinfo_io, :ipapi_com, :ipstack].include? l # does not use query string set_api_key!(l) url = Geocoder::Lookup.get(l).query_url(Geocoder::Query.new( "test", :params => {:one_in_the_hand => "two in the bush"} diff --git a/test/unit/lookups/ipstack_test.rb b/test/unit/lookups/ipstack_test.rb new file mode 100644 index 000000000..fd2a17682 --- /dev/null +++ b/test/unit/lookups/ipstack_test.rb @@ -0,0 +1,285 @@ +# encoding: utf-8 +require 'test_helper' + +class SpyLogger + def initialize + @log = [] + end + + def logged?(msg) + @log.include?(msg) + end + + def add(level, msg) + @log << msg + end +end + +class IpstackTest < GeocoderTestCase + + def setup + @logger = SpyLogger.new + Geocoder::Configuration.instance.data.clear + Geocoder::Configuration.set_defaults + Geocoder.configure( + :api_key => '123', + :ip_lookup => :ipstack, + :always_raise => :all, + :logger => @logger + ) + end + + def test_result_on_ip_address_search + result = Geocoder.search("134.201.250.155").first + assert result.is_a?(Geocoder::Result::Ipstack) + end + + def test_result_components + result = Geocoder.search("134.201.250.155").first + assert_equal "Los Angeles, CA 90013, United States", result.address + end + + def test_all_top_level_api_fields + result = Geocoder.search("134.201.250.155").first + assert_equal "134.201.250.155", result.ip + assert_equal "134.201.250.155", result.hostname + assert_equal "NA", result.continent_code + assert_equal "North America", result.continent_name + assert_equal "US", result.country_code + assert_equal "United States", result.country_name + assert_equal "CA", result.region_code + assert_equal "California", result.region_name + assert_equal "Los Angeles", result.city + assert_equal "90013", result.zip + assert_equal 34.0453, result.latitude + assert_equal (-118.2413), result.longitude + end + + def test_nested_api_fields + result = Geocoder.search("134.201.250.155").first + + assert result.location.is_a?(Hash) + assert_equal 5368361, result.location['geoname_id'] + + assert result.time_zone.is_a?(Hash) + assert_equal "America/Los_Angeles", result.time_zone['id'] + + assert result.currency.is_a?(Hash) + assert_equal "USD", result.currency['code'] + + assert result.connection.is_a?(Hash) + assert_equal 25876, result.connection['asn'] + + assert result.security.is_a?(Hash) + end + + def test_required_base_fields + result = Geocoder.search("134.201.250.155").first + assert_equal "California", result.state + assert_equal "CA", result.state_code + assert_equal "United States", result.country + assert_equal "90013", result.postal_code + assert_equal [34.0453, -118.2413], result.coordinates + end + + def test_logs_deprecation_of_metro_code_field + result = Geocoder.search("134.201.250.155").first + result.metro_code + + assert @logger.logged?("Ipstack does not implement `metro_code` in api results. Please discontinue use.") + end + + def test_localhost_loopback + result = Geocoder.search("127.0.0.1").first + assert_equal "127.0.0.1", result.ip + assert_equal "RD", result.country_code + assert_equal "Reserved", result.country_name + end + + def test_localhost_loopback_defaults + result = Geocoder.search("127.0.0.1").first + assert_equal "127.0.0.1", result.ip + assert_equal "", result.hostname + assert_equal "", result.continent_code + assert_equal "", result.continent_name + assert_equal "RD", result.country_code + assert_equal "Reserved", result.country_name + assert_equal "", result.region_code + assert_equal "", result.region_name + assert_equal "", result.city + assert_equal "", result.zip + assert_equal 0, result.latitude + assert_equal 0, result.longitude + assert_equal({}, result.location) + assert_equal({}, result.time_zone) + assert_equal({}, result.currency) + assert_equal({}, result.connection) + end + + def test_api_request_adds_access_key + lookup = Geocoder::Lookup.get(:ipstack) + assert_match 'http://api.ipstack.com/74.200.247.59?access_key=123', lookup.query_url(Geocoder::Query.new("74.200.247.59")) + end + + def test_api_request_adds_security_when_specified + lookup = Geocoder::Lookup.get(:ipstack) + + query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { security: '1' })) + + assert_match(/&security=1/, query_url) + end + + def test_api_request_adds_hostname_when_specified + lookup = Geocoder::Lookup.get(:ipstack) + + query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { hostname: '1' })) + + assert_match(/&hostname=1/, query_url) + end + + def test_api_request_adds_language_when_specified + lookup = Geocoder::Lookup.get(:ipstack) + + query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { language: 'es' })) + + assert_match(/&language=es/, query_url) + end + + def test_api_request_adds_fields_when_specified + lookup = Geocoder::Lookup.get(:ipstack) + + query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { fields: 'foo,bar' })) + + assert_match(/&fields=foo%2Cbar/, query_url) + end + + def test_logs_warning_when_errors_are_set_not_to_raise + Geocoder::Configuration.instance.data.clear + Geocoder::Configuration.set_defaults + Geocoder.configure(api_key: '123', ip_lookup: :ipstack, logger: @logger) + + lookup = Geocoder::Lookup.get(:ipstack) + + lookup.send(:results, Geocoder::Query.new("not_found")) + + assert @logger.logged?("Ipstack Geocoding API error: The requested resource does not exist.") + end + + def test_uses_lookup_specific_configuration + Geocoder::Configuration.instance.data.clear + Geocoder::Configuration.set_defaults + Geocoder.configure(api_key: '123', ip_lookup: :ipstack, logger: @logger, ipstack: { api_key: '345'}) + + lookup = Geocoder::Lookup.get(:ipstack) + assert_match 'http://api.ipstack.com/74.200.247.59?access_key=345', lookup.query_url(Geocoder::Query.new("74.200.247.59")) + end + + def test_not_authorized lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::InvalidRequest do + lookup.send(:results, Geocoder::Query.new("not_found")) + end + + assert_equal error.message, "The requested resource does not exist." + end + + def test_missing_access_key + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::InvalidApiKey do + lookup.send(:results, Geocoder::Query.new("missing_access_key")) + end + + assert_equal error.message, "No API Key was specified." + end + + def test_invalid_access_key + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::InvalidApiKey do + lookup.send(:results, Geocoder::Query.new("invalid_access_key")) + end + + assert_equal error.message, "No API Key was specified or an invalid API Key was specified." + end + + def test_inactive_user + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::Error do + lookup.send(:results, Geocoder::Query.new("inactive_user")) + end + + assert_equal error.message, "The current user account is not active. User will be prompted to get in touch with Customer Support." + end + + def test_invalid_api_function + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::InvalidRequest do + lookup.send(:results, Geocoder::Query.new("invalid_api_function")) + end + + assert_equal error.message, "The requested API endpoint does not exist." + end + + def test_usage_limit + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::OverQueryLimitError do + lookup.send(:results, Geocoder::Query.new("usage_limit")) + end + + assert_equal error.message, "The maximum allowed amount of monthly API requests has been reached." + end + + def test_access_restricted + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::RequestDenied do + lookup.send(:results, Geocoder::Query.new("access_restricted")) + end + + assert_equal error.message, "The current subscription plan does not support this API endpoint." + end + + def test_protocol_access_restricted + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::RequestDenied do + lookup.send(:results, Geocoder::Query.new("protocol_access_restricted")) + end + + assert_equal error.message, "The user's current subscription plan does not support HTTPS Encryption." + end + + def test_invalid_fields + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::InvalidRequest do + lookup.send(:results, Geocoder::Query.new("invalid_fields")) + end + + assert_equal error.message, "One or more invalid fields were specified using the fields parameter." + end + + def test_too_many_ips + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::InvalidRequest do + lookup.send(:results, Geocoder::Query.new("too_many_ips")) + end + + assert_equal error.message, "Too many IPs have been specified for the Bulk Lookup Endpoint. (max. 50)" + end + + def test_batch_not_supported + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::RequestDenied do + lookup.send(:results, Geocoder::Query.new("batch_not_supported")) + end + + assert_equal error.message, "The Bulk Lookup Endpoint is not supported on the current subscription plan" + end +end From 616a60e013133d691281a78a91db301788da1c38 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 21 May 2018 13:55:36 -0600 Subject: [PATCH 049/248] Update text for clarity and consistency. --- README.md | 46 +++++++++++++++++----------------------------- geocoder.gemspec | 7 +------ 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 67fb58f7b..cf21b6809 100644 --- a/README.md +++ b/README.md @@ -753,31 +753,17 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string ### IP Address Services -#### Ipstack (`:ipstack`) +#### IPInfo.io (`:ipinfo_io`) -* **API key**: required - see https://ipstack.com/product -* **Quota**: 10,000 requests per month (with free API Key, 50,000/day and up for paid plans) +* **API key**: optional - see http://ipinfo.io/pricing +* **Quota**: 1,000/day - more with api key * **Region**: world -* **SSL support**: yes ( only with paid plan ) -* **Languages**: English, German, Spanish, French, Japanese, Portugues (Brazil), Russian, Chinese -* **Documentation**: https://ipstack.com/documentation -* **Terms of Service**: ? -* **Limitations**: ? -* **Notes**: To use Ipstack set `Geocoder.configure(:ip_lookup => :ipstack, :api_key => "your_ipstack_api_key")`. Support for the ipstack JSONP, batch lookup, and requester lookup features has not been implemented yet. This lookup does support the params shown below: -* ```ruby - # Search Options Examples - - Geocoder.search('0.0.0.0', { - params: { - hostname: '1', - security: '1', - fields: 'country_code,location.capital,...', # see ipstack documentation - language: 'en' - } - }) - ``` +* **SSL support**: no (not without access key - see http://ipinfo.io/pricing) +* **Languages**: English +* **Documentation**: http://ipinfo.io/developers +* **Terms of Service**: http://ipinfo.io/developers -#### FreeGeoIP (`:freegeoip`) - DEPRECATED ( [ more information](https://github.com/alexreisner/geocoder/wiki/Freegeoip-Discontinuation) ) +#### FreeGeoIP (`:freegeoip`) - [DISCONTINUED](https://github.com/alexreisner/geocoder/wiki/Freegeoip-Discontinuation) * **API key**: none * **Quota**: 15,000 requests per hour. After reaching the hourly quota, all of your requests will result in HTTP 403 (Forbidden) until it clears up on the next roll over. @@ -850,15 +836,17 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Limitations**: ? * **Notes**: You must specify which MaxMind service you are using in your configuration, and also basic authentication. For example: `Geocoder.configure(:maxmind_geoip2 => {:service => :country, :basic_auth => {:user => '', :password => ''}})`. -#### IPInfo.io (`:ipinfo_io`) +#### Ipstack (`:ipstack`) -* **API key**: optional - see http://ipinfo.io/pricing -* **Quota**: 1,000/day - more with api key +* **API key**: required (see https://ipstack.com/product) +* **Quota**: 10,000 requests per month (with free API Key, 50,000/day and up for paid plans) * **Region**: world -* **SSL support**: no (not without access key - see http://ipinfo.io/pricing) -* **Languages**: English -* **Documentation**: http://ipinfo.io/developers -* **Terms of Service**: http://ipinfo.io/developers +* **SSL support**: yes ( only with paid plan ) +* **Languages**: English, German, Spanish, French, Japanese, Portugues (Brazil), Russian, Chinese +* **Documentation**: https://ipstack.com/documentation +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: To use Ipstack set `Geocoder.configure(:ip_lookup => :ipstack, :api_key => "your_ipstack_api_key")`. Supports the optional params: `:hostname`, `:security`, `:fields`, `:language` (see API documentation for details). #### IP-API.com (`:ipapi_com`) diff --git a/geocoder.gemspec b/geocoder.gemspec index 7488885ca..9a4fd52d1 100644 --- a/geocoder.gemspec +++ b/geocoder.gemspec @@ -21,12 +21,7 @@ Gem::Specification.new do |s| s.post_install_message = %q{ -IMPORTANT: Geocoder has recently switched its default ip lookup. If you have specified :freegeoip -in your configuration, you must choose a different ip lookup by July 1, 2018, which is when -the Freegeoip API will be discontinued. - -For more information visit: -https://github.com/alexreisner/geocoder/wiki/Freegeoip-Discontinuation +NOTE: Geocoder's default IP address lookup has changed from FreeGeoIP.net to IPInfo.io. If you explicitly specify :freegeoip in your configuration you must choose a different IP lookup before FreeGeoIP is discontinued on July 1, 2018. If you do not explicitly specify :freegeoip you do not need to change anything. } From ae251bc3753799c822afbd980e0bed163a1c92e5 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 21 May 2018 13:56:32 -0600 Subject: [PATCH 050/248] Prepare for release of gem version 1.4.8. --- CHANGELOG.md | 6 ++++++ lib/geocoder/version.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3305072ae..6e4970f60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ Changelog Major changes to Geocoder for each release. Please see the Git log for complete list of changes. +1.4.8 (2018 May 21) +------------------- +* Change default IP address lookup from :freegeoip to :ipinfo_io. +* Add support for :ipstack lookup (thanks github.com/Heath101). +* Fix incompatibility with redis-rb gem v4.0. + 1.4.7 (2018 Mar 13) ------------------- * Allow HTTP protocol for Nominatim. diff --git a/lib/geocoder/version.rb b/lib/geocoder/version.rb index 71cfe2adb..e5fd5a30d 100644 --- a/lib/geocoder/version.rb +++ b/lib/geocoder/version.rb @@ -1,3 +1,3 @@ module Geocoder - VERSION = "1.4.7" + VERSION = "1.4.8" end From f8d5eeb247c42d71dc7d5f9191d47484c2e469be Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Thu, 24 May 2018 13:20:14 -0600 Subject: [PATCH 051/248] Restore geoip2 result's #data method as public. --- lib/geocoder/results/geoip2.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/geocoder/results/geoip2.rb b/lib/geocoder/results/geoip2.rb index cf0f758a7..c7a1a913b 100644 --- a/lib/geocoder/results/geoip2.rb +++ b/lib/geocoder/results/geoip2.rb @@ -62,6 +62,10 @@ def language @language ||= default_language end + def data + @data.to_hash + end + private def default_language From 39381bd40131bde0eee1946ba94ad22ced2bcbb4 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 25 May 2018 13:08:44 -0600 Subject: [PATCH 052/248] Return lat/lon in #coordinates and remove separate #latitutde and #longitude methods (which are defined in base Result class). --- lib/geocoder/results/postcodes_io.rb | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/geocoder/results/postcodes_io.rb b/lib/geocoder/results/postcodes_io.rb index 82c97d626..caaa042ec 100644 --- a/lib/geocoder/results/postcodes_io.rb +++ b/lib/geocoder/results/postcodes_io.rb @@ -2,16 +2,9 @@ module Geocoder::Result class PostcodesIo < Base - def coordinates - [latitude, longitude] - end - def latitude - @data['latitude'].to_f - end - - def longitude - @data['longitude'].to_f + def coordinates + [@data['latitude'].to_f, @data['longitude'].to_f] end def quality From 4a7f09c652713eba3d7972ca17885caed9265e7d Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 25 May 2018 13:14:57 -0600 Subject: [PATCH 053/248] Add Postcodes.io to README. --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cf21b6809..e0ec01961 100644 --- a/README.md +++ b/README.md @@ -703,7 +703,18 @@ Data Science Toolkit provides an API whose response format is like Google's but * **Terms of Service**: http://wiki.geoportail.lu/doku.php?id=en:mcg_1 * **Limitations**: ? -#### PostcodeAnywhere Uk (`:postcode_anywhere_uk`) +#### Postcodes.io (`:postcodes_io`) + +* **API key**: none +* **Quota**: ? +* **Region**: UK +* **SSL support**: yes +* **Languages**: English +* **Documentation**: http://postcodes.io/docs +* **Terms of Service**: ? +* **Limitations**: UK postcodes only + +#### PostcodeAnywhere UK (`:postcode_anywhere_uk`) This uses the PostcodeAnywhere UK Geocode service, this will geocode any string from UK postcode, placename, point of interest or location. @@ -712,7 +723,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Region**: UK * **SSL support**: yes * **Languages**: English -* **Documentation**: [http://www.postcodeanywhere.co.uk/Support/WebService/Geocoding/UK/Geocode/2/](http://www.postcodeanywhere.co.uk/Support/WebService/Geocoding/UK/Geocode/2/) +* **Documentation**: http://www.postcodeanywhere.co.uk/Support/WebService/Geocoding/UK/Geocode/2/ * **Terms of Service**: ? * **Limitations**: ? * **Notes**: To use PostcodeAnywhere you must include an API key: `Geocoder.configure(:lookup => :postcode_anywhere_uk, :api_key => 'your_api_key')`. From fd63a05549a1b26a67a0e2c52dd6e8c37237c585 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 25 May 2018 14:19:40 -0600 Subject: [PATCH 054/248] Lock byebug to version 9.0.6 with Rails 3.2. --- gemfiles/Gemfile.rails3.2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gemfiles/Gemfile.rails3.2 b/gemfiles/Gemfile.rails3.2 index 994d0cbb5..0fd65abe4 100644 --- a/gemfiles/Gemfile.rails3.2 +++ b/gemfiles/Gemfile.rails3.2 @@ -9,7 +9,7 @@ group :development, :test do gem 'rails', '>= 3.2' gem 'test-unit' # needed for Ruby >=2.2.0 - gem 'byebug', platforms: :mri + gem 'byebug', '9.0.6', platforms: :mri platforms :jruby do gem 'jruby-openssl' From 501c19166a20705ee4334892acf333659a4960f5 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 27 May 2018 14:37:16 -0600 Subject: [PATCH 055/248] Prepare for release of gem version 1.4.9. --- CHANGELOG.md | 5 +++++ lib/geocoder/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e4970f60..303dc95b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ Changelog Major changes to Geocoder for each release. Please see the Git log for complete list of changes. +1.4.9 (2018 May 27) +------------------- +* Fix regression in :geoip2 lookup. +* Add support for Postcodes.io lookup (thanks github.com/sledge909). + 1.4.8 (2018 May 21) ------------------- * Change default IP address lookup from :freegeoip to :ipinfo_io. diff --git a/lib/geocoder/version.rb b/lib/geocoder/version.rb index e5fd5a30d..e2bfb0aef 100644 --- a/lib/geocoder/version.rb +++ b/lib/geocoder/version.rb @@ -1,3 +1,3 @@ module Geocoder - VERSION = "1.4.8" + VERSION = "1.4.9" end From c46346bab1763b1357a3e2fbd027803b93a1aa2b Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 15 Jun 2018 09:46:01 -0600 Subject: [PATCH 056/248] Move Rails 4.1+ count issue lower in README. --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e0ec01961..5f9d1772f 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,6 @@ Compatibility * Works very well outside of Rails, you just need to install either the `json` (for MRI) or `json_pure` (for JRuby) gem. -Note on Rails 4.1 and Greater ------------------------------ - -Due to [a change in ActiveRecord's `count` method](https://github.com/rails/rails/pull/10710) you will need to use `count(:all)` to explicitly count all columns ("*") when using a `near` scope. Using `near` and calling `count` with no argument will cause exceptions in many cases. - - Installation ------------ @@ -1270,6 +1264,10 @@ Please DO NOT use GitHub issues to ask questions about how to use Geocoder. Site ### Known Issues +#### Using `count` with Rails 4.1+ + +Due to [a change in ActiveRecord's `count` method](https://github.com/rails/rails/pull/10710) you will need to use `count(:all)` to explicitly count all columns ("*") when using a `near` scope. Using `near` and calling `count` with no argument will cause exceptions in many cases. + #### Using `near` with `includes` You cannot use the `near` scope with another scope that provides an `includes` option because the `SELECT` clause generated by `near` will overwrite it (or vice versa). From 5eaa2cad4cf5ee432f45840f1347b53c4cdfc83c Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 15 Jun 2018 09:55:52 -0600 Subject: [PATCH 057/248] Rename README headers for clarity. --- README.md | 124 +++++++++++++++++++++++++++++------------------------- 1 file changed, 67 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 5f9d1772f..178cfd439 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,8 @@ and run at the command prompt: bundle install -Object Geocoding ----------------- +Geocoding Objects +----------------- ### ActiveRecord @@ -124,8 +124,8 @@ The exact code will vary depending on the method you use for your geocodable str after_validation :geocode, if: ->(obj){ obj.address.present? and obj.address_changed? } -Request Geocoding by IP Address -------------------------------- +Geocoding HTTP Requests +----------------------- Geocoder adds `location` and `safe_location` methods to the standard `Rack::Request` object so you can easily look up the location of any HTTP request by IP address. For example, in a Rails controller or a Sinatra app: @@ -139,8 +139,8 @@ Note that these methods will usually return `nil` in your test and development e See _Advanced Geocoding_ below for more information about `Geocoder::Result` objects. -Location-Aware Database Queries -------------------------------- +Geographic Database Queries +--------------------------- ### For Mongo-backed models: @@ -266,8 +266,8 @@ You can also specify a proc if you want to choose a lookup based on a specific p end -Advanced Querying ------------------ +Advanced Database Queries +------------------------- When querying for objects (if you're using ActiveRecord) you can also look within a square rather than a radius (circle) by using the `within_bounding_box` scope: @@ -379,7 +379,7 @@ Or, to use parameters in your model: end -### Configure Multiple Services +### Configuring Multiple Services You can configure multiple geocoding services at once, like this: @@ -407,11 +407,12 @@ You can configure multiple geocoding services at once, like this: The above combines global and service-specific options and could be useful if you specify different geocoding services for different models or under different conditions. Lookup-specific settings override global settings. In the above example, the timeout for all lookups would be 2 seconds, except for Yandex which would be 5. -### Street Address Services +API Guide: Street Address Lookups +--------------------------------- The following is a comparison of the supported geocoding APIs. The "Limitations" listed for each are a very brief and incomplete summary of some special limitations beyond basic data source attribution. Please read the official Terms of Service for a service before using it. -#### Google (`:google`) +### Google (`:google`) * **API key**: optional, but quota is higher if key is used (use of key requires HTTPS so be sure to set: `:use_https => true` in `Geocoder.configure`) * **Key signup**: https://console.developers.google.com/flows/enableapi?apiid=geocoding_backend&keyType=SERVER_SIDE @@ -426,7 +427,7 @@ The following is a comparison of the supported geocoding APIs. The "Limitations" * **Terms of Service**: http://code.google.com/apis/maps/terms.html#section_10_12 * **Limitations**: "You must not use or display the Content without a corresponding Google map, unless you are explicitly permitted to do so in the Maps APIs Documentation, or through written permission from Google." "You must not pre-fetch, cache, or store any Content, except that you may store: (i) limited amounts of Content for the purpose of improving the performance of your Maps API Implementation..." -#### Google Maps API for Work (`:google_premier`) +### Google Maps API for Work (`:google_premier`) Similar to `:google`, with the following differences: @@ -434,7 +435,7 @@ Similar to `:google`, with the following differences: * **Key signup**: https://developers.google.com/maps/documentation/business/ * **Quota**: 100,000 requests/24 hrs, 10 requests/second -#### Google Places Details (`:google_places_details`) +### Google Places Details (`:google_places_details`) The [Google Places Details API](https://developers.google.com/places/documentation/details) is not, strictly speaking, a geocoding service. It accepts a Google `place_id` and returns address information, ratings and reviews. A `place_id` can be obtained from the Google Places Search lookup (`:google_places_search`) and should be passed to Geocoder as the first search argument: `Geocoder.search("ChIJhRwB-yFawokR5Phil-QQ3zM", lookup: :google_places_details)`. @@ -448,13 +449,13 @@ The [Google Places Details API](https://developers.google.com/places/documentati * **Terms of Service**: https://developers.google.com/places/policies * **Limitations**: "If your application displays Places API data on a page or view that does not also display a Google Map, you must show a "Powered by Google" logo with that data." -#### Google Places Search (`:google_places_search`) +### Google Places Search (`:google_places_search`) The [Google Places Search API](https://developers.google.com/places/web-service/search) is the geocoding service of Google Places API. It returns very limited location data, but it also returns a `place_id` which can be used with Google Place Details to get more detailed information. For a comparison between this and the regular Google Geocoding API, see https://maps-apis.googleblog.com/2016/11/address-geocoding-in-google-maps-apis.html * Same specifications as Google Places Details (see above). -#### Bing (`:bing`) +### Bing (`:bing`) * **API key**: required (set `Geocoder.configure(:lookup => :bing, :api_key => key)`) * **Key signup**: https://www.microsoft.com/maps/create-a-bing-maps-key.aspx @@ -466,7 +467,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Terms of Service**: http://www.microsoft.com/maps/product/terms.html * **Limitations**: No country codes or state names. Must be used on "public-facing, non-password protected web sites," "in conjunction with Bing Maps or an application that integrates Bing Maps." -#### Nominatim (`:nominatim`) +### Nominatim (`:nominatim`) * **API key**: none * **Quota**: 1 request/second @@ -477,7 +478,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Terms of Service**: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy * **Limitations**: Please limit request rate to 1 per second and include your contact information in User-Agent headers (eg: `Geocoder.configure(:http_headers => { "User-Agent" => "your contact info" })`). [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) -#### PickPoint (`:pickpoint`) +### PickPoint (`:pickpoint`) * **API key**: required * **Key signup**: [https://pickpoint.io](https://pickpoint.io) @@ -489,7 +490,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) -#### LocationIQ (`:location_iq`) +### LocationIQ (`:location_iq`) * **API key**: required * **Quota**: 60 requests/minute (2 req/sec, 10k req/day), then [ability to purchase more](http://locationiq.org/#pricing) @@ -500,7 +501,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Terms of Service**: https://unwiredlabs.com/tos * **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](https://www.openstreetmap.org/copyright) -#### OpenCageData (`:opencagedata`) +### OpenCageData (`:opencagedata`) * **API key**: required * **Key signup**: http://geocoder.opencagedata.com @@ -511,7 +512,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Documentation**: http://geocoder.opencagedata.com/api.html * **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) -#### Yandex (`:yandex`) +### Yandex (`:yandex`) * **API key**: optional, but without it lookup is territorially limited * **Quota**: 25000 requests / day @@ -522,7 +523,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Terms of Service**: http://api.yandex.com.tr/maps/doc/intro/concepts/intro.xml#rules * **Limitations**: ? -#### Geocoder.ca (`:geocoder_ca`) +### Geocoder.ca (`:geocoder_ca`) * **API key**: none * **Quota**: ? @@ -533,7 +534,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Terms of Service**: http://geocoder.ca/?terms=1 * **Limitations**: "Under no circumstances can our data be re-distributed or re-sold by anyone to other parties without our written permission." -#### Mapbox (`:mapbox`) +### Mapbox (`:mapbox`) * **API key**: required * **Dataset**: Uses `mapbox.places` dataset by default. Specify the `mapbox.places-permanent` dataset by setting: `Geocoder.configure(:mapbox => {:dataset => "mapbox.places-permanent"})` @@ -553,7 +554,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Limitations**: For `mapbox.places` dataset, must be displayed on a Mapbox map; Cache results for up to 30 days. For `mapbox.places-permanent` dataset, depends on plan. * **Notes**: Currently in public beta. -#### Mapquest (`:mapquest`) +### Mapquest (`:mapquest`) * **API key**: required * **Key signup**: https://developer.mapquest.com/plans @@ -568,7 +569,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Limitations**: ? * **Notes**: You can use the open (non-licensed) API by setting: `Geocoder.configure(:mapquest => {:open => true})` (defaults to licensed version) -#### Ovi/Nokia (`:ovi`) +### Ovi/Nokia (`:ovi`) * **API key**: not required, but performance restricted without it * **Quota**: ? @@ -579,7 +580,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Terms of Service**: http://www.developer.nokia.com/Develop/Maps/TC.html * **Limitations**: ? -#### Here/Nokia (`:here`) +### Here/Nokia (`:here`) * **API key**: required (set `Geocoder.configure(:api_key => [app_id, app_code])`) * **Quota**: Depending on the API key @@ -590,7 +591,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Terms of Service**: http://developer.here.com/faqs#l&t * **Limitations**: ? -#### ESRI (`:esri`) +### ESRI (`:esri`) * **API key**: optional (set `Geocoder.configure(:esri => {:api_key => ["client_id", "client_secret"]})`) * **Quota**: Required for some scenarios (see Terms of Service) @@ -602,7 +603,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Limitations**: Requires API key if results will be stored. Using API key will also remove rate limit. * **Notes**: You can specify which projection you want to use by setting, for example: `Geocoder.configure(:esri => {:outSR => 102100})`. If you will store results, set the flag and provide API key: `Geocoder.configure(:esri => {:api_key => ["client_id", "client_secret"], :for_storage => true})`. If you want to, you can also supply an ESRI token directly: `Geocoder.configure(:esri => {:token => Geocoder::EsriToken.new('TOKEN', Time.now + 1.day})` -#### Mapzen (`:mapzen`) +### Mapzen (`:mapzen`) * **API key**: required * **Quota**: 25,000 free requests/month and [ability to purchase more](https://mapzen.com/pricing/) @@ -614,7 +615,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Limitations**: [You must provide attribution](https://mapzen.com/rights/) * **Notes**: Mapzen is the primary author of Pelias and offers Pelias-as-a-service in free and paid versions https://mapzen.com/pelias. -#### Pelias (`:pelias`) +### Pelias (`:pelias`) * **API key**: configurable (self-hosted service) * **Quota**: none (self-hosted service) @@ -626,7 +627,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Limitations**: See terms * **Notes**: Configure your self-hosted pelias with the `endpoint` option: `Geocoder.configure(:lookup => :pelias, :api_key => 'your_api_key', :pelias => {:endpoint => 'self.hosted/pelias'})`. Defaults to `localhost`. -#### Data Science Toolkit (`:dstk`) +### Data Science Toolkit (`:dstk`) Data Science Toolkit provides an API whose response format is like Google's but which can be set up as a privately hosted service. @@ -640,7 +641,7 @@ Data Science Toolkit provides an API whose response format is like Google's but * **Limitations**: No reverse geocoding. * **Notes**: If you are hosting your own DSTK server you will need to configure the host name, eg: `Geocoder.configure(:lookup => :dstk, :dstk => {:host => "localhost:4567"})`. -#### Baidu (`:baidu`) +### Baidu (`:baidu`) * **API key**: required * **Quota**: No quota limits for geocoding @@ -652,7 +653,7 @@ Data Science Toolkit provides an API whose response format is like Google's but * **Limitations**: Only good for non-commercial use. For commercial usage please check http://developer.baidu.com/map/question.htm#qa0013 * **Notes**: To use Baidu set `Geocoder.configure(:lookup => :baidu, :api_key => "your_api_key")`. -#### Geocodio (`:geocodio`) +### Geocodio (`:geocodio`) * **API key**: required * **Quota**: 2,500 free requests/day then purchase $0.0005 for each, also has volume pricing and plans. @@ -663,7 +664,7 @@ Data Science Toolkit provides an API whose response format is like Google's but * **Terms of Service**: https://geocod.io/terms-of-use/ * **Limitations**: No restrictions on use -#### SmartyStreets (`:smarty_streets`) +### SmartyStreets (`:smarty_streets`) * **API key**: requires auth_id and auth_token (set `Geocoder.configure(:api_key => [id, token])`) * **Quota**: 250/month then purchase at sliding scale. @@ -675,7 +676,7 @@ Data Science Toolkit provides an API whose response format is like Google's but * **Limitations**: No reverse geocoding. -#### OKF Geocoder (`:okf`) +### OKF Geocoder (`:okf`) * **API key**: none * **Quota**: none @@ -686,7 +687,7 @@ Data Science Toolkit provides an API whose response format is like Google's but * **Terms of Service**: http://www.itella.fi/liitteet/palvelutjatuotteet/yhteystietopalvelut/Postinumeropalvelut-Palvelukuvausjakayttoehdot.pdf * **Limitations**: ? -#### Geoportail.lu (`:geoportail_lu`) +### Geoportail.lu (`:geoportail_lu`) * **API key**: none * **Quota**: none @@ -697,7 +698,7 @@ Data Science Toolkit provides an API whose response format is like Google's but * **Terms of Service**: http://wiki.geoportail.lu/doku.php?id=en:mcg_1 * **Limitations**: ? -#### Postcodes.io (`:postcodes_io`) +### Postcodes.io (`:postcodes_io`) * **API key**: none * **Quota**: ? @@ -708,7 +709,7 @@ Data Science Toolkit provides an API whose response format is like Google's but * **Terms of Service**: ? * **Limitations**: UK postcodes only -#### PostcodeAnywhere UK (`:postcode_anywhere_uk`) +### PostcodeAnywhere UK (`:postcode_anywhere_uk`) This uses the PostcodeAnywhere UK Geocode service, this will geocode any string from UK postcode, placename, point of interest or location. @@ -722,7 +723,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Limitations**: ? * **Notes**: To use PostcodeAnywhere you must include an API key: `Geocoder.configure(:lookup => :postcode_anywhere_uk, :api_key => 'your_api_key')`. -#### LatLon.io (`:latlon`) +### LatLon.io (`:latlon`) * **API key**: required * **Quota**: Depends on the user's plan (free and paid plans available) @@ -733,7 +734,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Terms of Service**: ? * **Limitations**: No restrictions on use -#### Base Adresse Nationale FR (`:ban_data_gouv_fr`) +### Base Adresse Nationale FR (`:ban_data_gouv_fr`) * **API key**: none * **Quota**: none @@ -744,7 +745,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Terms of Service**: https://adresse.data.gouv.fr/faq/ (in french) * **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://openstreetmap.fr/ban) -#### AMap (`:amap`) +### AMap (`:amap`) - **API key**: required - **Quota**: 2000/day and 2000/minute for personal developer, 4000000/day and 60000/minute for enterprise developer, for geocoding requests @@ -756,9 +757,11 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string - **Limitations**: Only good for non-commercial use. For commercial usage please check http://lbs.amap.com/home/terms/ - **Notes**: To use AMap set `Geocoder.configure(:lookup => :amap, :api_key => "your_api_key")`. -### IP Address Services -#### IPInfo.io (`:ipinfo_io`) +API Guide: IP Address Lookups +----------------------------- + +### IPInfo.io (`:ipinfo_io`) * **API key**: optional - see http://ipinfo.io/pricing * **Quota**: 1,000/day - more with api key @@ -768,7 +771,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Documentation**: http://ipinfo.io/developers * **Terms of Service**: http://ipinfo.io/developers -#### FreeGeoIP (`:freegeoip`) - [DISCONTINUED](https://github.com/alexreisner/geocoder/wiki/Freegeoip-Discontinuation) +### FreeGeoIP (`:freegeoip`) - [DISCONTINUED](https://github.com/alexreisner/geocoder/wiki/Freegeoip-Discontinuation) * **API key**: none * **Quota**: 15,000 requests per hour. After reaching the hourly quota, all of your requests will result in HTTP 403 (Forbidden) until it clears up on the next roll over. @@ -780,7 +783,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Limitations**: ? * **Notes**: If you are [running your own local instance of the FreeGeoIP service](https://github.com/fiorix/freegeoip) you can configure the host like this: `Geocoder.configure(freegeoip: {host: "..."})`. -#### Pointpin (`:pointpin`) +### Pointpin (`:pointpin`) * **API key**: required * **Quota**: 50,000/mo for €9 through 1m/mo for €49 @@ -792,7 +795,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Limitations**: ? * **Notes**: To use Pointpin set `Geocoder.configure(:ip_lookup => :pointpin, :api_key => "your_pointpin_api_key")`. -#### Telize (`:telize`) +### Telize (`:telize`) * **API key**: required * **Quota**: 1,000/day for $7/mo through 100,000/day for $100/mo @@ -805,7 +808,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Notes**: To use Telize set `Geocoder.configure(:ip_lookup => :telize, :api_key => "your_api_key")`. Or configure your self-hosted telize with the `host` option: `Geocoder.configure(:ip_lookup => :telize, :telize => {:host => "localhost"})`. -#### MaxMind Legacy Web Services (`:maxmind`) +### MaxMind Legacy Web Services (`:maxmind`) * **API key**: required * **Quota**: Request Packs can be purchased @@ -817,7 +820,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Limitations**: ? * **Notes**: You must specify which MaxMind service you are using in your configuration. For example: `Geocoder.configure(:maxmind => {:service => :omni})`. -#### Baidu IP (`:baidu_ip`) +### Baidu IP (`:baidu_ip`) * **API key**: required * **Quota**: No quota limits for geocoding @@ -829,7 +832,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Limitations**: Only good for non-commercial use. For commercial usage please check http://developer.baidu.com/map/question.htm#qa0013 * **Notes**: To use Baidu set `Geocoder.configure(:lookup => :baidu_ip, :api_key => "your_api_key")`. -#### MaxMind GeoIP2 Precision Web Services (`:maxmind_geoip2`) +### MaxMind GeoIP2 Precision Web Services (`:maxmind_geoip2`) * **API key**: required * **Quota**: Request Packs can be purchased @@ -841,7 +844,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Limitations**: ? * **Notes**: You must specify which MaxMind service you are using in your configuration, and also basic authentication. For example: `Geocoder.configure(:maxmind_geoip2 => {:service => :country, :basic_auth => {:user => '', :password => ''}})`. -#### Ipstack (`:ipstack`) +### Ipstack (`:ipstack`) * **API key**: required (see https://ipstack.com/product) * **Quota**: 10,000 requests per month (with free API Key, 50,000/day and up for paid plans) @@ -853,7 +856,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Limitations**: ? * **Notes**: To use Ipstack set `Geocoder.configure(:ip_lookup => :ipstack, :api_key => "your_ipstack_api_key")`. Supports the optional params: `:hostname`, `:security`, `:fields`, `:language` (see API documentation for details). -#### IP-API.com (`:ipapi_com`) +### IP-API.com (`:ipapi_com`) * **API key**: optional - see http://ip-api.com/docs/#usage_limits * **Quota**: 150/minute - unlimited with api key @@ -863,7 +866,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Documentation**: http://ip-api.com/docs/ * **Terms of Service**: https://signup.ip-api.com/terms -#### DB-IP.com (`:db_ip_com`) +### DB-IP.com (`:db_ip_com`) * **API key**: required * **Quota**: 2,500/day (with free API Key, 50,000/day and up for paid API keys) @@ -873,7 +876,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Documentation**: https://db-ip.com/api/doc.php * **Terms of Service**: https://db-ip.com/tos.php -#### Ipdata.co (`:ipdata_co`) +### Ipdata.co (`:ipdata_co`) * **API key**: optional, see: https://ipdata.co/pricing.html * **Quota**: 1500/day (up to 600k with paid API keys) @@ -887,7 +890,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string ### IP Address Local Database Services -#### MaxMind Local (`:maxmind_local`) - EXPERIMENTAL +### MaxMind Local (`:maxmind_local`) - EXPERIMENTAL This lookup provides methods for geocoding IP addresses without making a call to a remote API (improves speed and availability). It works, but support is new and should not be considered production-ready. Please [report any bugs](https://github.com/alexreisner/geocoder/issues) you encounter. @@ -919,7 +922,7 @@ You can generate ActiveRecord migrations and download and import data via provid You can replace `city` with `country` in any of the above tasks, generators, and configurations. -#### GeoLite2 (`:geoip2`) +### GeoLite2 (`:geoip2`) This lookup provides methods for geocoding IP addresses without making a call to a remote API (improves speed and availability). It works, but support is new and should not be considered production-ready. Please [report any bugs](https://github.com/alexreisner/geocoder/issues) you encounter. @@ -950,6 +953,7 @@ You must add either the *[hive_geoip2](https://rubygems.org/gems/hive_geoip2)* g } ) + Caching ------- @@ -1045,6 +1049,7 @@ For example: end + Use Outside of Rails -------------------- @@ -1116,6 +1121,7 @@ When you install the Geocoder gem it adds a `geocode` command to your shell. You There are also a number of options for setting the geocoding API, key, and language, viewing the raw JSON response, and more. Please run `geocode -h` for details. + Numeric Data Types and Precision -------------------------------- @@ -1123,6 +1129,7 @@ Geocoder works with any numeric data type (e.g. float, double, decimal) on which A summary of the relationship between geographic precision and the number of decimal places in latitude and longitude degree values is available on [Wikipedia](http://en.wikipedia.org/wiki/Decimal_degrees#Accuracy). As an example: at the equator, latitude/longitude values with 4 decimal places give about 11 metres precision, whereas 5 decimal places gives roughly 1 metre precision. + Notes on MongoDB ---------------- @@ -1144,6 +1151,7 @@ Calling `obj.coordinates` directly returns the internal representation of the co For consistency with the rest of Geocoder, always use the `to_coordinates` method instead. + Notes on Non-Rails Frameworks ----------------------------- @@ -1151,6 +1159,7 @@ If you are using Geocoder with ActiveRecord and a framework other than Rails (li extend Geocoder::Model::ActiveRecord + Optimisation of Distance Queries -------------------------------- @@ -1262,13 +1271,14 @@ When reporting an issue, please list the version of Geocoder you are using and a Please DO NOT use GitHub issues to ask questions about how to use Geocoder. Sites like [StackOverflow](http://www.stackoverflow.com/) are a better forum for such discussions. -### Known Issues +Known Issues +------------ -#### Using `count` with Rails 4.1+ +### Using `count` with Rails 4.1+ Due to [a change in ActiveRecord's `count` method](https://github.com/rails/rails/pull/10710) you will need to use `count(:all)` to explicitly count all columns ("*") when using a `near` scope. Using `near` and calling `count` with no argument will cause exceptions in many cases. -#### Using `near` with `includes` +### Using `near` with `includes` You cannot use the `near` scope with another scope that provides an `includes` option because the `SELECT` clause generated by `near` will overwrite it (or vice versa). @@ -1285,7 +1295,7 @@ Instead of using `includes` to reduce the number of database queries, try using If anyone has a more elegant solution to this problem I am very interested in seeing it. -#### Using `near` with objects close to the 180th meridian +### Using `near` with objects close to the 180th meridian The `near` method will not look across the 180th meridian to find objects close to a given point. In practice this is rarely an issue outside of New Zealand and certain surrounding islands. This problem does not exist with the zero-meridian. The problem is due to a shortcoming of the Haversine formula which Geocoder uses to calculate distances. From c538c5c1a2581508502c926687ac9120033fcbdf Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 15 Jun 2018 09:58:56 -0600 Subject: [PATCH 058/248] Remove "Tests" section (no longer relevant). --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index 178cfd439..3fdefb96e 100644 --- a/README.md +++ b/README.md @@ -1189,14 +1189,6 @@ There are few options for finding objects near a given point in SQLite without i Because Geocoder needs to provide this functionality as a scope, we must go with option #1, but feel free to implement #2 or #3 if you need more accuracy. -Tests ------ - -Geocoder comes with a test suite (just run `rake test`) that mocks ActiveRecord and is focused on testing the aspects of Geocoder that do not involve executing database queries. Geocoder uses many database engine-specific queries which must be tested against all supported databases (SQLite, MySQL, etc). Ideally this involves creating a full, working Rails application, and that seems beyond the scope of the included test suite. As such, I have created a separate repository which includes a full-blown Rails application and some utilities for easily running tests against multiple environments: - -http://github.com/alexreisner/geocoder_test - - Error Handling -------------- From d6254a50b874e6bd34cfbb2f3202e54d789d2fba Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 15 Jun 2018 10:11:19 -0600 Subject: [PATCH 059/248] README reorganization. --- README.md | 129 +++++++++++++++++++++++++----------------------------- 1 file changed, 60 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 3fdefb96e..d66fae744 100644 --- a/README.md +++ b/README.md @@ -142,10 +142,6 @@ See _Advanced Geocoding_ below for more information about `Geocoder::Result` obj Geographic Database Queries --------------------------- -### For Mongo-backed models: - -Please use MongoDB's [geospatial query language](https://docs.mongodb.org/manual/reference/command/geoNear/). Mongoid also provides [a DSL](http://mongoid.github.io/en/mongoid/docs/querying.html#geo_near) for doing near queries. - ### For ActiveRecord models: To find objects by location, use the following scopes: @@ -185,6 +181,10 @@ Some utility methods are also available: Please see the code for more methods and detailed information about arguments (eg, working with kilometers). +### For Mongo-backed models: + +Please use MongoDB's [geospatial query language](https://docs.mongodb.org/manual/reference/command/geoNear/). Mongoid also provides [a DSL](http://mongoid.github.io/en/mongoid/docs/querying.html#geo_near) for doing near queries. + Distance and Bearing -------------------- @@ -1050,16 +1050,6 @@ For example: end -Use Outside of Rails --------------------- - -You can use Geocoder outside of Rails by calling the `Geocoder.search` method: - - results = Geocoder.search("McCarren Park, Brooklyn, NY") - -This returns an array of `Geocoder::Result` objects with all data provided by the geocoding service. - - Testing Apps that Use Geocoder ------------------------------ @@ -1104,6 +1094,44 @@ Notes: - The stubbed result objects returned by the Test lookup do not support all the methods real result objects do. If you need to test interaction with real results it may be better to use an external stubbing tool and something like WebMock or VCR to prevent network calls. +Error Handling +-------------- + +By default Geocoder will rescue any exceptions raised by calls to a geocoding service and return an empty array. You can override this on a per-exception basis, and also have Geocoder raise its own exceptions for certain events (eg: API quota exceeded) by using the `:always_raise` option: + + Geocoder.configure(:always_raise => [SocketError, Timeout::Error]) + +You can also do this to raise all exceptions: + + Geocoder.configure(:always_raise => :all) + +The raise-able exceptions are: + + SocketError + Timeout::Error + Geocoder::OverQueryLimitError + Geocoder::RequestDenied + Geocoder::InvalidRequest + Geocoder::InvalidApiKey + Geocoder::ServiceUnavailable + +Note that only a few of the above exceptions are raised by any given lookup, so there's no guarantee if you configure Geocoder to raise `ServiceUnavailable` that it will actually be raised under those conditions (because most APIs don't return 503 when they should; you may get a `Timeout::Error` instead). Please see the source code for your particular lookup for details. + + +Use Outside of Rails +-------------------- + +You can use Geocoder outside of Rails by calling the `Geocoder.search` method: + + results = Geocoder.search("McCarren Park, Brooklyn, NY") + +This returns an array of `Geocoder::Result` objects with all data provided by the geocoding service. + +To use Geocoder with ActiveRecord and a framework other than Rails (like Sinatra or Padrino), you will need to add this in your model before calling Geocoder methods: + + extend Geocoder::Model::ActiveRecord + + Command Line Interface ---------------------- @@ -1122,12 +1150,12 @@ When you install the Geocoder gem it adds a `geocode` command to your shell. You There are also a number of options for setting the geocoding API, key, and language, viewing the raw JSON response, and more. Please run `geocode -h` for details. -Numeric Data Types and Precision --------------------------------- +Notes on ActiveRecord +--------------------- -Geocoder works with any numeric data type (e.g. float, double, decimal) on which trig (and other mathematical) functions can be performed. +In MySQL and Postgres, queries use a bounding box to limit the number of points over which a more precise distance calculation needs to be done. To take advantage of this optimisation, you need to add a composite index on latitude and longitude. In your Rails migration: -A summary of the relationship between geographic precision and the number of decimal places in latitude and longitude degree values is available on [Wikipedia](http://en.wikipedia.org/wiki/Decimal_degrees#Accuracy). As an example: at the equator, latitude/longitude values with 4 decimal places give about 11 metres precision, whereas 5 decimal places gives roughly 1 metre precision. + add_index :table, [:latitude, :longitude] Notes on MongoDB @@ -1152,32 +1180,13 @@ Calling `obj.coordinates` directly returns the internal representation of the co For consistency with the rest of Geocoder, always use the `to_coordinates` method instead. -Notes on Non-Rails Frameworks ------------------------------ - -If you are using Geocoder with ActiveRecord and a framework other than Rails (like Sinatra or Padrino), you will need to add this in your model before calling Geocoder methods: - - extend Geocoder::Model::ActiveRecord - - -Optimisation of Distance Queries --------------------------------- - -In MySQL and Postgres, the finding of objects near a given point is sped up by using a bounding box to limit the number of points over which a full distance calculation needs to be done. - -To take advantage of this optimisation, you need to add a composite index on latitude and longitude. In your Rails migration: - - add_index :table, [:latitude, :longitude] +Technical Discussions +--------------------- - -Distance Queries in SQLite --------------------------- +### Distance Queries in SQLite SQLite's lack of trigonometric functions requires an alternate implementation of the `near` scope. When using SQLite, Geocoder will automatically use a less accurate algorithm for finding objects near a given point. Results of this algorithm should not be trusted too much as it will return objects that are outside the given radius, along with inaccurate distance and bearing calculations. - -### Discussion - There are few options for finding objects near a given point in SQLite without installing extensions: 1. Use a square instead of a circle for finding nearby points. For example, if you want to find points near 40.71, 100.23, search for objects with latitude between 39.71 and 41.71 and longitude between 99.23 and 101.23. One degree of latitude or longitude is at most 69 miles so divide your radius (in miles) by 69.0 to get the amount to add and subtract from your center coordinates to get the upper and lower bounds. The results will not be very accurate (you'll get points outside the desired radius), but you will get all the points within the required radius. @@ -1188,29 +1197,11 @@ There are few options for finding objects near a given point in SQLite without i Because Geocoder needs to provide this functionality as a scope, we must go with option #1, but feel free to implement #2 or #3 if you need more accuracy. +### Numeric Data Types and Precision -Error Handling --------------- - -By default Geocoder will rescue any exceptions raised by calls to a geocoding service and return an empty array. You can override this on a per-exception basis, and also have Geocoder raise its own exceptions for certain events (eg: API quota exceeded) by using the `:always_raise` option: - - Geocoder.configure(:always_raise => [SocketError, Timeout::Error]) - -You can also do this to raise all exceptions: - - Geocoder.configure(:always_raise => :all) - -The raise-able exceptions are: - - SocketError - Timeout::Error - Geocoder::OverQueryLimitError - Geocoder::RequestDenied - Geocoder::InvalidRequest - Geocoder::InvalidApiKey - Geocoder::ServiceUnavailable +Geocoder works with any numeric data type (e.g. float, double, decimal) on which trig (and other mathematical) functions can be performed. -Note that only a few of the above exceptions are raised by any given lookup, so there's no guarantee if you configure Geocoder to raise `ServiceUnavailable` that it will actually be raised under those conditions (because most APIs don't return 503 when they should; you may get a `Timeout::Error` instead). Please see the source code for your particular lookup for details. +A summary of the relationship between geographic precision and the number of decimal places in latitude and longitude degree values is available on [Wikipedia](http://en.wikipedia.org/wiki/Decimal_degrees#Accuracy). As an example: at the equator, latitude/longitude values with 4 decimal places give about 11 metres precision, whereas 5 decimal places gives roughly 1 metre precision. Troubleshooting @@ -1255,14 +1246,6 @@ You can also fetch the response in the console: Geocoder::Lookup.get(:google).send(:fetch_raw_data, Geocoder::Query.new("...")) -Reporting Issues ----------------- - -When reporting an issue, please list the version of Geocoder you are using and any relevant information about your application (Rails version, database type and version, etc). Also avoid vague language like "it doesn't work." Please describe as specifically as you can what behavior you are actually seeing (eg: an error message? a nil return value?). - -Please DO NOT use GitHub issues to ask questions about how to use Geocoder. Sites like [StackOverflow](http://www.stackoverflow.com/) are a better forum for such discussions. - - Known Issues ------------ @@ -1292,6 +1275,14 @@ If anyone has a more elegant solution to this problem I am very interested in se The `near` method will not look across the 180th meridian to find objects close to a given point. In practice this is rarely an issue outside of New Zealand and certain surrounding islands. This problem does not exist with the zero-meridian. The problem is due to a shortcoming of the Haversine formula which Geocoder uses to calculate distances. +Reporting Issues +---------------- + +When reporting an issue, please list the version of Geocoder you are using and any relevant information about your application (Rails version, database type and version, etc). Please describe as specifically as you can what behavior you are seeing (eg: an error message? a nil return value?). + +Please DO NOT use GitHub issues to ask questions about how to use Geocoder. Sites like [StackOverflow](http://www.stackoverflow.com/) are a better forum for such discussions. + + Contributing ------------ From 1d5ad377f82dafc8f5829cc82ca2f499419b3c79 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 15 Jun 2018 11:33:51 -0600 Subject: [PATCH 060/248] Restructure README and add Table of Contents. --- README.md | 417 +++++++++++++++++++++++++----------------------------- 1 file changed, 192 insertions(+), 225 deletions(-) diff --git a/README.md b/README.md index d66fae744..a97778c38 100644 --- a/README.md +++ b/README.md @@ -31,21 +31,59 @@ and run at the command prompt: bundle install +Table of Contents +----------------- + +Basic Features: + +1. [Geocoding Objects](#geocoding-objects) +2. [Geocoding HTTP Requests](#geocoding-http-requests) +3. [Geographic Database Queries](#geographic-database-queries) +4. [Model Configuration](#model-configuration) +5. [Geocoding Service ("Lookup") Configuration](#geocoding-service-lookup-configuration) + +API Guide: + +6. [Street Address Lookups](#api-guide-street-address-lookups) +7. [IP Address Lookups](#api-guide-ip-address-lookups) + +Advanced Features: + +8. [Performance and Optimization](#performance-and-optimization) +9. [Advanced Geocoding](#advanced-geocoding) +10. [Advanced Database Queries](#advanced-database-queries) +11. [Testing](#testing) +12. [Error Handling](#error-handing) +13. [Use Outside of Rails](#use-outside-of-rails) +14. [Command Line Interface](#command-line-interface) + +The Rest: + +15. [Technical Discussions](#technical-discussions) +16. [Troubleshooting](#troubleshooting) +17. [Known Issues](#known-issues) +18. [Reporting Issues](#reporting-issues) +19. [Contributing](#contributing) + + Geocoding Objects ----------------- ### ActiveRecord -Your model must have two attributes (database columns) for storing latitude and longitude coordinates. By default they should be called `latitude` and `longitude` but this can be changed (see "Model Configuration" below): +Your model must have two attributes (database columns) for storing latitude and longitude coordinates. By default they should be called `latitude` and `longitude` but this can be changed (see [Model Configuration](#model-configuration) below. - rails generate migration AddLatitudeAndLongitudeToModel latitude:float longitude:float - rake db:migrate +For geocoding, your model must provide a method that returns an address. This can be a single attribute, but it can also be a method that returns a string assembled from different attributes (eg: `city`, `state`, and `country`). For example, if your model has `street`, `city`, `state`, and `country` attributes you might do something like this: -For geocoding, your model must provide a method that returns an address. This can be a single attribute, but it can also be a method that returns a string assembled from different attributes (eg: `city`, `state`, and `country`). + geocoded_by :address + + def address + [street, city, state, country].compact.join(', ') + end Next, your model must tell Geocoder which method returns your object's geocodable address: - geocoded_by :full_street_address # can also be an IP address + geocoded_by :address # can also be an IP address after_validation :geocode # auto-fetch coordinates For reverse geocoding, tell Geocoder which attributes store latitude and longitude: @@ -81,47 +119,21 @@ Once you've set up your model you'll need to create the necessary spatial indice rake db:mongoid:create_indexes -Be sure to read _Latitude/Longitude Order_ in the _Notes on MongoDB_ section below on how to properly retrieve latitude/longitude coordinates from your objects. - ### MongoMapper MongoMapper is very similar to Mongoid, just be sure to include `Geocoder::Model::MongoMapper`. -### Mongo Indices - -By default, the methods `geocoded_by` and `reverse_geocoded_by` create a geospatial index. You can avoid index creation with the `:skip_index option`, for example: - - include Geocoder::Model::Mongoid - geocoded_by :address, :skip_index => true - -### Bulk Geocoding - -If you have just added geocoding to an existing application with a lot of objects, you can use this Rake task to geocode them all: - - rake geocode:all CLASS=YourModel - -If you need reverse geocoding instead, call the task with REVERSE=true: - - rake geocode:all CLASS=YourModel REVERSE=true - -Geocoder will print warnings if you exceed the rate limit for your geocoding service. Some services — Google notably — enforce a per-second limit in addition to a per-day limit. To avoid exceeding the per-second limit, you can add a `SLEEP` option to pause between requests for a given amount of time. You can also load objects in batches to save memory, for example: - - rake geocode:all CLASS=YourModel SLEEP=0.25 BATCH=100 - -To avoid per-day limit issues (for example if you are trying to geocode thousands of objects and don't want to reach the limit), you can add a `LIMIT` option. Warning: This will ignore the `BATCH` value if provided. - - rake geocode:all CLASS=YourModel LIMIT=1000 +### Latitude/Longitude Order in MongoDB -### Avoiding Unnecessary API Requests +Coordinates are generally printed and spoken as latitude, then longitude ([lat,lon]). Geocoder respects this convention and always expects method arguments to be given in [lat,lon] order. However, MongoDB requires that coordinates be stored in [lon,lat] order as per the GeoJSON spec (http://geojson.org/geojson-spec.html#positions), so internally they are stored "backwards." However, this does not affect order of arguments to methods when using Mongoid or MongoMapper. -Geocoding only needs to be performed under certain conditions. To avoid unnecessary work (and quota usage) you will probably want to geocode an object only when: +To access an object's coordinates in the conventional order, use the `to_coordinates` instance method provided by Geocoder. For example: -* an address is present -* the address has been changed since last save (or it has never been saved) + obj.to_coordinates # => [37.7941013, -122.3951096] # [lat, lon] -The exact code will vary depending on the method you use for your geocodable string, but it would be something like this: +Calling `obj.coordinates` directly returns the internal representation of the coordinates which, in the case of MongoDB, is probably the reverse of what you want: - after_validation :geocode, if: ->(obj){ obj.address.present? and obj.address_changed? } + obj.coordinates # => [-122.3951096, 37.7941013] # [lon, lat] Geocoding HTTP Requests @@ -134,9 +146,7 @@ Geocoder adds `location` and `safe_location` methods to the standard `Rack::Requ **The `location` method is vulnerable to trivial IP address spoofing via HTTP headers.** If that's a problem for your application, use `safe_location` instead, but be aware that `safe_location` will *not* try to trace a request's originating IP through proxy headers; you will instead get the location of the last proxy the request passed through, if any (excepting any proxies you have explicitly whitelisted in your Rack config). -Note that these methods will usually return `nil` in your test and development environments because things like "localhost" and "0.0.0.0" are not an Internet IP addresses. - -See _Advanced Geocoding_ below for more information about `Geocoder::Result` objects. +Note that these methods will usually return `nil` in test and development environments because things like "localhost" and "0.0.0.0" are not geocodable IP addresses. Geographic Database Queries @@ -183,145 +193,27 @@ Please see the code for more methods and detailed information about arguments (e ### For Mongo-backed models: -Please use MongoDB's [geospatial query language](https://docs.mongodb.org/manual/reference/command/geoNear/). Mongoid also provides [a DSL](http://mongoid.github.io/en/mongoid/docs/querying.html#geo_near) for doing near queries. - - -Distance and Bearing --------------------- - -When you run a location-aware query the returned objects have two attributes added to them (only w/ ActiveRecord): - -* `obj.distance` - number of miles from the search point to this object -* `obj.bearing` - direction from the search point to this object - -Results are automatically sorted by distance from the search point, closest to farthest. Bearing is given as a number of clockwise degrees from due north, for example: - -* `0` - due north -* `180` - due south -* `90` - due east -* `270` - due west -* `230.1` - southwest -* `359.9` - almost due north - -You can convert these numbers to compass point names by using the utility method provided: - - Geocoder::Calculations.compass_point(355) # => "N" - Geocoder::Calculations.compass_point(45) # => "NE" - Geocoder::Calculations.compass_point(208) # => "SW" - -_Note: when using SQLite `distance` and `bearing` values are provided for interface consistency only. They are not very accurate._ - -To calculate accurate distance and bearing with SQLite or MongoDB: - - obj.distance_to([43.9,-98.6]) # distance from obj to point - obj.bearing_to([43.9,-98.6]) # bearing from obj to point - obj.bearing_from(obj2) # bearing from obj2 to obj - -The `bearing_from/to` methods take a single argument which can be: a `[lat,lon]` array, a geocoded object, or a geocodable address (string). The `distance_from/to` methods also take a units argument (`:mi`, `:km`, or `:nm` for nautical miles). +Please do not use Geocoder's `near` method. Instead use MongoDB's built-in [geospatial query language](https://docs.mongodb.org/manual/reference/command/geoNear/), which is faster. Mongoid also provides [a DSL](http://mongoid.github.io/en/mongoid/docs/querying.html#geo_near) for doing near queries. Model Configuration ------------------- -You are not stuck with using the `latitude` and `longitude` database column names (with ActiveRecord) or the `coordinates` array (Mongo) for storing coordinates. For example: +You are not stuck with the `latitude` and `longitude` database column names (with ActiveRecord) or the `coordinates` array (Mongo) for storing coordinates. For example: geocoded_by :address, :latitude => :lat, :longitude => :lon # ActiveRecord geocoded_by :address, :coordinates => :coords # MongoDB -The `address` method can return any string you'd use to search Google Maps. For example, any of the following are acceptable: - -* "714 Green St, Big Town, MO" -* "Eiffel Tower, Paris, FR" -* "Paris, TX, US" - -If your model has `street`, `city`, `state`, and `country` attributes you might do something like this: - - geocoded_by :address - - def address - [street, city, state, country].compact.join(', ') - end - -For reverse geocoding, you can also specify an alternate name attribute where the address will be stored. For example: +For reverse geocoding, you can specify the attribute where the address will be stored. For example: reverse_geocoded_by :latitude, :longitude, :address => :location # ActiveRecord reverse_geocoded_by :coordinates, :address => :loc # MongoDB -You can also configure a specific lookup for your model which will override the globally-configured lookup. For example: - - geocoded_by :address, :lookup => :yandex - -You can also specify a proc if you want to choose a lookup based on a specific property of an object. For example, you can use specialized lookups for different regions: - - geocoded_by :address, :lookup => lambda{ |obj| obj.geocoder_lookup } - - def geocoder_lookup - if country_code == "RU" - :yandex - elsif country_code == "CN" - :baidu - else - :google - end - end - - -Advanced Database Queries -------------------------- - -When querying for objects (if you're using ActiveRecord) you can also look within a square rather than a radius (circle) by using the `within_bounding_box` scope: - - distance = 20 - center_point = [40.71, 100.23] - box = Geocoder::Calculations.bounding_box(center_point, distance) - Venue.within_bounding_box(box) - -This can also dramatically improve query performance, especially when used in conjunction with indexes on the latitude/longitude columns. Note, however, that returned results do not include `distance` and `bearing` attributes. Also note that `#near` performs both bounding box and radius queries for speed. - -You can also specify a minimum radius (if you're using ActiveRecord and not Sqlite) to constrain the -lower bound (ie. think of a donut, or ring) by using the `:min_radius` option: - - box = Geocoder::Calculations.bounding_box(center_point, distance, :min_radius => 10.5) - -With ActiveRecord, you can specify alternate latitude and longitude column names for a geocoded model (useful if you store multiple sets of coordinates for each object): - - Venue.near("Paris", 50, latitude: :secondary_latitude, longitude: :secondary_longitude) - - -Advanced Geocoding ------------------- - -So far we have looked at shortcuts for assigning geocoding results to object attributes. However, if you need to do something fancy, you can skip the auto-assignment by providing a block (takes the object to be geocoded and an array of `Geocoder::Result` objects) in which you handle the parsed geocoding result any way you like, for example: - - reverse_geocoded_by :latitude, :longitude do |obj,results| - if geo = results.first - obj.city = geo.city - obj.zipcode = geo.postal_code - obj.country = geo.country_code - end - end - after_validation :reverse_geocode - -Every `Geocoder::Result` object, `result`, provides the following data: - -* `result.latitude` - float -* `result.longitude` - float -* `result.coordinates` - array of the above two in the form of `[lat,lon]` -* `result.address` - string -* `result.city` - string -* `result.state` - string -* `result.state_code` - string -* `result.postal_code` - string -* `result.country` - string -* `result.country_code` - string - -If you're familiar with the results returned by the geocoding service you're using you can access even more data (call the `#data` method of any Geocoder::Result object to get the full parsed response), but you'll need to be familiar with the particular `Geocoder::Result` object you're using and the structure of your geocoding service's responses. (See below for links to geocoding service documentation.) - Geocoding Service ("Lookup") Configuration ------------------------------------------ -Geocoder supports a variety of street and IP address geocoding services. The default lookups are `:google` for street addresses and `:ipinfo_io` for IP addresses. Please see the listing and comparison below for details on specific geocoding services (not all settings are supported by all services). +Geocoder supports a variety of street and IP address geocoding services. The default lookups are `:google` for street addresses and `:ipinfo_io` for IP addresses. Please see the [API Guide](#api-guide-street-address-services) for details on specific geocoding services (not all settings are supported by all services). To create a Rails initializer with an example configuration: @@ -332,10 +224,10 @@ Some common configuration options are: # config/initializers/geocoder.rb Geocoder.configure( - # geocoding service (see below for supported options): + # street address geocoding service (default :google) :lookup => :yandex, - # IP address geocoding service (see below for supported options): + # IP address geocoding service (default :ipinfo_io) :ip_lookup => :maxmind, # to use an API key: @@ -347,7 +239,7 @@ Some common configuration options are: # set default units to kilometers: :units => :km, - # caching (see below for details): + # caching (see [below](#caching) for details): :cache => Redis.new, :cache_prefix => "..." @@ -367,7 +259,7 @@ Or, to search within a particular region with Google: Geocoder.search("...", :params => {:region => "..."}) -Or, to use parameters in your model: +To specify parameters in your model: class Venue @@ -378,6 +270,19 @@ Or, to use parameters in your model: reverse_geocoded_by :latitude, :longitude, :address => :full_address, :params => {:region => "..."} end +Finally, you can specify a proc if you want to choose a lookup based on a specific property of an object. For example, you can use specialized lookups for different regions: + + geocoded_by :address, :lookup => lambda{ |obj| obj.geocoder_lookup } + + def geocoder_lookup + if country_code == "RU" + :yandex + elsif country_code == "CN" + :baidu + else + :google + end + end ### Configuring Multiple Services @@ -404,13 +309,13 @@ You can configure multiple geocoding services at once, like this: ) -The above combines global and service-specific options and could be useful if you specify different geocoding services for different models or under different conditions. Lookup-specific settings override global settings. In the above example, the timeout for all lookups would be 2 seconds, except for Yandex which would be 5. +The above example combines global and service-specific options. Lookup-specific settings override global settings, so the timeout for all lookups would be 2 seconds, except for Yandex which would be 5. API Guide: Street Address Lookups --------------------------------- -The following is a comparison of the supported geocoding APIs. The "Limitations" listed for each are a very brief and incomplete summary of some special limitations beyond basic data source attribution. Please read the official Terms of Service for a service before using it. +The following is a listing of the supported geocoding APIs. The "Limitations" listed for each are a very brief and incomplete summary of some special limitations beyond basic data source attribution. Please read the official Terms of Service for any API before using it. ### Google (`:google`) @@ -954,8 +859,32 @@ You must add either the *[hive_geoip2](https://rubygems.org/gems/hive_geoip2)* g ) -Caching -------- +Performance and Optimization +---------------------------- + +### Database Indices + +In MySQL and Postgres, queries use a bounding box to limit the number of points over which a more precise distance calculation needs to be done. To take advantage of this optimisation, you need to add a composite index on latitude and longitude. In your Rails migration: + + add_index :table, [:latitude, :longitude] + +In MongoDB, by default, the methods `geocoded_by` and `reverse_geocoded_by` create a geospatial index. You can avoid index creation with the `:skip_index option`, for example: + + include Geocoder::Model::Mongoid + geocoded_by :address, :skip_index => true + +### Avoiding Unnecessary API Requests + +Geocoding only needs to be performed under certain conditions. To avoid unnecessary work (and quota usage) you will probably want to geocode an object only when: + +* an address is present +* the address has been changed since last save (or it has never been saved) + +The exact code will vary depending on the method you use for your geocodable string, but it would be something like this: + + after_validation :geocode, if: ->(obj){ obj.address.present? and obj.address_changed? } + +### Caching When relying on any external service, it's always a good idea to cache retrieved data. When implemented correctly, it improves your app's response time and stability. It's easy to cache geocoding results with Geocoder -- just configure a cache store: @@ -992,10 +921,38 @@ For an example of a cache store with URL expiry, please see examples/autoexpire_ _Before you implement caching in your app please be sure that doing so does not violate the Terms of Service for your geocoding service._ -Forward and Reverse Geocoding in the Same Model ------------------------------------------------ +Advanced Geocoding +------------------ + +So far we have looked at shortcuts for assigning geocoding results to object attributes. However, if you need to do something fancy, you can skip the auto-assignment by providing a block (takes the object to be geocoded and an array of `Geocoder::Result` objects) in which you handle the parsed geocoding result any way you like, for example: + + reverse_geocoded_by :latitude, :longitude do |obj,results| + if geo = results.first + obj.city = geo.city + obj.zipcode = geo.postal_code + obj.country = geo.country_code + end + end + after_validation :reverse_geocode + +Every `Geocoder::Result` object, `result`, provides the following data: + +* `result.latitude` - float +* `result.longitude` - float +* `result.coordinates` - array of the above two in the form of `[lat,lon]` +* `result.address` - string +* `result.city` - string +* `result.state` - string +* `result.state_code` - string +* `result.postal_code` - string +* `result.country` - string +* `result.country_code` - string + +If you're familiar with the results returned by the geocoding service you're using you can access even more data (call the `#data` method of any Geocoder::Result object to get the full parsed response), but you'll need to be familiar with the particular `Geocoder::Result` object you're using and the structure of your geocoding service's responses. (See the [API Guide](#api-guide-street-address-services) for links to geocoding service documentation.) -If you apply both forward and reverse geocoding functionality to the same model (i.e. users can supply an address or coordinates and you want to fill in whatever's missing), you will provide two address methods: +### Forward and Reverse Geocoding in the Same Model + +If you apply both forward and reverse geocoding functionality to the same model (i.e. users can supply an address or coordinates and Geocoder fills in whatever's missing), you will need to provide two address methods: * one for storing the fetched address (reverse geocoding) * one for providing an address to use when fetching coordinates (forward geocoding) @@ -1011,47 +968,87 @@ For example: reverse_geocoded_by :latitude, :longitude, :address => :full_address end -However, there can be only one set of latitude/longitude attributes, and whichever you specify last will be used. For example: +However, for purposes of querying the database, there can be only one authoritative set of latitude/longitude attributes, and whichever you specify last will be used. For example, here the `:fetched_` attributes will not be the ones used in database queries: class Venue - geocoded_by :address, - :latitude => :fetched_latitude, # this will be overridden by the below - :longitude => :fetched_longitude # same here - + :latitude => :fetched_latitude, + :longitude => :fetched_longitude reverse_geocoded_by :latitude, :longitude end -We don't want ambiguity when doing distance calculations -- we need a single, authoritative source for coordinates! +### Batch Geocoding -Once both forward and reverse geocoding has been applied, it is possible to call them sequentially. +If you have just added geocoding to an existing application with a lot of objects, you can use this Rake task to geocode them all: -For example: + rake geocode:all CLASS=YourModel - class Venue +If you need reverse geocoding instead, call the task with REVERSE=true: - after_validation :geocode, :reverse_geocode + rake geocode:all CLASS=YourModel REVERSE=true - end +Geocoder will print warnings if you exceed the rate limit for your geocoding service. Some services — Google notably — enforce a per-second limit in addition to a per-day limit. To avoid exceeding the per-second limit, you can add a `SLEEP` option to pause between requests for a given amount of time. You can also load objects in batches to save memory, for example: -For certain geolocation services such as Google's geolocation API, this may cause issues during subsequent updates to database records if the longitude and latitude coordinates cannot be associated with a known location address (on a large body of water for example). On subsequent callbacks the following call: + rake geocode:all CLASS=YourModel SLEEP=0.25 BATCH=100 - after_validation :geocode +To avoid per-day limit issues (for example if you are trying to geocode thousands of objects and don't want to reach the limit), you can add a `LIMIT` option. Warning: This will ignore the `BATCH` value if provided. -will alter the longitude and latitude attributes based on the location field, which would be the closest known location to the original coordinates. In this case it is better to add conditions to each call, as not to override coordinates that do not have known location addresses associated with them. + rake geocode:all CLASS=YourModel LIMIT=1000 -For example: - class Venue +Advanced Database Queries +------------------------- - after_validation :reverse_geocode, :if => :has_coordinates - after_validation :geocode, :if => :has_location, :unless => :has_coordinates +When querying for objects (if you're using ActiveRecord) you can also look within a square rather than a radius (circle) by using the `within_bounding_box` scope: - end + distance = 20 + center_point = [40.71, 100.23] + box = Geocoder::Calculations.bounding_box(center_point, distance) + Venue.within_bounding_box(box) + +Note, however, that returned results will not include `distance` and `bearing` attributes. You can also specify a minimum radius (if you're using ActiveRecord and not Sqlite) to constrain the lower bound (ie. think of a donut, or ring) by using the `:min_radius` option: + + box = Geocoder::Calculations.bounding_box(center_point, distance, :min_radius => 10.5) + +With ActiveRecord, you can specify alternate latitude and longitude column names for a geocoded model (useful if you store multiple sets of coordinates for each object): + + Venue.near("Paris", 50, latitude: :secondary_latitude, longitude: :secondary_longitude) + +### Distance and Bearing + +When you run a location-aware query the returned objects have two attributes added to them (only w/ ActiveRecord): + +* `obj.distance` - number of miles from the search point to this object +* `obj.bearing` - direction from the search point to this object + +Results are automatically sorted by distance from the search point, closest to farthest. Bearing is given as a number of clockwise degrees from due north, for example: + +* `0` - due north +* `180` - due south +* `90` - due east +* `270` - due west +* `230.1` - southwest +* `359.9` - almost due north + +You can convert these numbers to compass point names by using the utility method provided: + + Geocoder::Calculations.compass_point(355) # => "N" + Geocoder::Calculations.compass_point(45) # => "NE" + Geocoder::Calculations.compass_point(208) # => "SW" + +_Note: when using SQLite `distance` and `bearing` values are provided for interface consistency only. They are not very accurate._ +To calculate accurate distance and bearing with SQLite or MongoDB: -Testing Apps that Use Geocoder ------------------------------- + obj.distance_to([43.9,-98.6]) # distance from obj to point + obj.bearing_to([43.9,-98.6]) # bearing from obj to point + obj.bearing_from(obj2) # bearing from obj2 to obj + +The `bearing_from/to` methods take a single argument which can be: a `[lat,lon]` array, a geocoded object, or a geocodable address (string). The `distance_from/to` methods also take a units argument (`:mi`, `:km`, or `:nm` for nautical miles). + + +Testing +------- When writing tests for an app that uses Geocoder it may be useful to avoid network calls and have Geocoder return consistent, configurable results. To do this, configure and use the `:test` lookup. For example: @@ -1150,36 +1147,6 @@ When you install the Geocoder gem it adds a `geocode` command to your shell. You There are also a number of options for setting the geocoding API, key, and language, viewing the raw JSON response, and more. Please run `geocode -h` for details. -Notes on ActiveRecord ---------------------- - -In MySQL and Postgres, queries use a bounding box to limit the number of points over which a more precise distance calculation needs to be done. To take advantage of this optimisation, you need to add a composite index on latitude and longitude. In your Rails migration: - - add_index :table, [:latitude, :longitude] - - -Notes on MongoDB ----------------- - -### The Near Method - -Mongo document classes (Mongoid and MongoMapper) have a built-in `near` scope, but since it only works two-dimensions Geocoder overrides it with its own spherical `near` method in geocoded classes. - -### Latitude/Longitude Order - -Coordinates are generally printed and spoken as latitude, then longitude ([lat,lon]). Geocoder respects this convention and always expects method arguments to be given in [lat,lon] order. However, MongoDB requires that coordinates be stored in [lon,lat] order as per the GeoJSON spec (http://geojson.org/geojson-spec.html#positions), so internally they are stored "backwards." However, this does not affect order of arguments to methods when using Mongoid or MongoMapper. - -To access an object's coordinates in the conventional order, use the `to_coordinates` instance method provided by Geocoder. For example: - - obj.to_coordinates # => [37.7941013, -122.3951096] # [lat, lon] - -Calling `obj.coordinates` directly returns the internal representation of the coordinates which, in the case of MongoDB, is probably the reverse of what you want: - - obj.coordinates # => [-122.3951096, 37.7941013] # [lon, lat] - -For consistency with the rest of Geocoder, always use the `to_coordinates` method instead. - - Technical Discussions --------------------- @@ -1300,4 +1267,4 @@ For all contributions, please respect the following guidelines: * If your pull request is merged, please do not ask for an immediate release of the gem. There are many factors contributing to when releases occur (remember that they affect thousands of apps with Geocoder in their Gemfiles). If necessary, please install from the Github source until the next official release. -Copyright (c) 2009-15 Alex Reisner, released under the MIT license +Copyright (c) 2009-18 Alex Reisner, released under the MIT license. From f904c5a95462b4dafd9bad1808b33da35a0589aa Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 15 Jun 2018 11:46:36 -0600 Subject: [PATCH 061/248] Add README header for local IP address services. --- README.md | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index a97778c38..68dc145a9 100644 --- a/README.md +++ b/README.md @@ -36,34 +36,35 @@ Table of Contents Basic Features: -1. [Geocoding Objects](#geocoding-objects) -2. [Geocoding HTTP Requests](#geocoding-http-requests) -3. [Geographic Database Queries](#geographic-database-queries) -4. [Model Configuration](#model-configuration) -5. [Geocoding Service ("Lookup") Configuration](#geocoding-service-lookup-configuration) +* [Geocoding Objects](#geocoding-objects) +* [Geocoding HTTP Requests](#geocoding-http-requests) +* [Geographic Database Queries](#geographic-database-queries) +* [Model Configuration](#model-configuration) +* [Geocoding Service ("Lookup") Configuration](#geocoding-service-lookup-configuration) API Guide: -6. [Street Address Lookups](#api-guide-street-address-lookups) -7. [IP Address Lookups](#api-guide-ip-address-lookups) +* [Street Address Lookups](#api-guide-street-address-lookups) +* [IP Address Lookups](#api-guide-ip-address-lookups) +* [Local IP Address Lookups](#api-guide-local-ip-address-lookups) Advanced Features: -8. [Performance and Optimization](#performance-and-optimization) -9. [Advanced Geocoding](#advanced-geocoding) -10. [Advanced Database Queries](#advanced-database-queries) -11. [Testing](#testing) -12. [Error Handling](#error-handing) -13. [Use Outside of Rails](#use-outside-of-rails) -14. [Command Line Interface](#command-line-interface) +* [Performance and Optimization](#performance-and-optimization) +* [Advanced Geocoding](#advanced-geocoding) +* [Advanced Database Queries](#advanced-database-queries) +* [Testing](#testing) +* [Error Handling](#error-handing) +* [Use Outside of Rails](#use-outside-of-rails) +* [Command Line Interface](#command-line-interface) The Rest: -15. [Technical Discussions](#technical-discussions) -16. [Troubleshooting](#troubleshooting) -17. [Known Issues](#known-issues) -18. [Reporting Issues](#reporting-issues) -19. [Contributing](#contributing) +* [Technical Discussions](#technical-discussions) +* [Troubleshooting](#troubleshooting) +* [Known Issues](#known-issues) +* [Reporting Issues](#reporting-issues) +* [Contributing](#contributing) Geocoding Objects @@ -793,7 +794,8 @@ API Guide: IP Address Lookups * **Limitations**: ? -### IP Address Local Database Services +API Guide: Local IP Address Lookups +----------------------------------- ### MaxMind Local (`:maxmind_local`) - EXPERIMENTAL From 35dd48d712b47dee49940a9aee2542739a5944c7 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 15 Jun 2018 14:01:07 -0600 Subject: [PATCH 062/248] Remove byebug from Gemfiles. --- Gemfile | 2 -- gemfiles/Gemfile.rails3.2 | 2 -- gemfiles/Gemfile.rails4.1 | 2 -- gemfiles/Gemfile.rails5.0 | 2 -- 4 files changed, 8 deletions(-) diff --git a/Gemfile b/Gemfile index b52115ad5..d514f4bee 100644 --- a/Gemfile +++ b/Gemfile @@ -9,8 +9,6 @@ group :development, :test do gem 'rails' gem 'test-unit' # needed for Ruby >=2.2.0 - gem 'byebug', platforms: :mri - platforms :jruby do gem 'jruby-openssl' gem 'jgeoip' diff --git a/gemfiles/Gemfile.rails3.2 b/gemfiles/Gemfile.rails3.2 index 0fd65abe4..31cceacd0 100644 --- a/gemfiles/Gemfile.rails3.2 +++ b/gemfiles/Gemfile.rails3.2 @@ -9,8 +9,6 @@ group :development, :test do gem 'rails', '>= 3.2' gem 'test-unit' # needed for Ruby >=2.2.0 - gem 'byebug', '9.0.6', platforms: :mri - platforms :jruby do gem 'jruby-openssl' gem 'jgeoip' diff --git a/gemfiles/Gemfile.rails4.1 b/gemfiles/Gemfile.rails4.1 index 5e5005937..9398b2697 100644 --- a/gemfiles/Gemfile.rails4.1 +++ b/gemfiles/Gemfile.rails4.1 @@ -9,8 +9,6 @@ group :development, :test do gem 'rails', '~> 4.1.13' gem 'test-unit' # needed for Ruby >=2.2.0 - gem 'byebug', '9.0.6', platforms: :mri - platforms :jruby do gem 'jruby-openssl' gem 'jgeoip' diff --git a/gemfiles/Gemfile.rails5.0 b/gemfiles/Gemfile.rails5.0 index 21370903a..2f127393f 100644 --- a/gemfiles/Gemfile.rails5.0 +++ b/gemfiles/Gemfile.rails5.0 @@ -9,8 +9,6 @@ group :development, :test do gem 'rails', '~> 5.0.1' gem 'test-unit' # needed for Ruby >=2.2.0 - gem 'byebug', platforms: :mri - platforms :jruby do gem 'jruby-openssl' gem 'jgeoip' From 66647c06854d1e3e269b35fc76ddd58bb55bbe3c Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 15 Jun 2018 16:10:03 -0600 Subject: [PATCH 063/248] Don't use main Gemfile w/ Ruby 2.0 or 2.1. --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index bd126ce7e..55271c151 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,10 +43,14 @@ matrix: gemfile: gemfiles/Gemfile.rails4.1 - env: DB= gemfile: gemfiles/Gemfile.rails5.0 + - rvm: 2.0.0 + gemfile: Gemfile - rvm: 2.0.0 gemfile: gemfiles/Gemfile.ruby1.9.3 - rvm: 2.0.0 gemfile: gemfiles/Gemfile.rails5.0 + - rvm: 2.1.2 + gemfile: Gemfile - rvm: 2.1.2 gemfile: gemfiles/Gemfile.ruby1.9.3 - rvm: 2.1.2 From e02340342261b5859cfa59e4df67ce5f54d22d0c Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 15 Jun 2018 16:14:45 -0600 Subject: [PATCH 064/248] Upgrade Travis Rubies to latest patch releases. --- .travis.yml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 55271c151..2059c8449 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,11 +12,11 @@ env: rvm: - 1.9.3 - 2.0.0 - - 2.1.2 - - 2.2.2 - - 2.3.0 - - 2.4.3 - - 2.5.0 + - 2.1.10 + - 2.2.10 + - 2.3.7 + - 2.4.4 + - 2.5.1 - jruby-19mode gemfile: - Gemfile @@ -49,29 +49,29 @@ matrix: gemfile: gemfiles/Gemfile.ruby1.9.3 - rvm: 2.0.0 gemfile: gemfiles/Gemfile.rails5.0 - - rvm: 2.1.2 + - rvm: 2.1.10 gemfile: Gemfile - - rvm: 2.1.2 + - rvm: 2.1.10 gemfile: gemfiles/Gemfile.ruby1.9.3 - rvm: 2.1.2 gemfile: gemfiles/Gemfile.rails5.0 - - rvm: 2.2.2 + - rvm: 2.2.10 gemfile: gemfiles/Gemfile.ruby1.9.3 - rvm: jruby-19mode gemfile: gemfiles/Gemfile.ruby1.9.3 - - rvm: 2.3.0 + - rvm: 2.3.7 gemfile: gemfiles/Gemfile.ruby1.9.3 - - rvm: 2.4.3 + - rvm: 2.4.4 gemfile: gemfiles/Gemfile.rails4.1 - - rvm: 2.5.0 + - rvm: 2.5.1 gemfile: gemfiles/Gemfile.rails4.1 - - rvm: 2.4.3 + - rvm: 2.4.4 gemfile: gemfiles/Gemfile.ruby1.9.3 - - rvm: 2.5.0 + - rvm: 2.5.1 gemfile: gemfiles/Gemfile.ruby1.9.3 - - rvm: 2.4.3 + - rvm: 2.4.4 gemfile: gemfiles/Gemfile.rails3.2 - - rvm: 2.5.0 + - rvm: 2.5.1 gemfile: gemfiles/Gemfile.rails3.2 - rvm: jruby-19mode gemfile: gemfiles/Gemfile.rails5.0 From 006cb5f4ac7b1b664104a9ac5dde70055ea70dd3 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 15 Jun 2018 17:05:01 -0600 Subject: [PATCH 065/248] Fix line missed by last commit. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2059c8449..fe90d5e34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,7 +53,7 @@ matrix: gemfile: Gemfile - rvm: 2.1.10 gemfile: gemfiles/Gemfile.ruby1.9.3 - - rvm: 2.1.2 + - rvm: 2.1.10 gemfile: gemfiles/Gemfile.rails5.0 - rvm: 2.2.10 gemfile: gemfiles/Gemfile.ruby1.9.3 From 7b0f37a98f2453533b529e7eaa6b638d05c8bd7d Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 15 Jun 2018 17:46:53 -0600 Subject: [PATCH 066/248] Truncate Mapbox query at semicolon. Fixes #1299. --- lib/geocoder/lookups/mapbox.rb | 4 +++- test/unit/lookups/mapbox_test.rb | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/mapbox.rb b/lib/geocoder/lookups/mapbox.rb index 36b11b018..9a8267575 100644 --- a/lib/geocoder/lookups/mapbox.rb +++ b/lib/geocoder/lookups/mapbox.rb @@ -36,7 +36,9 @@ def mapbox_search_term(query) lat,lon = query.coordinates "#{CGI.escape lon},#{CGI.escape lat}" else - CGI.escape query.text.to_s + # truncate at first semicolon so Mapbox doesn't go into batch mode + # (see Github issue #1299) + CGI.escape query.text.to_s.split(';').first.to_s end end diff --git a/test/unit/lookups/mapbox_test.rb b/test/unit/lookups/mapbox_test.rb index 5976442ef..e283bbf8c 100644 --- a/test/unit/lookups/mapbox_test.rb +++ b/test/unit/lookups/mapbox_test.rb @@ -44,4 +44,9 @@ def test_raises_exception_with_invalid_api_key Geocoder.search("invalid api key") end end + + def test_truncates_query_at_semicolon + result = Geocoder.search("Madison Square Garden, New York, NY;123 Another St").first + assert_equal [40.749688, -73.991566], result.coordinates + end end From 5398e9679e26389f1d165d50e74e9c7e07c6a800 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 16 Jun 2018 12:21:39 -0600 Subject: [PATCH 067/248] More README restructuring and cleanup. --- README.md | 297 ++++++++++++++++++++++++------------------------------ 1 file changed, 134 insertions(+), 163 deletions(-) diff --git a/README.md b/README.md index 68dc145a9..79b4eeb9f 100644 --- a/README.md +++ b/README.md @@ -37,9 +37,8 @@ Table of Contents Basic Features: * [Geocoding Objects](#geocoding-objects) +* [Geospatial Database Queries](#geospatial-database-queries) * [Geocoding HTTP Requests](#geocoding-http-requests) -* [Geographic Database Queries](#geographic-database-queries) -* [Model Configuration](#model-configuration) * [Geocoding Service ("Lookup") Configuration](#geocoding-service-lookup-configuration) API Guide: @@ -50,6 +49,7 @@ API Guide: Advanced Features: +* [Model Configuration](#model-configuration) * [Performance and Optimization](#performance-and-optimization) * [Advanced Geocoding](#advanced-geocoding) * [Advanced Database Queries](#advanced-database-queries) @@ -70,115 +70,81 @@ The Rest: Geocoding Objects ----------------- -### ActiveRecord - -Your model must have two attributes (database columns) for storing latitude and longitude coordinates. By default they should be called `latitude` and `longitude` but this can be changed (see [Model Configuration](#model-configuration) below. - -For geocoding, your model must provide a method that returns an address. This can be a single attribute, but it can also be a method that returns a string assembled from different attributes (eg: `city`, `state`, and `country`). For example, if your model has `street`, `city`, `state`, and `country` attributes you might do something like this: +To geocode your objects: - geocoded_by :address +1. Your model must provide a method that returns an address to geocode. This can be a single attribute, but it can also be a method that returns a string assembled from different attributes (eg: `city`, `state`, and `country`). For example, if your model has `street`, `city`, `state`, and `country` attributes you might do something like this: def address [street, city, state, country].compact.join(', ') end -Next, your model must tell Geocoder which method returns your object's geocodable address: - - geocoded_by :address # can also be an IP address - after_validation :geocode # auto-fetch coordinates - -For reverse geocoding, tell Geocoder which attributes store latitude and longitude: - - reverse_geocoded_by :latitude, :longitude - after_validation :reverse_geocode # auto-fetch address - -### Mongoid +2. Your model must have a way to store latitude/longitude coordinates. With ActiveRecord, add two attributes/columns (of type float or decimal) called `latitude` and `longitude`. For MongoDB, use a single field (of type Array) called `coordinates` (`field :coordinates, type: Array`). (See [Model Configuration](#model-configuration) for using different attribute names.) -First, your model must have an array field for storing coordinates: +3. In your model, tell geocoder where to find the object's address: - field :coordinates, :type => Array + geocoded_by :address -You may also want an address field, like this: +This adds a `geocode` method which you can invoke via callback: - field :address + after_validation :geocode -but if you store address components (city, state, country, etc) in separate fields you can instead define a method called `address` that combines them into a single string which will be used to query the geocoding service. +Reverse geocoding (given lat/lon coordinates, find an address) is similar: -Once your fields are defined, include the `Geocoder::Model::Mongoid` module and then call `geocoded_by`: + reverse_geocoded_by :latitude, :longitude + after_validation :reverse_geocode - include Geocoder::Model::Mongoid - geocoded_by :address # can also be an IP address - after_validation :geocode # auto-fetch coordinates +### One More Thing for MongoDB! -Reverse geocoding is similar: +Before you can call `geocoded_by` you'll need to include the necessary module using one of the following: include Geocoder::Model::Mongoid - reverse_geocoded_by :coordinates - after_validation :reverse_geocode # auto-fetch address + include Geocoder::Model::MongoMapper -Once you've set up your model you'll need to create the necessary spatial indices in your database: +You'll also need to create spatial indices: rake db:mongoid:create_indexes -### MongoMapper - -MongoMapper is very similar to Mongoid, just be sure to include `Geocoder::Model::MongoMapper`. - ### Latitude/Longitude Order in MongoDB -Coordinates are generally printed and spoken as latitude, then longitude ([lat,lon]). Geocoder respects this convention and always expects method arguments to be given in [lat,lon] order. However, MongoDB requires that coordinates be stored in [lon,lat] order as per the GeoJSON spec (http://geojson.org/geojson-spec.html#positions), so internally they are stored "backwards." However, this does not affect order of arguments to methods when using Mongoid or MongoMapper. - -To access an object's coordinates in the conventional order, use the `to_coordinates` instance method provided by Geocoder. For example: +Everywhere coordinates are passed to methods as two-element arrays, Geocoder expects them to be in the order: `[lat, lon]`. However, as per [the GeoJSON spec](http://geojson.org/geojson-spec.html#positions), MongoDB requires that coordinates be stored longitude-first (`[lon, lat]`), so internally they are stored "backwards." Geocoder's methods attempt to hide this, so calling `obj.to_coordinates` (a method added to the object by Geocoder via `geocoded_by`) returns coordinates in the conventional order: obj.to_coordinates # => [37.7941013, -122.3951096] # [lat, lon] -Calling `obj.coordinates` directly returns the internal representation of the coordinates which, in the case of MongoDB, is probably the reverse of what you want: +whereas calling the object's coordinates attribute directly (`obj.coordinates` by default) returns the internal representation which is probably the reverse of what you want: obj.coordinates # => [-122.3951096, 37.7941013] # [lon, lat] +So, you know, be careful. -Geocoding HTTP Requests ------------------------ - -Geocoder adds `location` and `safe_location` methods to the standard `Rack::Request` object so you can easily look up the location of any HTTP request by IP address. For example, in a Rails controller or a Sinatra app: - - # returns Geocoder::Result object - result = request.location - -**The `location` method is vulnerable to trivial IP address spoofing via HTTP headers.** If that's a problem for your application, use `safe_location` instead, but be aware that `safe_location` will *not* try to trace a request's originating IP through proxy headers; you will instead get the location of the last proxy the request passed through, if any (excepting any proxies you have explicitly whitelisted in your Rack config). -Note that these methods will usually return `nil` in test and development environments because things like "localhost" and "0.0.0.0" are not geocodable IP addresses. - - -Geographic Database Queries +Geospatial Database Queries --------------------------- ### For ActiveRecord models: To find objects by location, use the following scopes: - Venue.near('Omaha, NE, US') # venues within 20 (default) miles of Omaha - Venue.near([40.71, -100.23], 50) # venues within 50 miles of a point - Venue.near([40.71, -100.23], 50, :units => :km) - # venues within 50 kilometres of a point - Venue.geocoded # venues with coordinates - Venue.not_geocoded # venues without coordinates + Venue.near('Omaha, NE, US') # venues within 20 miles of Omaha + Venue.near([40.71, -100.23], 50) # venues within 50 miles of a point + Venue.near([40.71, -100.23], 50, units: :km) # venues within 50 kilometres of a point + Venue.geocoded # venues with coordinates + Venue.not_geocoded # venues without coordinates by default, objects are ordered by distance. To remove the ORDER BY clause use the following: - Venue.near('Omaha', 20, :order => false) + Venue.near('Omaha', 20, order: false) With geocoded objects you can do things like this: if obj.geocoded? - obj.nearbys(30) # other objects within 30 miles - obj.distance_from([40.714,-100.234]) # distance from arbitrary point to object - obj.bearing_to("Paris, France") # direction from object to arbitrary point + obj.nearbys(30) # other objects within 30 miles + obj.distance_from([40.714,-100.234]) # distance from arbitrary point to object + obj.bearing_to("Paris, France") # direction from object to arbitrary point end Some utility methods are also available: - # look up coordinates of some location (like searching Google Maps) + # look up coordinates of some location Geocoder.coordinates("25 Main St, Cooperstown, NY") => [42.700149, -74.922767] @@ -192,23 +158,22 @@ Some utility methods are also available: Please see the code for more methods and detailed information about arguments (eg, working with kilometers). -### For Mongo-backed models: +### For MongoDB-backed models: -Please do not use Geocoder's `near` method. Instead use MongoDB's built-in [geospatial query language](https://docs.mongodb.org/manual/reference/command/geoNear/), which is faster. Mongoid also provides [a DSL](http://mongoid.github.io/en/mongoid/docs/querying.html#geo_near) for doing near queries. +Please do not use Geocoder's `near` method. Instead use MongoDB's built-in [geospatial query language](https://docs.mongodb.org/manual/reference/command/geoNear/), which is faster. Mongoid also provides [a DSL](http://mongoid.github.io/en/mongoid/docs/querying.html#geo_near) for geospatial queries. -Model Configuration -------------------- +Geocoding HTTP Requests +----------------------- -You are not stuck with the `latitude` and `longitude` database column names (with ActiveRecord) or the `coordinates` array (Mongo) for storing coordinates. For example: +Geocoder adds `location` and `safe_location` methods to the standard `Rack::Request` object so you can easily look up the location of any HTTP request by IP address. For example, in a Rails controller or a Sinatra app: - geocoded_by :address, :latitude => :lat, :longitude => :lon # ActiveRecord - geocoded_by :address, :coordinates => :coords # MongoDB + # returns Geocoder::Result object + result = request.location -For reverse geocoding, you can specify the attribute where the address will be stored. For example: +**The `location` method is vulnerable to trivial IP address spoofing via HTTP headers.** If that's a problem for your application, use `safe_location` instead, but be aware that `safe_location` will *not* try to trace a request's originating IP through proxy headers; you will instead get the location of the last proxy the request passed through, if any (excepting any proxies you have explicitly whitelisted in your Rack config). - reverse_geocoded_by :latitude, :longitude, :address => :location # ActiveRecord - reverse_geocoded_by :coordinates, :address => :loc # MongoDB +Note that these methods will usually return `nil` in test and development environments because things like "localhost" and "0.0.0.0" are not geocodable IP addresses. Geocoding Service ("Lookup") Configuration @@ -216,101 +181,75 @@ Geocoding Service ("Lookup") Configuration Geocoder supports a variety of street and IP address geocoding services. The default lookups are `:google` for street addresses and `:ipinfo_io` for IP addresses. Please see the [API Guide](#api-guide-street-address-services) for details on specific geocoding services (not all settings are supported by all services). -To create a Rails initializer with an example configuration: +To create a Rails initializer with sample configuration: rails generate geocoder:config -Some common configuration options are: +Some common options are: # config/initializers/geocoder.rb Geocoder.configure( # street address geocoding service (default :google) - :lookup => :yandex, + lookup: :yandex, # IP address geocoding service (default :ipinfo_io) - :ip_lookup => :maxmind, + ip_lookup: :maxmind, # to use an API key: - :api_key => "...", + api_key: "...", # geocoding service request timeout, in seconds (default 3): - :timeout => 5, + timeout: 5, # set default units to kilometers: - :units => :km, + units: :km, # caching (see [below](#caching) for details): - :cache => Redis.new, - :cache_prefix => "..." + cache: Redis.new, + cache_prefix: "..." ) -Please see [`lib/geocoder/configuration.rb`](https://github.com/alexreisner/geocoder/blob/master/lib/geocoder/configuration.rb) for a complete list of configuration options. Additionally, some lookups have their own configuration options, some of which are directly supported by Geocoder. For example, to specify a value for Google's `bounds` parameter: +Please see [`lib/geocoder/configuration.rb`](https://github.com/alexreisner/geocoder/blob/master/lib/geocoder/configuration.rb) for a complete list of configuration options. Additionally, some lookups have their own special configuration options which are directly supported by Geocoder. For example, to specify a value for Google's `bounds` parameter: # with Google: - Geocoder.search("Paris", :bounds => [[32.1,-95.9], [33.9,-94.3]]) - -Please see the [source code for each lookup](https://github.com/alexreisner/geocoder/tree/master/lib/geocoder/lookups) to learn about directly supported parameters. Parameters which are not directly supported can be specified using the `:params` option, by which you can pass arbitrary parameters to any geocoding service. For example, to use Nominatim's `countrycodes` parameter: - - # with Nominatim: - Geocoder.search("Paris", :params => {:countrycodes => "gb,de,fr,es,us"}) + Geocoder.search("Paris", bounds: [[32.1,-95.9], [33.9,-94.3]]) -Or, to search within a particular region with Google: +Please see the [source code for each lookup](https://github.com/alexreisner/geocoder/tree/master/lib/geocoder/lookups) to learn about directly supported parameters. Parameters which are not directly supported can be specified using the `:params` option, which appends options to the query string of the geocoding request. For example: - Geocoder.search("...", :params => {:region => "..."}) + # Nominatim's `countrycodes` parameter: + Geocoder.search("Paris", params: {countrycodes: "gb,de,fr,es,us"}) -To specify parameters in your model: - - class Venue - - # build an address from street, city, and state attributes - geocoded_by :address_from_components, :params => {:region => "..."} - - # store the fetched address in the full_address attribute - reverse_geocoded_by :latitude, :longitude, :address => :full_address, :params => {:region => "..."} - end - -Finally, you can specify a proc if you want to choose a lookup based on a specific property of an object. For example, you can use specialized lookups for different regions: - - geocoded_by :address, :lookup => lambda{ |obj| obj.geocoder_lookup } - - def geocoder_lookup - if country_code == "RU" - :yandex - elsif country_code == "CN" - :baidu - else - :google - end - end + # Google's `region` parameter: + Geocoder.search("Paris", params: {region: "..."}) ### Configuring Multiple Services -You can configure multiple geocoding services at once, like this: +You can configure multiple geocoding services at once by using the service's name as a key for a sub-configuration hash, like this: Geocoder.configure( - :timeout => 2, - :cache => Redis.new, + timeout: 2, + cache: Redis.new, - :yandex => { - :api_key => "...", - :timeout => 5 + yandex: { + api_key: "...", + timeout: 5 }, - :baidu => { - :api_key => "..." + baidu: { + api_key: "..." }, - :maxmind => { - :api_key => "...", - :service => :omni + maxmind: { + api_key: "...", + service: :omni } ) -The above example combines global and service-specific options. Lookup-specific settings override global settings, so the timeout for all lookups would be 2 seconds, except for Yandex which would be 5. +Lookup-specific settings override global settings so, in this example, the timeout for all lookups is 2 seconds, except for Yandex which is 5. API Guide: Street Address Lookups @@ -320,7 +259,7 @@ The following is a listing of the supported geocoding APIs. The "Limitations" li ### Google (`:google`) -* **API key**: optional, but quota is higher if key is used (use of key requires HTTPS so be sure to set: `:use_https => true` in `Geocoder.configure`) +* **API key**: optional, but quota is higher if key is used (use of key requires HTTPS so be sure to set: `use_https: true` in `Geocoder.configure`) * **Key signup**: https://console.developers.google.com/flows/enableapi?apiid=geocoding_backend&keyType=SERVER_SIDE * **Quota**: 2,500 requests/24 hrs, 5 requests/second * **Region**: world @@ -337,7 +276,7 @@ The following is a listing of the supported geocoding APIs. The "Limitations" li Similar to `:google`, with the following differences: -* **API key**: required, plus client and channel (set `Geocoder.configure(:lookup => :google_premier, :api_key => [key, client, channel])`) +* **API key**: required, plus client and channel (set `Geocoder.configure(lookup: :google_premier, api_key: [key, client, channel])`) * **Key signup**: https://developers.google.com/maps/documentation/business/ * **Quota**: 100,000 requests/24 hrs, 10 requests/second @@ -363,7 +302,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ ### Bing (`:bing`) -* **API key**: required (set `Geocoder.configure(:lookup => :bing, :api_key => key)`) +* **API key**: required (set `Geocoder.configure(lookup: :bing, api_key: key)`) * **Key signup**: https://www.microsoft.com/maps/create-a-bing-maps-key.aspx * **Quota**: 50,0000 requests/day (Windows app), 125,000 requests/year (non-Windows app) * **Region**: world @@ -382,7 +321,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Languages**: ? * **Documentation**: http://wiki.openstreetmap.org/wiki/Nominatim * **Terms of Service**: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy -* **Limitations**: Please limit request rate to 1 per second and include your contact information in User-Agent headers (eg: `Geocoder.configure(:http_headers => { "User-Agent" => "your contact info" })`). [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) +* **Limitations**: Please limit request rate to 1 per second and include your contact information in User-Agent headers (eg: `Geocoder.configure(http_headers: { "User-Agent" => "your contact info" })`). [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) ### PickPoint (`:pickpoint`) @@ -443,7 +382,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ ### Mapbox (`:mapbox`) * **API key**: required -* **Dataset**: Uses `mapbox.places` dataset by default. Specify the `mapbox.places-permanent` dataset by setting: `Geocoder.configure(:mapbox => {:dataset => "mapbox.places-permanent"})` +* **Dataset**: Uses `mapbox.places` dataset by default. Specify the `mapbox.places-permanent` dataset by setting: `Geocoder.configure(mapbox: {dataset: "mapbox.places-permanent"})` * **Key signup**: https://www.mapbox.com/pricing/ * **Quota**: depends on plan * **Region**: complete coverage of US and Canada, partial coverage elsewhere (see for details: https://www.mapbox.com/developers/api/geocoding/#coverage) @@ -466,14 +405,14 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Key signup**: https://developer.mapquest.com/plans * **Quota**: ? * **HTTP Headers**: when using the licensed API you can specify a referer like so: - `Geocoder.configure(:http_headers => { "Referer" => "http://foo.com" })` + `Geocoder.configure(http_headers: { "Referer" => "http://foo.com" })` * **Region**: world * **SSL support**: no * **Languages**: English * **Documentation**: http://www.mapquestapi.com/geocoding/ * **Terms of Service**: http://info.mapquest.com/terms-of-use/ * **Limitations**: ? -* **Notes**: You can use the open (non-licensed) API by setting: `Geocoder.configure(:mapquest => {:open => true})` (defaults to licensed version) +* **Notes**: You can use the open (non-licensed) API by setting: `Geocoder.configure(mapquest: {open: true})` (defaults to licensed version) ### Ovi/Nokia (`:ovi`) @@ -488,7 +427,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ ### Here/Nokia (`:here`) -* **API key**: required (set `Geocoder.configure(:api_key => [app_id, app_code])`) +* **API key**: required (set `Geocoder.configure(api_key: [app_id, app_code])`) * **Quota**: Depending on the API key * **Region**: world * **SSL support**: yes @@ -499,7 +438,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ ### ESRI (`:esri`) -* **API key**: optional (set `Geocoder.configure(:esri => {:api_key => ["client_id", "client_secret"]})`) +* **API key**: optional (set `Geocoder.configure(esri: {api_key: ["client_id", "client_secret"]})`) * **Quota**: Required for some scenarios (see Terms of Service) * **Region**: world * **SSL support**: yes @@ -507,7 +446,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Documentation**: https://developers.arcgis.com/rest/geocode/api-reference/overview-world-geocoding-service.htm * **Terms of Service**: http://www.esri.com/legal/software-license * **Limitations**: Requires API key if results will be stored. Using API key will also remove rate limit. -* **Notes**: You can specify which projection you want to use by setting, for example: `Geocoder.configure(:esri => {:outSR => 102100})`. If you will store results, set the flag and provide API key: `Geocoder.configure(:esri => {:api_key => ["client_id", "client_secret"], :for_storage => true})`. If you want to, you can also supply an ESRI token directly: `Geocoder.configure(:esri => {:token => Geocoder::EsriToken.new('TOKEN', Time.now + 1.day})` +* **Notes**: You can specify which projection you want to use by setting, for example: `Geocoder.configure(esri: {outSR: 102100})`. If you will store results, set the flag and provide API key: `Geocoder.configure(esri: {api_key: ["client_id", "client_secret"], for_storage: true})`. If you want to, you can also supply an ESRI token directly: `Geocoder.configure(esri: {token: Geocoder::EsriToken.new('TOKEN', Time.now + 1.day})` ### Mapzen (`:mapzen`) @@ -531,7 +470,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Documentation**: http://pelias.io/ * **Terms of Service**: http://pelias.io/data_licenses.html * **Limitations**: See terms -* **Notes**: Configure your self-hosted pelias with the `endpoint` option: `Geocoder.configure(:lookup => :pelias, :api_key => 'your_api_key', :pelias => {:endpoint => 'self.hosted/pelias'})`. Defaults to `localhost`. +* **Notes**: Configure your self-hosted pelias with the `endpoint` option: `Geocoder.configure(lookup: :pelias, api_key: 'your_api_key', pelias: {endpoint: 'self.hosted/pelias'})`. Defaults to `localhost`. ### Data Science Toolkit (`:dstk`) @@ -545,7 +484,7 @@ Data Science Toolkit provides an API whose response format is like Google's but * **Documentation**: http://www.datasciencetoolkit.org/developerdocs * **Terms of Service**: http://www.datasciencetoolkit.org/developerdocs#googlestylegeocoder * **Limitations**: No reverse geocoding. -* **Notes**: If you are hosting your own DSTK server you will need to configure the host name, eg: `Geocoder.configure(:lookup => :dstk, :dstk => {:host => "localhost:4567"})`. +* **Notes**: If you are hosting your own DSTK server you will need to configure the host name, eg: `Geocoder.configure(lookup: :dstk, dstk: {host: "localhost:4567"})`. ### Baidu (`:baidu`) @@ -557,7 +496,7 @@ Data Science Toolkit provides an API whose response format is like Google's but * **Documentation**: http://developer.baidu.com/map/webservice-geocoding.htm * **Terms of Service**: http://developer.baidu.com/map/law.htm * **Limitations**: Only good for non-commercial use. For commercial usage please check http://developer.baidu.com/map/question.htm#qa0013 -* **Notes**: To use Baidu set `Geocoder.configure(:lookup => :baidu, :api_key => "your_api_key")`. +* **Notes**: To use Baidu set `Geocoder.configure(lookup: :baidu, api_key: "your_api_key")`. ### Geocodio (`:geocodio`) @@ -572,7 +511,7 @@ Data Science Toolkit provides an API whose response format is like Google's but ### SmartyStreets (`:smarty_streets`) -* **API key**: requires auth_id and auth_token (set `Geocoder.configure(:api_key => [id, token])`) +* **API key**: requires auth_id and auth_token (set `Geocoder.configure(api_key: [id, token])`) * **Quota**: 250/month then purchase at sliding scale. * **Region**: US * **SSL support**: yes (required) @@ -627,7 +566,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string * **Documentation**: http://www.postcodeanywhere.co.uk/Support/WebService/Geocoding/UK/Geocode/2/ * **Terms of Service**: ? * **Limitations**: ? -* **Notes**: To use PostcodeAnywhere you must include an API key: `Geocoder.configure(:lookup => :postcode_anywhere_uk, :api_key => 'your_api_key')`. +* **Notes**: To use PostcodeAnywhere you must include an API key: `Geocoder.configure(lookup: :postcode_anywhere_uk, api_key: 'your_api_key')`. ### LatLon.io (`:latlon`) @@ -661,7 +600,7 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string - **Documentation**: http://lbs.amap.com/api/webservice/guide/api/georegeo - **Terms of Service**: http://lbs.amap.com/home/terms/ - **Limitations**: Only good for non-commercial use. For commercial usage please check http://lbs.amap.com/home/terms/ -- **Notes**: To use AMap set `Geocoder.configure(:lookup => :amap, :api_key => "your_api_key")`. +- **Notes**: To use AMap set `Geocoder.configure(lookup: :amap, api_key: "your_api_key")`. API Guide: IP Address Lookups @@ -699,7 +638,7 @@ API Guide: IP Address Lookups * **Documentation**: https://pointp.in/docs/get-started * **Terms of Service**: https://pointp.in/terms * **Limitations**: ? -* **Notes**: To use Pointpin set `Geocoder.configure(:ip_lookup => :pointpin, :api_key => "your_pointpin_api_key")`. +* **Notes**: To use Pointpin set `Geocoder.configure(ip_lookup: :pointpin, api_key: "your_pointpin_api_key")`. ### Telize (`:telize`) @@ -711,7 +650,7 @@ API Guide: IP Address Lookups * **Documentation**: https://market.mashape.com/fcambus/telize * **Terms of Service**: ? * **Limitations**: ? -* **Notes**: To use Telize set `Geocoder.configure(:ip_lookup => :telize, :api_key => "your_api_key")`. Or configure your self-hosted telize with the `host` option: `Geocoder.configure(:ip_lookup => :telize, :telize => {:host => "localhost"})`. +* **Notes**: To use Telize set `Geocoder.configure(ip_lookup: :telize, api_key: "your_api_key")`. Or configure your self-hosted telize with the `host` option: `Geocoder.configure(ip_lookup: :telize, telize: {host: "localhost"})`. ### MaxMind Legacy Web Services (`:maxmind`) @@ -724,7 +663,7 @@ API Guide: IP Address Lookups * **Documentation**: http://dev.maxmind.com/geoip/legacy/web-services/ * **Terms of Service**: ? * **Limitations**: ? -* **Notes**: You must specify which MaxMind service you are using in your configuration. For example: `Geocoder.configure(:maxmind => {:service => :omni})`. +* **Notes**: You must specify which MaxMind service you are using in your configuration. For example: `Geocoder.configure(maxmind: {service: :omni})`. ### Baidu IP (`:baidu_ip`) @@ -736,7 +675,7 @@ API Guide: IP Address Lookups * **Documentation**: http://developer.baidu.com/map/webservice-geocoding.htm * **Terms of Service**: http://developer.baidu.com/map/law.htm * **Limitations**: Only good for non-commercial use. For commercial usage please check http://developer.baidu.com/map/question.htm#qa0013 -* **Notes**: To use Baidu set `Geocoder.configure(:lookup => :baidu_ip, :api_key => "your_api_key")`. +* **Notes**: To use Baidu set `Geocoder.configure(lookup: :baidu_ip, api_key: "your_api_key")`. ### MaxMind GeoIP2 Precision Web Services (`:maxmind_geoip2`) @@ -748,7 +687,7 @@ API Guide: IP Address Lookups * **Documentation**: http://dev.maxmind.com/geoip/geoip2/web-services/ * **Terms of Service**: ? * **Limitations**: ? -* **Notes**: You must specify which MaxMind service you are using in your configuration, and also basic authentication. For example: `Geocoder.configure(:maxmind_geoip2 => {:service => :country, :basic_auth => {:user => '', :password => ''}})`. +* **Notes**: You must specify which MaxMind service you are using in your configuration, and also basic authentication. For example: `Geocoder.configure(maxmind_geoip2: {service: :country, basic_auth: {user: '', password: ''}})`. ### Ipstack (`:ipstack`) @@ -760,7 +699,7 @@ API Guide: IP Address Lookups * **Documentation**: https://ipstack.com/documentation * **Terms of Service**: ? * **Limitations**: ? -* **Notes**: To use Ipstack set `Geocoder.configure(:ip_lookup => :ipstack, :api_key => "your_ipstack_api_key")`. Supports the optional params: `:hostname`, `:security`, `:fields`, `:language` (see API documentation for details). +* **Notes**: To use Ipstack set `Geocoder.configure(ip_lookup: :ipstack, api_key: "your_ipstack_api_key")`. Supports the optional params: `:hostname`, `:security`, `:fields`, `:language` (see API documentation for details). ### IP-API.com (`:ipapi_com`) @@ -861,6 +800,38 @@ You must add either the *[hive_geoip2](https://rubygems.org/gems/hive_geoip2)* g ) +Model Configuration +------------------- + +You are not stuck with the `latitude` and `longitude` database column names (with ActiveRecord) or the `coordinates` array (Mongo) for storing coordinates. For example: + + geocoded_by :address, latitude: :lat, longitude: :lon # ActiveRecord + geocoded_by :address, coordinates: :coords # MongoDB + +For reverse geocoding, you can specify the attribute where the address will be stored. For example: + + reverse_geocoded_by :latitude, :longitude, address: :loc # ActiveRecord + reverse_geocoded_by :coordinates, address: :street_address # MongoDB + +To specify geocoding parameters in your model: + + geocoded_by :address, params: {region: "..."} + +Supported parameters: `:lookup`, `:ip_lookup`, `:language`, and `:params`. You can specify an anonymous function if you want to set these on a per-request basis. For example, to use different lookups for objects in different regions: + + geocoded_by :address, lookup: lambda{ |obj| obj.geocoder_lookup } + + def geocoder_lookup + if country_code == "RU" + :yandex + elsif country_code == "CN" + :baidu + else + :google + end + end + + Performance and Optimization ---------------------------- @@ -873,7 +844,7 @@ In MySQL and Postgres, queries use a bounding box to limit the number of points In MongoDB, by default, the methods `geocoded_by` and `reverse_geocoded_by` create a geospatial index. You can avoid index creation with the `:skip_index option`, for example: include Geocoder::Model::Mongoid - geocoded_by :address, :skip_index => true + geocoded_by :address, skip_index: true ### Avoiding Unnecessary API Requests @@ -890,7 +861,7 @@ The exact code will vary depending on the method you use for your geocodable str When relying on any external service, it's always a good idea to cache retrieved data. When implemented correctly, it improves your app's response time and stability. It's easy to cache geocoding results with Geocoder -- just configure a cache store: - Geocoder.configure(:cache => Redis.new) + Geocoder.configure(cache: Redis.new) This example uses Redis, but the cache store can be any object that supports these methods: @@ -903,7 +874,7 @@ Even a plain Ruby hash will work, though it's not a great choice (cleared out wh You can also set a custom prefix to be used for cache keys: - Geocoder.configure(:cache_prefix => "...") + Geocoder.configure(cache_prefix: "...") By default the prefix is `geocoder:` @@ -967,15 +938,15 @@ For example: geocoded_by :address_from_components # store the fetched address in the full_address attribute - reverse_geocoded_by :latitude, :longitude, :address => :full_address + reverse_geocoded_by :latitude, :longitude, address: :full_address end However, for purposes of querying the database, there can be only one authoritative set of latitude/longitude attributes, and whichever you specify last will be used. For example, here the `:fetched_` attributes will not be the ones used in database queries: class Venue geocoded_by :address, - :latitude => :fetched_latitude, - :longitude => :fetched_longitude + latitude: :fetched_latitude, + longitude: :fetched_longitude reverse_geocoded_by :latitude, :longitude end @@ -1010,7 +981,7 @@ When querying for objects (if you're using ActiveRecord) you can also look withi Note, however, that returned results will not include `distance` and `bearing` attributes. You can also specify a minimum radius (if you're using ActiveRecord and not Sqlite) to constrain the lower bound (ie. think of a donut, or ring) by using the `:min_radius` option: - box = Geocoder::Calculations.bounding_box(center_point, distance, :min_radius => 10.5) + box = Geocoder::Calculations.bounding_box(center_point, distance, min_radius: 10.5) With ActiveRecord, you can specify alternate latitude and longitude column names for a geocoded model (useful if you store multiple sets of coordinates for each object): @@ -1054,7 +1025,7 @@ Testing When writing tests for an app that uses Geocoder it may be useful to avoid network calls and have Geocoder return consistent, configurable results. To do this, configure and use the `:test` lookup. For example: - Geocoder.configure(:lookup => :test) + Geocoder.configure(lookup: :test) Geocoder::Lookup::Test.add_stub( "New York, NY", [ @@ -1071,7 +1042,7 @@ When writing tests for an app that uses Geocoder it may be useful to avoid netwo Now, any time Geocoder looks up "New York, NY" its results array will contain one result with the above attributes. Note each lookup requires an exact match to the text you provide as the first argument. The above example would, therefore, not match a request for "New York, NY, USA" and a second stub would need to be created to match that particular request. You can also set a default stub, to be returned when no other stub is found for a given query: - Geocoder.configure(:lookup => :test) + Geocoder.configure(lookup: :test) Geocoder::Lookup::Test.set_default_stub( [ @@ -1088,7 +1059,7 @@ Now, any time Geocoder looks up "New York, NY" its results array will contain on Notes: -- Keys must be strings not symbols when calling `add_stub` or `set_default_stub`. For example `'latitude' =>` not `:latitude =>`. +- Keys must be strings not symbols when calling `add_stub` or `set_default_stub`. For example `'latitude' =>` not `latitude:`. - To clear stubs (e.g. prior to another spec), use `Geocoder::Lookup::Test.reset`. This will clear all stubs _including the default stub_. - The stubbed result objects returned by the Test lookup do not support all the methods real result objects do. If you need to test interaction with real results it may be better to use an external stubbing tool and something like WebMock or VCR to prevent network calls. @@ -1098,11 +1069,11 @@ Error Handling By default Geocoder will rescue any exceptions raised by calls to a geocoding service and return an empty array. You can override this on a per-exception basis, and also have Geocoder raise its own exceptions for certain events (eg: API quota exceeded) by using the `:always_raise` option: - Geocoder.configure(:always_raise => [SocketError, Timeout::Error]) + Geocoder.configure(always_raise: [SocketError, Timeout::Error]) You can also do this to raise all exceptions: - Geocoder.configure(:always_raise => :all) + Geocoder.configure(always_raise: :all) The raise-able exceptions are: @@ -1230,7 +1201,7 @@ Instead of using `includes` to reduce the number of database queries, try using # Pass a :select option to the near scope to get the columns you want. # Instead of City.near(...).includes(:venues), try: - City.near("Omaha, NE", 20, :select => "cities.*, venues.*").joins(:venues) + City.near("Omaha, NE", 20, select: "cities.*, venues.*").joins(:venues) # This preload call will normally trigger two queries regardless of the # number of results; one query on hotels, and one query on administrators. From 5c8915a55e64f85ed942b9de8d0b03b45f10bc20 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 16 Jun 2018 12:53:33 -0600 Subject: [PATCH 068/248] Add a "Basic Search" section to the README. --- README.md | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 79b4eeb9f..c96dd91c0 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ Geocoder Geocoder is a complete geocoding solution for Ruby. With Rails, it adds geocoding (by street or IP address), reverse geocoding (finding street address based on given coordinates), and distance queries. It's as simple as calling `geocode` on your objects, and then using a scope like `Venue.near("Billings, MT")`. -_Please note that this README is for the current `HEAD` and may document features not present in the latest gem release. For this reason, you may want to instead view the README for your [particular version](https://github.com/alexreisner/geocoder/releases)._ - Compatibility ------------- @@ -36,6 +34,7 @@ Table of Contents Basic Features: +* [Basic Search](#basic-search) * [Geocoding Objects](#geocoding-objects) * [Geospatial Database Queries](#geospatial-database-queries) * [Geocoding HTTP Requests](#geocoding-http-requests) @@ -67,10 +66,36 @@ The Rest: * [Contributing](#contributing) +Basic Search +------------ + +In its simplest form, Geocoder takes an address and searches for its latitude/longitude coordinates: + + results = Geocoder.search("Paris") + results.first.coordinates + => [48.856614, 2.3522219] # latitude and longitude + +The reverse is possible too. Given coordinates, it finds an address: + + results = Geocoder.search([48.856614, 2.3522219]) + results.first.address + => "Hôtel de Ville, 75004 Paris, France" + +You can also look up the location of an IP addresses: + + results = Geocoder.search("172.56.21.89") + results.first.coordinates + => [30.267153, -97.7430608] + results.first.country + => "United States" + +The success and accuracy of geocoding depends entirely on the API being used to do these lookups. Most queries work fairly well with the default configuration, but every application has different needs and every API has its particular strengths and weaknesses. If you need better coverage for your application you'll want to get familiar with the large number of supported APIs, listed below in the [API Guide](#api-guide-street-address-lookups). + + Geocoding Objects ----------------- -To geocode your objects: +To automatically geocode your objects: 1. Your model must provide a method that returns an address to geocode. This can be a single attribute, but it can also be a method that returns a string assembled from different attributes (eg: `city`, `state`, and `country`). For example, if your model has `street`, `city`, `state`, and `country` attributes you might do something like this: From 3257f1c063944f49a27c44b5f26a43f181567fc3 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 16 Jun 2018 12:55:35 -0600 Subject: [PATCH 069/248] More README reorganization. --- README.md | 143 +++++++++++++++++++++++++----------------------------- 1 file changed, 67 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index c96dd91c0..62a50e28e 100644 --- a/README.md +++ b/README.md @@ -48,13 +48,12 @@ API Guide: Advanced Features: -* [Model Configuration](#model-configuration) * [Performance and Optimization](#performance-and-optimization) -* [Advanced Geocoding](#advanced-geocoding) +* [Advanced Model Configuration](#advanced-model-configuration) * [Advanced Database Queries](#advanced-database-queries) +* [Batch Geocoding](#batch-geocoding) * [Testing](#testing) * [Error Handling](#error-handing) -* [Use Outside of Rails](#use-outside-of-rails) * [Command Line Interface](#command-line-interface) The Rest: @@ -103,7 +102,7 @@ To automatically geocode your objects: [street, city, state, country].compact.join(', ') end -2. Your model must have a way to store latitude/longitude coordinates. With ActiveRecord, add two attributes/columns (of type float or decimal) called `latitude` and `longitude`. For MongoDB, use a single field (of type Array) called `coordinates` (`field :coordinates, type: Array`). (See [Model Configuration](#model-configuration) for using different attribute names.) +2. Your model must have a way to store latitude/longitude coordinates. With ActiveRecord, add two attributes/columns (of type float or decimal) called `latitude` and `longitude`. For MongoDB, use a single field (of type Array) called `coordinates` (`field :coordinates, type: Array`). (See [Advanced Model Configuration](#advanced-model-configuration) for using different attribute names.) 3. In your model, tell geocoder where to find the object's address: @@ -141,6 +140,12 @@ whereas calling the object's coordinates attribute directly (`obj.coordinates` b So, you know, be careful. +### Use Outside of Rails + +To use Geocoder with ActiveRecord and a framework other than Rails (like Sinatra or Padrino), you will need to add this in your model before calling Geocoder methods: + + extend Geocoder::Model::ActiveRecord + Geospatial Database Queries --------------------------- @@ -825,38 +830,6 @@ You must add either the *[hive_geoip2](https://rubygems.org/gems/hive_geoip2)* g ) -Model Configuration -------------------- - -You are not stuck with the `latitude` and `longitude` database column names (with ActiveRecord) or the `coordinates` array (Mongo) for storing coordinates. For example: - - geocoded_by :address, latitude: :lat, longitude: :lon # ActiveRecord - geocoded_by :address, coordinates: :coords # MongoDB - -For reverse geocoding, you can specify the attribute where the address will be stored. For example: - - reverse_geocoded_by :latitude, :longitude, address: :loc # ActiveRecord - reverse_geocoded_by :coordinates, address: :street_address # MongoDB - -To specify geocoding parameters in your model: - - geocoded_by :address, params: {region: "..."} - -Supported parameters: `:lookup`, `:ip_lookup`, `:language`, and `:params`. You can specify an anonymous function if you want to set these on a per-request basis. For example, to use different lookups for objects in different regions: - - geocoded_by :address, lookup: lambda{ |obj| obj.geocoder_lookup } - - def geocoder_lookup - if country_code == "RU" - :yandex - elsif country_code == "CN" - :baidu - else - :google - end - end - - Performance and Optimization ---------------------------- @@ -919,10 +892,40 @@ For an example of a cache store with URL expiry, please see examples/autoexpire_ _Before you implement caching in your app please be sure that doing so does not violate the Terms of Service for your geocoding service._ -Advanced Geocoding ------------------- +Advanced Model Configuration +---------------------------- + +You are not stuck with the `latitude` and `longitude` database column names (with ActiveRecord) or the `coordinates` array (Mongo) for storing coordinates. For example: + + geocoded_by :address, latitude: :lat, longitude: :lon # ActiveRecord + geocoded_by :address, coordinates: :coords # MongoDB + +For reverse geocoding, you can specify the attribute where the address will be stored. For example: + + reverse_geocoded_by :latitude, :longitude, address: :loc # ActiveRecord + reverse_geocoded_by :coordinates, address: :street_address # MongoDB + +To specify geocoding parameters in your model: + + geocoded_by :address, params: {region: "..."} + +Supported parameters: `:lookup`, `:ip_lookup`, `:language`, and `:params`. You can specify an anonymous function if you want to set these on a per-request basis. For example, to use different lookups for objects in different regions: + + geocoded_by :address, lookup: lambda{ |obj| obj.geocoder_lookup } + + def geocoder_lookup + if country_code == "RU" + :yandex + elsif country_code == "CN" + :baidu + else + :google + end + end + +### Custom Result Handling -So far we have looked at shortcuts for assigning geocoding results to object attributes. However, if you need to do something fancy, you can skip the auto-assignment by providing a block (takes the object to be geocoded and an array of `Geocoder::Result` objects) in which you handle the parsed geocoding result any way you like, for example: +So far we have seen examples where geocoding results are assigned automatically to predefined object attributes. However, you can skip the auto-assignment by providing a block which handles the parsed geocoding results any way you like, for example: reverse_geocoded_by :latitude, :longitude do |obj,results| if geo = results.first @@ -946,13 +949,13 @@ Every `Geocoder::Result` object, `result`, provides the following data: * `result.country` - string * `result.country_code` - string -If you're familiar with the results returned by the geocoding service you're using you can access even more data (call the `#data` method of any Geocoder::Result object to get the full parsed response), but you'll need to be familiar with the particular `Geocoder::Result` object you're using and the structure of your geocoding service's responses. (See the [API Guide](#api-guide-street-address-services) for links to geocoding service documentation.) +Most APIs return other data in addition to these globally-supported attributes. To directly access the full response, call the `#data` method of any Geocoder::Result object. See the [API Guide](#api-guide-street-address-services) for links to documentation for all geocoding services. ### Forward and Reverse Geocoding in the Same Model -If you apply both forward and reverse geocoding functionality to the same model (i.e. users can supply an address or coordinates and Geocoder fills in whatever's missing), you will need to provide two address methods: +You can apply both forward and reverse geocoding to the same model (i.e. users can supply an address or coordinates and Geocoder fills in whatever's missing) but you'll need to provide two different address methods: -* one for storing the fetched address (reverse geocoding) +* one for storing the fetched address (when reverse geocoding) * one for providing an address to use when fetching coordinates (forward geocoding) For example: @@ -966,7 +969,7 @@ For example: reverse_geocoded_by :latitude, :longitude, address: :full_address end -However, for purposes of querying the database, there can be only one authoritative set of latitude/longitude attributes, and whichever you specify last will be used. For example, here the `:fetched_` attributes will not be the ones used in database queries: +The same goes for latitude/longitude. However, for purposes of querying the database, there can be only one authoritative set of latitude/longitude attributes for use in database queries. This is whichever you specify last. For example, here the attributes *without* the `fetched_` prefix will be authoritative: class Venue geocoded_by :address, @@ -975,29 +978,11 @@ However, for purposes of querying the database, there can be only one authoritat reverse_geocoded_by :latitude, :longitude end -### Batch Geocoding - -If you have just added geocoding to an existing application with a lot of objects, you can use this Rake task to geocode them all: - - rake geocode:all CLASS=YourModel - -If you need reverse geocoding instead, call the task with REVERSE=true: - - rake geocode:all CLASS=YourModel REVERSE=true - -Geocoder will print warnings if you exceed the rate limit for your geocoding service. Some services — Google notably — enforce a per-second limit in addition to a per-day limit. To avoid exceeding the per-second limit, you can add a `SLEEP` option to pause between requests for a given amount of time. You can also load objects in batches to save memory, for example: - - rake geocode:all CLASS=YourModel SLEEP=0.25 BATCH=100 - -To avoid per-day limit issues (for example if you are trying to geocode thousands of objects and don't want to reach the limit), you can add a `LIMIT` option. Warning: This will ignore the `BATCH` value if provided. - - rake geocode:all CLASS=YourModel LIMIT=1000 - Advanced Database Queries ------------------------- -When querying for objects (if you're using ActiveRecord) you can also look within a square rather than a radius (circle) by using the `within_bounding_box` scope: +When querying for objects you can also look within a square rather than a radius (circle) by using the `within_bounding_box` scope: distance = 20 center_point = [40.71, 100.23] @@ -1045,6 +1030,26 @@ To calculate accurate distance and bearing with SQLite or MongoDB: The `bearing_from/to` methods take a single argument which can be: a `[lat,lon]` array, a geocoded object, or a geocodable address (string). The `distance_from/to` methods also take a units argument (`:mi`, `:km`, or `:nm` for nautical miles). +Batch Geocoding +--------------- + +If you have just added geocoding to an existing application with a lot of objects, you can use this Rake task to geocode them all: + + rake geocode:all CLASS=YourModel + +If you need reverse geocoding instead, call the task with REVERSE=true: + + rake geocode:all CLASS=YourModel REVERSE=true + +Geocoder will print warnings if you exceed the rate limit for your geocoding service. Some services — Google notably — enforce a per-second limit in addition to a per-day limit. To avoid exceeding the per-second limit, you can add a `SLEEP` option to pause between requests for a given amount of time. You can also load objects in batches to save memory, for example: + + rake geocode:all CLASS=YourModel SLEEP=0.25 BATCH=100 + +To avoid per-day limit issues (for example if you are trying to geocode thousands of objects and don't want to reach the limit), you can add a `LIMIT` option. Warning: This will ignore the `BATCH` value if provided. + + rake geocode:all CLASS=YourModel LIMIT=1000 + + Testing ------- @@ -1113,20 +1118,6 @@ The raise-able exceptions are: Note that only a few of the above exceptions are raised by any given lookup, so there's no guarantee if you configure Geocoder to raise `ServiceUnavailable` that it will actually be raised under those conditions (because most APIs don't return 503 when they should; you may get a `Timeout::Error` instead). Please see the source code for your particular lookup for details. -Use Outside of Rails --------------------- - -You can use Geocoder outside of Rails by calling the `Geocoder.search` method: - - results = Geocoder.search("McCarren Park, Brooklyn, NY") - -This returns an array of `Geocoder::Result` objects with all data provided by the geocoding service. - -To use Geocoder with ActiveRecord and a framework other than Rails (like Sinatra or Padrino), you will need to add this in your model before calling Geocoder methods: - - extend Geocoder::Model::ActiveRecord - - Command Line Interface ---------------------- From ef1fdefc6708b1a3cd40c8b0c91c85d2b09fed00 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 16 Jun 2018 13:15:02 -0600 Subject: [PATCH 070/248] Fix formatting. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 62a50e28e..a78f9ef8a 100644 --- a/README.md +++ b/README.md @@ -96,15 +96,15 @@ Geocoding Objects To automatically geocode your objects: -1. Your model must provide a method that returns an address to geocode. This can be a single attribute, but it can also be a method that returns a string assembled from different attributes (eg: `city`, `state`, and `country`). For example, if your model has `street`, `city`, `state`, and `country` attributes you might do something like this: +**1.** Your model must provide a method that returns an address to geocode. This can be a single attribute, but it can also be a method that returns a string assembled from different attributes (eg: `city`, `state`, and `country`). For example, if your model has `street`, `city`, `state`, and `country` attributes you might do something like this: def address [street, city, state, country].compact.join(', ') end -2. Your model must have a way to store latitude/longitude coordinates. With ActiveRecord, add two attributes/columns (of type float or decimal) called `latitude` and `longitude`. For MongoDB, use a single field (of type Array) called `coordinates` (`field :coordinates, type: Array`). (See [Advanced Model Configuration](#advanced-model-configuration) for using different attribute names.) +**2.** Your model must have a way to store latitude/longitude coordinates. With ActiveRecord, add two attributes/columns (of type float or decimal) called `latitude` and `longitude`. For MongoDB, use a single field (of type Array) called `coordinates` (i.e., `field :coordinates, type: Array`). (See [Advanced Model Configuration](#advanced-model-configuration) for using different attribute names.) -3. In your model, tell geocoder where to find the object's address: +**3.** In your model, tell geocoder where to find the object's address: geocoded_by :address From 0b39b939eab0bf7091ff1cb8ddbcdef4f8e0e12b Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 16 Jun 2018 15:47:20 -0600 Subject: [PATCH 071/248] Move API Guide to separate file. The README was just way too long. --- README.md | 563 +------------------------------------------- README_API_GUIDE.md | 559 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 565 insertions(+), 557 deletions(-) create mode 100644 README_API_GUIDE.md diff --git a/README.md b/README.md index a78f9ef8a..81bda49e2 100644 --- a/README.md +++ b/README.md @@ -40,12 +40,6 @@ Basic Features: * [Geocoding HTTP Requests](#geocoding-http-requests) * [Geocoding Service ("Lookup") Configuration](#geocoding-service-lookup-configuration) -API Guide: - -* [Street Address Lookups](#api-guide-street-address-lookups) -* [IP Address Lookups](#api-guide-ip-address-lookups) -* [Local IP Address Lookups](#api-guide-local-ip-address-lookups) - Advanced Features: * [Performance and Optimization](#performance-and-optimization) @@ -64,6 +58,9 @@ The Rest: * [Reporting Issues](#reporting-issues) * [Contributing](#contributing) +See Also: + +* [Guide to Geocoding APIs](https://github.com/alexreisner/geocoder/blob/master/README_API_GUIDE.md) (formerly part of this README) Basic Search ------------ @@ -88,7 +85,7 @@ You can also look up the location of an IP addresses: results.first.country => "United States" -The success and accuracy of geocoding depends entirely on the API being used to do these lookups. Most queries work fairly well with the default configuration, but every application has different needs and every API has its particular strengths and weaknesses. If you need better coverage for your application you'll want to get familiar with the large number of supported APIs, listed below in the [API Guide](#api-guide-street-address-lookups). +The success and accuracy of geocoding depends entirely on the API being used to do these lookups. Most queries work fairly well with the default configuration, but every application has different needs and every API has its particular strengths and weaknesses. If you need better coverage for your application you'll want to get familiar with the large number of supported APIs, listed in the [API Guide](https://github.com/alexreisner/geocoder/blob/master/README_API_GUIDE.md). Geocoding Objects @@ -209,7 +206,7 @@ Note that these methods will usually return `nil` in test and development enviro Geocoding Service ("Lookup") Configuration ------------------------------------------ -Geocoder supports a variety of street and IP address geocoding services. The default lookups are `:google` for street addresses and `:ipinfo_io` for IP addresses. Please see the [API Guide](#api-guide-street-address-services) for details on specific geocoding services (not all settings are supported by all services). +Geocoder supports a variety of street and IP address geocoding services. The default lookups are `:google` for street addresses and `:ipinfo_io` for IP addresses. Please see the [API Guide](https://github.com/alexreisner/geocoder/blob/master/README_API_GUIDE.md) for details on specific geocoding services (not all settings are supported by all services). To create a Rails initializer with sample configuration: @@ -282,554 +279,6 @@ You can configure multiple geocoding services at once by using the service's nam Lookup-specific settings override global settings so, in this example, the timeout for all lookups is 2 seconds, except for Yandex which is 5. -API Guide: Street Address Lookups ---------------------------------- - -The following is a listing of the supported geocoding APIs. The "Limitations" listed for each are a very brief and incomplete summary of some special limitations beyond basic data source attribution. Please read the official Terms of Service for any API before using it. - -### Google (`:google`) - -* **API key**: optional, but quota is higher if key is used (use of key requires HTTPS so be sure to set: `use_https: true` in `Geocoder.configure`) -* **Key signup**: https://console.developers.google.com/flows/enableapi?apiid=geocoding_backend&keyType=SERVER_SIDE -* **Quota**: 2,500 requests/24 hrs, 5 requests/second -* **Region**: world -* **SSL support**: yes (required if key is used) -* **Languages**: see https://developers.google.com/maps/faq#languagesupport -* **Extra params**: - * `:bounds` - pass SW and NE coordinates as an array of two arrays to bias results towards a viewport - * `:google_place_id` - pass `true` if search query is a Google Place ID -* **Documentation**: https://developers.google.com/maps/documentation/geocoding/intro -* **Terms of Service**: http://code.google.com/apis/maps/terms.html#section_10_12 -* **Limitations**: "You must not use or display the Content without a corresponding Google map, unless you are explicitly permitted to do so in the Maps APIs Documentation, or through written permission from Google." "You must not pre-fetch, cache, or store any Content, except that you may store: (i) limited amounts of Content for the purpose of improving the performance of your Maps API Implementation..." - -### Google Maps API for Work (`:google_premier`) - -Similar to `:google`, with the following differences: - -* **API key**: required, plus client and channel (set `Geocoder.configure(lookup: :google_premier, api_key: [key, client, channel])`) -* **Key signup**: https://developers.google.com/maps/documentation/business/ -* **Quota**: 100,000 requests/24 hrs, 10 requests/second - -### Google Places Details (`:google_places_details`) - -The [Google Places Details API](https://developers.google.com/places/documentation/details) is not, strictly speaking, a geocoding service. It accepts a Google `place_id` and returns address information, ratings and reviews. A `place_id` can be obtained from the Google Places Search lookup (`:google_places_search`) and should be passed to Geocoder as the first search argument: `Geocoder.search("ChIJhRwB-yFawokR5Phil-QQ3zM", lookup: :google_places_details)`. - -* **API key**: required -* **Key signup**: https://code.google.com/apis/console/ -* **Quota**: 1,000 request/day, 100,000 after credit card authentication -* **Region**: world -* **SSL support**: yes -* **Languages**: ar, eu, bg, bn, ca, cs, da, de, el, en, en-AU, en-GB, es, eu, fa, fi, fil, fr, gl, gu, hi, hr, hu, id, it, iw, ja, kn, ko, lt, lv, ml, mr, nl, no, pl, pt, pt-BR, pt-PT, ro, ru, sk, sl, sr, sv, tl, ta, te, th, tr, uk, vi, zh-CN, zh-TW (see http://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1) -* **Documentation**: https://developers.google.com/places/documentation/details -* **Terms of Service**: https://developers.google.com/places/policies -* **Limitations**: "If your application displays Places API data on a page or view that does not also display a Google Map, you must show a "Powered by Google" logo with that data." - -### Google Places Search (`:google_places_search`) - -The [Google Places Search API](https://developers.google.com/places/web-service/search) is the geocoding service of Google Places API. It returns very limited location data, but it also returns a `place_id` which can be used with Google Place Details to get more detailed information. For a comparison between this and the regular Google Geocoding API, see https://maps-apis.googleblog.com/2016/11/address-geocoding-in-google-maps-apis.html - -* Same specifications as Google Places Details (see above). - -### Bing (`:bing`) - -* **API key**: required (set `Geocoder.configure(lookup: :bing, api_key: key)`) -* **Key signup**: https://www.microsoft.com/maps/create-a-bing-maps-key.aspx -* **Quota**: 50,0000 requests/day (Windows app), 125,000 requests/year (non-Windows app) -* **Region**: world -* **SSL support**: no -* **Languages**: ? -* **Documentation**: http://msdn.microsoft.com/en-us/library/ff701715.aspx -* **Terms of Service**: http://www.microsoft.com/maps/product/terms.html -* **Limitations**: No country codes or state names. Must be used on "public-facing, non-password protected web sites," "in conjunction with Bing Maps or an application that integrates Bing Maps." - -### Nominatim (`:nominatim`) - -* **API key**: none -* **Quota**: 1 request/second -* **Region**: world -* **SSL support**: yes -* **Languages**: ? -* **Documentation**: http://wiki.openstreetmap.org/wiki/Nominatim -* **Terms of Service**: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy -* **Limitations**: Please limit request rate to 1 per second and include your contact information in User-Agent headers (eg: `Geocoder.configure(http_headers: { "User-Agent" => "your contact info" })`). [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) - -### PickPoint (`:pickpoint`) - -* **API key**: required -* **Key signup**: [https://pickpoint.io](https://pickpoint.io) -* **Quota**: 2500 requests / day for free non-commercial usage, commercial plans are [available](https://pickpoint.io/#pricing). No rate limit. -* **Region**: world -* **SSL support**: required -* **Languages**: worldwide -* **Documentation**: [https://pickpoint.io/api-reference](https://pickpoint.io/api-reference) -* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) - - -### LocationIQ (`:location_iq`) - -* **API key**: required -* **Quota**: 60 requests/minute (2 req/sec, 10k req/day), then [ability to purchase more](http://locationiq.org/#pricing) -* **Region**: world -* **SSL support**: yes -* **Languages**: ? -* **Documentation**: https://locationiq.org/#docs -* **Terms of Service**: https://unwiredlabs.com/tos -* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](https://www.openstreetmap.org/copyright) - -### OpenCageData (`:opencagedata`) - -* **API key**: required -* **Key signup**: http://geocoder.opencagedata.com -* **Quota**: 2500 requests / day, then [ability to purchase more](https://geocoder.opencagedata.com/pricing) -* **Region**: world -* **SSL support**: yes -* **Languages**: worldwide -* **Documentation**: http://geocoder.opencagedata.com/api.html -* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) - -### Yandex (`:yandex`) - -* **API key**: optional, but without it lookup is territorially limited -* **Quota**: 25000 requests / day -* **Region**: world with API key. Otherwise restricted to Russia, Ukraine, Belarus, Kazakhstan, Georgia, Abkhazia, South Ossetia, Armenia, Azerbaijan, Moldova, Turkmenistan, Tajikistan, Uzbekistan, Kyrgyzstan and Turkey -* **SSL support**: HTTPS only -* **Languages**: Russian, Belarusian, Ukrainian, English, Turkish (only for maps of Turkey) -* **Documentation**: http://api.yandex.com.tr/maps/doc/intro/concepts/intro.xml -* **Terms of Service**: http://api.yandex.com.tr/maps/doc/intro/concepts/intro.xml#rules -* **Limitations**: ? - -### Geocoder.ca (`:geocoder_ca`) - -* **API key**: none -* **Quota**: ? -* **Region**: US and Canada -* **SSL support**: no -* **Languages**: English -* **Documentation**: ? -* **Terms of Service**: http://geocoder.ca/?terms=1 -* **Limitations**: "Under no circumstances can our data be re-distributed or re-sold by anyone to other parties without our written permission." - -### Mapbox (`:mapbox`) - -* **API key**: required -* **Dataset**: Uses `mapbox.places` dataset by default. Specify the `mapbox.places-permanent` dataset by setting: `Geocoder.configure(mapbox: {dataset: "mapbox.places-permanent"})` -* **Key signup**: https://www.mapbox.com/pricing/ -* **Quota**: depends on plan -* **Region**: complete coverage of US and Canada, partial coverage elsewhere (see for details: https://www.mapbox.com/developers/api/geocoding/#coverage) -* **SSL support**: yes -* **Languages**: English -* **Extra params** (see Mapbox docs for more): - * `:country` - restrict results to a specific country, e.g., `us` or `ca` - * `:types` - restrict results to categories such as `address`, - `neighborhood`, `postcode` - * `:proximity` - bias results toward a `lng,lat`, e.g., - `params: { proximity: "-84.0,42.5" }` -* **Documentation**: https://www.mapbox.com/developers/api/geocoding/ -* **Terms of Service**: https://www.mapbox.com/tos/ -* **Limitations**: For `mapbox.places` dataset, must be displayed on a Mapbox map; Cache results for up to 30 days. For `mapbox.places-permanent` dataset, depends on plan. -* **Notes**: Currently in public beta. - -### Mapquest (`:mapquest`) - -* **API key**: required -* **Key signup**: https://developer.mapquest.com/plans -* **Quota**: ? -* **HTTP Headers**: when using the licensed API you can specify a referer like so: - `Geocoder.configure(http_headers: { "Referer" => "http://foo.com" })` -* **Region**: world -* **SSL support**: no -* **Languages**: English -* **Documentation**: http://www.mapquestapi.com/geocoding/ -* **Terms of Service**: http://info.mapquest.com/terms-of-use/ -* **Limitations**: ? -* **Notes**: You can use the open (non-licensed) API by setting: `Geocoder.configure(mapquest: {open: true})` (defaults to licensed version) - -### Ovi/Nokia (`:ovi`) - -* **API key**: not required, but performance restricted without it -* **Quota**: ? -* **Region**: world -* **SSL support**: no -* **Languages**: English -* **Documentation**: http://api.maps.ovi.com/devguide/overview.html -* **Terms of Service**: http://www.developer.nokia.com/Develop/Maps/TC.html -* **Limitations**: ? - -### Here/Nokia (`:here`) - -* **API key**: required (set `Geocoder.configure(api_key: [app_id, app_code])`) -* **Quota**: Depending on the API key -* **Region**: world -* **SSL support**: yes -* **Languages**: The preferred language of address elements in the result. Language code must be provided according to RFC 4647 standard. -* **Documentation**: http://developer.here.com/rest-apis/documentation/geocoder -* **Terms of Service**: http://developer.here.com/faqs#l&t -* **Limitations**: ? - -### ESRI (`:esri`) - -* **API key**: optional (set `Geocoder.configure(esri: {api_key: ["client_id", "client_secret"]})`) -* **Quota**: Required for some scenarios (see Terms of Service) -* **Region**: world -* **SSL support**: yes -* **Languages**: English -* **Documentation**: https://developers.arcgis.com/rest/geocode/api-reference/overview-world-geocoding-service.htm -* **Terms of Service**: http://www.esri.com/legal/software-license -* **Limitations**: Requires API key if results will be stored. Using API key will also remove rate limit. -* **Notes**: You can specify which projection you want to use by setting, for example: `Geocoder.configure(esri: {outSR: 102100})`. If you will store results, set the flag and provide API key: `Geocoder.configure(esri: {api_key: ["client_id", "client_secret"], for_storage: true})`. If you want to, you can also supply an ESRI token directly: `Geocoder.configure(esri: {token: Geocoder::EsriToken.new('TOKEN', Time.now + 1.day})` - -### Mapzen (`:mapzen`) - -* **API key**: required -* **Quota**: 25,000 free requests/month and [ability to purchase more](https://mapzen.com/pricing/) -* **Region**: world -* **SSL support**: yes -* **Languages**: en; see https://mapzen.com/documentation/search/language-codes/ -* **Documentation**: https://mapzen.com/documentation/search/search/ -* **Terms of Service**: http://mapzen.com/terms -* **Limitations**: [You must provide attribution](https://mapzen.com/rights/) -* **Notes**: Mapzen is the primary author of Pelias and offers Pelias-as-a-service in free and paid versions https://mapzen.com/pelias. - -### Pelias (`:pelias`) - -* **API key**: configurable (self-hosted service) -* **Quota**: none (self-hosted service) -* **Region**: world -* **SSL support**: yes -* **Languages**: en; see https://mapzen.com/documentation/search/language-codes/ -* **Documentation**: http://pelias.io/ -* **Terms of Service**: http://pelias.io/data_licenses.html -* **Limitations**: See terms -* **Notes**: Configure your self-hosted pelias with the `endpoint` option: `Geocoder.configure(lookup: :pelias, api_key: 'your_api_key', pelias: {endpoint: 'self.hosted/pelias'})`. Defaults to `localhost`. - -### Data Science Toolkit (`:dstk`) - -Data Science Toolkit provides an API whose response format is like Google's but which can be set up as a privately hosted service. - -* **API key**: none -* **Quota**: No quota if you are self-hosting the service. -* **Region**: world -* **SSL support**: ? -* **Languages**: en -* **Documentation**: http://www.datasciencetoolkit.org/developerdocs -* **Terms of Service**: http://www.datasciencetoolkit.org/developerdocs#googlestylegeocoder -* **Limitations**: No reverse geocoding. -* **Notes**: If you are hosting your own DSTK server you will need to configure the host name, eg: `Geocoder.configure(lookup: :dstk, dstk: {host: "localhost:4567"})`. - -### Baidu (`:baidu`) - -* **API key**: required -* **Quota**: No quota limits for geocoding -* **Region**: China -* **SSL support**: no -* **Languages**: Chinese (Simplified) -* **Documentation**: http://developer.baidu.com/map/webservice-geocoding.htm -* **Terms of Service**: http://developer.baidu.com/map/law.htm -* **Limitations**: Only good for non-commercial use. For commercial usage please check http://developer.baidu.com/map/question.htm#qa0013 -* **Notes**: To use Baidu set `Geocoder.configure(lookup: :baidu, api_key: "your_api_key")`. - -### Geocodio (`:geocodio`) - -* **API key**: required -* **Quota**: 2,500 free requests/day then purchase $0.0005 for each, also has volume pricing and plans. -* **Region**: USA & Canada -* **SSL support**: yes -* **Languages**: en -* **Documentation**: https://geocod.io/docs/ -* **Terms of Service**: https://geocod.io/terms-of-use/ -* **Limitations**: No restrictions on use - -### SmartyStreets (`:smarty_streets`) - -* **API key**: requires auth_id and auth_token (set `Geocoder.configure(api_key: [id, token])`) -* **Quota**: 250/month then purchase at sliding scale. -* **Region**: US -* **SSL support**: yes (required) -* **Languages**: en -* **Documentation**: http://smartystreets.com/kb/liveaddress-api/rest-endpoint -* **Terms of Service**: http://smartystreets.com/legal/terms-of-service -* **Limitations**: No reverse geocoding. - - -### OKF Geocoder (`:okf`) - -* **API key**: none -* **Quota**: none -* **Region**: FI -* **SSL support**: no -* **Languages**: fi -* **Documentation**: http://books.okf.fi/geocoder/_full/ -* **Terms of Service**: http://www.itella.fi/liitteet/palvelutjatuotteet/yhteystietopalvelut/Postinumeropalvelut-Palvelukuvausjakayttoehdot.pdf -* **Limitations**: ? - -### Geoportail.lu (`:geoportail_lu`) - -* **API key**: none -* **Quota**: none -* **Region**: LU -* **SSL support**: yes -* **Languages**: en -* **Documentation**: http://wiki.geoportail.lu/doku.php?id=en:api -* **Terms of Service**: http://wiki.geoportail.lu/doku.php?id=en:mcg_1 -* **Limitations**: ? - -### Postcodes.io (`:postcodes_io`) - -* **API key**: none -* **Quota**: ? -* **Region**: UK -* **SSL support**: yes -* **Languages**: English -* **Documentation**: http://postcodes.io/docs -* **Terms of Service**: ? -* **Limitations**: UK postcodes only - -### PostcodeAnywhere UK (`:postcode_anywhere_uk`) - -This uses the PostcodeAnywhere UK Geocode service, this will geocode any string from UK postcode, placename, point of interest or location. - -* **API key**: required -* **Quota**: Dependant on service plan? -* **Region**: UK -* **SSL support**: yes -* **Languages**: English -* **Documentation**: http://www.postcodeanywhere.co.uk/Support/WebService/Geocoding/UK/Geocode/2/ -* **Terms of Service**: ? -* **Limitations**: ? -* **Notes**: To use PostcodeAnywhere you must include an API key: `Geocoder.configure(lookup: :postcode_anywhere_uk, api_key: 'your_api_key')`. - -### LatLon.io (`:latlon`) - -* **API key**: required -* **Quota**: Depends on the user's plan (free and paid plans available) -* **Region**: US -* **SSL support**: yes -* **Languages**: en -* **Documentation**: https://latlon.io/documentation -* **Terms of Service**: ? -* **Limitations**: No restrictions on use - -### Base Adresse Nationale FR (`:ban_data_gouv_fr`) - -* **API key**: none -* **Quota**: none -* **Region**: FR -* **SSL support**: yes -* **Languages**: en / fr -* **Documentation**: https://adresse.data.gouv.fr/api/ (in french) -* **Terms of Service**: https://adresse.data.gouv.fr/faq/ (in french) -* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://openstreetmap.fr/ban) - -### AMap (`:amap`) - -- **API key**: required -- **Quota**: 2000/day and 2000/minute for personal developer, 4000000/day and 60000/minute for enterprise developer, for geocoding requests -- **Region**: China -- **SSL support**: yes -- **Languages**: Chinese (Simplified) -- **Documentation**: http://lbs.amap.com/api/webservice/guide/api/georegeo -- **Terms of Service**: http://lbs.amap.com/home/terms/ -- **Limitations**: Only good for non-commercial use. For commercial usage please check http://lbs.amap.com/home/terms/ -- **Notes**: To use AMap set `Geocoder.configure(lookup: :amap, api_key: "your_api_key")`. - - -API Guide: IP Address Lookups ------------------------------ - -### IPInfo.io (`:ipinfo_io`) - -* **API key**: optional - see http://ipinfo.io/pricing -* **Quota**: 1,000/day - more with api key -* **Region**: world -* **SSL support**: no (not without access key - see http://ipinfo.io/pricing) -* **Languages**: English -* **Documentation**: http://ipinfo.io/developers -* **Terms of Service**: http://ipinfo.io/developers - -### FreeGeoIP (`:freegeoip`) - [DISCONTINUED](https://github.com/alexreisner/geocoder/wiki/Freegeoip-Discontinuation) - -* **API key**: none -* **Quota**: 15,000 requests per hour. After reaching the hourly quota, all of your requests will result in HTTP 403 (Forbidden) until it clears up on the next roll over. -* **Region**: world -* **SSL support**: no -* **Languages**: English -* **Documentation**: http://github.com/fiorix/freegeoip/blob/master/README.md -* **Terms of Service**: ? -* **Limitations**: ? -* **Notes**: If you are [running your own local instance of the FreeGeoIP service](https://github.com/fiorix/freegeoip) you can configure the host like this: `Geocoder.configure(freegeoip: {host: "..."})`. - -### Pointpin (`:pointpin`) - -* **API key**: required -* **Quota**: 50,000/mo for €9 through 1m/mo for €49 -* **Region**: world -* **SSL support**: yes -* **Languages**: English -* **Documentation**: https://pointp.in/docs/get-started -* **Terms of Service**: https://pointp.in/terms -* **Limitations**: ? -* **Notes**: To use Pointpin set `Geocoder.configure(ip_lookup: :pointpin, api_key: "your_pointpin_api_key")`. - -### Telize (`:telize`) - -* **API key**: required -* **Quota**: 1,000/day for $7/mo through 100,000/day for $100/mo -* **Region**: world -* **SSL support**: yes -* **Languages**: English -* **Documentation**: https://market.mashape.com/fcambus/telize -* **Terms of Service**: ? -* **Limitations**: ? -* **Notes**: To use Telize set `Geocoder.configure(ip_lookup: :telize, api_key: "your_api_key")`. Or configure your self-hosted telize with the `host` option: `Geocoder.configure(ip_lookup: :telize, telize: {host: "localhost"})`. - - -### MaxMind Legacy Web Services (`:maxmind`) - -* **API key**: required -* **Quota**: Request Packs can be purchased -* **Region**: world -* **SSL support**: yes -* **Languages**: English -* **Documentation**: http://dev.maxmind.com/geoip/legacy/web-services/ -* **Terms of Service**: ? -* **Limitations**: ? -* **Notes**: You must specify which MaxMind service you are using in your configuration. For example: `Geocoder.configure(maxmind: {service: :omni})`. - -### Baidu IP (`:baidu_ip`) - -* **API key**: required -* **Quota**: No quota limits for geocoding -* **Region**: China -* **SSL support**: no -* **Languages**: Chinese (Simplified) -* **Documentation**: http://developer.baidu.com/map/webservice-geocoding.htm -* **Terms of Service**: http://developer.baidu.com/map/law.htm -* **Limitations**: Only good for non-commercial use. For commercial usage please check http://developer.baidu.com/map/question.htm#qa0013 -* **Notes**: To use Baidu set `Geocoder.configure(lookup: :baidu_ip, api_key: "your_api_key")`. - -### MaxMind GeoIP2 Precision Web Services (`:maxmind_geoip2`) - -* **API key**: required -* **Quota**: Request Packs can be purchased -* **Region**: world -* **SSL support**: yes -* **Languages**: English -* **Documentation**: http://dev.maxmind.com/geoip/geoip2/web-services/ -* **Terms of Service**: ? -* **Limitations**: ? -* **Notes**: You must specify which MaxMind service you are using in your configuration, and also basic authentication. For example: `Geocoder.configure(maxmind_geoip2: {service: :country, basic_auth: {user: '', password: ''}})`. - -### Ipstack (`:ipstack`) - -* **API key**: required (see https://ipstack.com/product) -* **Quota**: 10,000 requests per month (with free API Key, 50,000/day and up for paid plans) -* **Region**: world -* **SSL support**: yes ( only with paid plan ) -* **Languages**: English, German, Spanish, French, Japanese, Portugues (Brazil), Russian, Chinese -* **Documentation**: https://ipstack.com/documentation -* **Terms of Service**: ? -* **Limitations**: ? -* **Notes**: To use Ipstack set `Geocoder.configure(ip_lookup: :ipstack, api_key: "your_ipstack_api_key")`. Supports the optional params: `:hostname`, `:security`, `:fields`, `:language` (see API documentation for details). - -### IP-API.com (`:ipapi_com`) - -* **API key**: optional - see http://ip-api.com/docs/#usage_limits -* **Quota**: 150/minute - unlimited with api key -* **Region**: world -* **SSL support**: no (not without access key - see https://signup.ip-api.com/) -* **Languages**: English -* **Documentation**: http://ip-api.com/docs/ -* **Terms of Service**: https://signup.ip-api.com/terms - -### DB-IP.com (`:db_ip_com`) - -* **API key**: required -* **Quota**: 2,500/day (with free API Key, 50,000/day and up for paid API keys) -* **Region**: world -* **SSL support**: yes (with paid API keys - see https://db-ip.com/api/) -* **Languages**: English (English with free API key, multiple languages with paid API keys) -* **Documentation**: https://db-ip.com/api/doc.php -* **Terms of Service**: https://db-ip.com/tos.php - -### Ipdata.co (`:ipdata_co`) - -* **API key**: optional, see: https://ipdata.co/pricing.html -* **Quota**: 1500/day (up to 600k with paid API keys) -* **Region**: world -* **SSL support**: yes -* **Languages**: English -* **Documentation**: https://ipdata.co/docs.html -* **Terms of Service**: https://ipdata.co/terms.html -* **Limitations**: ? - - -API Guide: Local IP Address Lookups ------------------------------------ - -### MaxMind Local (`:maxmind_local`) - EXPERIMENTAL - -This lookup provides methods for geocoding IP addresses without making a call to a remote API (improves speed and availability). It works, but support is new and should not be considered production-ready. Please [report any bugs](https://github.com/alexreisner/geocoder/issues) you encounter. - -* **API key**: none (requires the GeoLite City database which can be downloaded from [MaxMind](http://dev.maxmind.com/geoip/legacy/geolite/)) -* **Quota**: none -* **Region**: world -* **SSL support**: N/A -* **Languages**: English -* **Documentation**: http://www.maxmind.com/en/city -* **Terms of Service**: ? -* **Limitations**: ? -* **Notes**: There are two supported formats for MaxMind local data: binary file, and CSV file imported into an SQL database. **You must download a database from MaxMind and set either the `:file` or `:package` configuration option for local lookups to work.** - -**To use a binary file** you must add the *geoip* (or *jgeoip* for JRuby) gem to your Gemfile or have it installed in your system, and specify the path of the MaxMind database in your configuration. For example: - - Geocoder.configure(ip_lookup: :maxmind_local, maxmind_local: {file: File.join('folder', 'GeoLiteCity.dat')}) - -**To use a CSV file** you must import it into an SQL database. The GeoLite *City* and *Country* packages are supported. Configure like so: - - Geocoder.configure(ip_lookup: :maxmind_local, maxmind_local: {package: :city}) - -You can generate ActiveRecord migrations and download and import data via provided rake tasks: - - # generate migration to create tables - rails generate geocoder:maxmind:geolite_city - - # download, unpack, and import data - rake geocoder:maxmind:geolite:load PACKAGE=city - -You can replace `city` with `country` in any of the above tasks, generators, and configurations. - -### GeoLite2 (`:geoip2`) - -This lookup provides methods for geocoding IP addresses without making a call to a remote API (improves speed and availability). It works, but support is new and should not be considered production-ready. Please [report any bugs](https://github.com/alexreisner/geocoder/issues) you encounter. - -* **API key**: none (requires a GeoIP2 or free GeoLite2 City or Country binary database which can be downloaded from [MaxMind](http://dev.maxmind.com/geoip/geoip2/)) -* **Quota**: none -* **Region**: world -* **SSL support**: N/A -* **Languages**: English -* **Documentation**: http://www.maxmind.com/en/city -* **Terms of Service**: ? -* **Limitations**: ? -* **Notes**: **You must download a binary database file from MaxMind and set the `:file` configuration option.** The CSV format databases are not yet supported since they are still in alpha stage. Set the path to the database file in your configuration: - - Geocoder.configure( - ip_lookup: :geoip2, - geoip2: { - file: File.join('folder', 'GeoLite2-City.mmdb') - } - ) - -You must add either the *[hive_geoip2](https://rubygems.org/gems/hive_geoip2)* gem (native extension that relies on libmaxminddb) or the *[maxminddb](http://rubygems.org/gems/maxminddb)* gem (pure Ruby implementation) to your Gemfile or have it installed in your system. The pure Ruby gem (maxminddb) will be used by default. To use `hive_geoip2`: - - Geocoder.configure( - ip_lookup: :geoip2, - geoip2: { - lib: 'hive_geoip2', - file: File.join('folder', 'GeoLite2-City.mmdb') - } - ) - - Performance and Optimization ---------------------------- @@ -949,7 +398,7 @@ Every `Geocoder::Result` object, `result`, provides the following data: * `result.country` - string * `result.country_code` - string -Most APIs return other data in addition to these globally-supported attributes. To directly access the full response, call the `#data` method of any Geocoder::Result object. See the [API Guide](#api-guide-street-address-services) for links to documentation for all geocoding services. +Most APIs return other data in addition to these globally-supported attributes. To directly access the full response, call the `#data` method of any Geocoder::Result object. See the [API Guide](https://github.com/alexreisner/geocoder/blob/master/README_API_GUIDE.md) for links to documentation for all geocoding services. ### Forward and Reverse Geocoding in the Same Model diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md new file mode 100644 index 000000000..46b3507c0 --- /dev/null +++ b/README_API_GUIDE.md @@ -0,0 +1,559 @@ +Guide to Geocoding APIs +======================= + +This is a list of geocoding APIs supported by the Geocoder gem. Before using any API in a production environment, please read its official Terms of Service (links below). + +Table of Contents +----------------- + +* [Street Address Lookups](#street-address-lookups) +* [IP Address Lookups](#ip-address-lookups) +* [Local IP Address Lookups](#local-ip-address-lookups) + +Street Address Lookups +---------------------- + +### Google (`:google`) + +* **API key**: optional, but quota is higher if key is used (use of key requires HTTPS so be sure to set: `use_https: true` in `Geocoder.configure`) +* **Key signup**: https://console.developers.google.com/flows/enableapi?apiid=geocoding_backend&keyType=SERVER_SIDE +* **Quota**: 2,500 requests/24 hrs, 5 requests/second +* **Region**: world +* **SSL support**: yes (required if key is used) +* **Languages**: see https://developers.google.com/maps/faq#languagesupport +* **Extra params**: + * `:bounds` - pass SW and NE coordinates as an array of two arrays to bias results towards a viewport + * `:google_place_id` - pass `true` if search query is a Google Place ID +* **Documentation**: https://developers.google.com/maps/documentation/geocoding/intro +* **Terms of Service**: http://code.google.com/apis/maps/terms.html#section_10_12 +* **Limitations**: "You must not use or display the Content without a corresponding Google map, unless you are explicitly permitted to do so in the Maps APIs Documentation, or through written permission from Google." "You must not pre-fetch, cache, or store any Content, except that you may store: (i) limited amounts of Content for the purpose of improving the performance of your Maps API Implementation..." + +### Google Maps API for Work (`:google_premier`) + +Similar to `:google`, with the following differences: + +* **API key**: required, plus client and channel (set `Geocoder.configure(lookup: :google_premier, api_key: [key, client, channel])`) +* **Key signup**: https://developers.google.com/maps/documentation/business/ +* **Quota**: 100,000 requests/24 hrs, 10 requests/second + +### Google Places Details (`:google_places_details`) + +The [Google Places Details API](https://developers.google.com/places/documentation/details) is not, strictly speaking, a geocoding service. It accepts a Google `place_id` and returns address information, ratings and reviews. A `place_id` can be obtained from the Google Places Search lookup (`:google_places_search`) and should be passed to Geocoder as the first search argument: `Geocoder.search("ChIJhRwB-yFawokR5Phil-QQ3zM", lookup: :google_places_details)`. + +* **API key**: required +* **Key signup**: https://code.google.com/apis/console/ +* **Quota**: 1,000 request/day, 100,000 after credit card authentication +* **Region**: world +* **SSL support**: yes +* **Languages**: ar, eu, bg, bn, ca, cs, da, de, el, en, en-AU, en-GB, es, eu, fa, fi, fil, fr, gl, gu, hi, hr, hu, id, it, iw, ja, kn, ko, lt, lv, ml, mr, nl, no, pl, pt, pt-BR, pt-PT, ro, ru, sk, sl, sr, sv, tl, ta, te, th, tr, uk, vi, zh-CN, zh-TW (see http://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1) +* **Documentation**: https://developers.google.com/places/documentation/details +* **Terms of Service**: https://developers.google.com/places/policies +* **Limitations**: "If your application displays Places API data on a page or view that does not also display a Google Map, you must show a "Powered by Google" logo with that data." + +### Google Places Search (`:google_places_search`) + +The [Google Places Search API](https://developers.google.com/places/web-service/search) is the geocoding service of Google Places API. It returns very limited location data, but it also returns a `place_id` which can be used with Google Place Details to get more detailed information. For a comparison between this and the regular Google Geocoding API, see https://maps-apis.googleblog.com/2016/11/address-geocoding-in-google-maps-apis.html + +* Same specifications as Google Places Details (see above). + +### Bing (`:bing`) + +* **API key**: required (set `Geocoder.configure(lookup: :bing, api_key: key)`) +* **Key signup**: https://www.microsoft.com/maps/create-a-bing-maps-key.aspx +* **Quota**: 50,0000 requests/day (Windows app), 125,000 requests/year (non-Windows app) +* **Region**: world +* **SSL support**: no +* **Languages**: ? +* **Documentation**: http://msdn.microsoft.com/en-us/library/ff701715.aspx +* **Terms of Service**: http://www.microsoft.com/maps/product/terms.html +* **Limitations**: No country codes or state names. Must be used on "public-facing, non-password protected web sites," "in conjunction with Bing Maps or an application that integrates Bing Maps." + +### Nominatim (`:nominatim`) + +* **API key**: none +* **Quota**: 1 request/second +* **Region**: world +* **SSL support**: yes +* **Languages**: ? +* **Documentation**: http://wiki.openstreetmap.org/wiki/Nominatim +* **Terms of Service**: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy +* **Limitations**: Please limit request rate to 1 per second and include your contact information in User-Agent headers (eg: `Geocoder.configure(http_headers: { "User-Agent" => "your contact info" })`). [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) + +### PickPoint (`:pickpoint`) + +* **API key**: required +* **Key signup**: [https://pickpoint.io](https://pickpoint.io) +* **Quota**: 2500 requests / day for free non-commercial usage, commercial plans are [available](https://pickpoint.io/#pricing). No rate limit. +* **Region**: world +* **SSL support**: required +* **Languages**: worldwide +* **Documentation**: [https://pickpoint.io/api-reference](https://pickpoint.io/api-reference) +* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) + + +### LocationIQ (`:location_iq`) + +* **API key**: required +* **Quota**: 60 requests/minute (2 req/sec, 10k req/day), then [ability to purchase more](http://locationiq.org/#pricing) +* **Region**: world +* **SSL support**: yes +* **Languages**: ? +* **Documentation**: https://locationiq.org/#docs +* **Terms of Service**: https://unwiredlabs.com/tos +* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](https://www.openstreetmap.org/copyright) + +### OpenCageData (`:opencagedata`) + +* **API key**: required +* **Key signup**: http://geocoder.opencagedata.com +* **Quota**: 2500 requests / day, then [ability to purchase more](https://geocoder.opencagedata.com/pricing) +* **Region**: world +* **SSL support**: yes +* **Languages**: worldwide +* **Documentation**: http://geocoder.opencagedata.com/api.html +* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) + +### Yandex (`:yandex`) + +* **API key**: optional, but without it lookup is territorially limited +* **Quota**: 25000 requests / day +* **Region**: world with API key. Otherwise restricted to Russia, Ukraine, Belarus, Kazakhstan, Georgia, Abkhazia, South Ossetia, Armenia, Azerbaijan, Moldova, Turkmenistan, Tajikistan, Uzbekistan, Kyrgyzstan and Turkey +* **SSL support**: HTTPS only +* **Languages**: Russian, Belarusian, Ukrainian, English, Turkish (only for maps of Turkey) +* **Documentation**: http://api.yandex.com.tr/maps/doc/intro/concepts/intro.xml +* **Terms of Service**: http://api.yandex.com.tr/maps/doc/intro/concepts/intro.xml#rules +* **Limitations**: ? + +### Geocoder.ca (`:geocoder_ca`) + +* **API key**: none +* **Quota**: ? +* **Region**: US and Canada +* **SSL support**: no +* **Languages**: English +* **Documentation**: ? +* **Terms of Service**: http://geocoder.ca/?terms=1 +* **Limitations**: "Under no circumstances can our data be re-distributed or re-sold by anyone to other parties without our written permission." + +### Mapbox (`:mapbox`) + +* **API key**: required +* **Dataset**: Uses `mapbox.places` dataset by default. Specify the `mapbox.places-permanent` dataset by setting: `Geocoder.configure(mapbox: {dataset: "mapbox.places-permanent"})` +* **Key signup**: https://www.mapbox.com/pricing/ +* **Quota**: depends on plan +* **Region**: complete coverage of US and Canada, partial coverage elsewhere (see for details: https://www.mapbox.com/developers/api/geocoding/#coverage) +* **SSL support**: yes +* **Languages**: English +* **Extra params** (see Mapbox docs for more): + * `:country` - restrict results to a specific country, e.g., `us` or `ca` + * `:types` - restrict results to categories such as `address`, + `neighborhood`, `postcode` + * `:proximity` - bias results toward a `lng,lat`, e.g., + `params: { proximity: "-84.0,42.5" }` +* **Documentation**: https://www.mapbox.com/developers/api/geocoding/ +* **Terms of Service**: https://www.mapbox.com/tos/ +* **Limitations**: For `mapbox.places` dataset, must be displayed on a Mapbox map; Cache results for up to 30 days. For `mapbox.places-permanent` dataset, depends on plan. +* **Notes**: Currently in public beta. + +### Mapquest (`:mapquest`) + +* **API key**: required +* **Key signup**: https://developer.mapquest.com/plans +* **Quota**: ? +* **HTTP Headers**: when using the licensed API you can specify a referer like so: + `Geocoder.configure(http_headers: { "Referer" => "http://foo.com" })` +* **Region**: world +* **SSL support**: no +* **Languages**: English +* **Documentation**: http://www.mapquestapi.com/geocoding/ +* **Terms of Service**: http://info.mapquest.com/terms-of-use/ +* **Limitations**: ? +* **Notes**: You can use the open (non-licensed) API by setting: `Geocoder.configure(mapquest: {open: true})` (defaults to licensed version) + +### Ovi/Nokia (`:ovi`) + +* **API key**: not required, but performance restricted without it +* **Quota**: ? +* **Region**: world +* **SSL support**: no +* **Languages**: English +* **Documentation**: http://api.maps.ovi.com/devguide/overview.html +* **Terms of Service**: http://www.developer.nokia.com/Develop/Maps/TC.html +* **Limitations**: ? + +### Here/Nokia (`:here`) + +* **API key**: required (set `Geocoder.configure(api_key: [app_id, app_code])`) +* **Quota**: Depending on the API key +* **Region**: world +* **SSL support**: yes +* **Languages**: The preferred language of address elements in the result. Language code must be provided according to RFC 4647 standard. +* **Documentation**: http://developer.here.com/rest-apis/documentation/geocoder +* **Terms of Service**: http://developer.here.com/faqs#l&t +* **Limitations**: ? + +### ESRI (`:esri`) + +* **API key**: optional (set `Geocoder.configure(esri: {api_key: ["client_id", "client_secret"]})`) +* **Quota**: Required for some scenarios (see Terms of Service) +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://developers.arcgis.com/rest/geocode/api-reference/overview-world-geocoding-service.htm +* **Terms of Service**: http://www.esri.com/legal/software-license +* **Limitations**: Requires API key if results will be stored. Using API key will also remove rate limit. +* **Notes**: You can specify which projection you want to use by setting, for example: `Geocoder.configure(esri: {outSR: 102100})`. If you will store results, set the flag and provide API key: `Geocoder.configure(esri: {api_key: ["client_id", "client_secret"], for_storage: true})`. If you want to, you can also supply an ESRI token directly: `Geocoder.configure(esri: {token: Geocoder::EsriToken.new('TOKEN', Time.now + 1.day})` + +### Mapzen (`:mapzen`) + +* **API key**: required +* **Quota**: 25,000 free requests/month and [ability to purchase more](https://mapzen.com/pricing/) +* **Region**: world +* **SSL support**: yes +* **Languages**: en; see https://mapzen.com/documentation/search/language-codes/ +* **Documentation**: https://mapzen.com/documentation/search/search/ +* **Terms of Service**: http://mapzen.com/terms +* **Limitations**: [You must provide attribution](https://mapzen.com/rights/) +* **Notes**: Mapzen is the primary author of Pelias and offers Pelias-as-a-service in free and paid versions https://mapzen.com/pelias. + +### Pelias (`:pelias`) + +* **API key**: configurable (self-hosted service) +* **Quota**: none (self-hosted service) +* **Region**: world +* **SSL support**: yes +* **Languages**: en; see https://mapzen.com/documentation/search/language-codes/ +* **Documentation**: http://pelias.io/ +* **Terms of Service**: http://pelias.io/data_licenses.html +* **Limitations**: See terms +* **Notes**: Configure your self-hosted pelias with the `endpoint` option: `Geocoder.configure(lookup: :pelias, api_key: 'your_api_key', pelias: {endpoint: 'self.hosted/pelias'})`. Defaults to `localhost`. + +### Data Science Toolkit (`:dstk`) + +Data Science Toolkit provides an API whose response format is like Google's but which can be set up as a privately hosted service. + +* **API key**: none +* **Quota**: No quota if you are self-hosting the service. +* **Region**: world +* **SSL support**: ? +* **Languages**: en +* **Documentation**: http://www.datasciencetoolkit.org/developerdocs +* **Terms of Service**: http://www.datasciencetoolkit.org/developerdocs#googlestylegeocoder +* **Limitations**: No reverse geocoding. +* **Notes**: If you are hosting your own DSTK server you will need to configure the host name, eg: `Geocoder.configure(lookup: :dstk, dstk: {host: "localhost:4567"})`. + +### Baidu (`:baidu`) + +* **API key**: required +* **Quota**: No quota limits for geocoding +* **Region**: China +* **SSL support**: no +* **Languages**: Chinese (Simplified) +* **Documentation**: http://developer.baidu.com/map/webservice-geocoding.htm +* **Terms of Service**: http://developer.baidu.com/map/law.htm +* **Limitations**: Only good for non-commercial use. For commercial usage please check http://developer.baidu.com/map/question.htm#qa0013 +* **Notes**: To use Baidu set `Geocoder.configure(lookup: :baidu, api_key: "your_api_key")`. + +### Geocodio (`:geocodio`) + +* **API key**: required +* **Quota**: 2,500 free requests/day then purchase $0.0005 for each, also has volume pricing and plans. +* **Region**: USA & Canada +* **SSL support**: yes +* **Languages**: en +* **Documentation**: https://geocod.io/docs/ +* **Terms of Service**: https://geocod.io/terms-of-use/ +* **Limitations**: No restrictions on use + +### SmartyStreets (`:smarty_streets`) + +* **API key**: requires auth_id and auth_token (set `Geocoder.configure(api_key: [id, token])`) +* **Quota**: 250/month then purchase at sliding scale. +* **Region**: US +* **SSL support**: yes (required) +* **Languages**: en +* **Documentation**: http://smartystreets.com/kb/liveaddress-api/rest-endpoint +* **Terms of Service**: http://smartystreets.com/legal/terms-of-service +* **Limitations**: No reverse geocoding. + + +### OKF Geocoder (`:okf`) + +* **API key**: none +* **Quota**: none +* **Region**: FI +* **SSL support**: no +* **Languages**: fi +* **Documentation**: http://books.okf.fi/geocoder/_full/ +* **Terms of Service**: http://www.itella.fi/liitteet/palvelutjatuotteet/yhteystietopalvelut/Postinumeropalvelut-Palvelukuvausjakayttoehdot.pdf +* **Limitations**: ? + +### Geoportail.lu (`:geoportail_lu`) + +* **API key**: none +* **Quota**: none +* **Region**: LU +* **SSL support**: yes +* **Languages**: en +* **Documentation**: http://wiki.geoportail.lu/doku.php?id=en:api +* **Terms of Service**: http://wiki.geoportail.lu/doku.php?id=en:mcg_1 +* **Limitations**: ? + +### Postcodes.io (`:postcodes_io`) + +* **API key**: none +* **Quota**: ? +* **Region**: UK +* **SSL support**: yes +* **Languages**: English +* **Documentation**: http://postcodes.io/docs +* **Terms of Service**: ? +* **Limitations**: UK postcodes only + +### PostcodeAnywhere UK (`:postcode_anywhere_uk`) + +This uses the PostcodeAnywhere UK Geocode service, this will geocode any string from UK postcode, placename, point of interest or location. + +* **API key**: required +* **Quota**: Dependant on service plan? +* **Region**: UK +* **SSL support**: yes +* **Languages**: English +* **Documentation**: http://www.postcodeanywhere.co.uk/Support/WebService/Geocoding/UK/Geocode/2/ +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: To use PostcodeAnywhere you must include an API key: `Geocoder.configure(lookup: :postcode_anywhere_uk, api_key: 'your_api_key')`. + +### LatLon.io (`:latlon`) + +* **API key**: required +* **Quota**: Depends on the user's plan (free and paid plans available) +* **Region**: US +* **SSL support**: yes +* **Languages**: en +* **Documentation**: https://latlon.io/documentation +* **Terms of Service**: ? +* **Limitations**: No restrictions on use + +### Base Adresse Nationale FR (`:ban_data_gouv_fr`) + +* **API key**: none +* **Quota**: none +* **Region**: FR +* **SSL support**: yes +* **Languages**: en / fr +* **Documentation**: https://adresse.data.gouv.fr/api/ (in french) +* **Terms of Service**: https://adresse.data.gouv.fr/faq/ (in french) +* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://openstreetmap.fr/ban) + +### AMap (`:amap`) + +- **API key**: required +- **Quota**: 2000/day and 2000/minute for personal developer, 4000000/day and 60000/minute for enterprise developer, for geocoding requests +- **Region**: China +- **SSL support**: yes +- **Languages**: Chinese (Simplified) +- **Documentation**: http://lbs.amap.com/api/webservice/guide/api/georegeo +- **Terms of Service**: http://lbs.amap.com/home/terms/ +- **Limitations**: Only good for non-commercial use. For commercial usage please check http://lbs.amap.com/home/terms/ +- **Notes**: To use AMap set `Geocoder.configure(lookup: :amap, api_key: "your_api_key")`. + + +IP Address Lookups +------------------ + +### IPInfo.io (`:ipinfo_io`) + +* **API key**: optional - see http://ipinfo.io/pricing +* **Quota**: 1,000/day - more with api key +* **Region**: world +* **SSL support**: no (not without access key - see http://ipinfo.io/pricing) +* **Languages**: English +* **Documentation**: http://ipinfo.io/developers +* **Terms of Service**: http://ipinfo.io/developers + +### FreeGeoIP (`:freegeoip`) - [DISCONTINUED](https://github.com/alexreisner/geocoder/wiki/Freegeoip-Discontinuation) + +* **API key**: none +* **Quota**: 15,000 requests per hour. After reaching the hourly quota, all of your requests will result in HTTP 403 (Forbidden) until it clears up on the next roll over. +* **Region**: world +* **SSL support**: no +* **Languages**: English +* **Documentation**: http://github.com/fiorix/freegeoip/blob/master/README.md +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: If you are [running your own local instance of the FreeGeoIP service](https://github.com/fiorix/freegeoip) you can configure the host like this: `Geocoder.configure(freegeoip: {host: "..."})`. + +### Pointpin (`:pointpin`) + +* **API key**: required +* **Quota**: 50,000/mo for €9 through 1m/mo for €49 +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://pointp.in/docs/get-started +* **Terms of Service**: https://pointp.in/terms +* **Limitations**: ? +* **Notes**: To use Pointpin set `Geocoder.configure(ip_lookup: :pointpin, api_key: "your_pointpin_api_key")`. + +### Telize (`:telize`) + +* **API key**: required +* **Quota**: 1,000/day for $7/mo through 100,000/day for $100/mo +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://market.mashape.com/fcambus/telize +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: To use Telize set `Geocoder.configure(ip_lookup: :telize, api_key: "your_api_key")`. Or configure your self-hosted telize with the `host` option: `Geocoder.configure(ip_lookup: :telize, telize: {host: "localhost"})`. + + +### MaxMind Legacy Web Services (`:maxmind`) + +* **API key**: required +* **Quota**: Request Packs can be purchased +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: http://dev.maxmind.com/geoip/legacy/web-services/ +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: You must specify which MaxMind service you are using in your configuration. For example: `Geocoder.configure(maxmind: {service: :omni})`. + +### Baidu IP (`:baidu_ip`) + +* **API key**: required +* **Quota**: No quota limits for geocoding +* **Region**: China +* **SSL support**: no +* **Languages**: Chinese (Simplified) +* **Documentation**: http://developer.baidu.com/map/webservice-geocoding.htm +* **Terms of Service**: http://developer.baidu.com/map/law.htm +* **Limitations**: Only good for non-commercial use. For commercial usage please check http://developer.baidu.com/map/question.htm#qa0013 +* **Notes**: To use Baidu set `Geocoder.configure(lookup: :baidu_ip, api_key: "your_api_key")`. + +### MaxMind GeoIP2 Precision Web Services (`:maxmind_geoip2`) + +* **API key**: required +* **Quota**: Request Packs can be purchased +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: http://dev.maxmind.com/geoip/geoip2/web-services/ +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: You must specify which MaxMind service you are using in your configuration, and also basic authentication. For example: `Geocoder.configure(maxmind_geoip2: {service: :country, basic_auth: {user: '', password: ''}})`. + +### Ipstack (`:ipstack`) + +* **API key**: required (see https://ipstack.com/product) +* **Quota**: 10,000 requests per month (with free API Key, 50,000/day and up for paid plans) +* **Region**: world +* **SSL support**: yes ( only with paid plan ) +* **Languages**: English, German, Spanish, French, Japanese, Portugues (Brazil), Russian, Chinese +* **Documentation**: https://ipstack.com/documentation +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: To use Ipstack set `Geocoder.configure(ip_lookup: :ipstack, api_key: "your_ipstack_api_key")`. Supports the optional params: `:hostname`, `:security`, `:fields`, `:language` (see API documentation for details). + +### IP-API.com (`:ipapi_com`) + +* **API key**: optional - see http://ip-api.com/docs/#usage_limits +* **Quota**: 150/minute - unlimited with api key +* **Region**: world +* **SSL support**: no (not without access key - see https://signup.ip-api.com/) +* **Languages**: English +* **Documentation**: http://ip-api.com/docs/ +* **Terms of Service**: https://signup.ip-api.com/terms + +### DB-IP.com (`:db_ip_com`) + +* **API key**: required +* **Quota**: 2,500/day (with free API Key, 50,000/day and up for paid API keys) +* **Region**: world +* **SSL support**: yes (with paid API keys - see https://db-ip.com/api/) +* **Languages**: English (English with free API key, multiple languages with paid API keys) +* **Documentation**: https://db-ip.com/api/doc.php +* **Terms of Service**: https://db-ip.com/tos.php + +### Ipdata.co (`:ipdata_co`) + +* **API key**: optional, see: https://ipdata.co/pricing.html +* **Quota**: 1500/day (up to 600k with paid API keys) +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://ipdata.co/docs.html +* **Terms of Service**: https://ipdata.co/terms.html +* **Limitations**: ? + + +Local IP Address Lookups +------------------------ + +### MaxMind Local (`:maxmind_local`) - EXPERIMENTAL + +This lookup provides methods for geocoding IP addresses without making a call to a remote API (improves speed and availability). It works, but support is new and should not be considered production-ready. Please [report any bugs](https://github.com/alexreisner/geocoder/issues) you encounter. + +* **API key**: none (requires the GeoLite City database which can be downloaded from [MaxMind](http://dev.maxmind.com/geoip/legacy/geolite/)) +* **Quota**: none +* **Region**: world +* **SSL support**: N/A +* **Languages**: English +* **Documentation**: http://www.maxmind.com/en/city +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: There are two supported formats for MaxMind local data: binary file, and CSV file imported into an SQL database. **You must download a database from MaxMind and set either the `:file` or `:package` configuration option for local lookups to work.** + +**To use a binary file** you must add the *geoip* (or *jgeoip* for JRuby) gem to your Gemfile or have it installed in your system, and specify the path of the MaxMind database in your configuration. For example: + + Geocoder.configure(ip_lookup: :maxmind_local, maxmind_local: {file: File.join('folder', 'GeoLiteCity.dat')}) + +**To use a CSV file** you must import it into an SQL database. The GeoLite *City* and *Country* packages are supported. Configure like so: + + Geocoder.configure(ip_lookup: :maxmind_local, maxmind_local: {package: :city}) + +You can generate ActiveRecord migrations and download and import data via provided rake tasks: + + # generate migration to create tables + rails generate geocoder:maxmind:geolite_city + + # download, unpack, and import data + rake geocoder:maxmind:geolite:load PACKAGE=city + +You can replace `city` with `country` in any of the above tasks, generators, and configurations. + +### GeoLite2 (`:geoip2`) + +This lookup provides methods for geocoding IP addresses without making a call to a remote API (improves speed and availability). It works, but support is new and should not be considered production-ready. Please [report any bugs](https://github.com/alexreisner/geocoder/issues) you encounter. + +* **API key**: none (requires a GeoIP2 or free GeoLite2 City or Country binary database which can be downloaded from [MaxMind](http://dev.maxmind.com/geoip/geoip2/)) +* **Quota**: none +* **Region**: world +* **SSL support**: N/A +* **Languages**: English +* **Documentation**: http://www.maxmind.com/en/city +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: **You must download a binary database file from MaxMind and set the `:file` configuration option.** The CSV format databases are not yet supported since they are still in alpha stage. Set the path to the database file in your configuration: + + Geocoder.configure( + ip_lookup: :geoip2, + geoip2: { + file: File.join('folder', 'GeoLite2-City.mmdb') + } + ) + +You must add either the *[hive_geoip2](https://rubygems.org/gems/hive_geoip2)* gem (native extension that relies on libmaxminddb) or the *[maxminddb](http://rubygems.org/gems/maxminddb)* gem (pure Ruby implementation) to your Gemfile or have it installed in your system. The pure Ruby gem (maxminddb) will be used by default. To use `hive_geoip2`: + + Geocoder.configure( + ip_lookup: :geoip2, + geoip2: { + lib: 'hive_geoip2', + file: File.join('folder', 'GeoLite2-City.mmdb') + } + ) + + +Copyright (c) 2009-18 Alex Reisner, released under the MIT license. From 35655d6e1411471f91d44b4cab1422c7e8ed70ab Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 16 Jun 2018 16:00:09 -0600 Subject: [PATCH 072/248] More README cleanup. --- README.md | 16 ++++++---------- README_API_GUIDE.md | 2 -- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 81bda49e2..c90b444b3 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ You can also look up the location of an IP addresses: results.first.country => "United States" -The success and accuracy of geocoding depends entirely on the API being used to do these lookups. Most queries work fairly well with the default configuration, but every application has different needs and every API has its particular strengths and weaknesses. If you need better coverage for your application you'll want to get familiar with the large number of supported APIs, listed in the [API Guide](https://github.com/alexreisner/geocoder/blob/master/README_API_GUIDE.md). +**The success and accuracy of geocoding depends entirely on the API being used to do these lookups.** Most queries work fairly well with the default configuration, but every application has different needs and every API has its particular strengths and weaknesses. If you need better coverage for your application you'll want to get familiar with the large number of supported APIs, listed in the [API Guide](https://github.com/alexreisner/geocoder/blob/master/README_API_GUIDE.md). Geocoding Objects @@ -121,10 +121,6 @@ Before you can call `geocoded_by` you'll need to include the necessary module us include Geocoder::Model::Mongoid include Geocoder::Model::MongoMapper -You'll also need to create spatial indices: - - rake db:mongoid:create_indexes - ### Latitude/Longitude Order in MongoDB Everywhere coordinates are passed to methods as two-element arrays, Geocoder expects them to be in the order: `[lat, lon]`. However, as per [the GeoJSON spec](http://geojson.org/geojson-spec.html#positions), MongoDB requires that coordinates be stored longitude-first (`[lon, lat]`), so internally they are stored "backwards." Geocoder's methods attempt to hide this, so calling `obj.to_coordinates` (a method added to the object by Geocoder via `geocoded_by`) returns coordinates in the conventional order: @@ -135,7 +131,7 @@ whereas calling the object's coordinates attribute directly (`obj.coordinates` b obj.coordinates # => [-122.3951096, 37.7941013] # [lon, lat] -So, you know, be careful. +So, be careful. ### Use Outside of Rails @@ -502,10 +498,12 @@ To avoid per-day limit issues (for example if you are trying to geocode thousand Testing ------- -When writing tests for an app that uses Geocoder it may be useful to avoid network calls and have Geocoder return consistent, configurable results. To do this, configure and use the `:test` lookup. For example: +When writing tests for an app that uses Geocoder it may be useful to avoid network calls and have Geocoder return consistent, configurable results. To do this, configure the `:test` lookup: Geocoder.configure(lookup: :test) +Add stubs to define the results that will be returned: + Geocoder::Lookup::Test.add_stub( "New York, NY", [ { @@ -519,9 +517,7 @@ When writing tests for an app that uses Geocoder it may be useful to avoid netwo ] ) -Now, any time Geocoder looks up "New York, NY" its results array will contain one result with the above attributes. Note each lookup requires an exact match to the text you provide as the first argument. The above example would, therefore, not match a request for "New York, NY, USA" and a second stub would need to be created to match that particular request. You can also set a default stub, to be returned when no other stub is found for a given query: - - Geocoder.configure(lookup: :test) +With the above stub defined, any query for "New York, NY" will return the results array that follows. You can also set a default stub, to be returned when no other stub matches a given query: Geocoder::Lookup::Test.set_default_stub( [ diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 46b3507c0..3896e5e02 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -312,8 +312,6 @@ Data Science Toolkit provides an API whose response format is like Google's but ### PostcodeAnywhere UK (`:postcode_anywhere_uk`) -This uses the PostcodeAnywhere UK Geocode service, this will geocode any string from UK postcode, placename, point of interest or location. - * **API key**: required * **Quota**: Dependant on service plan? * **Region**: UK From 31adeba8320fec55a2d450536ae1aeb06b94843b Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 10:01:51 -0600 Subject: [PATCH 073/248] More README cleanup. --- README.md | 79 ++++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index c90b444b3..828dfef62 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,14 @@ -Geocoder -======== +Geocoder: a Ruby gem +==================== -Geocoder is a complete geocoding solution for Ruby. With Rails, it adds geocoding (by street or IP address), reverse geocoding (finding street address based on given coordinates), and distance queries. It's as simple as calling `geocode` on your objects, and then using a scope like `Venue.near("Billings, MT")`. +Geocoder is a complete geocoding solution for Ruby, featuring: + +* Forward and reverse geocoding, and IP address geocoding. +* Connects to more than 40 APIs worldwide. +* Performance-enhancing feaures like caching. +* Advanced configuration allows different parameters and APIs to be used in different conditions. +* Integrates with ActiveRecord and Mongoid. +* Basic geospatial queries: search within radius (or rectangle, or ring). Compatibility @@ -13,22 +20,6 @@ Compatibility * Works very well outside of Rails, you just need to install either the `json` (for MRI) or `json_pure` (for JRuby) gem. -Installation ------------- - -Install Geocoder like any other Ruby gem: - - gem install geocoder - -Or, if you're using Rails/Bundler, add this to your Gemfile: - - gem 'geocoder' - -and run at the command prompt: - - bundle install - - Table of Contents ----------------- @@ -62,6 +53,7 @@ See Also: * [Guide to Geocoding APIs](https://github.com/alexreisner/geocoder/blob/master/README_API_GUIDE.md) (formerly part of this README) + Basic Search ------------ @@ -114,6 +106,14 @@ Reverse geocoding (given lat/lon coordinates, find an address) is similar: reverse_geocoded_by :latitude, :longitude after_validation :reverse_geocode +With any geocoded objects, you can do the following: + + obj.distance_to([43.9,-98.6]) # distance from obj to point + obj.bearing_to([43.9,-98.6]) # bearing from obj to point + obj.bearing_from(obj2) # bearing from obj2 to obj + +The `bearing_from/to` methods take a single argument which can be: a `[lat,lon]` array, a geocoded object, or a geocodable address (string). The `distance_from/to` methods also take a units argument (`:mi`, `:km`, or `:nm` for nautical miles). See [Distance and Bearing](#distance-and-bearing) below for more info. + ### One More Thing for MongoDB! Before you can call `geocoded_by` you'll need to include the necessary module using one of the following: @@ -427,29 +427,34 @@ The same goes for latitude/longitude. However, for purposes of querying the data Advanced Database Queries ------------------------- -When querying for objects you can also look within a square rather than a radius (circle) by using the `within_bounding_box` scope: +*The following apply to ActiveRecord only. For MongoDB, please use the built-in geospatial features.* + +The default `near` search looks for objects within a circle. To search within a doughnut or ring use the `:min_radius` option: + + Venue.near("Austin, TX", 200, min_radius: 40) + +To search within a rectangle (note that results will *not* include `distance` and `bearing` attributes): - distance = 20 - center_point = [40.71, 100.23] - box = Geocoder::Calculations.bounding_box(center_point, distance) - Venue.within_bounding_box(box) + sw_corner = [40.71, 100.23] + ne_corner = [36.12, 88.65] + Venue.within_bounding_box(sw_corner, ne_corner) -Note, however, that returned results will not include `distance` and `bearing` attributes. You can also specify a minimum radius (if you're using ActiveRecord and not Sqlite) to constrain the lower bound (ie. think of a donut, or ring) by using the `:min_radius` option: +To search for objects near a certain point where each object has a different distance requirement (which is defined in the database), you can pass a column name for the radius: - box = Geocoder::Calculations.bounding_box(center_point, distance, min_radius: 10.5) + Venue.near([40.71, 99.23], :effective_radius) -With ActiveRecord, you can specify alternate latitude and longitude column names for a geocoded model (useful if you store multiple sets of coordinates for each object): +If you store multiple sets of coordinates for each object, you can specify latitude and longitude columns to use for a search: Venue.near("Paris", 50, latitude: :secondary_latitude, longitude: :secondary_longitude) ### Distance and Bearing -When you run a location-aware query the returned objects have two attributes added to them (only w/ ActiveRecord): +When you run a geospatial query, the returned objects have two attributes added: * `obj.distance` - number of miles from the search point to this object * `obj.bearing` - direction from the search point to this object -Results are automatically sorted by distance from the search point, closest to farthest. Bearing is given as a number of clockwise degrees from due north, for example: +Results are automatically sorted by distance from the search point, closest to farthest. Bearing is given as a number of degrees clockwise from due north, for example: * `0` - due north * `180` - due south @@ -458,21 +463,13 @@ Results are automatically sorted by distance from the search point, closest to f * `230.1` - southwest * `359.9` - almost due north -You can convert these numbers to compass point names by using the utility method provided: +You can convert these to compass point names via provided utility method: Geocoder::Calculations.compass_point(355) # => "N" Geocoder::Calculations.compass_point(45) # => "NE" Geocoder::Calculations.compass_point(208) # => "SW" -_Note: when using SQLite `distance` and `bearing` values are provided for interface consistency only. They are not very accurate._ - -To calculate accurate distance and bearing with SQLite or MongoDB: - - obj.distance_to([43.9,-98.6]) # distance from obj to point - obj.bearing_to([43.9,-98.6]) # bearing from obj to point - obj.bearing_from(obj2) # bearing from obj2 to obj - -The `bearing_from/to` methods take a single argument which can be: a `[lat,lon]` array, a geocoded object, or a geocodable address (string). The `distance_from/to` methods also take a units argument (`:mi`, `:km`, or `:nm` for nautical miles). +_Note: when running queries on SQLite, `distance` and `bearing` are provided for consistency only. They are not very accurate._ Batch Geocoding @@ -486,11 +483,11 @@ If you need reverse geocoding instead, call the task with REVERSE=true: rake geocode:all CLASS=YourModel REVERSE=true -Geocoder will print warnings if you exceed the rate limit for your geocoding service. Some services — Google notably — enforce a per-second limit in addition to a per-day limit. To avoid exceeding the per-second limit, you can add a `SLEEP` option to pause between requests for a given amount of time. You can also load objects in batches to save memory, for example: +In either case, it won't try to geocode objects that are already geocoded. The task will print warnings if you exceed the rate limit for your geocoding service. Some services enforce a per-second limit in addition to a per-day limit. To avoid exceeding the per-second limit, you can add a `SLEEP` option to pause between requests for a given amount of time. You can also load objects in batches to save memory, for example: rake geocode:all CLASS=YourModel SLEEP=0.25 BATCH=100 -To avoid per-day limit issues (for example if you are trying to geocode thousands of objects and don't want to reach the limit), you can add a `LIMIT` option. Warning: This will ignore the `BATCH` value if provided. +To avoid exceeding per-day limits you can add a `LIMIT` option. However, this will ignore the `BATCH` value, if provided. rake geocode:all CLASS=YourModel LIMIT=1000 From ae39b480dd69888ce4ac271c0ab5d39def9c0601 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 10:14:07 -0600 Subject: [PATCH 074/248] Minor readme improvements. Add badges. --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 828dfef62..c99f20069 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,15 @@ -Geocoder: a Ruby gem -==================== +Geocoder +======== -Geocoder is a complete geocoding solution for Ruby, featuring: +**A complete geocoding solution for Ruby.** + +[![Gem Version](https://badge.fury.io/rb/geocoder.svg)](http://badge.fury.io/rb/geocoder) +[![Code Climate](https://codeclimate.com/github/alexreisner/geocoder/badges/gpa.svg)](https://codeclimate.com/github/alexreisner/geocoder) +[![Build Status](https://travis-ci.org/alexreisner/geocoder.svg?branch=master)](https://travis-ci.org/alexreisner/geocoder) +[![GitHub Issues](https://img.shields.io/github/issues/alexreisner/geocoder.svg)](https://github.com/alexreisner/geocoder/issues) +[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT) + +Key features: * Forward and reverse geocoding, and IP address geocoding. * Connects to more than 40 APIs worldwide. @@ -10,9 +18,7 @@ Geocoder is a complete geocoding solution for Ruby, featuring: * Integrates with ActiveRecord and Mongoid. * Basic geospatial queries: search within radius (or rectangle, or ring). - -Compatibility -------------- +Compatibility: * Supports multiple Ruby versions: Ruby 1.9.3, 2.x, and JRuby. * Supports multiple databases: MySQL, PostgreSQL, SQLite, and MongoDB (1.7.0 and higher). From 4f56b9fc7e698c0cfb19d898e089ff0bb7c8c08c Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 10:40:50 -0600 Subject: [PATCH 075/248] Remove :ovi lookup. No longer seems to exist. --- README_API_GUIDE.md | 11 ---- lib/geocoder/lookup.rb | 1 - lib/geocoder/lookups/ovi.rb | 62 --------------------- lib/geocoder/results/ovi.rb | 71 ------------------------ test/fixtures/ovi_madison_square_garden | 72 ------------------------- test/fixtures/ovi_no_results | 8 --- test/unit/lookups/ovi_test.rb | 17 ------ 7 files changed, 242 deletions(-) delete mode 100644 lib/geocoder/lookups/ovi.rb delete mode 100644 lib/geocoder/results/ovi.rb delete mode 100644 test/fixtures/ovi_madison_square_garden delete mode 100644 test/fixtures/ovi_no_results delete mode 100644 test/unit/lookups/ovi_test.rb diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 3896e5e02..26d5da82a 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -170,17 +170,6 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Limitations**: ? * **Notes**: You can use the open (non-licensed) API by setting: `Geocoder.configure(mapquest: {open: true})` (defaults to licensed version) -### Ovi/Nokia (`:ovi`) - -* **API key**: not required, but performance restricted without it -* **Quota**: ? -* **Region**: world -* **SSL support**: no -* **Languages**: English -* **Documentation**: http://api.maps.ovi.com/devguide/overview.html -* **Terms of Service**: http://www.developer.nokia.com/Develop/Maps/TC.html -* **Limitations**: ? - ### Here/Nokia (`:here`) * **API key**: required (set `Geocoder.configure(api_key: [app_id, app_code])`) diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index 91482a918..baa85c9d2 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -39,7 +39,6 @@ def street_services :mapquest, :mapzen, :opencagedata, - :ovi, :pelias, :pickpoint, :here, diff --git a/lib/geocoder/lookups/ovi.rb b/lib/geocoder/lookups/ovi.rb deleted file mode 100644 index 17ef6bd0e..000000000 --- a/lib/geocoder/lookups/ovi.rb +++ /dev/null @@ -1,62 +0,0 @@ -require 'geocoder/lookups/base' -require 'geocoder/results/ovi' - -module Geocoder::Lookup - class Ovi < Base - - def name - "Ovi" - end - - def required_api_key_parts - [] - end - - def query_url(query) - "#{protocol}://lbs.ovi.com/search/6.2/#{if query.reverse_geocode? then 'reverse' end}geocode.json?" + url_query_string(query) - end - - private # --------------------------------------------------------------- - - def results(query) - return [] unless doc = fetch_data(query) - return [] unless doc['Response'] && doc['Response']['View'] - if r=doc['Response']['View'] - return [] if r.nil? || !r.is_a?(Array) || r.empty? - return r.first['Result'] - end - [] - end - - def query_url_params(query) - options = { - :gen=>1, - :app_id=>api_key, - :app_code=>api_code - } - - if query.reverse_geocode? - super.merge(options).merge( - :prox=>query.sanitized_text, - :mode=>:retrieveAddresses - ) - else - super.merge(options).merge( - :searchtext=>query.sanitized_text - ) - end - end - - def api_key - if a=configuration.api_key - return a.first if a.is_a?(Array) - end - end - - def api_code - if a=configuration.api_key - return a.last if a.is_a?(Array) - end - end - end -end diff --git a/lib/geocoder/results/ovi.rb b/lib/geocoder/results/ovi.rb deleted file mode 100644 index 552e2289c..000000000 --- a/lib/geocoder/results/ovi.rb +++ /dev/null @@ -1,71 +0,0 @@ -require 'geocoder/results/base' - -module Geocoder::Result - class Ovi < Base - - ## - # A string in the given format. - # - def address(format = :full) - address_data['Label'] - end - - ## - # A two-element array: [lat, lon]. - # - def coordinates - fail unless d = @data['Location']['DisplayPosition'] - [d['Latitude'].to_f, d['Longitude'].to_f] - end - - def state - address_data['County'] - end - - def province - address_data['County'] - end - - def postal_code - address_data['PostalCode'] - end - - def city - address_data['City'] - end - - def state_code - address_data['State'] - end - - def province_code - address_data['State'] - end - - def country - fail unless d = address_data['AdditionalData'] - if v = d.find{|ad| ad['key']=='CountryName'} - return v['value'] - end - end - - def country_code - address_data['Country'] - end - - def viewport - map_view = data['Location']['MapView'] || fail - south = map_view['BottomRight']['Latitude'] - west = map_view['TopLeft']['Longitude'] - north = map_view['TopLeft']['Latitude'] - east = map_view['BottomRight']['Longitude'] - [south, west, north, east] - end - - private # ---------------------------------------------------------------- - - def address_data - @data['Location']['Address'] || fail - end - end -end diff --git a/test/fixtures/ovi_madison_square_garden b/test/fixtures/ovi_madison_square_garden deleted file mode 100644 index 464b8f851..000000000 --- a/test/fixtures/ovi_madison_square_garden +++ /dev/null @@ -1,72 +0,0 @@ -{ - "Response": { - "MetaInfo": { - "Timestamp": "2013-02-08T16:26:39.382+0000" - }, - "View": [ - { - "_type": "SearchResultsViewType", - "ViewId": 0, - "Result": [ - { - "Relevance": 1.0, - "MatchLevel": "houseNumber", - "MatchQuality": { - "State": 1.0, - "City": 1.0, - "Street": [ - 1.0 - ], - "HouseNumber": 1.0 - }, - "MatchType": "pointAddress", - "Location": { - "LocationId": "NT_ArsGdYbpo6dqjPQel9gTID_4", - "LocationType": "point", - "DisplayPosition": { - "Latitude": 40.7504692, - "Longitude": -73.9933777 - }, - "NavigationPosition": [ - { - "Latitude": 40.7500305, - "Longitude": -73.9942398 - } - ], - "MapView": { - "TopLeft": { - "Latitude": 40.7515934, - "Longitude": -73.9948616 - }, - "BottomRight": { - "Latitude": 40.7493451, - "Longitude": -73.9918938 - } - }, - "Address": { - "Label": "4 Penn Plz, New York, NY 10001, United States", - "Country": "USA", - "State": "NY", - "County": "New York", - "City": "New York", - "Street": "Penn Plz", - "HouseNumber": "4", - "PostalCode": "10001", - "AdditionalData": [ - { - "value": "United States", - "key": "CountryName" - }, - { - "value": "New York", - "key": "StateName" - } - ] - } - } - } - ] - } - ] - } -} diff --git a/test/fixtures/ovi_no_results b/test/fixtures/ovi_no_results deleted file mode 100644 index 26fdaf93a..000000000 --- a/test/fixtures/ovi_no_results +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Response": { - "MetaInfo": { - "Timestamp": "2013-02-08T16:41:16.723+0000" - }, - "View": [] - } -} diff --git a/test/unit/lookups/ovi_test.rb b/test/unit/lookups/ovi_test.rb deleted file mode 100644 index 1404ed3ea..000000000 --- a/test/unit/lookups/ovi_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -# encoding: utf-8 -$: << File.join(File.dirname(__FILE__), "..", "..") -require 'test_helper' - -class OviTest < GeocoderTestCase - - def setup - Geocoder.configure(lookup: :ovi) - end - - def test_ovi_viewport - result = Geocoder.search("Madison Square Garden, New York, NY").first - assert_equal [40.7493451, -73.9948616, 40.7515934, -73.9918938], - result.viewport - end - -end From 2cb19748c66856832c7db09abf0c8f082f3e98be Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 10:52:01 -0600 Subject: [PATCH 076/248] Refactor to reduce code duplication. --- lib/geocoder/lookups/baidu.rb | 16 +++++++++------ lib/geocoder/lookups/baidu_ip.rb | 35 +++----------------------------- 2 files changed, 13 insertions(+), 38 deletions(-) diff --git a/lib/geocoder/lookups/baidu.rb b/lib/geocoder/lookups/baidu.rb index 65d38da08..6eb5e7ab0 100644 --- a/lib/geocoder/lookups/baidu.rb +++ b/lib/geocoder/lookups/baidu.rb @@ -23,26 +23,30 @@ def supported_protocols private # --------------------------------------------------------------- + def content_key + 'result' + end + def results(query, reverse = false) return [] unless doc = fetch_data(query) case doc['status'] when 0 - return [doc['result']] unless doc['result'].blank? + return [doc[content_key]] unless doc[content_key].blank? when 1, 3, 4 raise_error(Geocoder::Error, "server error.") || - Geocoder.log(:warn, "Baidu Geocoding API error: server error.") + Geocoder.log(:warn, "#{name} Geocoding API error: server error.") when 2 raise_error(Geocoder::InvalidRequest, "invalid request.") || - Geocoder.log(:warn, "Baidu Geocoding API error: invalid request.") + Geocoder.log(:warn, "#{name} Geocoding API error: invalid request.") when 5 raise_error(Geocoder::InvalidApiKey, "invalid api key") || - Geocoder.log(:warn, "Baidu Geocoding API error: invalid api key.") + Geocoder.log(:warn, "#{name} Geocoding API error: invalid api key.") when 101, 102, 200..299 raise_error(Geocoder::RequestDenied, "request denied") || - Geocoder.log(:warn, "Baidu Geocoding API error: request denied.") + Geocoder.log(:warn, "#{name} Geocoding API error: request denied.") when 300..399 raise_error(Geocoder::OverQueryLimitError, "over query limit.") || - Geocoder.log(:warn, "Baidu Geocoding API error: over query limit.") + Geocoder.log(:warn, "#{name} Geocoding API error: over query limit.") end return [] end diff --git a/lib/geocoder/lookups/baidu_ip.rb b/lib/geocoder/lookups/baidu_ip.rb index cbdaa47bc..c632d562d 100644 --- a/lib/geocoder/lookups/baidu_ip.rb +++ b/lib/geocoder/lookups/baidu_ip.rb @@ -2,49 +2,20 @@ require 'geocoder/results/baidu_ip' module Geocoder::Lookup - class BaiduIp < Base + class BaiduIp < Baidu def name "Baidu IP" end - def required_api_key_parts - ["key"] - end - def query_url(query) "#{protocol}://api.map.baidu.com/location/ip?" + url_query_string(query) end - # HTTP only - def supported_protocols - [:http] - end - private # --------------------------------------------------------------- - def results(query, reverse = false) - return [] unless doc = fetch_data(query) - case doc['status'] - when 0 - return [doc['content']] unless doc['content'].blank? - when 1, 3, 4 - raise_error(Geocoder::Error, "server error.") || - Geocoder.log(:warn, "Baidu IP Geocoding API error: server error.") - when 2 - raise_error(Geocoder::InvalidRequest, "invalid request.") || - Geocoder.log(:warn, "Baidu IP Geocoding API error: invalid request.") - when 5 - raise_error(Geocoder::InvalidApiKey, "invalid api key.") || - Geocoder.log(:warn, "Baidu IP Geocoding API error: invalid api key.") - when 101, 102, 200..299 - raise_error(Geocoder::RequestDenied, "request denied.") || - Geocoder.log(:warn, "Baidu IP Geocoding API error: request denied.") - when 300..399 - raise_error(Geocoder::OverQueryLimitError, "over query limit") || - Geocoder.log(:warn, "Baidu IP Geocoding API error: over query limit.") - end - return [] + def content_key + 'content' end def query_url_params(query) From f47fa5f8f8cd949f915c89b101b2102a7c5c5f0b Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 12:28:56 -0600 Subject: [PATCH 077/248] Return a proper reserved result. --- lib/geocoder/lookups/telize.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/telize.rb b/lib/geocoder/lookups/telize.rb index ded98c1af..964bc5b29 100644 --- a/lib/geocoder/lookups/telize.rb +++ b/lib/geocoder/lookups/telize.rb @@ -44,7 +44,23 @@ def empty_result?(doc) end def reserved_result(ip) - {"message" => "Input string is not a valid IP address", "code" => 401} + { + "ip": ip, + "latitude": 0, + "longitude": 0, + "city": "", + "timezone": "", + "asn": 0, + "region": "", + "offset": 0, + "organization": "", + "country_code": "", + "country_code3": "", + "postal_code": "", + "continent_code": "", + "country": "", + "region_code": "" + } end def api_key From c06cb644f17cd15e6671a66561a14d7056e62926 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 12:59:51 -0600 Subject: [PATCH 078/248] Return strict boolean, for clarity. --- lib/geocoder/ip_address.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/ip_address.rb b/lib/geocoder/ip_address.rb index 9174f8d3a..65d43e509 100644 --- a/lib/geocoder/ip_address.rb +++ b/lib/geocoder/ip_address.rb @@ -3,7 +3,7 @@ module Geocoder class IpAddress < String def loopback? - valid? and (self == "0.0.0.0" or self.match(/\A127\./) or self == "::1") + valid? and !!(self == "0.0.0.0" or self.match(/\A127\./) or self == "::1") end def valid? From 1f11fc5108aa32c25077fc9574ef5c5e3760dfa6 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 12:43:54 -0600 Subject: [PATCH 079/248] Handle Ipinfo.io responses correctly. --- lib/geocoder/lookups/ipinfo_io.rb | 15 ++++----------- test/unit/lookups/ipinfo_io_test.rb | 6 +++--- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/lib/geocoder/lookups/ipinfo_io.rb b/lib/geocoder/lookups/ipinfo_io.rb index b7966d46c..542c0d897 100644 --- a/lib/geocoder/lookups/ipinfo_io.rb +++ b/lib/geocoder/lookups/ipinfo_io.rb @@ -30,25 +30,18 @@ def supported_protocols def results(query) # don't look up a loopback address, just return the stored result return [reserved_result(query.text)] if query.loopback_ip_address? - if (doc = fetch_data(query)).nil? or doc['code'] == 401 or empty_result?(doc) + + if !(doc = fetch_data(query)).is_a?(Hash) or doc['error'] [] else [doc] end end - def empty_result?(doc) - !doc.is_a?(Hash) or doc.keys == ["ip"] - end - def reserved_result(ip) { - "ip" => ip, - "city" => "", - "region" => "", - "country" => "", - "loc" => "0,0", - "postal" => "" + "ip" => ip, + "bogon" => true } end diff --git a/test/unit/lookups/ipinfo_io_test.rb b/test/unit/lookups/ipinfo_io_test.rb index a66093ce4..206a71fd4 100644 --- a/test/unit/lookups/ipinfo_io_test.rb +++ b/test/unit/lookups/ipinfo_io_test.rb @@ -16,10 +16,10 @@ def test_ipinfo_io_uses_https_when_auth_token_set end def test_ipinfo_io_lookup_loopback_address - Geocoder.configure(:ip_lookup => :ipinfo_io, :use_https => true) + Geocoder.configure(:ip_lookup => :ipinfo_io) result = Geocoder.search("127.0.0.1").first - assert_equal 0.0, result.longitude - assert_equal 0.0, result.latitude + assert_nil result.latitude + assert_nil result.longitude assert_equal "127.0.0.1", result.ip end From 30aa62f1d4fd80c1559a7001d9ad46efb8f5323f Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 13:23:37 -0600 Subject: [PATCH 080/248] Remove unnecessary method. --- lib/geocoder/lookups/pointpin.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/geocoder/lookups/pointpin.rb b/lib/geocoder/lookups/pointpin.rb index 356006971..83d7c5e78 100644 --- a/lib/geocoder/lookups/pointpin.rb +++ b/lib/geocoder/lookups/pointpin.rb @@ -13,7 +13,7 @@ def required_api_key_parts end def query_url(query) - "#{ protocol }://geo.pointp.in/#{ api_key }/json/#{ query.sanitized_text }" + "#{protocol}://geo.pointp.in/#{configuration.api_key}/json/#{query.sanitized_text}" end private @@ -60,9 +60,5 @@ def reserved_result(ip) "country_code" => "RD" } end - - def api_key - configuration.api_key - end end end From 9e6c88605963fd40fcf33d763d93aece6785265b Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 13:23:46 -0600 Subject: [PATCH 081/248] Add TODO. --- lib/geocoder/lookups/pointpin.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/geocoder/lookups/pointpin.rb b/lib/geocoder/lookups/pointpin.rb index 83d7c5e78..cde1074b6 100644 --- a/lib/geocoder/lookups/pointpin.rb +++ b/lib/geocoder/lookups/pointpin.rb @@ -46,6 +46,7 @@ def data_contains_error?(parsed_data) parsed_data.keys.include?('error') end + # TODO: replace this hash with what's actually returned by Pointpin def reserved_result(ip) { "ip" => ip, From db6d269a75cb5c5dae9a2cc0a653094c40476de0 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 13:24:55 -0600 Subject: [PATCH 082/248] Remove line that was needed for Ruby 1.8! --- lib/geocoder/lookups/base.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb index 76abcfd07..53d17d77f 100644 --- a/lib/geocoder/lookups/base.rb +++ b/lib/geocoder/lookups/base.rb @@ -4,7 +4,6 @@ unless defined?(ActiveSupport::JSON) begin - require 'rubygems' # for Ruby 1.8 require 'json' rescue LoadError raise LoadError, "Please install the 'json' or 'json_pure' gem to parse geocoder results." From dc80aa3d264ca7dd4d23f3a24d53b76b226d6bbe Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 13:53:15 -0600 Subject: [PATCH 083/248] Refactor to reduce code duplication. --- lib/geocoder/results/base.rb | 14 +++++++++++++- lib/geocoder/results/db_ip_com.rb | 5 ----- lib/geocoder/results/freegeoip.rb | 5 ----- lib/geocoder/results/geoip2.rb | 4 ---- lib/geocoder/results/ipdata_co.rb | 5 ----- lib/geocoder/results/maxmind.rb | 5 ----- lib/geocoder/results/maxmind_local.rb | 5 ----- lib/geocoder/results/telize.rb | 5 ----- 8 files changed, 13 insertions(+), 35 deletions(-) diff --git a/lib/geocoder/results/base.rb b/lib/geocoder/results/base.rb index a798ced68..7fe179c92 100644 --- a/lib/geocoder/results/base.rb +++ b/lib/geocoder/results/base.rb @@ -20,8 +20,20 @@ def initialize(data) ## # A string in the given format. # + # This default implementation dumbly follows the United States address + # format and will return incorrect results for most countries. Some APIs + # return properly formatted addresses and those should be funneled + # through this method. + # def address(format = :full) - fail + if state_code.to_s != "" + s = ", #{state_code}" + elsif state.to_s != "" + s = ", #{state}" + else + s = "" + end + "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, '') end ## diff --git a/lib/geocoder/results/db_ip_com.rb b/lib/geocoder/results/db_ip_com.rb index 2328bd0dd..f5291bf2d 100644 --- a/lib/geocoder/results/db_ip_com.rb +++ b/lib/geocoder/results/db_ip_com.rb @@ -7,11 +7,6 @@ def coordinates ['latitude', 'longitude'].map{ |coordinate_name| @data[coordinate_name] } end - def address(format = :full) - s = state_code.to_s == "" ? "" : ", #{state_code}" - "#{city}#{s} #{zip_code}, #{country_name}".sub(/^[ ,]*/, "") - end - def city @data['city'] end diff --git a/lib/geocoder/results/freegeoip.rb b/lib/geocoder/results/freegeoip.rb index d990e5647..0ddde2f76 100644 --- a/lib/geocoder/results/freegeoip.rb +++ b/lib/geocoder/results/freegeoip.rb @@ -3,11 +3,6 @@ module Geocoder::Result class Freegeoip < Base - def address(format = :full) - s = state_code.to_s == "" ? "" : ", #{state_code}" - "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "") - end - def city @data['city'] end diff --git a/lib/geocoder/results/geoip2.rb b/lib/geocoder/results/geoip2.rb index c7a1a913b..1381747fc 100644 --- a/lib/geocoder/results/geoip2.rb +++ b/lib/geocoder/results/geoip2.rb @@ -3,10 +3,6 @@ module Geocoder module Result class Geoip2 < Base - def address(format = :full) - s = state.to_s == '' ? '' : ", #{state_code}" - "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, '') - end def coordinates %w[latitude longitude].map do |l| diff --git a/lib/geocoder/results/ipdata_co.rb b/lib/geocoder/results/ipdata_co.rb index 497ac156d..b6d2362c1 100644 --- a/lib/geocoder/results/ipdata_co.rb +++ b/lib/geocoder/results/ipdata_co.rb @@ -3,11 +3,6 @@ module Geocoder::Result class IpdataCo < Base - def address(format = :full) - s = state_code.to_s == "" ? "" : ", #{state_code}" - "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "") - end - def city @data['city'] end diff --git a/lib/geocoder/results/maxmind.rb b/lib/geocoder/results/maxmind.rb index 6682bfc64..a0744f8a8 100644 --- a/lib/geocoder/results/maxmind.rb +++ b/lib/geocoder/results/maxmind.rb @@ -87,11 +87,6 @@ def coordinates [data_hash[:latitude].to_f, data_hash[:longitude].to_f] end - def address(format = :full) - s = state_code.to_s == "" ? "" : ", #{state_code}" - "#{city}#{s} #{postal_code}, #{country_code}".sub(/^[ ,]*/, "") - end - def city data_hash[:city_name] end diff --git a/lib/geocoder/results/maxmind_local.rb b/lib/geocoder/results/maxmind_local.rb index 81b545ab4..4f8929e96 100644 --- a/lib/geocoder/results/maxmind_local.rb +++ b/lib/geocoder/results/maxmind_local.rb @@ -3,11 +3,6 @@ module Geocoder::Result class MaxmindLocal < Base - def address(format = :full) - s = state.to_s == "" ? "" : ", #{state}" - "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "") - end - def coordinates [@data[:latitude], @data[:longitude]] end diff --git a/lib/geocoder/results/telize.rb b/lib/geocoder/results/telize.rb index ee8880b76..d853faaf1 100644 --- a/lib/geocoder/results/telize.rb +++ b/lib/geocoder/results/telize.rb @@ -3,11 +3,6 @@ module Geocoder::Result class Telize < Base - def address(format = :full) - s = state_code.to_s == "" ? "" : ", #{state_code}" - "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "") - end - def city @data['city'] end From 396e78ac002d3e16b8d8445974c73e988e8174c4 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 15:19:24 -0600 Subject: [PATCH 084/248] Fix hash syntax (for Ruby less than 2.2). --- lib/geocoder/lookups/telize.rb | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/geocoder/lookups/telize.rb b/lib/geocoder/lookups/telize.rb index 964bc5b29..d585ff932 100644 --- a/lib/geocoder/lookups/telize.rb +++ b/lib/geocoder/lookups/telize.rb @@ -45,21 +45,21 @@ def empty_result?(doc) def reserved_result(ip) { - "ip": ip, - "latitude": 0, - "longitude": 0, - "city": "", - "timezone": "", - "asn": 0, - "region": "", - "offset": 0, - "organization": "", - "country_code": "", - "country_code3": "", - "postal_code": "", - "continent_code": "", - "country": "", - "region_code": "" + "ip" => ip, + "latitude" => 0, + "longitude" => 0, + "city" => "", + "timezone" => "", + "asn" => 0, + "region" => "", + "offset" => 0, + "organization" => "", + "country_code" => "", + "country_code3" => "", + "postal_code" => "", + "continent_code" => "", + "country" => "", + "region_code" => "" } end From 4af45d7a437dc3640e03c5344425e16a1ff4b3fc Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 17:03:05 -0600 Subject: [PATCH 085/248] Add trailing slash to avoid redirect. --- lib/geocoder/lookups/bing.rb | 6 +++--- test/unit/lookups/bing_test.rb | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/geocoder/lookups/bing.rb b/lib/geocoder/lookups/bing.rb index 5d46f3a83..5dd0ddca6 100644 --- a/lib/geocoder/lookups/bing.rb +++ b/lib/geocoder/lookups/bing.rb @@ -23,17 +23,17 @@ def query_url(query) private # --------------------------------------------------------------- def base_url(query) - url = "#{protocol}://dev.virtualearth.net/REST/v1/Locations" + url = "#{protocol}://dev.virtualearth.net/REST/v1/Locations/" if !query.reverse_geocode? if r = query.options[:region] - url << "/#{r}" + url << "#{r}/" end # use the more forgiving 'unstructured' query format to allow special # chars, newlines, brackets, typos. url + "?q=" + URI.escape(query.sanitized_text.strip) + "&" else - url + "/#{URI.escape(query.sanitized_text.strip)}?" + url + "#{URI.escape(query.sanitized_text.strip)}?" end end diff --git a/test/unit/lookups/bing_test.rb b/test/unit/lookups/bing_test.rb index 028f84107..3531add54 100644 --- a/test/unit/lookups/bing_test.rb +++ b/test/unit/lookups/bing_test.rb @@ -42,7 +42,7 @@ def test_query_url_contains_region "manchester", :region => "uk" )) - assert_match(/Locations\/uk\?q=manchester/, url) + assert_match(%r!Locations/uk/\?q=manchester!, url) assert_no_match(/query/, url) end @@ -51,7 +51,7 @@ def test_query_url_without_region url = lookup.query_url(Geocoder::Query.new( "manchester" )) - assert_match(/Locations\?q=manchester/, url) + assert_match(%r!Locations/\?q=manchester!, url) assert_no_match(/query/, url) end @@ -61,7 +61,7 @@ def test_query_url_contains_address_with_spaces "manchester, lancashire", :region => "uk" )) - assert_match(/Locations\/uk\?q=manchester,%20lancashire/, url) + assert_match(%r!Locations/uk/\?q=manchester,%20lancashire!, url) assert_no_match(/query/, url) end @@ -71,7 +71,7 @@ def test_query_url_contains_address_with_trailing_and_leading_spaces " manchester, lancashire ", :region => "uk" )) - assert_match(/Locations\/uk\?q=manchester,%20lancashire/, url) + assert_match(%r!Locations/uk/\?q=manchester,%20lancashire!, url) assert_no_match(/query/, url) end From 2216dccf2a0c1827ab7e287814ab57bab3b1d6dd Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 17:25:13 -0600 Subject: [PATCH 086/248] Refactor for readability. --- lib/geocoder/lookups/bing.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/geocoder/lookups/bing.rb b/lib/geocoder/lookups/bing.rb index 5dd0ddca6..acd18921c 100644 --- a/lib/geocoder/lookups/bing.rb +++ b/lib/geocoder/lookups/bing.rb @@ -23,17 +23,17 @@ def query_url(query) private # --------------------------------------------------------------- def base_url(query) + text = URI.escape(query.sanitized_text.strip) url = "#{protocol}://dev.virtualearth.net/REST/v1/Locations/" - - if !query.reverse_geocode? + if query.reverse_geocode? + url + "#{text}?" + else if r = query.options[:region] url << "#{r}/" end # use the more forgiving 'unstructured' query format to allow special # chars, newlines, brackets, typos. - url + "?q=" + URI.escape(query.sanitized_text.strip) + "&" - else - url + "#{URI.escape(query.sanitized_text.strip)}?" + url + "?q=#{text}&" end end From a318519c9f752a8778cdf2ff3a73aa373173e48e Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 17:25:35 -0600 Subject: [PATCH 087/248] Stop using URI.escape. Fixes #609. Bing seems to support this type of character escaping now. It's not discussed in their documentation but it works with every query I've tried so hopefully we're finally good on this issue. Also remove some unnecessary assertions from tests. --- lib/geocoder/lookups/bing.rb | 2 +- test/unit/lookups/bing_test.rb | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/geocoder/lookups/bing.rb b/lib/geocoder/lookups/bing.rb index acd18921c..269357774 100644 --- a/lib/geocoder/lookups/bing.rb +++ b/lib/geocoder/lookups/bing.rb @@ -23,7 +23,7 @@ def query_url(query) private # --------------------------------------------------------------- def base_url(query) - text = URI.escape(query.sanitized_text.strip) + text = CGI.escape(query.sanitized_text.strip) url = "#{protocol}://dev.virtualearth.net/REST/v1/Locations/" if query.reverse_geocode? url + "#{text}?" diff --git a/test/unit/lookups/bing_test.rb b/test/unit/lookups/bing_test.rb index 3531add54..9f28c109e 100644 --- a/test/unit/lookups/bing_test.rb +++ b/test/unit/lookups/bing_test.rb @@ -43,7 +43,6 @@ def test_query_url_contains_region :region => "uk" )) assert_match(%r!Locations/uk/\?q=manchester!, url) - assert_no_match(/query/, url) end def test_query_url_without_region @@ -52,27 +51,24 @@ def test_query_url_without_region "manchester" )) assert_match(%r!Locations/\?q=manchester!, url) - assert_no_match(/query/, url) end - def test_query_url_contains_address_with_spaces + def test_query_url_escapes_spaces_in_address lookup = Geocoder::Lookup::Bing.new url = lookup.query_url(Geocoder::Query.new( "manchester, lancashire", :region => "uk" )) - assert_match(%r!Locations/uk/\?q=manchester,%20lancashire!, url) - assert_no_match(/query/, url) + assert_match(%r!Locations/uk/\?q=manchester%2C\+lancashire!, url) end - def test_query_url_contains_address_with_trailing_and_leading_spaces + def test_query_url_strips_trailing_and_leading_spaces lookup = Geocoder::Lookup::Bing.new url = lookup.query_url(Geocoder::Query.new( " manchester, lancashire ", :region => "uk" )) - assert_match(%r!Locations/uk/\?q=manchester,%20lancashire!, url) - assert_no_match(/query/, url) + assert_match(%r!Locations/uk/\?q=manchester%2C\+lancashire!, url) end def test_raises_exception_when_service_unavailable From bf87abe75cfa909d48b2af66ce1b3a3be98654f2 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 19:19:19 -0600 Subject: [PATCH 088/248] Country code clarifications. --- README_API_GUIDE.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 26d5da82a..c7ca51b92 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -117,7 +117,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **API key**: optional, but without it lookup is territorially limited * **Quota**: 25000 requests / day -* **Region**: world with API key. Otherwise restricted to Russia, Ukraine, Belarus, Kazakhstan, Georgia, Abkhazia, South Ossetia, Armenia, Azerbaijan, Moldova, Turkmenistan, Tajikistan, Uzbekistan, Kyrgyzstan and Turkey +* **Region**: world with API key, else restricted to Russia, Ukraine, Belarus, Kazakhstan, Georgia, Abkhazia, South Ossetia, Armenia, Azerbaijan, Moldova, Turkmenistan, Tajikistan, Uzbekistan, Kyrgyzstan and Turkey * **SSL support**: HTTPS only * **Languages**: Russian, Belarusian, Ukrainian, English, Turkish (only for maps of Turkey) * **Documentation**: http://api.yandex.com.tr/maps/doc/intro/concepts/intro.xml @@ -247,7 +247,7 @@ Data Science Toolkit provides an API whose response format is like Google's but * **API key**: required * **Quota**: 2,500 free requests/day then purchase $0.0005 for each, also has volume pricing and plans. -* **Region**: USA & Canada +* **Region**: US & Canada * **SSL support**: yes * **Languages**: en * **Documentation**: https://geocod.io/docs/ @@ -281,7 +281,7 @@ Data Science Toolkit provides an API whose response format is like Google's but * **API key**: none * **Quota**: none -* **Region**: LU +* **Region**: Luxembourg * **SSL support**: yes * **Languages**: en * **Documentation**: http://wiki.geoportail.lu/doku.php?id=en:api @@ -326,7 +326,7 @@ Data Science Toolkit provides an API whose response format is like Google's but * **API key**: none * **Quota**: none -* **Region**: FR +* **Region**: France * **SSL support**: yes * **Languages**: en / fr * **Documentation**: https://adresse.data.gouv.fr/api/ (in french) From 3375c03f5900cab9063a7b50f32e7884401f6eb2 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 19:21:25 -0600 Subject: [PATCH 089/248] Remove :okf lookup. Appears to be defunct. --- README_API_GUIDE.md | 12 ---- lib/geocoder/lookup.rb | 1 - lib/geocoder/lookups/okf.rb | 44 ------------- lib/geocoder/results/okf.rb | 106 ------------------------------- test/fixtures/okf_kirstinmaki | 67 ------------------- test/fixtures/okf_no_results | 4 -- test/test_helper.rb | 8 --- test/unit/error_handling_test.rb | 4 +- test/unit/lookups/okf_test.rb | 37 ----------- 9 files changed, 2 insertions(+), 281 deletions(-) delete mode 100644 lib/geocoder/lookups/okf.rb delete mode 100644 lib/geocoder/results/okf.rb delete mode 100644 test/fixtures/okf_kirstinmaki delete mode 100644 test/fixtures/okf_no_results delete mode 100644 test/unit/lookups/okf_test.rb diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index c7ca51b92..046279151 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -265,18 +265,6 @@ Data Science Toolkit provides an API whose response format is like Google's but * **Terms of Service**: http://smartystreets.com/legal/terms-of-service * **Limitations**: No reverse geocoding. - -### OKF Geocoder (`:okf`) - -* **API key**: none -* **Quota**: none -* **Region**: FI -* **SSL support**: no -* **Languages**: fi -* **Documentation**: http://books.okf.fi/geocoder/_full/ -* **Terms of Service**: http://www.itella.fi/liitteet/palvelutjatuotteet/yhteystietopalvelut/Postinumeropalvelut-Palvelukuvausjakayttoehdot.pdf -* **Limitations**: ? - ### Geoportail.lu (`:geoportail_lu`) * **API key**: none diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index baa85c9d2..df284da44 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -45,7 +45,6 @@ def street_services :baidu, :geocodio, :smarty_streets, - :okf, :postcode_anywhere_uk, :postcodes_io, :geoportail_lu, diff --git a/lib/geocoder/lookups/okf.rb b/lib/geocoder/lookups/okf.rb deleted file mode 100644 index 54909bb2d..000000000 --- a/lib/geocoder/lookups/okf.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'geocoder/lookups/base' -require "geocoder/results/okf" - -module Geocoder::Lookup - class Okf < Base - - def name - "Okf" - end - - def query_url(query) - "#{protocol}://data.okf.fi/gis/1/geocode/json?" + url_query_string(query) - end - - private # --------------------------------------------------------------- - - def valid_response?(response) - json = parse_json(response.body) - status = json["status"] if json - super(response) and ['OK', 'ZERO_RESULTS'].include?(status) - end - - def results(query) - return [] unless doc = fetch_data(query) - case doc['status']; when "OK" # OK status implies >0 results - return doc['results'] - end - return [] - end - - def query_url_okf_params(query) - params = { - (query.reverse_geocode? ? :latlng : :address) => query.sanitized_text, - :sensor => "false", - :language => (query.language || configuration.language) - } - params - end - - def query_url_params(query) - query_url_okf_params(query).merge(super) - end - end -end diff --git a/lib/geocoder/results/okf.rb b/lib/geocoder/results/okf.rb deleted file mode 100644 index 973922591..000000000 --- a/lib/geocoder/results/okf.rb +++ /dev/null @@ -1,106 +0,0 @@ -require 'geocoder/results/base' - -module Geocoder::Result - class Okf < Base - - def coordinates - ['lat', 'lng'].map{ |i| geometry['location'][i] } - end - - def address(format = :full) - formatted_address - end - - def city - fields = [:locality, :sublocality, - :administrative_area_level_3, - :administrative_area_level_2] - fields.each do |f| - if entity = address_components_of_type(f).first - return entity['long_name'] - end - end - return nil # no appropriate components found - end - - def state - "" - end - - def sub_state - "" - end - - def state_code - "" - end - - def country - if country = address_components_of_type(:country).first - country['long_name'] - end - end - - def country_code - if country = address_components_of_type(:country).first - country['short_name'] - end - end - - def postal_code - if postal = address_components_of_type(:postal_code).first - postal['long_name'] - end - end - - def route - if route = address_components_of_type(:route).first - route['long_name'] - end - end - - def street_number - if street_number = address_components_of_type(:street_number).first - street_number['long_name'] - end - end - - def street_address - [route, street_number].compact.join(' ') - end - - def types - @data['types'] - end - - def formatted_address - @data['formatted_address'] - end - - def address_components - @data['address_components'] - end - - ## - # Get address components of a given type. Valid types are defined in - # Google's Geocoding API documentation and include (among others): - # - # :street_number - # :locality - # :neighborhood - # :route - # :postal_code - # - def address_components_of_type(type) - address_components.select{ |c| c['types'].include?(type.to_s) } - end - - def geometry - @data['geometry'] - end - - def precision - geometry['location_type'] if geometry - end - end -end diff --git a/test/fixtures/okf_kirstinmaki b/test/fixtures/okf_kirstinmaki deleted file mode 100644 index 79d50b963..000000000 --- a/test/fixtures/okf_kirstinmaki +++ /dev/null @@ -1,67 +0,0 @@ -{ - "status" : "OK", - "results" : [ - { - "formatted_address" : "Kirstinmäki 1, 02760 Espoo, Suomi", - "sources" : [ - { - "name" : "National Land Survey of Finland - Topographic Dataset (2013-03-08)", - "terms_of_use" : "National Land Survey open data licence - version 1.0 - 1 May 2012\nhttp://www.maanmittauslaitos.fi/en/NLS_open_data_licence_version1_20120501" - }, - { - "name" : "Itella perusosoitteisto (2014-02-01)", - "terms_of_use" : "http://www.itella.fi/liitteet/palvelutjatuotteet/yhteystietopalvelut/Postinumeropalvelut-Palvelukuvausjakayttoehdot.pdf" - } - ], - "types" : [ - "street_address" - ], - "address_components" : [ - { - "types" : [ - "street_number" - ], - "short_name" : "1", - "long_name" : "1" - }, - { - "types" : [ - "route" - ], - "short_name" : "Kirstinmäki", - "long_name" : "Kirstinmäki" - }, - { - "types" : [ - "administrative_area_level_3", - "political" - ], - "short_name" : "Espoo", - "long_name" : "Espoo" - }, - { - "types" : [ - "postal_code" - ], - "short_name" : "02760", - "long_name" : "02760" - }, - { - "types" : [ - "country", - "political" - ], - "short_name" : "FI", - "long_name" : "Suomi" - } - ], - "geometry" : { - "location" : { - "lat" : 60.2015185792087, - "lng" : 24.6667520050026 - }, - "location_type" : "RANGE_INTERPOLATED" - } - } - ] -} diff --git a/test/fixtures/okf_no_results b/test/fixtures/okf_no_results deleted file mode 100644 index 184b56dea..000000000 --- a/test/fixtures/okf_no_results +++ /dev/null @@ -1,4 +0,0 @@ -{ - "status" : "ZERO_RESULTS", - "results" : [] -} diff --git a/test/test_helper.rb b/test/test_helper.rb index 1f67af1bb..627495658 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -318,14 +318,6 @@ def default_fixture_filename end end - require 'geocoder/lookups/okf' - class Okf - private - def default_fixture_filename - "okf_kirstinmaki" - end - end - require 'geocoder/lookups/postcode_anywhere_uk' class PostcodeAnywhereUk private diff --git a/test/unit/error_handling_test.rb b/test/unit/error_handling_test.rb index 689d1fe56..00066a3f5 100644 --- a/test/unit/error_handling_test.rb +++ b/test/unit/error_handling_test.rb @@ -19,7 +19,7 @@ def test_does_not_choke_on_timeout def test_always_raise_response_parse_error Geocoder.configure(:always_raise => [Geocoder::ResponseParseError]) - [:freegeoip, :google, :ipdata_co, :okf].each do |l| + [:freegeoip, :google, :ipdata_co].each do |l| lookup = Geocoder::Lookup.get(l) set_api_key!(l) assert_raises Geocoder::ResponseParseError do @@ -29,7 +29,7 @@ def test_always_raise_response_parse_error end def test_never_raise_response_parse_error - [:freegeoip, :google, :ipdata_co, :okf].each do |l| + [:freegeoip, :google, :ipdata_co].each do |l| lookup = Geocoder::Lookup.get(l) set_api_key!(l) silence_warnings do diff --git a/test/unit/lookups/okf_test.rb b/test/unit/lookups/okf_test.rb deleted file mode 100644 index b05cce85d..000000000 --- a/test/unit/lookups/okf_test.rb +++ /dev/null @@ -1,37 +0,0 @@ -# encoding: utf-8 -require 'test_helper' - -class OkfTest < GeocoderTestCase - - def setup - Geocoder.configure(lookup: :okf) - end - - def test_okf_result_components - result = Geocoder.search("Kirstinmäki 11b28").first - assert_equal "Espoo", - result.address_components_of_type(:administrative_area_level_3).first['long_name'] - end - - def test_okf_result_components_contains_route - result = Geocoder.search("Kirstinmäki 11b28").first - assert_equal "Kirstinmäki", - result.address_components_of_type(:route).first['long_name'] - end - - def test_okf_result_components_contains_street_number - result = Geocoder.search("Kirstinmäki 11b28").first - assert_equal "1", - result.address_components_of_type(:street_number).first['long_name'] - end - - def test_okf_street_address_returns_formatted_street_address - result = Geocoder.search("Kirstinmäki 11b28").first - assert_equal "Kirstinmäki 1", result.street_address - end - - def test_okf_precision - result = Geocoder.search("Kirstinmäki 11b28").first - assert_equal "RANGE_INTERPOLATED", result.precision - end -end From e4f610db0cc49be9394b045e85afee5642272088 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 19:45:03 -0600 Subject: [PATCH 090/248] Don't depend on methods provided by Rails. Culprits: .present? and .try --- lib/geocoder/results/geoportail_lu.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/geocoder/results/geoportail_lu.rb b/lib/geocoder/results/geoportail_lu.rb index eeccb34b6..48521ea39 100644 --- a/lib/geocoder/results/geoportail_lu.rb +++ b/lib/geocoder/results/geoportail_lu.rb @@ -59,11 +59,13 @@ def detailled_address private def geolocalized? - try_to_extract('coordinates', geomlonlat).present? + !!try_to_extract('coordinates', geomlonlat) end - def try_to_extract(key, nullable_hash) - nullable_hash.try(:[], key) + def try_to_extract(key, hash) + if hash.is_a?(Hash) and hash.include?(key) + hash[key] + end end end end From ff129508fad6465ebc437842d09f2a3c09428337 Mon Sep 17 00:00:00 2001 From: Ed Freyfogle <freyfogle@users.noreply.github.com> Date: Tue, 19 Jun 2018 16:46:52 +0200 Subject: [PATCH 091/248] OpenCage website URLs have changed --- README_API_GUIDE.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 046279151..5f83d5568 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -105,12 +105,12 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ ### OpenCageData (`:opencagedata`) * **API key**: required -* **Key signup**: http://geocoder.opencagedata.com -* **Quota**: 2500 requests / day, then [ability to purchase more](https://geocoder.opencagedata.com/pricing) +* **Key signup**: https://opencagedata.com +* **Quota**: 2500 requests / day, then [ability to purchase more](https://opencagedata.com/pricing) * **Region**: world * **SSL support**: yes * **Languages**: worldwide -* **Documentation**: http://geocoder.opencagedata.com/api.html +* **Documentation**: https://opencagedata.com/api * **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) ### Yandex (`:yandex`) From 22051b907e3b6f18d5c9c82011aa080b890cd03d Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Tue, 19 Jun 2018 09:33:22 -0600 Subject: [PATCH 092/248] More README cleanup. --- README.md | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index c99f20069..69d8ef5a4 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Advanced Features: * [Performance and Optimization](#performance-and-optimization) * [Advanced Model Configuration](#advanced-model-configuration) * [Advanced Database Queries](#advanced-database-queries) +* [Geospatial Calculations](#geospatial-calculations) * [Batch Geocoding](#batch-geocoding) * [Testing](#testing) * [Error Handling](#error-handing) @@ -159,10 +160,6 @@ To find objects by location, use the following scopes: Venue.geocoded # venues with coordinates Venue.not_geocoded # venues without coordinates -by default, objects are ordered by distance. To remove the ORDER BY clause use the following: - - Venue.near('Omaha', 20, order: false) - With geocoded objects you can do things like this: if obj.geocoded? @@ -171,22 +168,6 @@ With geocoded objects you can do things like this: obj.bearing_to("Paris, France") # direction from object to arbitrary point end -Some utility methods are also available: - - # look up coordinates of some location - Geocoder.coordinates("25 Main St, Cooperstown, NY") - => [42.700149, -74.922767] - - # distance between Eiffel Tower and Empire State Building - Geocoder::Calculations.distance_between([47.858205,2.294359], [40.748433,-73.985655]) - => 3619.77359999382 # in configured units (default miles) - - # find the geographic center (aka center of gravity) of objects or points - Geocoder::Calculations.geographic_center([city1, city2, [40.22,-73.99], city4]) - => [35.14968, -90.048929] - -Please see the code for more methods and detailed information about arguments (eg, working with kilometers). - ### For MongoDB-backed models: Please do not use Geocoder's `near` method. Instead use MongoDB's built-in [geospatial query language](https://docs.mongodb.org/manual/reference/command/geoNear/), which is faster. Mongoid also provides [a DSL](http://mongoid.github.io/en/mongoid/docs/querying.html#geo_near) for geospatial queries. @@ -469,7 +450,7 @@ Results are automatically sorted by distance from the search point, closest to f * `230.1` - southwest * `359.9` - almost due north -You can convert these to compass point names via provided utility method: +You can convert these to compass point names via provided method: Geocoder::Calculations.compass_point(355) # => "N" Geocoder::Calculations.compass_point(45) # => "NE" @@ -477,6 +458,24 @@ You can convert these to compass point names via provided utility method: _Note: when running queries on SQLite, `distance` and `bearing` are provided for consistency only. They are not very accurate._ +For more advanced geospatial querying, please see the [rgeo gem](https://github.com/rgeo/rgeo). + + +Geospatial Calculations +----------------------- + +The `Geocoder::Calculations` module contains some useful methods: + + # find the distance between two arbitrary points + Geocoder::Calculations.distance_between([47.858205,2.294359], [40.748433,-73.985655]) + => 3619.77359999382 # in configured units (default miles) + + # find the geographic center (aka center of gravity) of objects or points + Geocoder::Calculations.geographic_center([city1, city2, [40.22,-73.99], city4]) + => [35.14968, -90.048929] + +See [the code](https://github.com/alexreisner/geocoder/blob/master/lib/geocoder/calculations.rb) for more! + Batch Geocoding --------------- From 89976570c2ce5b2291687318ea3ed2a1f61b810a Mon Sep 17 00:00:00 2001 From: Jon Rowe <mail@jonrowe.co.uk> Date: Tue, 26 Jun 2018 08:49:07 +0400 Subject: [PATCH 093/248] Add error details --- lib/geocoder/lookups/google.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/geocoder/lookups/google.rb b/lib/geocoder/lookups/google.rb index d048a2639..4c1fff07f 100644 --- a/lib/geocoder/lookups/google.rb +++ b/lib/geocoder/lookups/google.rb @@ -52,11 +52,11 @@ def results(query) raise_error(Geocoder::OverQueryLimitError) || Geocoder.log(:warn, "#{name} API error: over query limit.") when "REQUEST_DENIED" - raise_error(Geocoder::RequestDenied) || - Geocoder.log(:warn, "#{name} API error: request denied.") + raise_error(Geocoder::RequestDenied, doc['error_message']) || + Geocoder.log(:warn, "#{name} API error: request denied, google returned '#{doc['error_message']}'.") when "INVALID_REQUEST" - raise_error(Geocoder::InvalidRequest) || - Geocoder.log(:warn, "#{name} API error: invalid request.") + raise_error(Geocoder::InvalidRequest, doc['error_message']) || + Geocoder.log(:warn, "#{name} API error: invalid request, google returned '#{doc['error_message']}'.") end return [] end From 12dded6886a5ec0f537cc8de236726e524544677 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 27 Jun 2018 09:36:54 -0600 Subject: [PATCH 094/248] Error message formatting (for consistency). --- lib/geocoder/lookups/google.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/geocoder/lookups/google.rb b/lib/geocoder/lookups/google.rb index 4c1fff07f..a9aff2580 100644 --- a/lib/geocoder/lookups/google.rb +++ b/lib/geocoder/lookups/google.rb @@ -53,10 +53,10 @@ def results(query) Geocoder.log(:warn, "#{name} API error: over query limit.") when "REQUEST_DENIED" raise_error(Geocoder::RequestDenied, doc['error_message']) || - Geocoder.log(:warn, "#{name} API error: request denied, google returned '#{doc['error_message']}'.") + Geocoder.log(:warn, "#{name} API error: request denied (#{doc['error_message']}).") when "INVALID_REQUEST" raise_error(Geocoder::InvalidRequest, doc['error_message']) || - Geocoder.log(:warn, "#{name} API error: invalid request, google returned '#{doc['error_message']}'.") + Geocoder.log(:warn, "#{name} API error: invalid request (#{doc['error_message']}).") end return [] end From 5d92d0b5a423e0a061d15049b7011631914465d1 Mon Sep 17 00:00:00 2001 From: James Wozniak <wozza35@hotmail.com> Date: Sun, 22 Jul 2018 18:39:43 +0100 Subject: [PATCH 095/248] Update Railtie initializer to run before config intializers --- lib/geocoder/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/railtie.rb b/lib/geocoder/railtie.rb index ec1113170..809d6f236 100644 --- a/lib/geocoder/railtie.rb +++ b/lib/geocoder/railtie.rb @@ -4,7 +4,7 @@ module Geocoder if defined? Rails::Railtie require 'rails' class Railtie < Rails::Railtie - initializer 'geocoder.insert_into_active_record' do + initializer 'geocoder.insert_into_active_record', before: :load_config_initializers do ActiveSupport.on_load :active_record do Geocoder::Railtie.insert end From 41a8c9c9d0e403553867b9eeda9762fe976b180d Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 25 Jul 2018 08:45:12 -0400 Subject: [PATCH 096/248] Update README with changes to Google's API. --- README_API_GUIDE.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 5f83d5568..cec0bd091 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -15,9 +15,9 @@ Street Address Lookups ### Google (`:google`) -* **API key**: optional, but quota is higher if key is used (use of key requires HTTPS so be sure to set: `use_https: true` in `Geocoder.configure`) -* **Key signup**: https://console.developers.google.com/flows/enableapi?apiid=geocoding_backend&keyType=SERVER_SIDE -* **Quota**: 2,500 requests/24 hrs, 5 requests/second +* **API key**: required +* **Key signup**: https://developers.google.com/maps/documentation/geocoding/usage-and-billing +* **Quota**: pay-as-you-go pricing; 50 requests/second * **Region**: world * **SSL support**: yes (required if key is used) * **Languages**: see https://developers.google.com/maps/faq#languagesupport @@ -33,7 +33,7 @@ Street Address Lookups Similar to `:google`, with the following differences: * **API key**: required, plus client and channel (set `Geocoder.configure(lookup: :google_premier, api_key: [key, client, channel])`) -* **Key signup**: https://developers.google.com/maps/documentation/business/ +* **Key signup**: https://developers.google.com/maps/premium/ * **Quota**: 100,000 requests/24 hrs, 10 requests/second ### Google Places Details (`:google_places_details`) From 0269d33a6b4e7a007cb8203e151f76fe6aada82b Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 27 Jul 2018 10:48:26 -0400 Subject: [PATCH 097/248] Update README and test response for Geocoder.ca. --- README_API_GUIDE.md | 4 ++-- test/fixtures/geocoder_ca_madison_square_garden | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index cec0bd091..e9c0c0a8e 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -128,10 +128,10 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **API key**: none * **Quota**: ? -* **Region**: US and Canada +* **Region**: US, Canada, Mexico * **SSL support**: no * **Languages**: English -* **Documentation**: ? +* **Documentation**: https://geocoder.ca/?premium_api=1 * **Terms of Service**: http://geocoder.ca/?terms=1 * **Limitations**: "Under no circumstances can our data be re-distributed or re-sold by anyone to other parties without our written permission." diff --git a/test/fixtures/geocoder_ca_madison_square_garden b/test/fixtures/geocoder_ca_madison_square_garden index 7592108f6..b7bb6b720 100644 --- a/test/fixtures/geocoder_ca_madison_square_garden +++ b/test/fixtures/geocoder_ca_madison_square_garden @@ -1 +1 @@ -test({"longt":"-73.992006","latt":"40.749101"}); +test({ "standard" : { "staddress" : "Madison Square Garden", "stnumber" : "1", "prov" : "NY", "city" : "New York", "confidence" : "0.9" }, "longt" : "-73.994240", "latt" : "40.750050"}); From bc04354c0533e8f6a6afae8e93c17da8ca0b1a2d Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 27 Jul 2018 10:52:08 -0400 Subject: [PATCH 098/248] Check req'd attrs for both forward and reverse. --- test/unit/result_test.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/unit/result_test.rb b/test/unit/result_test.rb index ecb31377d..c87f7fd2c 100644 --- a/test/unit/result_test.rb +++ b/test/unit/result_test.rb @@ -3,7 +3,16 @@ class ResultTest < GeocoderTestCase - def test_result_has_required_attributes + def test_forward_geocoding_result_has_required_attributes + Geocoder::Lookup.all_services_except_test.each do |l| + Geocoder.configure(:lookup => l) + set_api_key!(l) + result = Geocoder.search("Madison Square Garden").first + assert_result_has_required_attributes(result) + end + end + + def test_reverse_geocoding_result_has_required_attributes Geocoder::Lookup.all_services_except_test.each do |l| Geocoder.configure(:lookup => l) set_api_key!(l) From 2267c534d0373e891a7016fb411e465c5943d16b Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 27 Jul 2018 11:08:56 -0400 Subject: [PATCH 099/248] Fix missing attributes in some Result classes. --- lib/geocoder/results/baidu.rb | 20 ++++++++++---------- lib/geocoder/results/bing.rb | 2 +- lib/geocoder/results/geocoder_ca.rb | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/geocoder/results/baidu.rb b/lib/geocoder/results/baidu.rb index 62fbc6f1d..b30265e56 100644 --- a/lib/geocoder/results/baidu.rb +++ b/lib/geocoder/results/baidu.rb @@ -11,34 +11,34 @@ def address @data['formatted_address'] end - def state - province - end - def province - @data['addressComponent']['province'] + @data['addressComponent'] and @data['addressComponent']['province'] or "" end + alias_method :state, :province + def city - @data['addressComponent']['city'] + @data['addressComponent'] and @data['addressComponent']['city'] or "" end def district - @data['addressComponent']['district'] + @data['addressComponent'] and @data['addressComponent']['district'] or "" end def street - @data['addressComponent']['street'] + @data['addressComponent'] and @data['addressComponent']['street'] or "" end def street_number - @data['addressComponent']['street_number'] + @data['addressComponent'] and @data['addressComponent']['street_number'] end def formatted_address - @data['formatted_address'] + @data['formatted_address'] or "" end + alias_method :address, :formatted_address + def address_components @data['addressComponent'] end diff --git a/lib/geocoder/results/bing.rb b/lib/geocoder/results/bing.rb index 77b5eee34..ea184e397 100644 --- a/lib/geocoder/results/bing.rb +++ b/lib/geocoder/results/bing.rb @@ -24,7 +24,7 @@ def country alias_method :country_code, :country def postal_code - @data['address']['postalCode'] + @data['address']['postalCode'].to_s end def coordinates diff --git a/lib/geocoder/results/geocoder_ca.rb b/lib/geocoder/results/geocoder_ca.rb index 4edb80a83..c16ec5a33 100644 --- a/lib/geocoder/results/geocoder_ca.rb +++ b/lib/geocoder/results/geocoder_ca.rb @@ -16,17 +16,17 @@ def street_address end def city - @data['city'] + @data['city'] or (@data['standard'] and @data['standard']['city']) or "" end def state - @data['prov'] + @data['prov'] or (@data['standard'] and @data['standard']['prov']) or "" end alias_method :state_code, :state def postal_code - @data['postal'] + @data['postal'] or (@data['standard'] and @data['standard']['postal']) or "" end def country From b8a9cf4cc70051dabe5634ee3d9ca6172b01ff18 Mon Sep 17 00:00:00 2001 From: ip2location <support@ip2location.com> Date: Thu, 26 Jul 2018 14:07:24 +0800 Subject: [PATCH 100/248] Add IP2Location Web Service. --- README_API_GUIDE.md | 11 ++ lib/geocoder/lookup.rb | 1 + lib/geocoder/lookups/ip2location_api.rb | 73 +++++++++++++ lib/geocoder/results/ip2location_api.rb | 101 ++++++++++++++++++ test/fixtures/ip2location_api_8_8_8_8 | 22 ++++ test/fixtures/ip2location_api_invalid_api_key | 3 + test/unit/lookups/ip2location_api_test.rb | 25 +++++ 7 files changed, 236 insertions(+) create mode 100644 lib/geocoder/lookups/ip2location_api.rb create mode 100644 lib/geocoder/results/ip2location_api.rb create mode 100644 test/fixtures/ip2location_api_8_8_8_8 create mode 100644 test/fixtures/ip2location_api_invalid_api_key create mode 100644 test/unit/lookups/ip2location_api_test.rb diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index e9c0c0a8e..1a6ce9dbd 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -463,6 +463,17 @@ IP Address Lookups * **Terms of Service**: https://ipdata.co/terms.html * **Limitations**: ? +### IP2Location Web Service (`:ip2location_api`) + +* **API key**: optional, see: https://www.ip2location.com/web-service +* **Quota**: 20 query/day (up to 100k credits with paid API key) +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://www.ip2location.com/web-service +* **Terms of Service**: https://www.ip2location.com/web-service +* **Notes**: To use IP2Location Web Service with API Key set `Geocoder.configure(:ip_lookup => :ip2location_api, :api_key => "IP2LOCATION_WEB_SERVICE_API_KEY")`. Supports the optional param :package with `Geocoder.configure(:ip2location_api => {:package => "WSX"})` (see API documentation for package offered in details). + Local IP Address Lookups ------------------------ diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index df284da44..e9802d073 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -73,6 +73,7 @@ def ip_services :ipdata_co, :db_ip_com, :ipstack, + :ip2location_api, ] end diff --git a/lib/geocoder/lookups/ip2location_api.rb b/lib/geocoder/lookups/ip2location_api.rb new file mode 100644 index 000000000..5650fe743 --- /dev/null +++ b/lib/geocoder/lookups/ip2location_api.rb @@ -0,0 +1,73 @@ +require 'geocoder/lookups/base' +require 'geocoder/results/ip2location_api' + +module Geocoder::Lookup + class Ip2locationApi < Base + + def name + "IP2LocationApi" + end + + def query_url(query) + api_key = configuration.api_key ? configuration.api_key : "demo" + url_ = "#{protocol}://api.ip2location.com/?ip=#{query.sanitized_text}&key=#{api_key}&format=json" + + if (params = url_query_string(query)) && !params.empty? + url_ + "&" + params + else + url_ + end + end + + def supported_protocols + [:http, :https] + end + + private + + def results(query) + return [reserved_result(query.text)] if query.loopback_ip_address? + + return [] unless doc = fetch_data(query) + + if doc["response"] == "INVALID ACCOUNT" + raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "INVALID ACCOUNT") + return [] + else + return [doc] + end + end + + def reserved_result(query) + { + "country_code" => "INVALID IP ADDRESS", + "country_name" => "INVALID IP ADDRESS", + "region_name" => "INVALID IP ADDRESS", + "city_name" => "INVALID IP ADDRESS", + "latitude" => "INVALID IP ADDRESS", + "longitude" => "INVALID IP ADDRESS", + "zip_code" => "INVALID IP ADDRESS", + "time_zone" => "INVALID IP ADDRESS", + "isp" => "INVALID IP ADDRESS", + "domain" => "INVALID IP ADDRESS", + "net_speed" => "INVALID IP ADDRESS", + "idd_code" => "INVALID IP ADDRESS", + "area_code" => "INVALID IP ADDRESS", + "weather_station_code" => "INVALID IP ADDRESS", + "weather_station_name" => "INVALID IP ADDRESS", + "mcc" => "INVALID IP ADDRESS", + "mnc" => "INVALID IP ADDRESS", + "mobile_brand" => "INVALID IP ADDRESS", + "elevation" => "INVALID IP ADDRESS", + "usage_type" => "INVALID IP ADDRESS" + } + end + + def query_url_params(query) + params = {} + params.merge!(package: configuration[:package]) if configuration.has_key?(:package) + params.merge(super) + end + + end +end diff --git a/lib/geocoder/results/ip2location_api.rb b/lib/geocoder/results/ip2location_api.rb new file mode 100644 index 000000000..091580541 --- /dev/null +++ b/lib/geocoder/results/ip2location_api.rb @@ -0,0 +1,101 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class Ip2locationApi < Base + + def address(format = :full) + "#{city_name} #{zip_code}, #{country_name}".sub(/^[ ,]*/, '') + end + + def country_code + country_code + end + + def country_name + country_name + end + + def region_name + region_name + end + + def city_name + city_name + end + + def latitude + latitude + end + + def longitude + longitude + end + + def zip_code + zip_code + end + + def time_zone + time_zone + end + + def isp + isp + end + + def domain + domain + end + + def net_speed + net_speed + end + + def idd_code + idd_code + end + + def area_code + area_code + end + + def weather_station_code + weather_station_code + end + + def weather_station_name + weather_station_name + end + + def mcc + mcc + end + + def mnc + mnc + end + + def mobile_brand + mobile_brand + end + + def elevation + elevation + end + + def usage_type + usage_type + end + + def self.response_attributes + %w[country_code country_name region_name city_name latitude longitude zip_code time_zone isp domain net_speed idd_code area_code weather_station_code weather_station_name mcc mnc mobile_brand elevation usage_type] + end + + response_attributes.each do |attribute| + define_method attribute do + @data[attribute] + end + end + + end +end diff --git a/test/fixtures/ip2location_api_8_8_8_8 b/test/fixtures/ip2location_api_8_8_8_8 new file mode 100644 index 000000000..84d967d69 --- /dev/null +++ b/test/fixtures/ip2location_api_8_8_8_8 @@ -0,0 +1,22 @@ +{ + "country_code":"US", + "country_name":"United States", + "region_name":"California", + "city_name":"Mountain View", + "latitude":"37.405992", + "longitude":"-122.078515", + "zip_code":"94043", + "time_zone":"-07:00", + "isp":"Google LLC", + "domain":"google.com", + "net_speed":"T1", + "idd_code":"1", + "area_code":"650", + "weather_station_code":"USCA0746", + "weather_station_name":"Mountain View", + "mcc":"-", + "mnc":"-", + "mobile_brand":"-", + "elevation":"31", + "usage_type":"DCH" +} \ No newline at end of file diff --git a/test/fixtures/ip2location_api_invalid_api_key b/test/fixtures/ip2location_api_invalid_api_key new file mode 100644 index 000000000..698205b4f --- /dev/null +++ b/test/fixtures/ip2location_api_invalid_api_key @@ -0,0 +1,3 @@ +{ + "response":"INVALID ACCOUNT" +} \ No newline at end of file diff --git a/test/unit/lookups/ip2location_api_test.rb b/test/unit/lookups/ip2location_api_test.rb new file mode 100644 index 000000000..43f3c1284 --- /dev/null +++ b/test/unit/lookups/ip2location_api_test.rb @@ -0,0 +1,25 @@ +# encoding: utf-8 +require 'test_helper' + +class Ip2locationApiTest < GeocoderTestCase + + def test_ip2location_api_lookup_address + Geocoder.configure(:ip_lookup => :ip2location_api) + result = Geocoder.search("8.8.8.8").first + assert_equal "US", result.country_code + end + + def test_ip2location_api_lookup_loopback_address + Geocoder.configure(:ip_lookup => :ip2location_api) + result = Geocoder.search("127.0.0.1").first + assert_equal "INVALID IP ADDRESS", result.country_code + end + + def test_ip2location_api_extra_data + Geocoder.configure(:ip_lookup => :ip2location_api, :ip2location_api => {:package => "WS3"}) + result = Geocoder.search("8.8.8.8").first + assert_equal "United States", result.country_name + assert_equal "California", result.region_name + assert_equal "Mountain View", result.city_name + end +end From 7ea84fa37d46f43fc1cc1ff79a998b3d2dfa1234 Mon Sep 17 00:00:00 2001 From: ip2location <support@ip2location.com> Date: Fri, 27 Jul 2018 10:42:45 +0800 Subject: [PATCH 101/248] Update Result class and test. --- lib/geocoder/results/ip2location_api.rb | 50 +++++++++-------------- test/fixtures/ip2location_api_no_results | 0 test/unit/lookups/ip2location_api_test.rb | 8 ++-- 3 files changed, 25 insertions(+), 33 deletions(-) create mode 100644 test/fixtures/ip2location_api_no_results diff --git a/lib/geocoder/results/ip2location_api.rb b/lib/geocoder/results/ip2location_api.rb index 091580541..5b469af33 100644 --- a/lib/geocoder/results/ip2location_api.rb +++ b/lib/geocoder/results/ip2location_api.rb @@ -8,93 +8,83 @@ def address(format = :full) end def country_code - country_code + @data['country_code'] end def country_name - country_name + @data['country_name'] end def region_name - region_name + @data['region_name'] end def city_name - city_name + @data['city_name'] end def latitude - latitude + @data['latitude'] end def longitude - longitude + @data['longitude'] end def zip_code - zip_code + @data['zip_code'] end def time_zone - time_zone + @data['time_zone'] end def isp - isp + @data['isp'] end def domain - domain + @data['domain'] end def net_speed - net_speed + @data['net_speed'] end def idd_code - idd_code + @data['idd_code'] end def area_code - area_code + @data['area_code'] end def weather_station_code - weather_station_code + @data['weather_station_code'] end def weather_station_name - weather_station_name + @data['weather_station_name'] end def mcc - mcc + @data['mcc'] end def mnc - mnc + @data['mnc'] end def mobile_brand - mobile_brand + @data['mobile_brand'] end def elevation - elevation + @data['elevation'] end def usage_type - usage_type - end - - def self.response_attributes - %w[country_code country_name region_name city_name latitude longitude zip_code time_zone isp domain net_speed idd_code area_code weather_station_code weather_station_name mcc mnc mobile_brand elevation usage_type] - end - - response_attributes.each do |attribute| - define_method attribute do - @data[attribute] - end + @data['usage_type'] end end diff --git a/test/fixtures/ip2location_api_no_results b/test/fixtures/ip2location_api_no_results new file mode 100644 index 000000000..e69de29bb diff --git a/test/unit/lookups/ip2location_api_test.rb b/test/unit/lookups/ip2location_api_test.rb index 43f3c1284..6dab7372f 100644 --- a/test/unit/lookups/ip2location_api_test.rb +++ b/test/unit/lookups/ip2location_api_test.rb @@ -3,20 +3,22 @@ class Ip2locationApiTest < GeocoderTestCase - def test_ip2location_api_lookup_address + def setup Geocoder.configure(:ip_lookup => :ip2location_api) + end + + def test_ip2location_api_lookup_address result = Geocoder.search("8.8.8.8").first assert_equal "US", result.country_code end def test_ip2location_api_lookup_loopback_address - Geocoder.configure(:ip_lookup => :ip2location_api) result = Geocoder.search("127.0.0.1").first assert_equal "INVALID IP ADDRESS", result.country_code end def test_ip2location_api_extra_data - Geocoder.configure(:ip_lookup => :ip2location_api, :ip2location_api => {:package => "WS3"}) + Geocoder.configure(:ip2location_api => {:package => "WS3"}) result = Geocoder.search("8.8.8.8").first assert_equal "United States", result.country_name assert_equal "California", result.region_name From d6d29626f65f607fc7d23bc26330083bae7fc687 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 27 Jul 2018 11:09:32 -0400 Subject: [PATCH 102/248] Set default fixture for Ip2Location. --- test/test_helper.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 627495658..c7063990b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -217,6 +217,14 @@ def default_fixture_filename end end + require 'geocoder/lookups/ip2location_api' + class Ip2locationApi + private + def default_fixture_filename + "ip2location_api_8_8_8_8" + end + end + require 'geocoder/lookups/ipstack' class Ipstack private From 780089e533ceceb14c740c51370fc104a6d2b47d Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 27 Jul 2018 13:06:58 -0400 Subject: [PATCH 103/248] Remove "api" from lookup name (redundant). --- README_API_GUIDE.md | 4 ++-- lib/geocoder/lookup.rb | 2 +- .../lookups/{ip2location_api.rb => ip2location.rb} | 4 ++-- .../results/{ip2location_api.rb => ip2location.rb} | 2 +- .../{ip2location_api_8_8_8_8 => ip2location_8_8_8_8} | 0 ...i_invalid_api_key => ip2location_invalid_api_key} | 0 ...ocation_api_no_results => ip2location_no_results} | 0 test/test_helper.rb | 6 +++--- .../{ip2location_api_test.rb => ip2location_test.rb} | 12 ++++++------ 9 files changed, 15 insertions(+), 15 deletions(-) rename lib/geocoder/lookups/{ip2location_api.rb => ip2location.rb} (96%) rename lib/geocoder/results/{ip2location_api.rb => ip2location.rb} (97%) rename test/fixtures/{ip2location_api_8_8_8_8 => ip2location_8_8_8_8} (100%) rename test/fixtures/{ip2location_api_invalid_api_key => ip2location_invalid_api_key} (100%) rename test/fixtures/{ip2location_api_no_results => ip2location_no_results} (100%) rename test/unit/lookups/{ip2location_api_test.rb => ip2location_test.rb} (62%) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 1a6ce9dbd..da3db7c46 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -463,7 +463,7 @@ IP Address Lookups * **Terms of Service**: https://ipdata.co/terms.html * **Limitations**: ? -### IP2Location Web Service (`:ip2location_api`) +### IP2Location Web Service (`:ip2location`) * **API key**: optional, see: https://www.ip2location.com/web-service * **Quota**: 20 query/day (up to 100k credits with paid API key) @@ -472,7 +472,7 @@ IP Address Lookups * **Languages**: English * **Documentation**: https://www.ip2location.com/web-service * **Terms of Service**: https://www.ip2location.com/web-service -* **Notes**: To use IP2Location Web Service with API Key set `Geocoder.configure(:ip_lookup => :ip2location_api, :api_key => "IP2LOCATION_WEB_SERVICE_API_KEY")`. Supports the optional param :package with `Geocoder.configure(:ip2location_api => {:package => "WSX"})` (see API documentation for package offered in details). +* **Notes**: To use IP2Location Web Service with API Key set `Geocoder.configure(:ip_lookup => :ip2location, :api_key => "IP2LOCATION_WEB_SERVICE_API_KEY")`. Supports the optional param :package with `Geocoder.configure(:ip2location => {:package => "WSX"})` (see API documentation for package offered in details). Local IP Address Lookups diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index e9802d073..5ccae1022 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -73,7 +73,7 @@ def ip_services :ipdata_co, :db_ip_com, :ipstack, - :ip2location_api, + :ip2location ] end diff --git a/lib/geocoder/lookups/ip2location_api.rb b/lib/geocoder/lookups/ip2location.rb similarity index 96% rename from lib/geocoder/lookups/ip2location_api.rb rename to lib/geocoder/lookups/ip2location.rb index 5650fe743..019a6dad2 100644 --- a/lib/geocoder/lookups/ip2location_api.rb +++ b/lib/geocoder/lookups/ip2location.rb @@ -1,8 +1,8 @@ require 'geocoder/lookups/base' -require 'geocoder/results/ip2location_api' +require 'geocoder/results/ip2location' module Geocoder::Lookup - class Ip2locationApi < Base + class Ip2location < Base def name "IP2LocationApi" diff --git a/lib/geocoder/results/ip2location_api.rb b/lib/geocoder/results/ip2location.rb similarity index 97% rename from lib/geocoder/results/ip2location_api.rb rename to lib/geocoder/results/ip2location.rb index 5b469af33..f6cbf74ef 100644 --- a/lib/geocoder/results/ip2location_api.rb +++ b/lib/geocoder/results/ip2location.rb @@ -1,7 +1,7 @@ require 'geocoder/results/base' module Geocoder::Result - class Ip2locationApi < Base + class Ip2location < Base def address(format = :full) "#{city_name} #{zip_code}, #{country_name}".sub(/^[ ,]*/, '') diff --git a/test/fixtures/ip2location_api_8_8_8_8 b/test/fixtures/ip2location_8_8_8_8 similarity index 100% rename from test/fixtures/ip2location_api_8_8_8_8 rename to test/fixtures/ip2location_8_8_8_8 diff --git a/test/fixtures/ip2location_api_invalid_api_key b/test/fixtures/ip2location_invalid_api_key similarity index 100% rename from test/fixtures/ip2location_api_invalid_api_key rename to test/fixtures/ip2location_invalid_api_key diff --git a/test/fixtures/ip2location_api_no_results b/test/fixtures/ip2location_no_results similarity index 100% rename from test/fixtures/ip2location_api_no_results rename to test/fixtures/ip2location_no_results diff --git a/test/test_helper.rb b/test/test_helper.rb index c7063990b..d6243a919 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -217,11 +217,11 @@ def default_fixture_filename end end - require 'geocoder/lookups/ip2location_api' - class Ip2locationApi + require 'geocoder/lookups/ip2location' + class Ip2location private def default_fixture_filename - "ip2location_api_8_8_8_8" + "ip2location_8_8_8_8" end end diff --git a/test/unit/lookups/ip2location_api_test.rb b/test/unit/lookups/ip2location_test.rb similarity index 62% rename from test/unit/lookups/ip2location_api_test.rb rename to test/unit/lookups/ip2location_test.rb index 6dab7372f..392282208 100644 --- a/test/unit/lookups/ip2location_api_test.rb +++ b/test/unit/lookups/ip2location_test.rb @@ -1,24 +1,24 @@ # encoding: utf-8 require 'test_helper' -class Ip2locationApiTest < GeocoderTestCase +class Ip2locationTest < GeocoderTestCase def setup - Geocoder.configure(:ip_lookup => :ip2location_api) + Geocoder.configure(:ip_lookup => :ip2location) end - def test_ip2location_api_lookup_address + def test_ip2location_lookup_address result = Geocoder.search("8.8.8.8").first assert_equal "US", result.country_code end - def test_ip2location_api_lookup_loopback_address + def test_ip2location_lookup_loopback_address result = Geocoder.search("127.0.0.1").first assert_equal "INVALID IP ADDRESS", result.country_code end - def test_ip2location_api_extra_data - Geocoder.configure(:ip2location_api => {:package => "WS3"}) + def test_ip2location_extra_data + Geocoder.configure(:ip2location => {:package => "WS3"}) result = Geocoder.search("8.8.8.8").first assert_equal "United States", result.country_name assert_equal "California", result.region_name From 20a8c016cab24bee06b8ba2ffe7ca5c034da0a2e Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 27 Jul 2018 13:13:14 -0400 Subject: [PATCH 104/248] Exempt ip2location from attribute tests. --- test/unit/result_test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unit/result_test.rb b/test/unit/result_test.rb index c87f7fd2c..eeb579ee8 100644 --- a/test/unit/result_test.rb +++ b/test/unit/result_test.rb @@ -5,6 +5,7 @@ class ResultTest < GeocoderTestCase def test_forward_geocoding_result_has_required_attributes Geocoder::Lookup.all_services_except_test.each do |l| + next if l == :ip2location # has pay-per-attribute pricing model Geocoder.configure(:lookup => l) set_api_key!(l) result = Geocoder.search("Madison Square Garden").first @@ -14,6 +15,7 @@ def test_forward_geocoding_result_has_required_attributes def test_reverse_geocoding_result_has_required_attributes Geocoder::Lookup.all_services_except_test.each do |l| + next if l == :ip2location # has pay-per-attribute pricing model Geocoder.configure(:lookup => l) set_api_key!(l) result = Geocoder.search([45.423733, -75.676333]).first From e329eb36a1a8eb38d2bf2849fea8ca2fcdf95800 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 27 Jul 2018 13:26:09 -0400 Subject: [PATCH 105/248] Refactor code to follow gem's typical style. --- README_API_GUIDE.md | 8 +-- lib/geocoder/lookups/ip2location.rb | 22 ++++---- lib/geocoder/results/ip2location.rb | 85 +++-------------------------- 3 files changed, 23 insertions(+), 92 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index da3db7c46..cf1a5ebc5 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -463,16 +463,16 @@ IP Address Lookups * **Terms of Service**: https://ipdata.co/terms.html * **Limitations**: ? -### IP2Location Web Service (`:ip2location`) +### IP2Location (`:ip2location`) -* **API key**: optional, see: https://www.ip2location.com/web-service -* **Quota**: 20 query/day (up to 100k credits with paid API key) +* **API key**: optional (20 free demo queries per day) +* **Quota**: up to 100k credits with paid API key * **Region**: world * **SSL support**: yes * **Languages**: English * **Documentation**: https://www.ip2location.com/web-service * **Terms of Service**: https://www.ip2location.com/web-service -* **Notes**: To use IP2Location Web Service with API Key set `Geocoder.configure(:ip_lookup => :ip2location, :api_key => "IP2LOCATION_WEB_SERVICE_API_KEY")`. Supports the optional param :package with `Geocoder.configure(:ip2location => {:package => "WSX"})` (see API documentation for package offered in details). +* **Notes**: With the non-free version, specify your desired package: `Geocoder.configure(ip2location: {package: "WSX"})` (see API documentation for package details). Local IP Address Lookups diff --git a/lib/geocoder/lookups/ip2location.rb b/lib/geocoder/lookups/ip2location.rb index 019a6dad2..56eab4a2e 100644 --- a/lib/geocoder/lookups/ip2location.rb +++ b/lib/geocoder/lookups/ip2location.rb @@ -10,26 +10,24 @@ def name def query_url(query) api_key = configuration.api_key ? configuration.api_key : "demo" - url_ = "#{protocol}://api.ip2location.com/?ip=#{query.sanitized_text}&key=#{api_key}&format=json" + url = "#{protocol}://api.ip2location.com/?ip=#{query.sanitized_text}&key=#{api_key}&format=json" - if (params = url_query_string(query)) && !params.empty? - url_ + "&" + params - else - url_ + if (params = url_query_string(query)) and !params.empty? + url << "&" + params end + + url end def supported_protocols [:http, :https] end - private + private # ---------------------------------------------------------------- def results(query) return [reserved_result(query.text)] if query.loopback_ip_address? - return [] unless doc = fetch_data(query) - if doc["response"] == "INVALID ACCOUNT" raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "INVALID ACCOUNT") return [] @@ -64,9 +62,11 @@ def reserved_result(query) end def query_url_params(query) - params = {} - params.merge!(package: configuration[:package]) if configuration.has_key?(:package) - params.merge(super) + params = super + if configuration.has_key?(:package) + params.merge!(package: configuration[:package]) + end + params end end diff --git a/lib/geocoder/results/ip2location.rb b/lib/geocoder/results/ip2location.rb index f6cbf74ef..57d0c1785 100644 --- a/lib/geocoder/results/ip2location.rb +++ b/lib/geocoder/results/ip2location.rb @@ -7,85 +7,16 @@ def address(format = :full) "#{city_name} #{zip_code}, #{country_name}".sub(/^[ ,]*/, '') end - def country_code - @data['country_code'] + def self.response_attributes + %w[country_code country_name region_name city_name latitude longitude + zip_code time_zone isp domain net_speed idd_code area_code usage_type + weather_station_code weather_station_name mcc mnc mobile_brand elevation] end - def country_name - @data['country_name'] + response_attributes.each do |attr| + define_method attr do + @data[attr] || "" + end end - - def region_name - @data['region_name'] - end - - def city_name - @data['city_name'] - end - - def latitude - @data['latitude'] - end - - def longitude - @data['longitude'] - end - - def zip_code - @data['zip_code'] - end - - def time_zone - @data['time_zone'] - end - - def isp - @data['isp'] - end - - def domain - @data['domain'] - end - - def net_speed - @data['net_speed'] - end - - def idd_code - @data['idd_code'] - end - - def area_code - @data['area_code'] - end - - def weather_station_code - @data['weather_station_code'] - end - - def weather_station_name - @data['weather_station_name'] - end - - def mcc - @data['mcc'] - end - - def mnc - @data['mnc'] - end - - def mobile_brand - @data['mobile_brand'] - end - - def elevation - @data['elevation'] - end - - def usage_type - @data['usage_type'] - end - end end From e114787734a70acaa841e0a854941e6b1a48b079 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 15 Jun 2018 16:47:28 -0600 Subject: [PATCH 106/248] Structure Test result data like other results, viz: add `coordinates` attribute and remove `latitude` and `longitude`. Fixes #1258 and #1302. --- README.md | 2 +- lib/geocoder/results/test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 69d8ef5a4..cfe71199f 100644 --- a/README.md +++ b/README.md @@ -536,7 +536,7 @@ With the above stub defined, any query for "New York, NY" will return the result Notes: -- Keys must be strings not symbols when calling `add_stub` or `set_default_stub`. For example `'latitude' =>` not `latitude:`. +- Keys must be strings (not symbols) when calling `add_stub` or `set_default_stub`. For example `'country' =>` not `:country =>`. - To clear stubs (e.g. prior to another spec), use `Geocoder::Lookup::Test.reset`. This will clear all stubs _including the default stub_. - The stubbed result objects returned by the Test lookup do not support all the methods real result objects do. If you need to test interaction with real results it may be better to use an external stubbing tool and something like WebMock or VCR to prevent network calls. diff --git a/lib/geocoder/results/test.rb b/lib/geocoder/results/test.rb index 61d422ce1..06dfca10c 100644 --- a/lib/geocoder/results/test.rb +++ b/lib/geocoder/results/test.rb @@ -15,7 +15,7 @@ def self.add_result_attribute(attr) end end - %w[latitude longitude neighborhood city state state_code sub_state + %w[coordinates neighborhood city state state_code sub_state sub_state_code province province_code postal_code country country_code address street_address street_number route geometry].each do |attr| add_result_attribute(attr) From c1784cee26629bdd012d2b10b207a45f655e214d Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 15 Jun 2018 17:10:06 -0600 Subject: [PATCH 107/248] Drop Ruby 1.9.3 support. --- .travis.yml | 22 ---------------------- README.md | 2 +- gemfiles/Gemfile.ruby1.9.3 | 35 ----------------------------------- geocoder.gemspec | 2 +- lib/geocoder/exceptions.rb | 2 +- 5 files changed, 3 insertions(+), 60 deletions(-) delete mode 100644 gemfiles/Gemfile.ruby1.9.3 diff --git a/.travis.yml b/.travis.yml index fe90d5e34..ae2020d65 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ env: - DB=postgres - DB=mysql rvm: - - 1.9.3 - 2.0.0 - 2.1.10 - 2.2.10 @@ -20,7 +19,6 @@ rvm: - jruby-19mode gemfile: - Gemfile - - gemfiles/Gemfile.ruby1.9.3 - gemfiles/Gemfile.rails3.2 - gemfiles/Gemfile.rails4.1 - gemfiles/Gemfile.rails5.0 @@ -29,14 +27,6 @@ before_install: - gem update --system matrix: exclude: - - rvm: 1.9.3 - gemfile: Gemfile - - rvm: 1.9.3 - gemfile: gemfiles/Gemfile.rails3.2 - - rvm: 1.9.3 - gemfile: gemfiles/Gemfile.rails4.1 - - rvm: 1.9.3 - gemfile: gemfiles/Gemfile.rails5.0 - env: DB= gemfile: gemfiles/Gemfile.rails3.2 - env: DB= @@ -45,8 +35,6 @@ matrix: gemfile: gemfiles/Gemfile.rails5.0 - rvm: 2.0.0 gemfile: Gemfile - - rvm: 2.0.0 - gemfile: gemfiles/Gemfile.ruby1.9.3 - rvm: 2.0.0 gemfile: gemfiles/Gemfile.rails5.0 - rvm: 2.1.10 @@ -55,20 +43,10 @@ matrix: gemfile: gemfiles/Gemfile.ruby1.9.3 - rvm: 2.1.10 gemfile: gemfiles/Gemfile.rails5.0 - - rvm: 2.2.10 - gemfile: gemfiles/Gemfile.ruby1.9.3 - - rvm: jruby-19mode - gemfile: gemfiles/Gemfile.ruby1.9.3 - - rvm: 2.3.7 - gemfile: gemfiles/Gemfile.ruby1.9.3 - rvm: 2.4.4 gemfile: gemfiles/Gemfile.rails4.1 - rvm: 2.5.1 gemfile: gemfiles/Gemfile.rails4.1 - - rvm: 2.4.4 - gemfile: gemfiles/Gemfile.ruby1.9.3 - - rvm: 2.5.1 - gemfile: gemfiles/Gemfile.ruby1.9.3 - rvm: 2.4.4 gemfile: gemfiles/Gemfile.rails3.2 - rvm: 2.5.1 diff --git a/README.md b/README.md index cfe71199f..993030d12 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Key features: Compatibility: -* Supports multiple Ruby versions: Ruby 1.9.3, 2.x, and JRuby. +* Supports multiple Ruby versions: Ruby 2.x, and JRuby. * Supports multiple databases: MySQL, PostgreSQL, SQLite, and MongoDB (1.7.0 and higher). * Supports Rails 3, 4, and 5. If you need to use it with Rails 2 please see the `rails2` branch (no longer maintained, limited feature set). * Works very well outside of Rails, you just need to install either the `json` (for MRI) or `json_pure` (for JRuby) gem. diff --git a/gemfiles/Gemfile.ruby1.9.3 b/gemfiles/Gemfile.ruby1.9.3 deleted file mode 100644 index cc8f66197..000000000 --- a/gemfiles/Gemfile.ruby1.9.3 +++ /dev/null @@ -1,35 +0,0 @@ -source "https://rubygems.org" - -group :development, :test do - gem 'rake', '12.2.1' - gem 'mongoid', '2.6.0' - gem 'bson_ext', :platforms => :ruby - gem 'geoip' - gem 'rubyzip' - gem 'rack-cache', '1.7.1' - gem 'rails' - gem 'sqlite3' - gem 'sqlite_ext', '~> 1.5.0' - gem 'pg', '0.18.4' - gem 'mysql2', '~> 0.3.11' - gem 'public_suffix', '1.4.6' - - # i18n gem >=0.7.0 does not work with Ruby 1.9.2 - gem 'i18n', '0.6.1' - gem 'test-unit' # install newer version with omit() method - - gem 'debugger' - gem 'webmock', '2.3.2' - - platforms :jruby do - gem 'jruby-openssl' - gem 'jgeoip' - end - - platforms :rbx do - gem 'rubysl', '~> 2.0' - gem 'rubysl-test-unit' - end -end - -gemspec :path => '../' diff --git a/geocoder.gemspec b/geocoder.gemspec index 9a4fd52d1..40c812fe7 100644 --- a/geocoder.gemspec +++ b/geocoder.gemspec @@ -5,7 +5,7 @@ require "geocoder/version" Gem::Specification.new do |s| s.name = "geocoder" - s.required_ruby_version = '>= 1.9.3' + s.required_ruby_version = '>= 2.0.0' s.version = Geocoder::VERSION s.platform = Gem::Platform::RUBY s.authors = ["Alex Reisner"] diff --git a/lib/geocoder/exceptions.rb b/lib/geocoder/exceptions.rb index 228c45b3a..2e6a21beb 100644 --- a/lib/geocoder/exceptions.rb +++ b/lib/geocoder/exceptions.rb @@ -1,4 +1,4 @@ -require 'timeout' # required for Ruby 1.9.3 +require 'timeout' module Geocoder From 319a0e58a96c8d63e871f92d30517dbcf835c8be Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 17 Jun 2018 17:47:12 -0600 Subject: [PATCH 108/248] De-Googleize. Make Nominatim the default lookup and map provider. Closes #1026. --- README.md | 18 +++++++++--------- .../geocoder/config/templates/initializer.rb | 2 +- lib/geocoder/cli.rb | 4 ++-- lib/geocoder/configuration.rb | 2 +- test/unit/geocoder_test.rb | 11 +++++------ test/unit/lookups/google_test.rb | 4 ++++ test/unit/method_aliases_test.rb | 8 ++------ test/unit/model_test.rb | 5 ++--- test/unit/mongoid_test.rb | 6 +++--- 9 files changed, 29 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 993030d12..4f40f478b 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ Note that these methods will usually return `nil` in test and development enviro Geocoding Service ("Lookup") Configuration ------------------------------------------ -Geocoder supports a variety of street and IP address geocoding services. The default lookups are `:google` for street addresses and `:ipinfo_io` for IP addresses. Please see the [API Guide](https://github.com/alexreisner/geocoder/blob/master/README_API_GUIDE.md) for details on specific geocoding services (not all settings are supported by all services). +Geocoder supports a variety of street and IP address geocoding services. The default lookups are `:nominatim` for street addresses and `:ipinfo_io` for IP addresses. Please see the [API Guide](https://github.com/alexreisner/geocoder/blob/master/README_API_GUIDE.md) for details on specific geocoding services (not all settings are supported by all services). To create a Rails initializer with sample configuration: @@ -200,7 +200,7 @@ Some common options are: # config/initializers/geocoder.rb Geocoder.configure( - # street address geocoding service (default :google) + # street address geocoding service (default :nominatim) lookup: :yandex, # IP address geocoding service (default :ipinfo_io) @@ -311,8 +311,8 @@ By default the prefix is `geocoder:` If you need to expire cached content: Geocoder::Lookup.get(Geocoder.config[:lookup]).cache.expire(:all) # expire cached results for current Lookup - Geocoder::Lookup.get(:google).cache.expire("http://...") # expire cached result for a specific URL - Geocoder::Lookup.get(:google).cache.expire(:all) # expire cached results for Google Lookup + Geocoder::Lookup.get(:nominatim).cache.expire("http://...") # expire cached result for a specific URL + Geocoder::Lookup.get(:nominatim).cache.expire(:all) # expire cached results for Google Lookup # expire all cached results for all Lookups. # Be aware that this methods spawns a new Lookup object for each Service Geocoder::Lookup.all_services.each{|service| Geocoder::Lookup.get(service).cache.expire(:all)} @@ -351,7 +351,7 @@ Supported parameters: `:lookup`, `:ip_lookup`, `:language`, and `:params`. You c elsif country_code == "CN" :baidu else - :google + :nominatim end end @@ -578,7 +578,7 @@ When you install the Geocoder gem it adds a `geocode` command to your shell. You State/province: Louisiana Postal code: 70112 Country: United States - Google map: http://maps.google.com/maps?q=29.952211,-90.080563 + Map: http://maps.google.com/maps?q=29.952211,-90.080563 There are also a number of options for setting the geocoding API, key, and language, viewing the raw JSON response, and more. Please run `geocode -h` for details. @@ -640,13 +640,13 @@ For the most part, the speed of geocoding requests has little to do with the Geo Take a look at the server's raw response. You can do this by getting the request URL in an app console: - Geocoder::Lookup.get(:google).query_url(Geocoder::Query.new("...")) + Geocoder::Lookup.get(:nominatim).query_url(Geocoder::Query.new("...")) -Replace `:google` with the lookup you are using and replace `...` with the address you are trying to geocode. Then visit the returned URL in your web browser. Often the API will return an error message that helps you resolve the problem. If, after reading the raw response, you believe there is a problem with Geocoder, please post an issue and include both the URL and raw response body. +Replace `:nominatim` with the lookup you are using and replace `...` with the address you are trying to geocode. Then visit the returned URL in your web browser. Often the API will return an error message that helps you resolve the problem. If, after reading the raw response, you believe there is a problem with Geocoder, please post an issue and include both the URL and raw response body. You can also fetch the response in the console: - Geocoder::Lookup.get(:google).send(:fetch_raw_data, Geocoder::Query.new("...")) + Geocoder::Lookup.get(:nominatim).send(:fetch_raw_data, Geocoder::Query.new("...")) Known Issues diff --git a/lib/generators/geocoder/config/templates/initializer.rb b/lib/generators/geocoder/config/templates/initializer.rb index 88c64890c..0e6417303 100644 --- a/lib/generators/geocoder/config/templates/initializer.rb +++ b/lib/generators/geocoder/config/templates/initializer.rb @@ -1,7 +1,7 @@ Geocoder.configure( # Geocoding options # timeout: 3, # geocoding service timeout (secs) - # lookup: :google, # name of geocoding service (symbol) + # lookup: :nominatim, # name of geocoding service (symbol) # ip_lookup: :ipinfo_io, # name of IP address geocoding service (symbol) # language: :en, # ISO-639 language code # use_https: false, # use HTTPS for lookup requests? (if supported) diff --git a/lib/geocoder/cli.rb b/lib/geocoder/cli.rb index f4832a15d..2314aa187 100644 --- a/lib/geocoder/cli.rb +++ b/lib/geocoder/cli.rb @@ -97,7 +97,7 @@ def self.run(args, out = STDOUT) end if (result = Geocoder.search(query).first) - google = Geocoder::Lookup.get(:google) + nominatim = Geocoder::Lookup.get(:nominatim) lines = [ ["Latitude", result.latitude], ["Longitude", result.longitude], @@ -106,7 +106,7 @@ def self.run(args, out = STDOUT) ["State/province", result.state], ["Postal code", result.postal_code], ["Country", result.country], - ["Google map", google.map_link_url(result.coordinates)], + ["Map", nominatim.map_link_url(result.coordinates)], ] lines.each do |line| out << (line[0] + ": ").ljust(18) + line[1].to_s + "\n" diff --git a/lib/geocoder/configuration.rb b/lib/geocoder/configuration.rb index f2fbccf92..8e097a2d0 100644 --- a/lib/geocoder/configuration.rb +++ b/lib/geocoder/configuration.rb @@ -97,7 +97,7 @@ def set_defaults # geocoding options @data[:timeout] = 3 # geocoding service timeout (secs) - @data[:lookup] = :google # name of street address geocoding service (symbol) + @data[:lookup] = :nominatim # name of street address geocoding service (symbol) @data[:ip_lookup] = :ipinfo_io # name of IP address geocoding service (symbol) @data[:language] = :en # ISO-639 language code @data[:http_headers] = {} # HTTP headers for lookup diff --git a/test/unit/geocoder_test.rb b/test/unit/geocoder_test.rb index 8dda2ba22..a73c92032 100644 --- a/test/unit/geocoder_test.rb +++ b/test/unit/geocoder_test.rb @@ -27,9 +27,9 @@ def test_geographic_center_doesnt_overwrite_argument_value def test_geocode_assigns_and_returns_coordinates v = Place.new(*geocoded_object_params(:msg)) - coords = [40.750354, -73.993371] - assert_equal coords, v.geocode - assert_equal coords, [v.latitude, v.longitude] + assert_equal [Float, Float], v.geocode.map(&:class) + assert_kind_of Numeric, v.latitude + assert_kind_of Numeric, v.longitude end def test_geocode_block_executed_when_no_results @@ -40,9 +40,8 @@ def test_geocode_block_executed_when_no_results def test_reverse_geocode_assigns_and_returns_address v = PlaceReverseGeocoded.new(*reverse_geocoded_object_params(:msg)) - address = "4 Penn Plaza, New York, NY 10001, USA" - assert_equal address, v.reverse_geocode - assert_equal address, v.address + assert_match /New York/, v.reverse_geocode + assert_match /New York/, v.address end def test_forward_and_reverse_geocoding_on_same_model_works diff --git a/test/unit/lookups/google_test.rb b/test/unit/lookups/google_test.rb index 7fe6a4847..47a2b8ddf 100644 --- a/test/unit/lookups/google_test.rb +++ b/test/unit/lookups/google_test.rb @@ -3,6 +3,10 @@ class GoogleTest < GeocoderTestCase + def setup + Geocoder.configure(lookup: :google) + end + def test_google_result_components result = Geocoder.search("Madison Square Garden, New York, NY").first assert_equal "Manhattan", diff --git a/test/unit/method_aliases_test.rb b/test/unit/method_aliases_test.rb index d33afc483..bd2f1c66f 100644 --- a/test/unit/method_aliases_test.rb +++ b/test/unit/method_aliases_test.rb @@ -11,15 +11,11 @@ def test_distance_from_is_alias_for_distance_to def test_fetch_coordinates_is_alias_for_geocode v = Place.new(*geocoded_object_params(:msg)) - coords = [40.750354, -73.993371] - assert_equal coords, v.fetch_coordinates - assert_equal coords, [v.latitude, v.longitude] + assert_equal [Float, Float], v.fetch_coordinates.map(&:class) end def test_fetch_address_is_alias_for_reverse_geocode v = PlaceReverseGeocoded.new(*reverse_geocoded_object_params(:msg)) - address = "4 Penn Plaza, New York, NY 10001, USA" - assert_equal address, v.fetch_address - assert_equal address, v.address + assert_match /New York/, v.fetch_address end end diff --git a/test/unit/model_test.rb b/test/unit/model_test.rb index b2fe06960..ed1dae046 100644 --- a/test/unit/model_test.rb +++ b/test/unit/model_test.rb @@ -5,9 +5,8 @@ class ModelTest < GeocoderTestCase def test_geocode_with_block_runs_block e = PlaceWithCustomResultsHandling.new(*geocoded_object_params(:msg)) - coords = [40.750354, -73.993371] e.geocode - assert_equal coords.map{ |c| c.to_s }.join(','), e.coords_string + assert_match /[0-9\.,\-]+/, e.coords_string end def test_geocode_with_block_doesnt_auto_assign_coordinates @@ -20,7 +19,7 @@ def test_geocode_with_block_doesnt_auto_assign_coordinates def test_reverse_geocode_with_block_runs_block e = PlaceReverseGeocodedWithCustomResultsHandling.new(*reverse_geocoded_object_params(:msg)) e.reverse_geocode - assert_equal "US", e.country + assert_equal "US", e.country.upcase end def test_reverse_geocode_with_block_doesnt_auto_assign_address diff --git a/test/unit/mongoid_test.rb b/test/unit/mongoid_test.rb index cea0fa73d..d2a662ec8 100644 --- a/test/unit/mongoid_test.rb +++ b/test/unit/mongoid_test.rb @@ -44,18 +44,18 @@ def test_geocoded_with_custom_handling p = PlaceUsingMongoidWithCustomResultsHandling.new(*geocoded_object_params(:msg)) p.location = [40.750354, -73.993371] p.geocode - assert p.coords_string == "40.750354,-73.993371" + assert_match /[0-9\.,\-]+/, p.coords_string end def test_reverse_geocoded p = PlaceUsingMongoidReverseGeocoded.new(*reverse_geocoded_object_params(:msg)) p.reverse_geocode - assert p.address == "4 Penn Plaza, New York, NY 10001, USA" + assert_match /New York/, p.address end def test_reverse_geocoded_with_custom_handling p = PlaceUsingMongoidReverseGeocodedWithCustomResultsHandling.new(*reverse_geocoded_object_params(:msg)) p.reverse_geocode - assert p.country == "US" + assert_equal "US", p.country.upcase end end From 9ef67facffad97a58d2f8add85d760644909e61b Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 16 Jul 2018 19:43:09 -0400 Subject: [PATCH 109/248] Fix Rails 6.0 deprecation warning by making all class methods public. Previously a call to #near or within_bounding_box produced: DEPRECATION WARNING: Delegating missing full_column_name method to Venue. Accessibility of private/protected class methods in :scope is deprecated and will be removed in Rails 6.0. I don't like turning all these methods public but at the moment I don't see any way around it. --- lib/geocoder/stores/active_record.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/geocoder/stores/active_record.rb b/lib/geocoder/stores/active_record.rb index e7c423a9f..26b814557 100644 --- a/lib/geocoder/stores/active_record.rb +++ b/lib/geocoder/stores/active_record.rb @@ -166,8 +166,6 @@ def near_scope_options(latitude, longitude, radius = 20, options = {}) } end - private # ---------------------------------------------------------------- - ## # SQL for calculating distance based on the current database's # capabilities (trig functions?). From c18c0e084496b9dc84ac1fdb5d293da67cc45de8 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Tue, 31 Jul 2018 12:23:52 -0400 Subject: [PATCH 110/248] Omit API credentials from cache keys. Fixes #1059. --- lib/geocoder/lookups/amap.rb | 10 ++++--- lib/geocoder/lookups/baidu.rb | 8 +++--- lib/geocoder/lookups/baidu_ip.rb | 8 +++--- lib/geocoder/lookups/ban_data_gouv_fr.rb | 8 +++--- lib/geocoder/lookups/base.rb | 23 ++++++++++++++-- lib/geocoder/lookups/bing.rb | 6 +---- lib/geocoder/lookups/db_ip_com.rb | 15 ++++++----- lib/geocoder/lookups/dstk.rb | 6 +++-- lib/geocoder/lookups/esri.rb | 17 +----------- lib/geocoder/lookups/freegeoip.rb | 4 +++ lib/geocoder/lookups/geocoder_ca.rb | 8 +++--- lib/geocoder/lookups/geocoder_us.rb | 26 ++++++++++++------- lib/geocoder/lookups/geocodio.rb | 10 +++---- lib/geocoder/lookups/geoportail_lu.rb | 14 +++++----- lib/geocoder/lookups/google.rb | 8 +++--- lib/geocoder/lookups/google_places_details.rb | 8 +++--- lib/geocoder/lookups/google_places_search.rb | 8 +++--- lib/geocoder/lookups/google_premier.rb | 10 +++++++ lib/geocoder/lookups/here.rb | 8 +++--- lib/geocoder/lookups/ip2location.rb | 23 ++++++++-------- lib/geocoder/lookups/ipapi_com.rb | 19 +++++--------- lib/geocoder/lookups/ipdata_co.rb | 4 +++ lib/geocoder/lookups/ipinfo_io.rb | 14 +++++----- lib/geocoder/lookups/ipstack.rb | 19 +++++++------- lib/geocoder/lookups/latlon.rb | 8 +++--- lib/geocoder/lookups/location_iq.rb | 14 +++++++--- lib/geocoder/lookups/mapbox.rb | 9 +++---- lib/geocoder/lookups/mapquest.rb | 9 +++---- lib/geocoder/lookups/maxmind.rb | 8 +++--- lib/geocoder/lookups/maxmind_geoip2.rb | 4 +++ lib/geocoder/lookups/nominatim.rb | 8 +++--- lib/geocoder/lookups/opencagedata.rb | 11 ++++---- lib/geocoder/lookups/pelias.rb | 12 ++++----- lib/geocoder/lookups/pickpoint.rb | 12 ++++++--- lib/geocoder/lookups/pointpin.rb | 6 ++++- lib/geocoder/lookups/postcode_anywhere_uk.rb | 9 +++---- lib/geocoder/lookups/postcodes_io.rb | 9 ++++--- lib/geocoder/lookups/smarty_streets.rb | 16 ++++++------ lib/geocoder/lookups/telize.rb | 4 +++ lib/geocoder/lookups/yandex.rb | 8 +++--- test/unit/lookups/google_premier_test.rb | 8 ++++++ test/unit/lookups/location_iq_test.rb | 2 +- test/unit/lookups/pickpoint_test.rb | 5 ++-- test/unit/lookups/telize_test.rb | 10 +++++++ 44 files changed, 263 insertions(+), 193 deletions(-) diff --git a/lib/geocoder/lookups/amap.rb b/lib/geocoder/lookups/amap.rb index 6989f1bdc..ff2ac1803 100644 --- a/lib/geocoder/lookups/amap.rb +++ b/lib/geocoder/lookups/amap.rb @@ -12,13 +12,17 @@ def required_api_key_parts ["key"] end - def query_url(query) - path = query.reverse_geocode? ? 'regeo' : 'geo' - "http://restapi.amap.com/v3/geocode/#{path}?" + url_query_string(query) + def supported_protocols + [:http] end private # --------------------------------------------------------------- + def base_query_url(query) + path = query.reverse_geocode? ? 'regeo' : 'geo' + "http://restapi.amap.com/v3/geocode/#{path}?" + end + def results(query, reverse = false) return [] unless doc = fetch_data(query) case [doc['status'], doc['info']] diff --git a/lib/geocoder/lookups/baidu.rb b/lib/geocoder/lookups/baidu.rb index 6eb5e7ab0..597c00127 100644 --- a/lib/geocoder/lookups/baidu.rb +++ b/lib/geocoder/lookups/baidu.rb @@ -12,10 +12,6 @@ def required_api_key_parts ["key"] end - def query_url(query) - "#{protocol}://api.map.baidu.com/geocoder/v2/?" + url_query_string(query) - end - # HTTP only def supported_protocols [:http] @@ -23,6 +19,10 @@ def supported_protocols private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://api.map.baidu.com/geocoder/v2/?" + end + def content_key 'result' end diff --git a/lib/geocoder/lookups/baidu_ip.rb b/lib/geocoder/lookups/baidu_ip.rb index c632d562d..9ce54e8eb 100644 --- a/lib/geocoder/lookups/baidu_ip.rb +++ b/lib/geocoder/lookups/baidu_ip.rb @@ -8,12 +8,12 @@ def name "Baidu IP" end - def query_url(query) - "#{protocol}://api.map.baidu.com/location/ip?" + url_query_string(query) - end - private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://api.map.baidu.com/location/ip?" + end + def content_key 'content' end diff --git a/lib/geocoder/lookups/ban_data_gouv_fr.rb b/lib/geocoder/lookups/ban_data_gouv_fr.rb index 0c577f053..b4b2e81f4 100644 --- a/lib/geocoder/lookups/ban_data_gouv_fr.rb +++ b/lib/geocoder/lookups/ban_data_gouv_fr.rb @@ -14,13 +14,13 @@ def map_link_url(coordinates) "https://www.openstreetmap.org/#map=19/#{coordinates.join('/')}" end - def query_url(query) + private # --------------------------------------------------------------- + + def base_query_url(query) method = query.reverse_geocode? ? "reverse" : "search" - "#{protocol}://api-adresse.data.gouv.fr/#{method}/?" + url_query_string(query) + "#{protocol}://api-adresse.data.gouv.fr/#{method}/?" end - private # --------------------------------------------------------------- - def any_result?(doc) doc['features'].any? end diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb index 53d17d77f..1e7a47431 100644 --- a/lib/geocoder/lookups/base.rb +++ b/lib/geocoder/lookups/base.rb @@ -71,8 +71,12 @@ def required_api_key_parts ## # URL to use for querying the geocoding engine. # + # Subclasses should not modify this method. Instead they should define + # base_query_url and url_query_string. If absolutely necessary to + # subclss this method, they must also subclass #cache_key. + # def query_url(query) - fail + base_query_url(query) + url_query_string(query) end ## @@ -96,6 +100,14 @@ def supported_protocols private # ------------------------------------------------------------- + ## + # String which, when concatenated with url_query_string(query) + # produces the full query URL. Should include the "?" a the end. + # + def base_query_url(query) + fail + end + ## # An object with configuration data for this particular lookup. # @@ -146,7 +158,14 @@ def url_query_string(query) # something else (like the URL before OAuth encoding). # def cache_key(query) - query_url(query) + base_query_url(query) + hash_to_query(cache_key_params(query)) + end + + def cache_key_params(query) + # omit api_key and token because they may vary among requests + query_url_params(query).reject do |key,value| + key.to_s.match /(key|token)/ + end end ## diff --git a/lib/geocoder/lookups/bing.rb b/lib/geocoder/lookups/bing.rb index 269357774..53894c2ff 100644 --- a/lib/geocoder/lookups/bing.rb +++ b/lib/geocoder/lookups/bing.rb @@ -16,13 +16,9 @@ def required_api_key_parts ["key"] end - def query_url(query) - base_url(query) + url_query_string(query) - end - private # --------------------------------------------------------------- - def base_url(query) + def base_query_url(query) text = CGI.escape(query.sanitized_text.strip) url = "#{protocol}://dev.virtualearth.net/REST/v1/Locations/" if query.reverse_geocode? diff --git a/lib/geocoder/lookups/db_ip_com.rb b/lib/geocoder/lookups/db_ip_com.rb index bd7144d6e..7da241c03 100644 --- a/lib/geocoder/lookups/db_ip_com.rb +++ b/lib/geocoder/lookups/db_ip_com.rb @@ -16,15 +16,18 @@ def required_api_key_parts ['api_key'] end - def query_url(query) - query_params = if query.options[:params] - "?#{url_query_string(query)}" - end + private # ---------------------------------------------------------------- - "#{protocol}://api.db-ip.com/v2/#{configuration.api_key}/#{query.sanitized_text}#{query_params}" + def base_query_url(query) + "#{protocol}://api.db-ip.com/v2/#{configuration.api_key}/#{query.sanitized_text}?" end - private + ## + # Same as query_url but without the api key. + # + def cache_key(query) + "#{protocol}://api.db-ip.com/v2/#{query.sanitized_text}?" + hash_to_query(cache_key_params(query)) + end def results(query) return [] unless (doc = fetch_data(query)) diff --git a/lib/geocoder/lookups/dstk.rb b/lib/geocoder/lookups/dstk.rb index 681860530..f5c16cfc5 100644 --- a/lib/geocoder/lookups/dstk.rb +++ b/lib/geocoder/lookups/dstk.rb @@ -12,9 +12,11 @@ def name "Data Science Toolkit" end - def query_url(query) + private # ---------------------------------------------------------------- + + def base_query_url(query) host = configuration[:host] || "www.datasciencetoolkit.org" - "#{protocol}://#{host}/maps/api/geocode/json?" + url_query_string(query) + "#{protocol}://#{host}/maps/api/geocode/json?" end end end diff --git a/lib/geocoder/lookups/esri.rb b/lib/geocoder/lookups/esri.rb index 16bf95e0f..bd8a7390d 100644 --- a/lib/geocoder/lookups/esri.rb +++ b/lib/geocoder/lookups/esri.rb @@ -4,15 +4,11 @@ module Geocoder::Lookup class Esri < Base - + def name "Esri" end - def query_url(query) - base_query_url(query) + url_query_string(query) - end - private # --------------------------------------------------------------- def base_query_url(query) @@ -34,17 +30,6 @@ def results(query) end end - def cache_key(query) - base_query_url(query) + hash_to_query(cache_key_params(query)) - end - - def cache_key_params(query) - # omit api_key and token because they may vary among requests - query_url_params(query).reject do |key,value| - [:api_key, :token].include?(key) - end - end - def query_url_params(query) params = { :f => "pjson", diff --git a/lib/geocoder/lookups/freegeoip.rb b/lib/geocoder/lookups/freegeoip.rb index bad90279f..809762f70 100644 --- a/lib/geocoder/lookups/freegeoip.rb +++ b/lib/geocoder/lookups/freegeoip.rb @@ -23,6 +23,10 @@ def query_url(query) private # --------------------------------------------------------------- + def cache_key(query) + query_url(query) + end + def parse_raw_data(raw_data) raw_data.match(/^<html><title>404/) ? nil : super(raw_data) end diff --git a/lib/geocoder/lookups/geocoder_ca.rb b/lib/geocoder/lookups/geocoder_ca.rb index 14d7492fb..98bb55471 100644 --- a/lib/geocoder/lookups/geocoder_ca.rb +++ b/lib/geocoder/lookups/geocoder_ca.rb @@ -8,12 +8,12 @@ def name "Geocoder.ca" end - def query_url(query) - "#{protocol}://geocoder.ca/?" + url_query_string(query) - end - private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://geocoder.ca/?" + end + def results(query) return [] unless doc = fetch_data(query) if doc['error'].nil? diff --git a/lib/geocoder/lookups/geocoder_us.rb b/lib/geocoder/lookups/geocoder_us.rb index dab787ab5..cc9869cb3 100644 --- a/lib/geocoder/lookups/geocoder_us.rb +++ b/lib/geocoder/lookups/geocoder_us.rb @@ -8,20 +8,28 @@ def name "Geocoder.us" end - def supported_protocols - [:http] - end + def supported_protocols + [:http] + end + + private # ---------------------------------------------------------------- + + def base_query_url(query) + base_query_url_with_optional_key(configuration.api_key) + end - def query_url(query) + def cache_key(query) + base_query_url_with_optional_key(nil) + url_query_string(query) + end + + def base_query_url_with_optional_key(key = nil) + base = "#{protocol}://" if configuration.api_key - "#{protocol}://#{configuration.api_key}@geocoder.us/member/service/csv/geocode?" + url_query_string(query) - else - "#{protocol}://geocoder.us/service/csv/geocode?" + url_query_string(query) + base << "#{configuration.api_key}@" end + base + "geocoder.us/member/service/csv/geocode?" end - private - def results(query) return [] unless doc = fetch_data(query) if doc[0].to_s =~ /^(\d+)\:/ diff --git a/lib/geocoder/lookups/geocodio.rb b/lib/geocoder/lookups/geocodio.rb index c4c88e5a1..14e26554f 100644 --- a/lib/geocoder/lookups/geocodio.rb +++ b/lib/geocoder/lookups/geocodio.rb @@ -8,11 +8,6 @@ def name "Geocodio" end - def query_url(query) - path = query.reverse_geocode? ? "reverse" : "geocode" - "#{protocol}://api.geocod.io/v1.3/#{path}?#{url_query_string(query)}" - end - def results(query) return [] unless doc = fetch_data(query) return doc["results"] if doc['error'].nil? @@ -32,6 +27,11 @@ def results(query) private # --------------------------------------------------------------- + def base_query_url(query) + path = query.reverse_geocode? ? "reverse" : "geocode" + "#{protocol}://api.geocod.io/v1.3/#{path}?" + end + def query_url_params(query) { :api_key => configuration.api_key, diff --git a/lib/geocoder/lookups/geoportail_lu.rb b/lib/geocoder/lookups/geoportail_lu.rb index a5ff00ea9..bb35a0ee0 100644 --- a/lib/geocoder/lookups/geoportail_lu.rb +++ b/lib/geocoder/lookups/geoportail_lu.rb @@ -9,14 +9,14 @@ def name "Geoportail.lu" end - def query_url(query) - url_base_path(query) + url_query_string(query) - end - - private + private # --------------------------------------------------------------- - def url_base_path(query) - query.reverse_geocode? ? reverse_geocode_url_base_path : search_url_base_path + def base_query_url(query) + if query.reverse_geocode? + reverse_geocode_url_base_path + else + search_url_base_path + end end def search_url_base_path diff --git a/lib/geocoder/lookups/google.rb b/lib/geocoder/lookups/google.rb index a9aff2580..b209f8d4b 100644 --- a/lib/geocoder/lookups/google.rb +++ b/lib/geocoder/lookups/google.rb @@ -21,12 +21,12 @@ def supported_protocols end end - def query_url(query) - "#{protocol}://maps.googleapis.com/maps/api/geocode/json?" + url_query_string(query) - end - private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://maps.googleapis.com/maps/api/geocode/json?" + end + def configure_ssl!(client) client.instance_eval { @ssl_context = OpenSSL::SSL::SSLContext.new diff --git a/lib/geocoder/lookups/google_places_details.rb b/lib/geocoder/lookups/google_places_details.rb index c4825f81e..5bc1b17e2 100644 --- a/lib/geocoder/lookups/google_places_details.rb +++ b/lib/geocoder/lookups/google_places_details.rb @@ -16,12 +16,12 @@ def supported_protocols [:https] end - def query_url(query) - "#{protocol}://maps.googleapis.com/maps/api/place/details/json?#{url_query_string(query)}" - end - private + def base_query_url(query) + "#{protocol}://maps.googleapis.com/maps/api/place/details/json?" + end + def results(query) return [] unless doc = fetch_data(query) diff --git a/lib/geocoder/lookups/google_places_search.rb b/lib/geocoder/lookups/google_places_search.rb index c8761d9a1..246103385 100644 --- a/lib/geocoder/lookups/google_places_search.rb +++ b/lib/geocoder/lookups/google_places_search.rb @@ -16,12 +16,12 @@ def supported_protocols [:https] end - def query_url(query) - "#{protocol}://maps.googleapis.com/maps/api/place/textsearch/json?#{url_query_string(query)}" - end - private + def base_query_url(query) + "#{protocol}://maps.googleapis.com/maps/api/place/textsearch/json?" + end + def query_url_google_params(query) { query: query.text, diff --git a/lib/geocoder/lookups/google_premier.rb b/lib/geocoder/lookups/google_premier.rb index 0a1a93c4e..c985bd875 100644 --- a/lib/geocoder/lookups/google_premier.rb +++ b/lib/geocoder/lookups/google_premier.rb @@ -21,6 +21,16 @@ def query_url(query) private # --------------------------------------------------------------- + def cache_key(query) + "#{protocol}://maps.googleapis.com/maps/api/geocode/json?" + hash_to_query(cache_key_params(query)) + end + + def cache_key_params(query) + query_url_google_params(query).merge(super).reject do |k,v| + [:key, :client, :channel].include?(k) + end + end + def query_url_params(query) query_url_google_params(query).merge(super).merge( :key => nil, # don't use param inherited from Google lookup diff --git a/lib/geocoder/lookups/here.rb b/lib/geocoder/lookups/here.rb index 54148fbd4..f99eaee81 100644 --- a/lib/geocoder/lookups/here.rb +++ b/lib/geocoder/lookups/here.rb @@ -12,12 +12,12 @@ def required_api_key_parts ["app_id", "app_code"] end - def query_url(query) - "#{protocol}://#{if query.reverse_geocode? then 'reverse.' end}geocoder.api.here.com/6.2/#{if query.reverse_geocode? then 'reverse' end}geocode.json?" + url_query_string(query) - end - private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://#{if query.reverse_geocode? then 'reverse.' end}geocoder.api.here.com/6.2/#{if query.reverse_geocode? then 'reverse' end}geocode.json?" + end + def results(query) return [] unless doc = fetch_data(query) return [] unless doc['Response'] && doc['Response']['View'] diff --git a/lib/geocoder/lookups/ip2location.rb b/lib/geocoder/lookups/ip2location.rb index 56eab4a2e..f02583cd5 100644 --- a/lib/geocoder/lookups/ip2location.rb +++ b/lib/geocoder/lookups/ip2location.rb @@ -8,23 +8,24 @@ def name "IP2LocationApi" end - def query_url(query) - api_key = configuration.api_key ? configuration.api_key : "demo" - url = "#{protocol}://api.ip2location.com/?ip=#{query.sanitized_text}&key=#{api_key}&format=json" - - if (params = url_query_string(query)) and !params.empty? - url << "&" + params - end - - url - end - def supported_protocols [:http, :https] end private # ---------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://api.ip2location.com/?" + end + + def query_url_params(query) + { + key: configuration.api_key ? configuration.api_key : "demo", + format: "json", + ip: query.sanitized_text + }.merge(super) + end + def results(query) return [reserved_result(query.text)] if query.loopback_ip_address? return [] unless doc = fetch_data(query) diff --git a/lib/geocoder/lookups/ipapi_com.rb b/lib/geocoder/lookups/ipapi_com.rb index a799297a1..9137c6bcf 100644 --- a/lib/geocoder/lookups/ipapi_com.rb +++ b/lib/geocoder/lookups/ipapi_com.rb @@ -8,17 +8,6 @@ def name "ip-api.com" end - def query_url(query) - domain = configuration.api_key ? "pro.ip-api.com" : "ip-api.com" - url_ = "#{protocol}://#{domain}/json/#{query.sanitized_text}" - - if (params = url_query_string(query)) && !params.empty? - url_ + "?" + params - else - url_ - end - end - def supported_protocols if configuration.api_key [:http, :https] @@ -27,8 +16,14 @@ def supported_protocols end end + private # ---------------------------------------------------------------- - private + def base_query_url(query) + domain = configuration.api_key ? "pro.ip-api.com" : "ip-api.com" + url = "#{protocol}://#{domain}/json/#{query.sanitized_text}" + url << "?" if not url_query_string(query).empty? + url + end def parse_raw_data(raw_data) if raw_data.chomp == "invalid key" diff --git a/lib/geocoder/lookups/ipdata_co.rb b/lib/geocoder/lookups/ipdata_co.rb index 0e18fd836..2062823e5 100644 --- a/lib/geocoder/lookups/ipdata_co.rb +++ b/lib/geocoder/lookups/ipdata_co.rb @@ -18,6 +18,10 @@ def query_url(query) private # --------------------------------------------------------------- + def cache_key(query) + query_url(query) + end + def results(query) Geocoder.configure(:ipdata_co => {:http_headers => { "api-key" => configuration.api_key }}) if configuration.api_key # don't look up a loopback address, just return the stored result diff --git a/lib/geocoder/lookups/ipinfo_io.rb b/lib/geocoder/lookups/ipinfo_io.rb index 542c0d897..e160c975a 100644 --- a/lib/geocoder/lookups/ipinfo_io.rb +++ b/lib/geocoder/lookups/ipinfo_io.rb @@ -8,14 +8,6 @@ def name "Ipinfo.io" end - def query_url(query) - if configuration.api_key - "#{protocol}://ipinfo.io/#{query.sanitized_text}/geo?" + url_query_string(query) - else - "#{protocol}://ipinfo.io/#{query.sanitized_text}/geo" - end - end - # HTTPS available only for paid plans def supported_protocols if configuration.api_key @@ -27,6 +19,12 @@ def supported_protocols private # --------------------------------------------------------------- + def base_query_url(query) + url = "#{protocol}://ipinfo.io/#{query.sanitized_text}/geo" + url << "?" if configuration.api_key + url + end + def results(query) # don't look up a loopback address, just return the stored result return [reserved_result(query.text)] if query.loopback_ip_address? diff --git a/lib/geocoder/lookups/ipstack.rb b/lib/geocoder/lookups/ipstack.rb index 2d8d3c328..03449ffb4 100644 --- a/lib/geocoder/lookups/ipstack.rb +++ b/lib/geocoder/lookups/ipstack.rb @@ -21,14 +21,17 @@ def name "Ipstack" end - def query_url(query) - extra_params = url_query_string(query) - url = "#{protocol}://#{host}/#{query.sanitized_text}?access_key=#{api_key}" - url << "&#{extra_params}" unless extra_params.empty? - url + private # ---------------------------------------------------------------- + + def base_query_url(query) + "#{protocol}://#{host}/#{query.sanitized_text}?" end - private + def query_url_params(query) + { + access_key: configuration.api_key + }.merge(super) + end def results(query) # don't look up a loopback address, just return the stored result @@ -56,9 +59,5 @@ def reserved_result(ip) def host configuration[:host] || "api.ipstack.com" end - - def api_key - configuration.api_key - end end end diff --git a/lib/geocoder/lookups/latlon.rb b/lib/geocoder/lookups/latlon.rb index b496c9b84..e6a77f299 100644 --- a/lib/geocoder/lookups/latlon.rb +++ b/lib/geocoder/lookups/latlon.rb @@ -12,12 +12,12 @@ def required_api_key_parts ["api_key"] end - def query_url(query) - "#{protocol}://latlon.io/api/v1/#{'reverse_' if query.reverse_geocode?}geocode?#{url_query_string(query)}" - end - private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://latlon.io/api/v1/#{'reverse_' if query.reverse_geocode?}geocode?" + end + def results(query) return [] unless doc = fetch_data(query) if doc['error'].nil? diff --git a/lib/geocoder/lookups/location_iq.rb b/lib/geocoder/lookups/location_iq.rb index d9fb0659b..341055722 100644 --- a/lib/geocoder/lookups/location_iq.rb +++ b/lib/geocoder/lookups/location_iq.rb @@ -10,13 +10,19 @@ def name def required_api_key_parts ["api_key"] end - - def query_url(query) + + private # ---------------------------------------------------------------- + + def base_query_url(query) method = query.reverse_geocode? ? "reverse" : "search" - "#{protocol}://#{configured_host}/v1/#{method}.php?key=#{configuration.api_key}&" + url_query_string(query) + "#{protocol}://#{configured_host}/v1/#{method}.php?" end - private + def query_url_params(query) + { + key: configuration.api_key + }.merge(super) + end def configured_host configuration[:host] || "locationiq.org" diff --git a/lib/geocoder/lookups/mapbox.rb b/lib/geocoder/lookups/mapbox.rb index 9a8267575..fa2f5753c 100644 --- a/lib/geocoder/lookups/mapbox.rb +++ b/lib/geocoder/lookups/mapbox.rb @@ -8,13 +8,12 @@ def name "Mapbox" end - def query_url(query) - path = "#{mapbox_search_term(query)}.json?#{url_query_string(query)}" - "#{protocol}://api.mapbox.com/geocoding/v5/#{dataset}/#{path}" - end - private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://api.mapbox.com/geocoding/v5/#{dataset}/#{mapbox_search_term(query)}.json?" + end + def results(query) return [] unless data = fetch_data(query) if data['features'] diff --git a/lib/geocoder/lookups/mapquest.rb b/lib/geocoder/lookups/mapquest.rb index 7f53c093e..d7081e10f 100644 --- a/lib/geocoder/lookups/mapquest.rb +++ b/lib/geocoder/lookups/mapquest.rb @@ -13,14 +13,13 @@ def required_api_key_parts ["key"] end - def query_url(query) + private # --------------------------------------------------------------- + + def base_query_url(query) domain = configuration[:open] ? "open" : "www" - url = "#{protocol}://#{domain}.mapquestapi.com/geocoding/v1/#{search_type(query)}?" - url + url_query_string(query) + "#{protocol}://#{domain}.mapquestapi.com/geocoding/v1/#{search_type(query)}?" end - private # --------------------------------------------------------------- - def search_type(query) query.reverse_geocode? ? "reverse" : "address" end diff --git a/lib/geocoder/lookups/maxmind.rb b/lib/geocoder/lookups/maxmind.rb index 393a2bf85..5cf9eeccb 100644 --- a/lib/geocoder/lookups/maxmind.rb +++ b/lib/geocoder/lookups/maxmind.rb @@ -9,12 +9,12 @@ def name "MaxMind" end - def query_url(query) - "#{protocol}://geoip.maxmind.com/#{service_code}?" + url_query_string(query) - end - private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://geoip.maxmind.com/#{service_code}?" + end + ## # Return the name of the configured service, or raise an exception. # diff --git a/lib/geocoder/lookups/maxmind_geoip2.rb b/lib/geocoder/lookups/maxmind_geoip2.rb index ebe81a178..666684fb4 100644 --- a/lib/geocoder/lookups/maxmind_geoip2.rb +++ b/lib/geocoder/lookups/maxmind_geoip2.rb @@ -20,6 +20,10 @@ def query_url(query) private # --------------------------------------------------------------- + def cache_key(query) + query_url(query) + end + ## # Return the name of the configured service, or raise an exception. # diff --git a/lib/geocoder/lookups/nominatim.rb b/lib/geocoder/lookups/nominatim.rb index cee363a53..f7e119a98 100644 --- a/lib/geocoder/lookups/nominatim.rb +++ b/lib/geocoder/lookups/nominatim.rb @@ -12,13 +12,13 @@ def map_link_url(coordinates) "https://www.openstreetmap.org/?lat=#{coordinates[0]}&lon=#{coordinates[1]}&zoom=15&layers=M" end - def query_url(query) + private # --------------------------------------------------------------- + + def base_query_url(query) method = query.reverse_geocode? ? "reverse" : "search" - "#{protocol}://#{configured_host}/#{method}?" + url_query_string(query) + "#{protocol}://#{configured_host}/#{method}?" end - private # --------------------------------------------------------------- - def configured_host configuration[:host] || "nominatim.openstreetmap.org" end diff --git a/lib/geocoder/lookups/opencagedata.rb b/lib/geocoder/lookups/opencagedata.rb index 230c6914d..dcd4ef641 100644 --- a/lib/geocoder/lookups/opencagedata.rb +++ b/lib/geocoder/lookups/opencagedata.rb @@ -8,15 +8,15 @@ def name "OpenCageData" end - def query_url(query) - "#{protocol}://api.opencagedata.com/geocode/v1/json?key=#{configuration.api_key}&#{url_query_string(query)}" - end - def required_api_key_parts ["key"] end - private + private # ---------------------------------------------------------------- + + def base_query_url(query) + "#{protocol}://api.opencagedata.com/geocode/v1/json?" + end def results(query) return [] unless doc = fetch_data(query) @@ -44,6 +44,7 @@ def results(query) def query_url_params(query) params = { :q => query.sanitized_text, + :key => configuration.api_key, :language => (query.language || configuration.language) }.merge(super) diff --git a/lib/geocoder/lookups/pelias.rb b/lib/geocoder/lookups/pelias.rb index 225462550..fd8a7444d 100644 --- a/lib/geocoder/lookups/pelias.rb +++ b/lib/geocoder/lookups/pelias.rb @@ -11,16 +11,16 @@ def endpoint configuration[:endpoint] || 'localhost' end - def query_url(query) - query_type = query.reverse_geocode? ? 'reverse' : 'search' - "#{protocol}://#{endpoint}/v1/#{query_type}?" + url_query_string(query) - end - def required_api_key_parts ['search-XXXX'] end - private + private # ---------------------------------------------------------------- + + def base_query_url(query) + query_type = query.reverse_geocode? ? 'reverse' : 'search' + "#{protocol}://#{endpoint}/v1/#{query_type}?" + end def query_url_params(query) params = { diff --git a/lib/geocoder/lookups/pickpoint.rb b/lib/geocoder/lookups/pickpoint.rb index 314b8d116..e298e8951 100644 --- a/lib/geocoder/lookups/pickpoint.rb +++ b/lib/geocoder/lookups/pickpoint.rb @@ -15,12 +15,18 @@ def required_api_key_parts ["api_key"] end - def query_url(query) + private # ---------------------------------------------------------------- + + def base_query_url(query) method = query.reverse_geocode? ? "reverse" : "forward" - "#{protocol}://api.pickpoint.io/v1/#{method}?key=#{configuration.api_key}&" + url_query_string(query) + "#{protocol}://api.pickpoint.io/v1/#{method}?" end - private + def query_url_params(query) + params = { + key: configuration.api_key + }.merge(super) + end def results(query) return [] unless doc = fetch_data(query) diff --git a/lib/geocoder/lookups/pointpin.rb b/lib/geocoder/lookups/pointpin.rb index cde1074b6..5476849cf 100644 --- a/lib/geocoder/lookups/pointpin.rb +++ b/lib/geocoder/lookups/pointpin.rb @@ -16,7 +16,11 @@ def query_url(query) "#{protocol}://geo.pointp.in/#{configuration.api_key}/json/#{query.sanitized_text}" end - private + private # ---------------------------------------------------------------- + + def cache_key(query) + "#{protocol}://geo.pointp.in/json/#{query.sanitized_text}" + end def results(query) # don't look up a loopback address, just return the stored result diff --git a/lib/geocoder/lookups/postcode_anywhere_uk.rb b/lib/geocoder/lookups/postcode_anywhere_uk.rb index 017b42104..2d23ff3cf 100644 --- a/lib/geocoder/lookups/postcode_anywhere_uk.rb +++ b/lib/geocoder/lookups/postcode_anywhere_uk.rb @@ -4,7 +4,6 @@ module Geocoder::Lookup class PostcodeAnywhereUk < Base # API documentation: http://www.postcodeanywhere.co.uk/Support/WebService/Geocoding/UK/Geocode/2/ - BASE_URL_GEOCODE_V2_00 = 'services.postcodeanywhere.co.uk/Geocoding/UK/Geocode/v2.00/json.ws' DAILY_LIMIT_EXEEDED_ERROR_CODES = ['8', '17'] # api docs say these two codes are the same error INVALID_API_KEY_ERROR_CODE = '2' @@ -16,11 +15,11 @@ def required_api_key_parts %w(key) end - def query_url(query) - format('%s://%s?%s', protocol, BASE_URL_GEOCODE_V2_00, url_query_string(query)) - end + private # ---------------------------------------------------------------- - private + def base_query_url(query) + "#{protocol}://services.postcodeanywhere.co.uk/Geocoding/UK/Geocode/v2.00/json.ws?" + end def results(query) response = fetch_data(query) diff --git a/lib/geocoder/lookups/postcodes_io.rb b/lib/geocoder/lookups/postcodes_io.rb index 169571327..f2cdb4c24 100644 --- a/lib/geocoder/lookups/postcodes_io.rb +++ b/lib/geocoder/lookups/postcodes_io.rb @@ -8,15 +8,18 @@ def name end def query_url(query) - str = query.sanitized_text.gsub(/\s/, '') - format('%s://%s/%s', protocol, 'api.postcodes.io/postcodes', str) + "#{protocol}://api.postcodes.io/postcodes/#{query.sanitized_text.gsub(/\s/, '')}" end def supported_protocols [:https] end - private + private # ---------------------------------------------------------------- + + def cache_key(query) + query_url(query) + end def results(query) response = fetch_data(query) diff --git a/lib/geocoder/lookups/smarty_streets.rb b/lib/geocoder/lookups/smarty_streets.rb index 5d092cb94..a1fe31402 100644 --- a/lib/geocoder/lookups/smarty_streets.rb +++ b/lib/geocoder/lookups/smarty_streets.rb @@ -11,14 +11,6 @@ def required_api_key_parts %w(auti-id auth-token) end - def query_url(query) - if zipcode_only?(query) - "#{protocol}://us-zipcode.api.smartystreets.com/lookup?#{url_query_string(query)}" - else - "#{protocol}://us-street.api.smartystreets.com/street-address?#{url_query_string(query)}" - end - end - # required by API as of 26 March 2015 def supported_protocols [:https] @@ -26,6 +18,14 @@ def supported_protocols private # --------------------------------------------------------------- + def base_query_url(query) + if zipcode_only?(query) + "#{protocol}://us-zipcode.api.smartystreets.com/lookup?" + else + "#{protocol}://us-street.api.smartystreets.com/street-address?" + end + end + def zipcode_only?(query) !query.text.is_a?(Array) and query.to_s.strip =~ /\A\d{5}(-\d{4})?\Z/ end diff --git a/lib/geocoder/lookups/telize.rb b/lib/geocoder/lookups/telize.rb index d585ff932..c41efbd91 100644 --- a/lib/geocoder/lookups/telize.rb +++ b/lib/geocoder/lookups/telize.rb @@ -29,6 +29,10 @@ def supported_protocols private # --------------------------------------------------------------- + def cache_key(query) + query_url(query)[/(.*)\?.*/, 1] + end + def results(query) # don't look up a loopback address, just return the stored result return [reserved_result(query.text)] if query.loopback_ip_address? diff --git a/lib/geocoder/lookups/yandex.rb b/lib/geocoder/lookups/yandex.rb index 2d9ffd3b9..61a6afee9 100644 --- a/lib/geocoder/lookups/yandex.rb +++ b/lib/geocoder/lookups/yandex.rb @@ -12,16 +12,16 @@ def map_link_url(coordinates) "http://maps.yandex.ru/?ll=#{coordinates.reverse.join(',')}" end - def query_url(query) - "#{protocol}://geocode-maps.yandex.ru/1.x/?" + url_query_string(query) - end - def supported_protocols [:https] end private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://geocode-maps.yandex.ru/1.x/?" + end + def results(query) return [] unless doc = fetch_data(query) if err = doc['error'] diff --git a/test/unit/lookups/google_premier_test.rb b/test/unit/lookups/google_premier_test.rb index ceb5e8c6a..63ba87fd9 100644 --- a/test/unit/lookups/google_premier_test.rb +++ b/test/unit/lookups/google_premier_test.rb @@ -18,4 +18,12 @@ def test_query_url query = Geocoder::Query.new("Madison Square Garden, New York, NY") assert_equal "https://maps.googleapis.com/maps/api/geocode/json?address=Madison+Square+Garden%2C+New+York%2C+NY&channel=test-dev&client=gme-test&language=en&sensor=false&signature=doJvJqX7YJzgV9rJ0DnVkTGZqTg=", query.url end + + def test_cache_key + Geocoder.configure(google_premier: {api_key: ["deadbeef", "gme-test", "test-dev"]}) + lookup = Geocoder::Lookup.get(:google_premier) + query = Geocoder::Query.new("Madison Square Garden, New York, NY") + cache_key = lookup.send(:cache_key, query) + assert_equal "https://maps.googleapis.com/maps/api/geocode/json?address=Madison+Square+Garden%2C+New+York%2C+NY&language=en&sensor=false", cache_key + end end diff --git a/test/unit/lookups/location_iq_test.rb b/test/unit/lookups/location_iq_test.rb index d2a80b6c2..bfb3fc7ad 100644 --- a/test/unit/lookups/location_iq_test.rb +++ b/test/unit/lookups/location_iq_test.rb @@ -12,7 +12,7 @@ def setup def test_url_contains_api_key Geocoder.configure(location_iq: {api_key: "abc123"}) query = Geocoder::Query.new("Leadville, CO") - assert_equal "http://locationiq.org/v1/search.php?key=abc123&accept-language=en&addressdetails=1&format=json&q=Leadville%2C+CO", query.url + assert_match /key=abc123/, query.url end def test_raises_exception_with_invalid_api_key diff --git a/test/unit/lookups/pickpoint_test.rb b/test/unit/lookups/pickpoint_test.rb index a4cb4cd7d..77d5532d6 100644 --- a/test/unit/lookups/pickpoint_test.rb +++ b/test/unit/lookups/pickpoint_test.rb @@ -14,14 +14,13 @@ def test_result_components def test_result_viewport result = Geocoder.search("Madison Square Garden, New York, NY").first - assert_equal [40.749828338623, -73.9943389892578, 40.7511596679688, -73.9926528930664], - result.viewport + assert_equal [40.749828338623, -73.9943389892578, 40.7511596679688, -73.9926528930664], result.viewport end def test_url_contains_api_key Geocoder.configure(pickpoint: {api_key: "pickpoint-api-key"}) query = Geocoder::Query.new("Leadville, CO") - assert_equal "https://api.pickpoint.io/v1/forward?key=pickpoint-api-key&accept-language=en&addressdetails=1&format=json&q=Leadville%2C+CO", query.url + assert_match /key=pickpoint-api-key/, query.url end def test_raises_exception_with_invalid_api_key diff --git a/test/unit/lookups/telize_test.rb b/test/unit/lookups/telize_test.rb index 751161771..a4260bc15 100644 --- a/test/unit/lookups/telize_test.rb +++ b/test/unit/lookups/telize_test.rb @@ -62,4 +62,14 @@ def test_invalid_address results = Geocoder.search("555.555.555.555", ip_address: true) assert_equal 0, results.length end + + def test_cache_key_strips_off_query_string + Geocoder.configure(telize: {api_key: "xxxxx"}) + lookup = Geocoder::Lookup.get(:telize) + query = Geocoder::Query.new("10.10.10.10") + qurl = lookup.send(:query_url, query) + key = lookup.send(:cache_key, query) + assert qurl.include?("mashape-key") + assert !key.include?("mashape-key") + end end From 1adf2e520a0c568a046e8ef70bed98c5be2038a2 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Tue, 31 Jul 2018 13:36:42 -0400 Subject: [PATCH 111/248] Prepare for release of gem version 1.5.0. --- CHANGELOG.md | 9 +++++++++ lib/geocoder/version.rb | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 303dc95b8..0dc21450f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,15 @@ Changelog Major changes to Geocoder for each release. Please see the Git log for complete list of changes. +1.5.0 (2018 Jul 31) +------------------- +* Drop support for Ruby <2.0. +* Change default street address lookup from :google to :nominatim. +* Cache keys no longer include API credentials. This means many entries in existing cache implementations will be invalidated. +* Test lookup fixtures should now return `coordinates` and NOT `latitude`/`longitude` attributes (see #1258). This may break some people's tests. +* Add support for :ip2location lookup (thanks github.com/ip2location). +* Remove :ovi and :okf lookups. + 1.4.9 (2018 May 27) ------------------- * Fix regression in :geoip2 lookup. diff --git a/lib/geocoder/version.rb b/lib/geocoder/version.rb index e2bfb0aef..12905f099 100644 --- a/lib/geocoder/version.rb +++ b/lib/geocoder/version.rb @@ -1,3 +1,3 @@ module Geocoder - VERSION = "1.4.9" + VERSION = "1.5.0" end From c077f83de477f1e2d3b7faf0a45a550e03d16029 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 1 Aug 2018 16:54:24 -0400 Subject: [PATCH 112/248] Improve config instructions. (Don't set globally.) --- lib/geocoder/lookups/maxmind_geoip2.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/geocoder/lookups/maxmind_geoip2.rb b/lib/geocoder/lookups/maxmind_geoip2.rb index 666684fb4..89be78125 100644 --- a/lib/geocoder/lookups/maxmind_geoip2.rb +++ b/lib/geocoder/lookups/maxmind_geoip2.rb @@ -32,11 +32,7 @@ def configured_service! return s else raise( - Geocoder::ConfigurationError, - "When using MaxMind GeoIP2 you MUST specify a service name and basic_auth: " + - "Geocoder.configure(:maxmind_geoip2 => {:service => ...}, " + - ":basic_auth => {:user ..., :password => ...}), " + - "where service is one of: #{services.inspect}" + Geocoder::ConfigurationError, "When using MaxMind GeoIP2 you must specify a service and credentials: Geocoder.configure(maxmind_geoip2: {service: ..., basic_auth: {user: ..., password: ...}}), where service is one of: #{services.inspect}" ) end end From 56900af0b0cf65be7d322e971cd18ac944e102b1 Mon Sep 17 00:00:00 2001 From: Tim Neems <tim@neems.co> Date: Wed, 22 Aug 2018 16:53:51 +0900 Subject: [PATCH 113/248] Allow for_storage to be set on a per call basis --- lib/geocoder/lookups/esri.rb | 12 +++++++++++- test/unit/lookups/esri_test.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/esri.rb b/lib/geocoder/lookups/esri.rb index bd8a7390d..0becfee26 100644 --- a/lib/geocoder/lookups/esri.rb +++ b/lib/geocoder/lookups/esri.rb @@ -41,11 +41,21 @@ def query_url_params(query) params[:text] = query.sanitized_text end params[:token] = token - params[:forStorage] = configuration[:for_storage] if configuration[:for_storage] + if for_storage_value = for_storage(query) + params[:forStorage] = for_storage_value + end params[:sourceCountry] = configuration[:source_country] if configuration[:source_country] params.merge(super) end + def for_storage(query) + if query.options.has_key?(:for_storage) + query.options[:for_storage] + else + configuration[:for_storage] + end + end + def token create_and_save_token! if !valid_token_configured? and configuration.api_key configuration[:token].to_s unless configuration[:token].nil? diff --git a/test/unit/lookups/esri_test.rb b/test/unit/lookups/esri_test.rb index f7d09d069..132bb6432 100644 --- a/test/unit/lookups/esri_test.rb +++ b/test/unit/lookups/esri_test.rb @@ -34,6 +34,34 @@ def test_query_for_geocode_with_token_and_for_storage assert_match %r{token=xxxxx}, url end + def test_query_for_geocode_with_config_for_storage_false + Geocoder.configure(esri: {for_storage: false}) + + query = Geocoder::Query.new("Bluffton, SC", for_storage: true) + lookup = Geocoder::Lookup.get(:esri) + url = lookup.query_url(query) + assert_match %r{forStorage=true}, url + + query = Geocoder::Query.new("Bluffton, SC", for_storage: false) + lookup = Geocoder::Lookup.get(:esri) + url = lookup.query_url(query) + assert_no_match %r{forStorage}, url + end + + def test_query_for_geocode_with_config_for_storage_true + Geocoder.configure(esri: {for_storage: true}) + + query = Geocoder::Query.new("Bluffton, SC", for_storage: true) + lookup = Geocoder::Lookup.get(:esri) + url = lookup.query_url(query) + assert_match %r{forStorage=true}, url + + query = Geocoder::Query.new("Bluffton, SC", for_storage: false) + lookup = Geocoder::Lookup.get(:esri) + url = lookup.query_url(query) + assert_no_match %r{forStorage}, url + end + def test_token_generation_doesnt_overwrite_existing_config Geocoder.configure(esri: {api_key: ['id','secret'], for_storage: true}) From 1658b655d66d1ec7c82b61340db0089f44b2eb7a Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Tue, 28 Aug 2018 16:44:33 -0600 Subject: [PATCH 114/248] Allow bounds to be passed w/out containing array. Fixes #1307. --- lib/geocoder/stores/active_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/stores/active_record.rb b/lib/geocoder/stores/active_record.rb index 26b814557..be7870c27 100644 --- a/lib/geocoder/stores/active_record.rb +++ b/lib/geocoder/stores/active_record.rb @@ -60,7 +60,7 @@ def self.included(base) # corner followed by the northeast corner of the box # (<tt>[[sw_lat, sw_lon], [ne_lat, ne_lon]]</tt>). # - scope :within_bounding_box, lambda{ |bounds| + scope :within_bounding_box, lambda{ |*bounds| sw_lat, sw_lng, ne_lat, ne_lng = bounds.flatten if bounds if sw_lat && sw_lng && ne_lat && ne_lng where(Geocoder::Sql.within_bounding_box( From 3936dca6a81373ba5da8fcc8dcf8190072f7bdf2 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 3 Sep 2018 15:47:23 -0600 Subject: [PATCH 115/248] Fix warning "ambiguous first argument; put parentheses or a space even after `/' operator". Fixes #1333 --- lib/geocoder/lookups/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb index 1e7a47431..c23c9e667 100644 --- a/lib/geocoder/lookups/base.rb +++ b/lib/geocoder/lookups/base.rb @@ -164,7 +164,7 @@ def cache_key(query) def cache_key_params(query) # omit api_key and token because they may vary among requests query_url_params(query).reject do |key,value| - key.to_s.match /(key|token)/ + key.to_s.match(/(key|token)/) end end From 749c1d8f069a8184cb7c7c77a27da29ffbacc68f Mon Sep 17 00:00:00 2001 From: Tim Neems <tim@neems.co> Date: Tue, 4 Sep 2018 15:19:25 -0400 Subject: [PATCH 116/248] Allow esri token to be set at call time --- lib/geocoder/lookups/esri.rb | 39 +++++++++++++++++++++++----------- test/unit/lookups/esri_test.rb | 18 ++++++++++++++++ 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/lib/geocoder/lookups/esri.rb b/lib/geocoder/lookups/esri.rb index 0becfee26..6f6cf0eb8 100644 --- a/lib/geocoder/lookups/esri.rb +++ b/lib/geocoder/lookups/esri.rb @@ -40,7 +40,9 @@ def query_url_params(query) else params[:text] = query.sanitized_text end - params[:token] = token + + params[:token] = token(query) + if for_storage_value = for_storage(query) params[:forStorage] = for_storage_value end @@ -56,25 +58,38 @@ def for_storage(query) end end - def token - create_and_save_token! if !valid_token_configured? and configuration.api_key - configuration[:token].to_s unless configuration[:token].nil? + def token(query) + token_instance = if query.options[:token] + query.options[:token] + else + configuration[:token] + end + + if !valid_token_configured?(token_instance) && configuration.api_key + token_instance = create_and_save_token!(query) + end + + token_instance.to_s unless token_instance.nil? end - def valid_token_configured? - !configuration[:token].nil? and configuration[:token].active? + def valid_token_configured?(token_instance) + !token_instance.nil? && token_instance.active? end - def create_and_save_token! - save_token!(create_token) + def create_and_save_token!(query) + token_instance = create_token + + if query.options[:token] + query.options[:token] = token_instance + else + Geocoder.merge_into_lookup_config(:esri, token: token_instance) + end + + token_instance end def create_token Geocoder::EsriToken.generate_token(*configuration.api_key) end - - def save_token!(token_instance) - Geocoder.merge_into_lookup_config(:esri, token: token_instance) - end end end diff --git a/test/unit/lookups/esri_test.rb b/test/unit/lookups/esri_test.rb index 132bb6432..4329276d4 100644 --- a/test/unit/lookups/esri_test.rb +++ b/test/unit/lookups/esri_test.rb @@ -34,6 +34,24 @@ def test_query_for_geocode_with_token_and_for_storage assert_match %r{token=xxxxx}, url end + def test_token_from_options + options_token = Geocoder::EsriToken.new('options_token', Time.now + 60*60*24) + query = Geocoder::Query.new("Bluffton, SC", token: options_token) + lookup = Geocoder::Lookup.get(:esri) + url = lookup.query_url(query) + assert_match %r{token=options_token}, url + end + + def test_token_from_options_overrides_configuration + config_token = Geocoder::EsriToken.new('config_token', Time.now + 60*60*24) + options_token = Geocoder::EsriToken.new('options_token', Time.now + 60*60*24) + Geocoder.configure(esri: { token: config_token }) + query = Geocoder::Query.new("Bluffton, SC", token: options_token) + lookup = Geocoder::Lookup.get(:esri) + url = lookup.query_url(query) + assert_match %r{token=options_token}, url + end + def test_query_for_geocode_with_config_for_storage_false Geocoder.configure(esri: {for_storage: false}) From 7cdb4f7b2b0bcf1e227c6b9b1eab8a7f6aa93e33 Mon Sep 17 00:00:00 2001 From: rsmokeUM <rsmoke@umich.edu> Date: Tue, 4 Sep 2018 16:02:53 -0400 Subject: [PATCH 117/248] Fixed a typo missing a t in features in point three under 'Key features:' --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f40f478b..1128e8b0a 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Key features: * Forward and reverse geocoding, and IP address geocoding. * Connects to more than 40 APIs worldwide. -* Performance-enhancing feaures like caching. +* Performance-enhancing features like caching. * Advanced configuration allows different parameters and APIs to be used in different conditions. * Integrates with ActiveRecord and Mongoid. * Basic geospatial queries: search within radius (or rectangle, or ring). From 0307089888d9717ba3ba8819abdfe777a9381a7d Mon Sep 17 00:00:00 2001 From: Mihail-K <mihail@platterz.ca> Date: Fri, 7 Sep 2018 10:37:15 -0400 Subject: [PATCH 118/248] Embed API key into query URL. --- lib/geocoder/lookups/ipdata_co.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/geocoder/lookups/ipdata_co.rb b/lib/geocoder/lookups/ipdata_co.rb index 2062823e5..d61215025 100644 --- a/lib/geocoder/lookups/ipdata_co.rb +++ b/lib/geocoder/lookups/ipdata_co.rb @@ -13,7 +13,9 @@ def supported_protocols end def query_url(query) - "#{protocol}://#{host}/#{query.sanitized_text}" + # Ipdata.co requires that the API key be sent as a query parameter. + # It no longer supports API keys sent as headers. + "#{protocol}://#{host}/#{query.sanitized_text}?api-key=#{configuration.api_key}" end private # --------------------------------------------------------------- @@ -23,7 +25,6 @@ def cache_key(query) end def results(query) - Geocoder.configure(:ipdata_co => {:http_headers => { "api-key" => configuration.api_key }}) if configuration.api_key # don't look up a loopback address, just return the stored result return [reserved_result(query.text)] if query.loopback_ip_address? # note: Ipdata.co returns plain text on bad request From 6e79b62c8bdc276ee78b6c9e0c1bbe5420383df4 Mon Sep 17 00:00:00 2001 From: Mihail-K <mihail@platterz.ca> Date: Fri, 7 Sep 2018 10:51:12 -0400 Subject: [PATCH 119/248] Update unittests to match behaviour. --- test/unit/lookups/ipdata_co_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/lookups/ipdata_co_test.rb b/test/unit/lookups/ipdata_co_test.rb index 88a4d16c1..5704c9023 100644 --- a/test/unit/lookups/ipdata_co_test.rb +++ b/test/unit/lookups/ipdata_co_test.rb @@ -42,7 +42,7 @@ def test_api_key require 'webmock/test_unit' WebMock.enable! - stubbed_request = WebMock.stub_request(:get, "https://api.ipdata.co/8.8.8.8").with(headers: {'api-key' => 'XXXX'}).to_return(status: 200) + stubbed_request = WebMock.stub_request(:get, "https://api.ipdata.co/8.8.8.8?api-key=XXXX").to_return(status: 200) g = Geocoder::Lookup::IpdataCo.new g.send(:actual_make_api_request, Geocoder::Query.new('8.8.8.8')) From 1dcc22de225da94f93cb30d0e2c83f0729f2e56c Mon Sep 17 00:00:00 2001 From: Anders Eriksson <aeri3@kth.se> Date: Sat, 8 Sep 2018 17:51:55 +0200 Subject: [PATCH 120/248] add Tencent test fixtures --- test/fixtures/tencent_invalid_key | 4 + test/fixtures/tencent_no_results | 4 + test/fixtures/tencent_reverse | 291 +++++++++++++++++++++ test/fixtures/tencent_shanghai_pearl_tower | 22 ++ 4 files changed, 321 insertions(+) create mode 100644 test/fixtures/tencent_invalid_key create mode 100644 test/fixtures/tencent_no_results create mode 100644 test/fixtures/tencent_reverse create mode 100644 test/fixtures/tencent_shanghai_pearl_tower diff --git a/test/fixtures/tencent_invalid_key b/test/fixtures/tencent_invalid_key new file mode 100644 index 000000000..f5dd70fd3 --- /dev/null +++ b/test/fixtures/tencent_invalid_key @@ -0,0 +1,4 @@ +{ + "status":311, + "message":"key格式错误" +} diff --git a/test/fixtures/tencent_no_results b/test/fixtures/tencent_no_results new file mode 100644 index 000000000..178fff935 --- /dev/null +++ b/test/fixtures/tencent_no_results @@ -0,0 +1,4 @@ +{ + "status":347, + "message":"查询无结果" +} diff --git a/test/fixtures/tencent_reverse b/test/fixtures/tencent_reverse new file mode 100644 index 000000000..0c8045ed3 --- /dev/null +++ b/test/fixtures/tencent_reverse @@ -0,0 +1,291 @@ +{ + "status":0, + "message":"query ok", + "request_id":"94d35ae6-b37c-11e8-97fd-6c92bf5349ef", + "result":{ + "location":{ + "lat":31.239664, + "lng":121.499809 + }, + "address":"上海市浦东新区世纪大道1号", + "formatted_addresses":{ + "recommend":"浦东新区东方明珠广播电视塔", + "rough":"浦东新区东方明珠广播电视塔" + }, + "address_component":{ + "nation":"中国", + "province":"上海市", + "city":"上海市", + "district":"浦东新区", + "street":"世纪大道", + "street_number":"世纪大道1号" + }, + "ad_info":{ + "nation_code":"156", + "adcode":"310115", + "city_code":"156310000", + "name":"中国,上海市,上海市,浦东新区", + "location":{ + "lat":31.239664, + "lng":121.499809 + }, + "nation":"中国", + "province":"上海市", + "city":"上海市", + "district":"浦东新区" + }, + "address_reference":{ + "business_area":{ + "id":"17883725287589114835", + "title":"陆家嘴", + "location":{ + "lat":31.239664, + "lng":121.499809 + }, + "_distance":0, + "_dir_desc":"内" + }, + "famous_area":{ + "id":"17883725287589114835", + "title":"陆家嘴", + "location":{ + "lat":31.239664, + "lng":121.499809 + }, + "_distance":0, + "_dir_desc":"内" + }, + "crossroad":{ + "id":"5571681", + "title":"丰和路/明珠塔路(路口)", + "location":{ + "lat":31.23901, + "lng":121.499138 + }, + "_distance":91.4, + "_dir_desc":"东北" + }, + "town":{ + "id":"310115005", + "title":"陆家嘴街道", + "location":{ + "lat":31.239664, + "lng":121.499809 + }, + "_distance":0, + "_dir_desc":"内" + }, + "street_number":{ + "id":"15588308480676188216", + "title":"世纪大道1号", + "location":{ + "lat":31.239777, + "lng":121.49968 + }, + "_distance":17.6, + "_dir_desc":"" + }, + "street":{ + "id":"9311677944217128536", + "title":"明珠塔路", + "location":{ + "lat":31.23901, + "lng":121.499138 + }, + "_distance":91.4, + "_dir_desc":"北" + }, + "landmark_l2":{ + "id":"15588308480676188216", + "title":"东方明珠广播电视塔", + "location":{ + "lat":31.239691, + "lng":121.499718 + }, + "_distance":0, + "_dir_desc":"内" + } + }, + "poi_count":10, + "pois":[{ + "id":"15588308480676188216", + "title":"东方明珠广播电视塔", + "address":"上海市浦东新区世纪大道1号", + "category":"旅游景点:国家级景点", + "location":{ + "lat":31.239691, + "lng":121.499718 + }, + "ad_info":{ + "adcode":"310115", + "province":"上海市", + "city":"上海市", + "district":"浦东新区" + }, + "_distance":0, + "_dir_desc":"内" + }, + { + "id":"12244833939506466993", + "title":"陆家嘴金融贸易区", + "address":"上海市浦东新区陆家嘴街道", + "category":"房产小区:产业园区", + "location":{ + "lat":31.23003, + "lng":121.533234 + }, + "ad_info":{ + "adcode":"310115", + "province":"上海市", + "city":"上海市", + "district":"浦东新区" + }, + "_distance":0, + "_dir_desc":"内" + }, + { + "id":"2213909629871914016", + "title":"东方明珠主观光层", + "address":"上海市浦东新区世纪大道1号(东方明珠塔2号门)", + "category":"娱乐休闲:户外活动:游乐场", + "location":{ + "lat":31.239664, + "lng":121.499809 + }, + "ad_info":{ + "adcode":"310115", + "province":"上海市", + "city":"上海市", + "district":"浦东新区" + }, + "_distance":0, + "_dir_desc":"" + }, + { + "id":"17288849619811641839", + "title":"东方明珠-城市广场", + "address":"上海市浦东新区世纪大道1号", + "category":"旅游景点:城市广场", + "location":{ + "lat":31.239725, + "lng":121.499649 + }, + "ad_info":{ + "adcode":"310115", + "province":"上海市", + "city":"上海市", + "district":"浦东新区" + }, + "_distance":16.7, + "_dir_desc":"" + }, + { + "id":"10738802411805476989", + "title":"东方明珠一二球", + "address":"上海市浦东新区世纪大道1号", + "category":"运动健身:其它运动健身", + "location":{ + "lat":31.239779, + "lng":121.499672 + }, + "ad_info":{ + "adcode":"310115", + "province":"上海市", + "city":"上海市", + "district":"浦东新区" + }, + "_distance":18.3, + "_dir_desc":"" + }, + { + "id":"4589232990105472767", + "title":"东方明珠Coca-Cola欢乐餐厅", + "address":"上海市浦东新区世纪大道1号东方明珠塔内", + "category":"美食:自助餐", + "location":{ + "lat":31.239836, + "lng":121.499771 + }, + "ad_info":{ + "adcode":"310115", + "province":"上海市", + "city":"上海市", + "district":"浦东新区" + }, + "_distance":19.5, + "_dir_desc":"" + }, + { + "id":"14186599042253070517", + "title":"东方明珠全透明观光廊", + "address":"上海市浦东新区世纪大道1号", + "category":"娱乐休闲:户外活动:游乐场", + "location":{ + "lat":31.23988, + "lng":121.499725 + }, + "ad_info":{ + "adcode":"310115", + "province":"上海市", + "city":"上海市", + "district":"浦东新区" + }, + "_distance":25.3, + "_dir_desc":"" + }, + { + "id":"12532486901850489743", + "title":"上海城市历史发展陈列馆", + "address":"上海市浦东新区世纪大道1号东方明珠零米大厅内(丰和路明珠塔路)", + "category":"文化场馆:展览馆", + "location":{ + "lat":31.23946, + "lng":121.500526 + }, + "ad_info":{ + "adcode":"310115", + "province":"上海市", + "city":"上海市", + "district":"浦东新区" + }, + "_distance":71.9, + "_dir_desc":"西" + }, + { + "id":"6490317229244709308", + "title":"东方明珠空中旋转餐厅", + "address":"上海市浦东新区世纪大道1号东方明珠塔267米", + "category":"美食:中餐厅:其它中餐厅", + "location":{ + "lat":31.23946, + "lng":121.500526 + }, + "ad_info":{ + "adcode":"310115", + "province":"上海市", + "city":"上海市", + "district":"浦东新区" + }, + "_distance":71.9, + "_dir_desc":"西" + }, + { + "id":"17660553244266222022", + "title":"老上海8号餐厅(东方明珠店)", + "address":"上海市浦东新区世纪大道1号东方明珠8号门国际新闻中心1层(近二号线陆家嘴站)", + "category":"美食:中餐厅:上海菜", + "location":{ + "lat":31.240456, + "lng":121.50061 + }, + "ad_info":{ + "adcode":"310115", + "province":"上海市", + "city":"上海市", + "district":"浦东新区" + }, + "_distance":68.2, + "_dir_desc":"西南" + }] + } +} diff --git a/test/fixtures/tencent_shanghai_pearl_tower b/test/fixtures/tencent_shanghai_pearl_tower new file mode 100644 index 000000000..a4f31248b --- /dev/null +++ b/test/fixtures/tencent_shanghai_pearl_tower @@ -0,0 +1,22 @@ +{ + "status":0, + "message":"query ok", + "result":{ + "title":"东方明珠主观光层", + "location":{ + "lng":121.499809, + "lat":31.239664 + }, + "address_components":{ + "province":"上海市", + "city":"上海市", + "district":"浦东新区", + "street":"", + "street_number":"" + }, + "similarity":0.8, + "deviation":1000, + "reliability":7, + "level":11 + } +} \ No newline at end of file From 242bc840094c959b19c60e1b8b4807193824e433 Mon Sep 17 00:00:00 2001 From: Anders Eriksson <aeri3@kth.se> Date: Sat, 8 Sep 2018 18:40:53 +0200 Subject: [PATCH 121/248] update Tencent reverse fixture to not include Points of Interest --- test/fixtures/tencent_reverse | 185 +--------------------------------- 1 file changed, 2 insertions(+), 183 deletions(-) diff --git a/test/fixtures/tencent_reverse b/test/fixtures/tencent_reverse index 0c8045ed3..268376f59 100644 --- a/test/fixtures/tencent_reverse +++ b/test/fixtures/tencent_reverse @@ -1,7 +1,7 @@ { "status":0, "message":"query ok", - "request_id":"94d35ae6-b37c-11e8-97fd-6c92bf5349ef", + "request_id":"b8580ff8-b385-11e8-bb66-246e965de502", "result":{ "location":{ "lat":31.239664, @@ -105,187 +105,6 @@ "_distance":0, "_dir_desc":"内" } - }, - "poi_count":10, - "pois":[{ - "id":"15588308480676188216", - "title":"东方明珠广播电视塔", - "address":"上海市浦东新区世纪大道1号", - "category":"旅游景点:国家级景点", - "location":{ - "lat":31.239691, - "lng":121.499718 - }, - "ad_info":{ - "adcode":"310115", - "province":"上海市", - "city":"上海市", - "district":"浦东新区" - }, - "_distance":0, - "_dir_desc":"内" - }, - { - "id":"12244833939506466993", - "title":"陆家嘴金融贸易区", - "address":"上海市浦东新区陆家嘴街道", - "category":"房产小区:产业园区", - "location":{ - "lat":31.23003, - "lng":121.533234 - }, - "ad_info":{ - "adcode":"310115", - "province":"上海市", - "city":"上海市", - "district":"浦东新区" - }, - "_distance":0, - "_dir_desc":"内" - }, - { - "id":"2213909629871914016", - "title":"东方明珠主观光层", - "address":"上海市浦东新区世纪大道1号(东方明珠塔2号门)", - "category":"娱乐休闲:户外活动:游乐场", - "location":{ - "lat":31.239664, - "lng":121.499809 - }, - "ad_info":{ - "adcode":"310115", - "province":"上海市", - "city":"上海市", - "district":"浦东新区" - }, - "_distance":0, - "_dir_desc":"" - }, - { - "id":"17288849619811641839", - "title":"东方明珠-城市广场", - "address":"上海市浦东新区世纪大道1号", - "category":"旅游景点:城市广场", - "location":{ - "lat":31.239725, - "lng":121.499649 - }, - "ad_info":{ - "adcode":"310115", - "province":"上海市", - "city":"上海市", - "district":"浦东新区" - }, - "_distance":16.7, - "_dir_desc":"" - }, - { - "id":"10738802411805476989", - "title":"东方明珠一二球", - "address":"上海市浦东新区世纪大道1号", - "category":"运动健身:其它运动健身", - "location":{ - "lat":31.239779, - "lng":121.499672 - }, - "ad_info":{ - "adcode":"310115", - "province":"上海市", - "city":"上海市", - "district":"浦东新区" - }, - "_distance":18.3, - "_dir_desc":"" - }, - { - "id":"4589232990105472767", - "title":"东方明珠Coca-Cola欢乐餐厅", - "address":"上海市浦东新区世纪大道1号东方明珠塔内", - "category":"美食:自助餐", - "location":{ - "lat":31.239836, - "lng":121.499771 - }, - "ad_info":{ - "adcode":"310115", - "province":"上海市", - "city":"上海市", - "district":"浦东新区" - }, - "_distance":19.5, - "_dir_desc":"" - }, - { - "id":"14186599042253070517", - "title":"东方明珠全透明观光廊", - "address":"上海市浦东新区世纪大道1号", - "category":"娱乐休闲:户外活动:游乐场", - "location":{ - "lat":31.23988, - "lng":121.499725 - }, - "ad_info":{ - "adcode":"310115", - "province":"上海市", - "city":"上海市", - "district":"浦东新区" - }, - "_distance":25.3, - "_dir_desc":"" - }, - { - "id":"12532486901850489743", - "title":"上海城市历史发展陈列馆", - "address":"上海市浦东新区世纪大道1号东方明珠零米大厅内(丰和路明珠塔路)", - "category":"文化场馆:展览馆", - "location":{ - "lat":31.23946, - "lng":121.500526 - }, - "ad_info":{ - "adcode":"310115", - "province":"上海市", - "city":"上海市", - "district":"浦东新区" - }, - "_distance":71.9, - "_dir_desc":"西" - }, - { - "id":"6490317229244709308", - "title":"东方明珠空中旋转餐厅", - "address":"上海市浦东新区世纪大道1号东方明珠塔267米", - "category":"美食:中餐厅:其它中餐厅", - "location":{ - "lat":31.23946, - "lng":121.500526 - }, - "ad_info":{ - "adcode":"310115", - "province":"上海市", - "city":"上海市", - "district":"浦东新区" - }, - "_distance":71.9, - "_dir_desc":"西" - }, - { - "id":"17660553244266222022", - "title":"老上海8号餐厅(东方明珠店)", - "address":"上海市浦东新区世纪大道1号东方明珠8号门国际新闻中心1层(近二号线陆家嘴站)", - "category":"美食:中餐厅:上海菜", - "location":{ - "lat":31.240456, - "lng":121.50061 - }, - "ad_info":{ - "adcode":"310115", - "province":"上海市", - "city":"上海市", - "district":"浦东新区" - }, - "_distance":68.2, - "_dir_desc":"西南" - }] + } } } From d2303b67ff7d8a328c7bebd67952e3dc05a715ce Mon Sep 17 00:00:00 2001 From: Anders Eriksson <aeri3@kth.se> Date: Sat, 8 Sep 2018 22:02:02 +0200 Subject: [PATCH 122/248] add Tencent geocoding & reverse geocoding API --- lib/geocoder/lookup.rb | 1 + lib/geocoder/lookups/tencent.rb | 56 +++++++++++++++++++++++++ lib/geocoder/results/tencent.rb | 73 +++++++++++++++++++++++++++++++++ test/test_helper.rb | 8 ++++ 4 files changed, 138 insertions(+) create mode 100644 lib/geocoder/lookups/tencent.rb create mode 100644 lib/geocoder/results/tencent.rb diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index 5ccae1022..b80fb4f2f 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -43,6 +43,7 @@ def street_services :pickpoint, :here, :baidu, + :tencent, :geocodio, :smarty_streets, :postcode_anywhere_uk, diff --git a/lib/geocoder/lookups/tencent.rb b/lib/geocoder/lookups/tencent.rb new file mode 100644 index 000000000..2dade5187 --- /dev/null +++ b/lib/geocoder/lookups/tencent.rb @@ -0,0 +1,56 @@ +require 'geocoder/lookups/base' +require "geocoder/results/tencent" + +module Geocoder::Lookup + class Tencent < Base + + def name + "Tencent" + end + + def required_api_key_parts + ["key"] + end + + def supported_protocols + [:https] + end + + private # --------------------------------------------------------------- + + def base_query_url(query) + "#{protocol}://apis.map.qq.com/ws/geocoder/v1/?" + end + + def content_key + 'result' + end + + def results(query, reverse = false) + return [] unless doc = fetch_data(query) + case doc['status'] + when 0 + return [doc[content_key]] + when 311 + raise_error(Geocoder::RequestDenied, "request denied") || + Geocoder.log(:warn, "#{name} Geocoding API error: request denied.") + when 310, 306 + raise_error(Geocoder::InvalidRequest, "invalid request.") || + Geocoder.log(:warn, "#{name} Geocoding API error: invalid request.") + when 311 + raise_error(Geocoder::InvalidApiKey, "invalid api key") || + Geocoder.log(:warn, "#{name} Geocoding API error: invalid api key.") + end + return [] + end + + def query_url_params(query) + { + (query.reverse_geocode? ? :location : :address) => query.sanitized_text, + :key => configuration.api_key, + :output => "json" + }.merge(super) + end + + end +end diff --git a/lib/geocoder/results/tencent.rb b/lib/geocoder/results/tencent.rb new file mode 100644 index 000000000..d546bad6a --- /dev/null +++ b/lib/geocoder/results/tencent.rb @@ -0,0 +1,73 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class Tencent < Base + + def coordinates + ['lat', 'lng'].map{ |i| @data['location'][i] } + end + + def address + "#{province}#{city}#{district}#{street}#{street_number}" + + #@data['title'] or @data['address'] + end + + # The Tencent reverse reverse geocoding API has the field named + # 'address_component' compared to 'address_components' in the + # regular geocoding API. + + def province + @data['address_components'] and (@data['address_components']['province']) or + (@data['address_component'] and @data['address_component']['province']) or + "" + end + + alias_method :state, :province + + def city + @data['address_components'] and (@data['address_components']['city']) or + (@data['address_component'] and @data['address_component']['city']) or + "" + end + + def district + @data['address_components'] and (@data['address_components']['district']) or + (@data['address_component'] and @data['address_component']['district']) or + "" + end + + def street + @data['address_components'] and (@data['address_components']['street']) or + (@data['address_component'] and @data['address_component']['street']) or + "" + end + + def street_number + @data['address_components'] and (@data['address_components']['street_number']) or + (@data['address_component'] and @data['address_component']['street_number']) or + "" + end + + def address_components + @data['address_components'] or @data['address_component'] + end + + def state_code + "" + end + + def postal_code + "" + end + + def country + "China" + end + + def country_code + "CN" + end + + end +end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index d6243a919..a760407b5 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -318,6 +318,14 @@ def default_fixture_filename end end + require 'geocoder/lookups/tencent' + class Tencent + private + def default_fixture_filename + "tencent_shanghai_pearl_tower" + end + end + require 'geocoder/lookups/geocodio' class Geocodio private From dd263a9b2b9be16b2c4d0c82d815e8dc6722ce09 Mon Sep 17 00:00:00 2001 From: Anders Eriksson <aeri3@kth.se> Date: Sat, 8 Sep 2018 22:13:15 +0200 Subject: [PATCH 123/248] add Tencent information to API Guide --- README_API_GUIDE.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index cf1a5ebc5..d278a85e6 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -243,6 +243,19 @@ Data Science Toolkit provides an API whose response format is like Google's but * **Limitations**: Only good for non-commercial use. For commercial usage please check http://developer.baidu.com/map/question.htm#qa0013 * **Notes**: To use Baidu set `Geocoder.configure(lookup: :baidu, api_key: "your_api_key")`. +### Tencent (`:tencent`) + +* **API key**: required +* **Key signup**: http://lbs.qq.com/console/mykey.html +* **Quota**: 10,000 free requests per day per key. 5 requests per second per key. For increased quota, one must first apply to become a corporate developer and then apply for increased quota. +* **Region**: China +* **SSL support**: no +* **Languages**: Chinese (Simplified) +* **Documentation**: http://lbs.qq.com/webservice_v1/guide-geocoder.html (Standard) & http://lbs.qq.com/webservice_v1/guide-gcoder.html (Reverse) +* **Terms of Service**: http://lbs.qq.com/terms.html +* **Limitations**: Only works for locations in Greater China (mainland China, Hong Kong, Macau, and Taiwan). +* **Notes**: To use Tencent, set `Geocoder.configure(lookup: :tencent, api_key: "your_api_key")`. + ### Geocodio (`:geocodio`) * **API key**: required From e89a4f79c7e3109acd7a228c52ae26fc04541023 Mon Sep 17 00:00:00 2001 From: Ignatius Reza <lyoneil.de.sire@gmail.com> Date: Tue, 11 Sep 2018 11:46:53 +0900 Subject: [PATCH 124/248] Don't try to look up private IP address. --- lib/geocoder/ip_address.rb | 13 +++++++++ lib/geocoder/lookups/freegeoip.rb | 6 ++--- lib/geocoder/lookups/ip2location.rb | 3 ++- lib/geocoder/lookups/ipapi_com.rb | 3 ++- lib/geocoder/lookups/ipdata_co.rb | 4 +-- lib/geocoder/lookups/ipinfo_io.rb | 4 +-- lib/geocoder/lookups/ipstack.rb | 4 +-- lib/geocoder/lookups/maxmind.rb | 4 +-- lib/geocoder/lookups/maxmind_geoip2.rb | 5 ++-- lib/geocoder/lookups/pointpin.rb | 6 ++--- lib/geocoder/lookups/telize.rb | 4 +-- lib/geocoder/query.rb | 14 ++++++++++ ...{pointpin_10_10_10_10 => pointpin_8_8_8_8} | 0 test/fixtures/telize_10_10_10_10 | 1 - test/fixtures/telize_8_8_8_8 | 1 + test/fixtures/telize_no_results | 2 +- test/unit/ip_address_test.rb | 27 +++++++++++++++++++ test/unit/lookups/freegeoip_test.rb | 14 ++++++++++ test/unit/lookups/ip2location_test.rb | 5 ++++ test/unit/lookups/ipapi_com_test.rb | 12 ++++++++- test/unit/lookups/ipdata_co_test.rb | 14 ++++++++++ test/unit/lookups/ipinfo_io_test.rb | 8 ++++++ test/unit/lookups/ipstack_test.rb | 7 +++++ test/unit/lookups/maxmind_test.rb | 12 +++++++++ test/unit/lookups/pointpin_test.rb | 12 ++++++++- test/unit/lookups/telize_test.rb | 18 +++++++++++-- test/unit/query_test.rb | 16 +++++++++++ test/unit/request_test.rb | 4 +++ 28 files changed, 197 insertions(+), 26 deletions(-) rename test/fixtures/{pointpin_10_10_10_10 => pointpin_8_8_8_8} (100%) delete mode 100644 test/fixtures/telize_10_10_10_10 create mode 100644 test/fixtures/telize_8_8_8_8 diff --git a/lib/geocoder/ip_address.rb b/lib/geocoder/ip_address.rb index 65d43e509..c6858cc74 100644 --- a/lib/geocoder/ip_address.rb +++ b/lib/geocoder/ip_address.rb @@ -1,11 +1,24 @@ require 'resolv' module Geocoder class IpAddress < String + PRIVATE_IPS = [ + '10.0.0.0/8', + '172.16.0.0/12', + '192.168.0.0/16', + ].map { |ip| IPAddr.new(ip) }.freeze + + def internal? + loopback? || private? + end def loopback? valid? and !!(self == "0.0.0.0" or self.match(/\A127\./) or self == "::1") end + def private? + valid? && PRIVATE_IPS.any? { |ip| ip.include?(self) } + end + def valid? !!((self =~ Resolv::IPv4::Regex) || (self =~ Resolv::IPv6::Regex)) end diff --git a/lib/geocoder/lookups/freegeoip.rb b/lib/geocoder/lookups/freegeoip.rb index 809762f70..6b551a22f 100644 --- a/lib/geocoder/lookups/freegeoip.rb +++ b/lib/geocoder/lookups/freegeoip.rb @@ -7,7 +7,7 @@ class Freegeoip < Base def name "FreeGeoIP" end - + def supported_protocols if configuration[:host] [:http, :https] @@ -32,8 +32,8 @@ def parse_raw_data(raw_data) end def results(query) - # don't look up a loopback address, just return the stored result - return [reserved_result(query.text)] if query.loopback_ip_address? + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? # note: Freegeoip.net returns plain text "Not Found" on bad request (doc = fetch_data(query)) ? [doc] : [] end diff --git a/lib/geocoder/lookups/ip2location.rb b/lib/geocoder/lookups/ip2location.rb index f02583cd5..3e29a799e 100644 --- a/lib/geocoder/lookups/ip2location.rb +++ b/lib/geocoder/lookups/ip2location.rb @@ -27,7 +27,8 @@ def query_url_params(query) end def results(query) - return [reserved_result(query.text)] if query.loopback_ip_address? + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? return [] unless doc = fetch_data(query) if doc["response"] == "INVALID ACCOUNT" raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "INVALID ACCOUNT") diff --git a/lib/geocoder/lookups/ipapi_com.rb b/lib/geocoder/lookups/ipapi_com.rb index 9137c6bcf..bf22c364f 100644 --- a/lib/geocoder/lookups/ipapi_com.rb +++ b/lib/geocoder/lookups/ipapi_com.rb @@ -34,7 +34,8 @@ def parse_raw_data(raw_data) end def results(query) - return [reserved_result(query.text)] if query.loopback_ip_address? + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? return [] unless doc = fetch_data(query) diff --git a/lib/geocoder/lookups/ipdata_co.rb b/lib/geocoder/lookups/ipdata_co.rb index d61215025..d061696bd 100644 --- a/lib/geocoder/lookups/ipdata_co.rb +++ b/lib/geocoder/lookups/ipdata_co.rb @@ -25,8 +25,8 @@ def cache_key(query) end def results(query) - # don't look up a loopback address, just return the stored result - return [reserved_result(query.text)] if query.loopback_ip_address? + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? # note: Ipdata.co returns plain text on bad request (doc = fetch_data(query)) ? [doc] : [] end diff --git a/lib/geocoder/lookups/ipinfo_io.rb b/lib/geocoder/lookups/ipinfo_io.rb index e160c975a..d3a6cc2fb 100644 --- a/lib/geocoder/lookups/ipinfo_io.rb +++ b/lib/geocoder/lookups/ipinfo_io.rb @@ -26,8 +26,8 @@ def base_query_url(query) end def results(query) - # don't look up a loopback address, just return the stored result - return [reserved_result(query.text)] if query.loopback_ip_address? + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? if !(doc = fetch_data(query)).is_a?(Hash) or doc['error'] [] diff --git a/lib/geocoder/lookups/ipstack.rb b/lib/geocoder/lookups/ipstack.rb index 03449ffb4..f01f15288 100644 --- a/lib/geocoder/lookups/ipstack.rb +++ b/lib/geocoder/lookups/ipstack.rb @@ -34,8 +34,8 @@ def query_url_params(query) end def results(query) - # don't look up a loopback address, just return the stored result - return [reserved_result(query.text)] if query.loopback_ip_address? + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? return [] unless doc = fetch_data(query) diff --git a/lib/geocoder/lookups/maxmind.rb b/lib/geocoder/lookups/maxmind.rb index 5cf9eeccb..c9ba59535 100644 --- a/lib/geocoder/lookups/maxmind.rb +++ b/lib/geocoder/lookups/maxmind.rb @@ -57,8 +57,8 @@ def services end def results(query) - # don't look up a loopback address, just return the stored result - return [reserved_result] if query.loopback_ip_address? + # don't look up a loopback or private address, just return the stored result + return [reserved_result] if query.internal_ip_address? doc = fetch_data(query) if doc and doc.is_a?(Array) if !data_contains_error?(doc) diff --git a/lib/geocoder/lookups/maxmind_geoip2.rb b/lib/geocoder/lookups/maxmind_geoip2.rb index 89be78125..0640a251b 100644 --- a/lib/geocoder/lookups/maxmind_geoip2.rb +++ b/lib/geocoder/lookups/maxmind_geoip2.rb @@ -53,8 +53,9 @@ def services end def results(query) - # don't look up a loopback address - return [] if query.loopback_ip_address? + # don't look up a loopback or private address, just return the stored result + return [] if query.internal_ip_address? + doc = fetch_data(query) if doc if !data_contains_error?(doc) diff --git a/lib/geocoder/lookups/pointpin.rb b/lib/geocoder/lookups/pointpin.rb index 5476849cf..0e279a12d 100644 --- a/lib/geocoder/lookups/pointpin.rb +++ b/lib/geocoder/lookups/pointpin.rb @@ -23,8 +23,8 @@ def cache_key(query) end def results(query) - # don't look up a loopback address, just return the stored result - return [] if query.loopback_ip_address? + # don't look up a loopback or private address, just return the stored result + return [] if query.internal_ip_address? doc = fetch_data(query) if doc and doc.is_a?(Hash) if !data_contains_error?(doc) @@ -42,7 +42,7 @@ def results(query) raise_error(Geocoder::Error) || Geocoder.log(:warn, "Pointpin server error") end end - + return [] end diff --git a/lib/geocoder/lookups/telize.rb b/lib/geocoder/lookups/telize.rb index c41efbd91..2dd84523a 100644 --- a/lib/geocoder/lookups/telize.rb +++ b/lib/geocoder/lookups/telize.rb @@ -34,8 +34,8 @@ def cache_key(query) end def results(query) - # don't look up a loopback address, just return the stored result - return [reserved_result(query.text)] if query.loopback_ip_address? + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? if (doc = fetch_data(query)).nil? or doc['code'] == 401 or empty_result?(doc) [] else diff --git a/lib/geocoder/query.rb b/lib/geocoder/query.rb index 61710ef92..223cb3167 100644 --- a/lib/geocoder/query.rb +++ b/lib/geocoder/query.rb @@ -66,6 +66,13 @@ def ip_address? IpAddress.new(text).valid? rescue false end + ## + # Is the Query text a loopback or private IP address? + # + def internal_ip_address? + ip_address? && IpAddress.new(text).internal? + end + ## # Is the Query text a loopback IP address? # @@ -73,6 +80,13 @@ def loopback_ip_address? ip_address? && IpAddress.new(text).loopback? end + ## + # Is the Query text a private IP address? + # + def private_ip_address? + ip_address? && IpAddress.new(text).private? + end + ## # Does the given string look like latitude/longitude coordinates? # diff --git a/test/fixtures/pointpin_10_10_10_10 b/test/fixtures/pointpin_8_8_8_8 similarity index 100% rename from test/fixtures/pointpin_10_10_10_10 rename to test/fixtures/pointpin_8_8_8_8 diff --git a/test/fixtures/telize_10_10_10_10 b/test/fixtures/telize_10_10_10_10 deleted file mode 100644 index 700f75cc5..000000000 --- a/test/fixtures/telize_10_10_10_10 +++ /dev/null @@ -1 +0,0 @@ -{"ip":"10.10.10.10"} diff --git a/test/fixtures/telize_8_8_8_8 b/test/fixtures/telize_8_8_8_8 new file mode 100644 index 000000000..e1cbeb593 --- /dev/null +++ b/test/fixtures/telize_8_8_8_8 @@ -0,0 +1 @@ +{"ip":"8.8.8.8"} diff --git a/test/fixtures/telize_no_results b/test/fixtures/telize_no_results index 700f75cc5..e1cbeb593 100644 --- a/test/fixtures/telize_no_results +++ b/test/fixtures/telize_no_results @@ -1 +1 @@ -{"ip":"10.10.10.10"} +{"ip":"8.8.8.8"} diff --git a/test/unit/ip_address_test.rb b/test/unit/ip_address_test.rb index 0b4c3c4da..e2dedf79e 100644 --- a/test/unit/ip_address_test.rb +++ b/test/unit/ip_address_test.rb @@ -15,12 +15,39 @@ def test_valid assert !Geocoder::IpAddress.new("Test\n232.65.123.94").valid? end + def test_internal + assert Geocoder::IpAddress.new("0.0.0.0").internal? + assert Geocoder::IpAddress.new("127.0.0.1").internal? + assert Geocoder::IpAddress.new("::1").internal? + assert Geocoder::IpAddress.new("172.19.0.1").internal? + assert Geocoder::IpAddress.new("10.100.100.1").internal? + assert Geocoder::IpAddress.new("192.168.0.1").internal? + assert !Geocoder::IpAddress.new("232.65.123.234").internal? + assert !Geocoder::IpAddress.new("127 Main St.").internal? + assert !Geocoder::IpAddress.new("John Doe\n127 Main St.\nAnywhere, USA").internal? + end + def test_loopback assert Geocoder::IpAddress.new("0.0.0.0").loopback? assert Geocoder::IpAddress.new("127.0.0.1").loopback? assert Geocoder::IpAddress.new("::1").loopback? + assert !Geocoder::IpAddress.new("172.19.0.1").loopback? + assert !Geocoder::IpAddress.new("10.100.100.1").loopback? + assert !Geocoder::IpAddress.new("192.168.0.1").loopback? assert !Geocoder::IpAddress.new("232.65.123.234").loopback? assert !Geocoder::IpAddress.new("127 Main St.").loopback? assert !Geocoder::IpAddress.new("John Doe\n127 Main St.\nAnywhere, USA").loopback? end + + def test_private + assert Geocoder::IpAddress.new("172.19.0.1").private? + assert Geocoder::IpAddress.new("10.100.100.1").private? + assert Geocoder::IpAddress.new("192.168.0.1").private? + assert !Geocoder::IpAddress.new("0.0.0.0").private? + assert !Geocoder::IpAddress.new("127.0.0.1").private? + assert !Geocoder::IpAddress.new("::1").private? + assert !Geocoder::IpAddress.new("232.65.123.234").private? + assert !Geocoder::IpAddress.new("127 Main St.").private? + assert !Geocoder::IpAddress.new("John Doe\n127 Main St.\nAnywhere, USA").private? + end end diff --git a/test/unit/lookups/freegeoip_test.rb b/test/unit/lookups/freegeoip_test.rb index 565efb6b8..766e000a8 100644 --- a/test/unit/lookups/freegeoip_test.rb +++ b/test/unit/lookups/freegeoip_test.rb @@ -12,6 +12,20 @@ def test_result_on_ip_address_search assert result.is_a?(Geocoder::Result::Freegeoip) end + def test_result_on_loopback_ip_address_search + result = Geocoder.search("127.0.0.1").first + assert_equal "127.0.0.1", result.ip + assert_equal 'RD', result.country_code + assert_equal "Reserved", result.country + end + + def test_result_on_private_ip_address_search + result = Geocoder.search("172.19.0.1").first + assert_equal "172.19.0.1", result.ip + assert_equal 'RD', result.country_code + assert_equal "Reserved", result.country + end + def test_result_components result = Geocoder.search("74.200.247.59").first assert_equal "Plano, TX 75093, United States", result.address diff --git a/test/unit/lookups/ip2location_test.rb b/test/unit/lookups/ip2location_test.rb index 392282208..6c6ad7a85 100644 --- a/test/unit/lookups/ip2location_test.rb +++ b/test/unit/lookups/ip2location_test.rb @@ -17,6 +17,11 @@ def test_ip2location_lookup_loopback_address assert_equal "INVALID IP ADDRESS", result.country_code end + def test_ip2location_lookup_private_address + result = Geocoder.search("172.19.0.1").first + assert_equal "INVALID IP ADDRESS", result.country_code + end + def test_ip2location_extra_data Geocoder.configure(:ip2location => {:package => "WS3"}) result = Geocoder.search("8.8.8.8").first diff --git a/test/unit/lookups/ipapi_com_test.rb b/test/unit/lookups/ipapi_com_test.rb index 103bbaf7c..e7c92a4c1 100644 --- a/test/unit/lookups/ipapi_com_test.rb +++ b/test/unit/lookups/ipapi_com_test.rb @@ -41,7 +41,7 @@ def test_all_api_fields assert_equal nil, result.message end - def test_localhost + def test_loopback result = Geocoder.search("::1").first assert_equal nil, result.lat assert_equal nil, result.lon @@ -51,6 +51,16 @@ def test_localhost assert_equal "fail", result.status end + def test_private + result = Geocoder.search("172.19.0.1").first + assert_equal nil, result.lat + assert_equal nil, result.lon + assert_equal [nil, nil], result.coordinates + assert_equal nil, result.reverse + assert_equal "172.19.0.1", result.query + assert_equal "fail", result.status + end + def test_api_key Geocoder.configure(:api_key => "MY_KEY") g = Geocoder::Lookup::IpapiCom.new diff --git a/test/unit/lookups/ipdata_co_test.rb b/test/unit/lookups/ipdata_co_test.rb index 5704c9023..704783fb4 100644 --- a/test/unit/lookups/ipdata_co_test.rb +++ b/test/unit/lookups/ipdata_co_test.rb @@ -12,6 +12,20 @@ def test_result_on_ip_address_search assert result.is_a?(Geocoder::Result::IpdataCo) end + def test_result_on_loopback_ip_address_search + result = Geocoder.search("127.0.0.1").first + assert_equal "127.0.0.1", result.ip + assert_equal 'RD', result.country_code + assert_equal "Reserved", result.country + end + + def test_result_on_private_ip_address_search + result = Geocoder.search("172.19.0.1").first + assert_equal "172.19.0.1", result.ip + assert_equal 'RD', result.country_code + assert_equal "Reserved", result.country + end + def test_invalid_json Geocoder.configure(:always_raise => [Geocoder::ResponseParseError]) assert_raise Geocoder::ResponseParseError do diff --git a/test/unit/lookups/ipinfo_io_test.rb b/test/unit/lookups/ipinfo_io_test.rb index 206a71fd4..a654ad7dc 100644 --- a/test/unit/lookups/ipinfo_io_test.rb +++ b/test/unit/lookups/ipinfo_io_test.rb @@ -23,6 +23,14 @@ def test_ipinfo_io_lookup_loopback_address assert_equal "127.0.0.1", result.ip end + def test_ipinfo_io_lookup_private_address + Geocoder.configure(:ip_lookup => :ipinfo_io) + result = Geocoder.search("172.19.0.1").first + assert_nil result.latitude + assert_nil result.longitude + assert_equal "172.19.0.1", result.ip + end + def test_ipinfo_io_extra_attributes Geocoder.configure(:ip_lookup => :ipinfo_io, :use_https => true) result = Geocoder.search("8.8.8.8").first diff --git a/test/unit/lookups/ipstack_test.rb b/test/unit/lookups/ipstack_test.rb index fd2a17682..455eefc15 100644 --- a/test/unit/lookups/ipstack_test.rb +++ b/test/unit/lookups/ipstack_test.rb @@ -116,6 +116,13 @@ def test_localhost_loopback_defaults assert_equal({}, result.connection) end + def test_localhost_private + result = Geocoder.search("172.19.0.1").first + assert_equal "172.19.0.1", result.ip + assert_equal "RD", result.country_code + assert_equal "Reserved", result.country_name + end + def test_api_request_adds_access_key lookup = Geocoder::Lookup.get(:ipstack) assert_match 'http://api.ipstack.com/74.200.247.59?access_key=123', lookup.query_url(Geocoder::Query.new("74.200.247.59")) diff --git a/test/unit/lookups/maxmind_test.rb b/test/unit/lookups/maxmind_test.rb index 6fc6cb024..99672c9b1 100644 --- a/test/unit/lookups/maxmind_test.rb +++ b/test/unit/lookups/maxmind_test.rb @@ -59,4 +59,16 @@ def test_maxmind_works_when_loopback_address_on_country result = Geocoder.search("127.0.0.1").first assert_equal "", result.country_code end + + def test_maxmind_works_when_private_address_on_omni + Geocoder.configure(maxmind: {service: :omni}) + result = Geocoder.search("172.19.0.1").first + assert_equal "", result.country_code + end + + def test_maxmind_works_when_private_address_on_country + Geocoder.configure(maxmind: {service: :country}) + result = Geocoder.search("172.19.0.1").first + assert_equal "", result.country_code + end end diff --git a/test/unit/lookups/pointpin_test.rb b/test/unit/lookups/pointpin_test.rb index 86549e994..3d81c6624 100644 --- a/test/unit/lookups/pointpin_test.rb +++ b/test/unit/lookups/pointpin_test.rb @@ -12,6 +12,16 @@ def test_result_on_ip_address_search assert result.is_a?(Geocoder::Result::Pointpin) end + def test_result_on_loopback_ip_address_search + results = Geocoder.search("127.0.0.1") + assert_equal 0, results.length + end + + def test_result_on_private_ip_address_search + results = Geocoder.search("172.19.0.1") + assert_equal 0, results.length + end + def test_result_components result = Geocoder.search("80.111.55.55").first assert_equal "Dublin, Dublin City, 8, Ireland", result.address @@ -19,7 +29,7 @@ def test_result_components def test_no_results silence_warnings do - results = Geocoder.search("10.10.10.10") + results = Geocoder.search("8.8.8.8") assert_equal 0, results.length end end diff --git a/test/unit/lookups/telize_test.rb b/test/unit/lookups/telize_test.rb index a4260bc15..4280fe241 100644 --- a/test/unit/lookups/telize_test.rb +++ b/test/unit/lookups/telize_test.rb @@ -46,6 +46,20 @@ def test_result_on_ip_address_search assert result.is_a?(Geocoder::Result::Telize) end + def test_result_on_loopback_ip_address_search + result = Geocoder.search("127.0.0.1").first + assert_equal "127.0.0.1", result.ip + assert_equal '', result.country_code + assert_equal '', result.country + end + + def test_result_on_private_ip_address_search + result = Geocoder.search("172.19.0.1").first + assert_equal "172.19.0.1", result.ip + assert_equal '', result.country_code + assert_equal '', result.country + end + def test_result_components result = Geocoder.search("74.200.247.59").first assert_equal "Jersey City, NJ 07302, United States", result.address @@ -54,7 +68,7 @@ def test_result_components end def test_no_results - results = Geocoder.search("10.10.10.10") + results = Geocoder.search("8.8.8.8") assert_equal 0, results.length end @@ -66,7 +80,7 @@ def test_invalid_address def test_cache_key_strips_off_query_string Geocoder.configure(telize: {api_key: "xxxxx"}) lookup = Geocoder::Lookup.get(:telize) - query = Geocoder::Query.new("10.10.10.10") + query = Geocoder::Query.new("8.8.8.8") qurl = lookup.send(:query_url, query) key = lookup.send(:cache_key, query) assert qurl.include?("mashape-key") diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 51c713c36..862e1b072 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -34,11 +34,27 @@ def test_coordinates_detection assert !Geocoder::Query.new("Test\n51.178844, -1.826189").coordinates? end + def test_internal_ip_address + assert Geocoder::Query.new("127.0.0.1").internal_ip_address? + assert Geocoder::Query.new("172.19.0.1").internal_ip_address? + assert Geocoder::Query.new("10.100.100.1").internal_ip_address? + assert Geocoder::Query.new("192.168.0.1").internal_ip_address? + assert !Geocoder::Query.new("232.65.123.234").internal_ip_address? + end + def test_loopback_ip_address assert Geocoder::Query.new("127.0.0.1").loopback_ip_address? assert !Geocoder::Query.new("232.65.123.234").loopback_ip_address? end + def test_private_ip_address + assert Geocoder::Query.new("172.19.0.1").private_ip_address? + assert Geocoder::Query.new("10.100.100.1").private_ip_address? + assert Geocoder::Query.new("192.168.0.1").private_ip_address? + assert !Geocoder::Query.new("127.0.0.1").private_ip_address? + assert !Geocoder::Query.new("232.65.123.234").private_ip_address? + end + def test_sanitized_text_with_array q = Geocoder::Query.new([43.1313,11.3131]) assert_equal "43.1313,11.3131", q.sanitized_text diff --git a/test/unit/request_test.rb b/test/unit/request_test.rb index 8db88b1ea..a77f5bf26 100644 --- a/test/unit/request_test.rb +++ b/test/unit/request_test.rb @@ -53,6 +53,10 @@ def test_with_loopback_x_forwarded_for req = MockRequest.new({"HTTP_X_FORWARDED_FOR" => "127.0.0.1"}, "74.200.247.59") assert_equal "US", req.location.country_code end + def test_with_private_x_forwarded_for + req = MockRequest.new({"HTTP_X_FORWARDED_FOR" => "172.19.0.1"}, "74.200.247.59") + assert_equal "US", req.location.country_code + end def test_http_x_forwarded_for_with_misconfigured_proxies req = MockRequest.new({"HTTP_X_FORWARDED_FOR" => ","}, "74.200.247.59") assert req.location.is_a?(Geocoder::Result::Freegeoip) From 0efc1ea599c5c6d7a418c9eae4ab939017605816 Mon Sep 17 00:00:00 2001 From: Michael Holroyd <meekohi@gmail.com> Date: Tue, 11 Sep 2018 14:49:54 -0400 Subject: [PATCH 125/248] Fix typo in README.md Fixes link anchor in table of contents to the Error Handling section --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1128e8b0a..d4e67706d 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Advanced Features: * [Geospatial Calculations](#geospatial-calculations) * [Batch Geocoding](#batch-geocoding) * [Testing](#testing) -* [Error Handling](#error-handing) +* [Error Handling](#error-handling) * [Command Line Interface](#command-line-interface) The Rest: From 8c919117370284c5f65a7d5e4c272f69d6c9790e Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 1 Oct 2018 08:33:57 -0600 Subject: [PATCH 126/248] API key required for ipdata.co. --- README_API_GUIDE.md | 4 ++-- lib/geocoder/lookups/ipdata_co.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index cf1a5ebc5..23123f153 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -454,8 +454,8 @@ IP Address Lookups ### Ipdata.co (`:ipdata_co`) -* **API key**: optional, see: https://ipdata.co/pricing.html -* **Quota**: 1500/day (up to 600k with paid API keys) +* **API key**: required, see: https://ipdata.co/pricing.html +* **Quota**: 1500/day for free, up to 600k with paid API keys * **Region**: world * **SSL support**: yes * **Languages**: English diff --git a/lib/geocoder/lookups/ipdata_co.rb b/lib/geocoder/lookups/ipdata_co.rb index d061696bd..c4798ea4b 100644 --- a/lib/geocoder/lookups/ipdata_co.rb +++ b/lib/geocoder/lookups/ipdata_co.rb @@ -12,6 +12,10 @@ def supported_protocols [:https] end + def required_api_key_parts + ["api_key"] + end + def query_url(query) # Ipdata.co requires that the API key be sent as a query parameter. # It no longer supports API keys sent as headers. From 24db7141929b1e1b2d3f1f932235d8230c6682b7 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 3 Oct 2018 09:47:12 -0600 Subject: [PATCH 127/248] Don't require api key parts. This fixes erroring tests for ESRI lookup, which seem unrelated. Something weird is going on. Need to investigate. --- lib/geocoder/lookups/ipdata_co.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/geocoder/lookups/ipdata_co.rb b/lib/geocoder/lookups/ipdata_co.rb index c4798ea4b..d061696bd 100644 --- a/lib/geocoder/lookups/ipdata_co.rb +++ b/lib/geocoder/lookups/ipdata_co.rb @@ -12,10 +12,6 @@ def supported_protocols [:https] end - def required_api_key_parts - ["api_key"] - end - def query_url(query) # Ipdata.co requires that the API key be sent as a query parameter. # It no longer supports API keys sent as headers. From f46e9be522b85b03527e1327ae98e95d10cd54c7 Mon Sep 17 00:00:00 2001 From: Alberto Vena <kennyadsl@gmail.com> Date: Thu, 4 Oct 2018 16:36:57 +0200 Subject: [PATCH 128/248] Update Nominatim Terms of Service policy link --- README_API_GUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 23123f153..8f7bd6761 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -76,7 +76,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **SSL support**: yes * **Languages**: ? * **Documentation**: http://wiki.openstreetmap.org/wiki/Nominatim -* **Terms of Service**: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy +* **Terms of Service**: https://operations.osmfoundation.org/policies/nominatim/ * **Limitations**: Please limit request rate to 1 per second and include your contact information in User-Agent headers (eg: `Geocoder.configure(http_headers: { "User-Agent" => "your contact info" })`). [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) ### PickPoint (`:pickpoint`) From 5ae95ded12b0bf808bc049167458adb838b9a50f Mon Sep 17 00:00:00 2001 From: Jose Ramon C <joserracamacho@gmail.com> Date: Thu, 4 Oct 2018 10:23:48 -0500 Subject: [PATCH 129/248] Add ip_lookup to test instructions --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d4e67706d..cfcb0edfb 100644 --- a/README.md +++ b/README.md @@ -500,9 +500,9 @@ To avoid exceeding per-day limits you can add a `LIMIT` option. However, this wi Testing ------- -When writing tests for an app that uses Geocoder it may be useful to avoid network calls and have Geocoder return consistent, configurable results. To do this, configure the `:test` lookup: +When writing tests for an app that uses Geocoder it may be useful to avoid network calls and have Geocoder return consistent, configurable results. To do this, configure the `:test` lookup and `:ip_lookup` - Geocoder.configure(lookup: :test) + Geocoder.configure(lookup: :test, ip_lookup: :test) Add stubs to define the results that will be returned: From e45f8bd3173c28e03efbfaf03eab7c5afaf4621a Mon Sep 17 00:00:00 2001 From: Alex Reisner <alexreisner@users.noreply.github.com> Date: Thu, 4 Oct 2018 09:37:59 -0600 Subject: [PATCH 130/248] Clarify: don't need to set both lookups to :test. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cfcb0edfb..15de6ba62 100644 --- a/README.md +++ b/README.md @@ -500,7 +500,7 @@ To avoid exceeding per-day limits you can add a `LIMIT` option. However, this wi Testing ------- -When writing tests for an app that uses Geocoder it may be useful to avoid network calls and have Geocoder return consistent, configurable results. To do this, configure the `:test` lookup and `:ip_lookup` +When writing tests for an app that uses Geocoder it may be useful to avoid network calls and have Geocoder return consistent, configurable results. To do this, configure the `:test` lookup and/or `:ip_lookup` Geocoder.configure(lookup: :test, ip_lookup: :test) From bb4af670adafe4dac9abd05f51eeff542a85528b Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 17 Oct 2018 23:00:02 -0700 Subject: [PATCH 131/248] Remove :mapzen lookup. Defunct as of Feb 1, 2018: https://mapzen.com/blog/shutdown/ --- README_API_GUIDE.md | 12 ------------ lib/geocoder/lookup.rb | 1 - lib/geocoder/lookups/mapzen.rb | 15 --------------- lib/geocoder/results/mapzen.rb | 5 ----- test/test_helper.rb | 7 ------- test/unit/lookups/mapzen_test.rb | 17 ----------------- 6 files changed, 57 deletions(-) delete mode 100644 lib/geocoder/lookups/mapzen.rb delete mode 100644 lib/geocoder/results/mapzen.rb delete mode 100644 test/unit/lookups/mapzen_test.rb diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 8f7bd6761..65708d9f6 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -193,18 +193,6 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Limitations**: Requires API key if results will be stored. Using API key will also remove rate limit. * **Notes**: You can specify which projection you want to use by setting, for example: `Geocoder.configure(esri: {outSR: 102100})`. If you will store results, set the flag and provide API key: `Geocoder.configure(esri: {api_key: ["client_id", "client_secret"], for_storage: true})`. If you want to, you can also supply an ESRI token directly: `Geocoder.configure(esri: {token: Geocoder::EsriToken.new('TOKEN', Time.now + 1.day})` -### Mapzen (`:mapzen`) - -* **API key**: required -* **Quota**: 25,000 free requests/month and [ability to purchase more](https://mapzen.com/pricing/) -* **Region**: world -* **SSL support**: yes -* **Languages**: en; see https://mapzen.com/documentation/search/language-codes/ -* **Documentation**: https://mapzen.com/documentation/search/search/ -* **Terms of Service**: http://mapzen.com/terms -* **Limitations**: [You must provide attribution](https://mapzen.com/rights/) -* **Notes**: Mapzen is the primary author of Pelias and offers Pelias-as-a-service in free and paid versions https://mapzen.com/pelias. - ### Pelias (`:pelias`) * **API key**: configurable (self-hosted service) diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index 5ccae1022..ccfa1698f 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -37,7 +37,6 @@ def street_services :nominatim, :mapbox, :mapquest, - :mapzen, :opencagedata, :pelias, :pickpoint, diff --git a/lib/geocoder/lookups/mapzen.rb b/lib/geocoder/lookups/mapzen.rb deleted file mode 100644 index 0bb70d309..000000000 --- a/lib/geocoder/lookups/mapzen.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'geocoder/lookups/pelias' -require 'geocoder/results/mapzen' - -# https://mapzen.com/documentation/search/search/ for more information -module Geocoder::Lookup - class Mapzen < Pelias - def name - 'Mapzen' - end - - def endpoint - configuration[:endpoint] || 'search.mapzen.com' - end - end -end diff --git a/lib/geocoder/results/mapzen.rb b/lib/geocoder/results/mapzen.rb deleted file mode 100644 index 125f4da86..000000000 --- a/lib/geocoder/results/mapzen.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'geocoder/results/pelias' - -module Geocoder::Result - class Mapzen < Pelias; end -end diff --git a/test/test_helper.rb b/test/test_helper.rb index d6243a919..4b1cb3375 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -370,13 +370,6 @@ def default_fixture_filename end end - require 'geocoder/lookups/mapzen' - class Mapzen - def fixture_prefix - 'pelias' - end - end - require 'geocoder/lookups/ipinfo_io' class IpinfoIo private diff --git a/test/unit/lookups/mapzen_test.rb b/test/unit/lookups/mapzen_test.rb deleted file mode 100644 index 83ad909d1..000000000 --- a/test/unit/lookups/mapzen_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -# encoding: utf-8 -require 'test_helper' - -class MapzenTest < GeocoderTestCase - def setup - Geocoder.configure(lookup: :mapzen, api_key: 'abc123') - end - - def test_configure_default_endpoint - query = Geocoder::Query.new('Madison Square Garden, New York, NY') - assert_true query.url.start_with?('http://search.mapzen.com/v1/search'), query.url - end - - def test_inherits_from_pelias - assert_true Geocoder::Lookup::Mapzen.new.is_a?(Geocoder::Lookup::Pelias) - end -end From d1e03c81e50066196e75328ce8434cd9d18a79bb Mon Sep 17 00:00:00 2001 From: Ryan Dlugosz <ryan@dlugosz.net> Date: Thu, 18 Oct 2018 11:12:03 -0400 Subject: [PATCH 132/248] Allow https for IPInfo.io queries without an API key It appears that at some point they changed the "TLS only for paying customers" rule. See: https://ipinfo.io/developers#https-ssl "Our API is available over a secure HTTPS connection for all users, even on the free plan." --- README_API_GUIDE.md | 2 +- lib/geocoder/lookups/ipinfo_io.rb | 9 --------- test/unit/lookups/ipinfo_io_test.rb | 13 ------------- 3 files changed, 1 insertion(+), 23 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 8f7bd6761..363e8f2fc 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -342,7 +342,7 @@ IP Address Lookups * **API key**: optional - see http://ipinfo.io/pricing * **Quota**: 1,000/day - more with api key * **Region**: world -* **SSL support**: no (not without access key - see http://ipinfo.io/pricing) +* **SSL support**: yes * **Languages**: English * **Documentation**: http://ipinfo.io/developers * **Terms of Service**: http://ipinfo.io/developers diff --git a/lib/geocoder/lookups/ipinfo_io.rb b/lib/geocoder/lookups/ipinfo_io.rb index d3a6cc2fb..ef0cdf0bc 100644 --- a/lib/geocoder/lookups/ipinfo_io.rb +++ b/lib/geocoder/lookups/ipinfo_io.rb @@ -8,15 +8,6 @@ def name "Ipinfo.io" end - # HTTPS available only for paid plans - def supported_protocols - if configuration.api_key - [:http, :https] - else - [:http] - end - end - private # --------------------------------------------------------------- def base_query_url(query) diff --git a/test/unit/lookups/ipinfo_io_test.rb b/test/unit/lookups/ipinfo_io_test.rb index a654ad7dc..6d4335cee 100644 --- a/test/unit/lookups/ipinfo_io_test.rb +++ b/test/unit/lookups/ipinfo_io_test.rb @@ -2,19 +2,6 @@ require 'test_helper' class IpinfoIoTest < GeocoderTestCase - - def test_ipinfo_io_use_http_without_token - Geocoder.configure(:ip_lookup => :ipinfo_io, :use_https => true) - query = Geocoder::Query.new("8.8.8.8") - assert_match(/^http:/, query.url) - end - - def test_ipinfo_io_uses_https_when_auth_token_set - Geocoder.configure(:ip_lookup => :ipinfo_io, :api_key => "FOO_BAR_TOKEN", :use_https => true) - query = Geocoder::Query.new("8.8.8.8") - assert_match(/^https:/, query.url) - end - def test_ipinfo_io_lookup_loopback_address Geocoder.configure(:ip_lookup => :ipinfo_io) result = Geocoder.search("127.0.0.1").first From 5e01e8acd203f82481c0a56e6f40aea01a06cc60 Mon Sep 17 00:00:00 2001 From: Jorge Santos <jorgeoliveirasantos@gmail.com> Date: Fri, 19 Oct 2018 10:54:01 +0800 Subject: [PATCH 133/248] Modify Pelias lookup to return multiple results - Fixes #1353 - Do not limit the results returned from Pelias to 1; - Removed test that was enforcing this condition; --- lib/geocoder/lookups/pelias.rb | 5 ++--- test/unit/lookups/pelias_test.rb | 7 +------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/geocoder/lookups/pelias.rb b/lib/geocoder/lookups/pelias.rb index fd8a7444d..dc48cbdb1 100644 --- a/lib/geocoder/lookups/pelias.rb +++ b/lib/geocoder/lookups/pelias.rb @@ -24,12 +24,11 @@ def base_query_url(query) def query_url_params(query) params = { - api_key: configuration.api_key, - size: 1 + api_key: configuration.api_key }.merge(super) if query.reverse_geocode? - lat,lon = query.coordinates + lat, lon = query.coordinates params[:'point.lat'] = lat params[:'point.lon'] = lon else diff --git a/test/unit/lookups/pelias_test.rb b/test/unit/lookups/pelias_test.rb index 13566d2a3..47dfa1718 100644 --- a/test/unit/lookups/pelias_test.rb +++ b/test/unit/lookups/pelias_test.rb @@ -17,14 +17,9 @@ def test_configure_custom_endpoint assert_true query.url.start_with?('http://self.hosted.pelias/proxy/v1/search'), query.url end - def test_query_url_defaults_to_one - query = Geocoder::Query.new('Madison Square Garden, New York, NY') - assert_match 'size=1', query.url - end - def test_query_for_reverse_geocode lookup = Geocoder::Lookup::Pelias.new url = lookup.query_url(Geocoder::Query.new([45.423733, -75.676333])) - assert_match(/point.lat=45.423733&point.lon=-75.676333&size=1/, url) + assert_match(/point.lat=45.423733&point.lon=-75.676333/, url) end end From 6ae6e62dc51b5fbb076d9849b9876867f65d2da8 Mon Sep 17 00:00:00 2001 From: cain <cain@beansmile.com> Date: Mon, 5 Nov 2018 17:22:36 +0800 Subject: [PATCH 134/248] fix: baidu_ip lookups require 'geocoder/lookups/baidu' --- lib/geocoder/lookups/baidu_ip.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/baidu_ip.rb b/lib/geocoder/lookups/baidu_ip.rb index 9ce54e8eb..e48af508a 100644 --- a/lib/geocoder/lookups/baidu_ip.rb +++ b/lib/geocoder/lookups/baidu_ip.rb @@ -1,4 +1,4 @@ -require 'geocoder/lookups/base' +require 'geocoder/lookups/baidu' require 'geocoder/results/baidu_ip' module Geocoder::Lookup From d7b4e744e28ed72a14fcc72758eaebcab05cb968 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Tue, 6 Nov 2018 08:46:39 -0500 Subject: [PATCH 135/248] Replace Paris, TX example in README with one that's more likely to work. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 15de6ba62..4e2c2589e 100644 --- a/README.md +++ b/README.md @@ -224,15 +224,15 @@ Some common options are: Please see [`lib/geocoder/configuration.rb`](https://github.com/alexreisner/geocoder/blob/master/lib/geocoder/configuration.rb) for a complete list of configuration options. Additionally, some lookups have their own special configuration options which are directly supported by Geocoder. For example, to specify a value for Google's `bounds` parameter: # with Google: - Geocoder.search("Paris", bounds: [[32.1,-95.9], [33.9,-94.3]]) + Geocoder.search("Middletown", bounds: [[40.6,-77.9], [39.9,-75.9]]) Please see the [source code for each lookup](https://github.com/alexreisner/geocoder/tree/master/lib/geocoder/lookups) to learn about directly supported parameters. Parameters which are not directly supported can be specified using the `:params` option, which appends options to the query string of the geocoding request. For example: # Nominatim's `countrycodes` parameter: - Geocoder.search("Paris", params: {countrycodes: "gb,de,fr,es,us"}) + Geocoder.search("Rome", params: {countrycodes: "us,ca"}) # Google's `region` parameter: - Geocoder.search("Paris", params: {region: "..."}) + Geocoder.search("Rome", params: {region: "..."}) ### Configuring Multiple Services From 447aa2555980f4982293ce0d3ad9c496eba3cf9c Mon Sep 17 00:00:00 2001 From: Tiago Teixeira <tiagocmtex@gmail.com> Date: Mon, 12 Nov 2018 16:50:19 +0100 Subject: [PATCH 136/248] Allow to pass language parameter for bing and here lookups --- README_API_GUIDE.md | 2 +- lib/geocoder/lookups/bing.rb | 3 ++- lib/geocoder/lookups/here.rb | 13 +++++++------ test/unit/lookup_test.rb | 2 ++ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 773491b33..b19fd6809 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -63,7 +63,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Quota**: 50,0000 requests/day (Windows app), 125,000 requests/year (non-Windows app) * **Region**: world * **SSL support**: no -* **Languages**: ? +* **Languages**: The preferred language of address elements in the result. Language code must be provided according to RFC 4647 standard. * **Documentation**: http://msdn.microsoft.com/en-us/library/ff701715.aspx * **Terms of Service**: http://www.microsoft.com/maps/product/terms.html * **Limitations**: No country codes or state names. Must be used on "public-facing, non-password protected web sites," "in conjunction with Bing Maps or an application that integrates Bing Maps." diff --git a/lib/geocoder/lookups/bing.rb b/lib/geocoder/lookups/bing.rb index 53894c2ff..c2d0edcfc 100644 --- a/lib/geocoder/lookups/bing.rb +++ b/lib/geocoder/lookups/bing.rb @@ -53,7 +53,8 @@ def results(query) def query_url_params(query) { - key: configuration.api_key + key: configuration.api_key, + language: (query.language || configuration.language) }.merge(super) end diff --git a/lib/geocoder/lookups/here.rb b/lib/geocoder/lookups/here.rb index f99eaee81..420c6e34c 100644 --- a/lib/geocoder/lookups/here.rb +++ b/lib/geocoder/lookups/here.rb @@ -30,19 +30,20 @@ def results(query) def query_url_params(query) options = { - :gen=>4, - :app_id=>api_key, - :app_code=>api_code + gen: 4, + app_id: api_key, + app_code: api_code, + language: (query.language || configuration.language) } if query.reverse_geocode? super.merge(options).merge( - :prox=>query.sanitized_text, - :mode=>:retrieveAddresses + prox: query.sanitized_text, + mode: :retrieveAddresses ) else super.merge(options).merge( - :searchtext=>query.sanitized_text + searchtext: query.sanitized_text ) end end diff --git a/test/unit/lookup_test.rb b/test/unit/lookup_test.rb index e98f883cb..d2ba813a0 100644 --- a/test/unit/lookup_test.rb +++ b/test/unit/lookup_test.rb @@ -56,8 +56,10 @@ def test_query_url_contains_values_in_params_hash end { + :bing => :language, :google => :language, :google_premier => :language, + :here => :language, :nominatim => :"accept-language", :yandex => :plng }.each do |l,p| From c28e933106aa9208cdad598d54dfa28766d0861e Mon Sep 17 00:00:00 2001 From: Andrew Kane <andrew@chartkick.com> Date: Thu, 29 Nov 2018 22:37:49 -0800 Subject: [PATCH 137/248] Fixed typo --- lib/geocoder/lookups/smarty_streets.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/smarty_streets.rb b/lib/geocoder/lookups/smarty_streets.rb index a1fe31402..c16a6e8c4 100644 --- a/lib/geocoder/lookups/smarty_streets.rb +++ b/lib/geocoder/lookups/smarty_streets.rb @@ -8,7 +8,7 @@ def name end def required_api_key_parts - %w(auti-id auth-token) + %w(auth-id auth-token) end # required by API as of 26 March 2015 From 373eac549519bfa490088dcc7b9837126885a84b Mon Sep 17 00:00:00 2001 From: Andrew Kane <andrew@chartkick.com> Date: Fri, 30 Nov 2018 00:05:26 -0800 Subject: [PATCH 138/248] Added support for Smarty Streets International API --- lib/geocoder/lookups/smarty_streets.rb | 14 +++++- lib/geocoder/results/smarty_streets.rb | 66 +++++++++++++++++++------- 2 files changed, 60 insertions(+), 20 deletions(-) diff --git a/lib/geocoder/lookups/smarty_streets.rb b/lib/geocoder/lookups/smarty_streets.rb index a1fe31402..e09d174ec 100644 --- a/lib/geocoder/lookups/smarty_streets.rb +++ b/lib/geocoder/lookups/smarty_streets.rb @@ -19,7 +19,9 @@ def supported_protocols private # --------------------------------------------------------------- def base_query_url(query) - if zipcode_only?(query) + if international?(query) + "#{protocol}://international-street.api.smartystreets.com/verify?" + elsif zipcode_only?(query) "#{protocol}://us-zipcode.api.smartystreets.com/lookup?" else "#{protocol}://us-street.api.smartystreets.com/street-address?" @@ -30,9 +32,17 @@ def zipcode_only?(query) !query.text.is_a?(Array) and query.to_s.strip =~ /\A\d{5}(-\d{4})?\Z/ end + def international?(query) + !query.options[:country].nil? + end + def query_url_params(query) params = {} - if zipcode_only?(query) + if international?(query) + params[:freeform] = query.sanitized_text + params[:country] = query.options[:country] + params[:geocode] = true + elsif zipcode_only?(query) params[:zipcode] = query.sanitized_text else params[:street] = query.sanitized_text diff --git a/lib/geocoder/results/smarty_streets.rb b/lib/geocoder/results/smarty_streets.rb index b4850677f..aaabe181c 100644 --- a/lib/geocoder/results/smarty_streets.rb +++ b/lib/geocoder/results/smarty_streets.rb @@ -15,51 +15,77 @@ def coordinates end def address - [ - delivery_line_1, - delivery_line_2, - last_line - ].select{ |i| i.to_s != "" }.join(" ") + parts = + if international_endpoint? + (1..4).map { |i| @data["address#{i}"] } + else + [ + delivery_line_1, + delivery_line_2, + last_line + ] + end + parts.select{ |i| i.to_s != "" }.join(" ") end def state - zipcode_endpoint? ? - city_states.first['state'] : + if international_endpoint? + components['administrative_area'] + elsif zipcode_endpoint? + city_states.first['state'] + else components['state_abbreviation'] + end end def state_code - zipcode_endpoint? ? - city_states.first['state_abbreviation'] : + if international_endpoint? + components['administrative_area'] + elsif zipcode_endpoint? + city_states.first['state_abbreviation'] + else components['state_abbreviation'] + end end def country - # SmartyStreets returns results for USA only - "United States" + international_endpoint? ? + components['country_iso_3'] : + "United States" end def country_code - # SmartyStreets returns results for USA only - "US" + international_endpoint? ? + components['country_iso_3'] : + "US" end ## Extra methods not in base.rb ------------------------ def street - components['street_name'] + international_endpoint? ? + @data['address1'] : + components['street_name'] end def city - zipcode_endpoint? ? - city_states.first['city'] : + if international_endpoint? + components['locality'] + elsif zipcode_endpoint? + city_states.first['city'] + else components['city_name'] + end end def zipcode - zipcode_endpoint? ? - zipcodes.first['zipcode'] : + if international_endpoint? + components['postal_code'] + elsif zipcode_endpoint? + zipcodes.first['zipcode'] + else components['zipcode'] + end end alias_method :postal_code, :zipcode @@ -78,6 +104,10 @@ def zipcode_endpoint? zipcodes.any? end + def international_endpoint? + !@data['address1'].nil? + end + [ :delivery_line_1, :delivery_line_2, From 755c6c5b45d7ae4a68d94701bf11893240f5978b Mon Sep 17 00:00:00 2001 From: Andrew Kane <andrew@chartkick.com> Date: Fri, 30 Nov 2018 14:11:47 -0800 Subject: [PATCH 139/248] Added tests --- lib/geocoder/results/smarty_streets.rb | 4 +-- .../smarty_streets_13_rue_yves_toudic_75010 | 33 +++++++++++++++++++ test/unit/lookups/smarty_streets_test.rb | 16 +++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/smarty_streets_13_rue_yves_toudic_75010 diff --git a/lib/geocoder/results/smarty_streets.rb b/lib/geocoder/results/smarty_streets.rb index aaabe181c..62ce8acc5 100644 --- a/lib/geocoder/results/smarty_streets.rb +++ b/lib/geocoder/results/smarty_streets.rb @@ -17,7 +17,7 @@ def coordinates def address parts = if international_endpoint? - (1..4).map { |i| @data["address#{i}"] } + (1..12).map { |i| @data["address#{i}"] } else [ delivery_line_1, @@ -64,7 +64,7 @@ def country_code def street international_endpoint? ? - @data['address1'] : + components['thoroughfare_name'] : components['street_name'] end diff --git a/test/fixtures/smarty_streets_13_rue_yves_toudic_75010 b/test/fixtures/smarty_streets_13_rue_yves_toudic_75010 new file mode 100644 index 000000000..9948ad473 --- /dev/null +++ b/test/fixtures/smarty_streets_13_rue_yves_toudic_75010 @@ -0,0 +1,33 @@ +[ + { + "address1": "13 Rue Yves Toudic", + "address2": "10E Arrondissement", + "address3": "75010 Paris", + "components": { + "super_administrative_area": "Ile-De-France", + "administrative_area": "Paris", + "country_iso_3": "FRA", + "locality": "Paris", + "dependent_locality": "10E Arrondissement", + "postal_code": "75010", + "postal_code_short": "75010", + "premise": "13", + "premise_number": "13", + "thoroughfare": "Rue Yves Toudic", + "thoroughfare_name": "Yves Toudic", + "thoroughfare_type": "Rue" + }, + "metadata": { + "latitude": 48.870131, + "longitude": 2.363473, + "geocode_precision": "Premise", + "max_geocode_precision": "DeliveryPoint", + "address_format": "premise thoroughfare|dependent_locality|postal_code locality" + }, + "analysis": { + "verification_status": "Verified", + "address_precision": "Premise", + "max_address_precision": "DeliveryPoint" + } + } +] diff --git a/test/unit/lookups/smarty_streets_test.rb b/test/unit/lookups/smarty_streets_test.rb index fe89335e8..1baf99c25 100644 --- a/test/unit/lookups/smarty_streets_test.rb +++ b/test/unit/lookups/smarty_streets_test.rb @@ -29,6 +29,11 @@ def test_query_for_zipfour_geocode assert_match(/us-zipcode\.api\.smartystreets\.com\/lookup\?/, query.url) end + def test_query_for_international_geocode + query = Geocoder::Query.new("13 rue yves toudic 75010", country: "France") + assert_match(/international-street\.api\.smartystreets\.com\/verify\?/, query.url) + end + def test_smarty_streets_result_components result = Geocoder.search("Madison Square Garden, New York, NY").first assert_equal "Penn", result.street @@ -36,6 +41,7 @@ def test_smarty_streets_result_components assert_equal "1703", result.zip4 assert_equal "New York", result.city assert_equal "36061", result.fips + assert_equal "US", result.country_code assert !result.zipcode_endpoint? end @@ -44,9 +50,19 @@ def test_smarty_streets_result_components_with_zipcode_only_query assert_equal "Brooklyn", result.city assert_equal "New York", result.state assert_equal "NY", result.state_code + assert_equal "US", result.country_code assert result.zipcode_endpoint? end + def test_smarty_streets_result_components_with_international_query + result = Geocoder.search("13 rue yves toudic 75010", country: "France").first + assert_equal 'Yves Toudic', result.street + assert_equal 'Paris', result.city + assert_equal '75010', result.postal_code + assert_equal 'FRA', result.country_code + assert result.international_endpoint? + end + def test_smarty_streets_when_longitude_latitude_does_not_exist result = Geocoder.search("96628").first assert_equal nil, result.coordinates From 608667a0fb8264e2ff95a9c9512f7f2ead452ae2 Mon Sep 17 00:00:00 2001 From: Andy Perkins <aperkins81@gmail.com> Date: Mon, 17 Dec 2018 09:04:18 +1000 Subject: [PATCH 140/248] Fix: compass_point (#1372) Fix: compass_point, 341-348 degrees missing value in 16-wind compass rose --- lib/geocoder/calculations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/calculations.rb b/lib/geocoder/calculations.rb index 84ab009c8..e70388cf1 100644 --- a/lib/geocoder/calculations.rb +++ b/lib/geocoder/calculations.rb @@ -154,7 +154,7 @@ def bearing_between(point1, point2, options = {}) # Translate a bearing (float) into a compass direction (string, eg "North"). # def compass_point(bearing, points = COMPASS_POINTS) - seg_size = 360 / points.size + seg_size = 360.0 / points.size points[((bearing + (seg_size / 2)) % 360) / seg_size] end From 04a56f4a3c575526d3cd2879b419a8eca0838418 Mon Sep 17 00:00:00 2001 From: Francisco Caiceo <jfcaiceo55@gmail.com> Date: Thu, 10 Jan 2019 11:30:41 -0300 Subject: [PATCH 141/248] Add country and mapview as extra parameters to here lookup --- README_API_GUIDE.md | 3 +++ lib/geocoder/lookups/here.rb | 30 ++++++++++++++++++++++-------- test/unit/lookups/here_test.rb | 26 +++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index b19fd6809..94f023c47 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -177,6 +177,9 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Region**: world * **SSL support**: yes * **Languages**: The preferred language of address elements in the result. Language code must be provided according to RFC 4647 standard. +* **Extra params**: + * `:mapview` - pass NW and SE coordinates as an array of two arrays to bias results towards a viewport + * `:country` - pass the country or list of countries using the country code (3 bytes, ISO 3166-1-alpha-3) or the country name, to filter the results * **Documentation**: http://developer.here.com/rest-apis/documentation/geocoder * **Terms of Service**: http://developer.here.com/faqs#l&t * **Limitations**: ? diff --git a/lib/geocoder/lookups/here.rb b/lib/geocoder/lookups/here.rb index 420c6e34c..f15104239 100644 --- a/lib/geocoder/lookups/here.rb +++ b/lib/geocoder/lookups/here.rb @@ -28,34 +28,48 @@ def results(query) [] end - def query_url_params(query) + def query_url_here_options(query, reverse_geocode) options = { - gen: 4, + gen: 9, app_id: api_key, app_code: api_code, language: (query.language || configuration.language) } + if reverse_geocode + options[:mode] = :retrieveAddresses + return options + end + + unless (country = query.options[:country]).nil? + options[:country] = country + end + unless (mapview = query.options[:mapview]).nil? + options[:mapview] = mapview.map{ |point| "%f,%f" % point }.join(';') + end + options + end + + def query_url_params(query) if query.reverse_geocode? - super.merge(options).merge( - prox: query.sanitized_text, - mode: :retrieveAddresses + super.merge(query_url_here_options(query, true)).merge( + prox: query.sanitized_text ) else - super.merge(options).merge( + super.merge(query_url_here_options(query, false)).merge( searchtext: query.sanitized_text ) end end def api_key - if a=configuration.api_key + if (a = configuration.api_key) return a.first if a.is_a?(Array) end end def api_code - if a=configuration.api_key + if (a = configuration.api_key) return a.last if a.is_a?(Array) end end diff --git a/test/unit/lookups/here_test.rb b/test/unit/lookups/here_test.rb index cec6bcbad..153cebf8e 100644 --- a/test/unit/lookups/here_test.rb +++ b/test/unit/lookups/here_test.rb @@ -3,16 +3,36 @@ require 'test_helper' class HereTest < GeocoderTestCase - def setup Geocoder.configure(lookup: :here) set_api_key!(:here) end def test_here_viewport - result = Geocoder.search("Madison Square Garden, New York, NY").first + result = Geocoder.search('Madison Square Garden, New York, NY').first assert_equal [40.7493451, -73.9948616, 40.7515934, -73.9918938], - result.viewport + result.viewport + end + + def test_here_query_url_contains_country + lookup = Geocoder::Lookup::Here.new + url = lookup.query_url( + Geocoder::Query.new( + 'Some Intersection', + country: 'GBR' + ) + ) + assert_match(/country=GBR/, url) end + def test_here_query_url_contains_mapview + lookup = Geocoder::Lookup::Here.new + url = lookup.query_url( + Geocoder::Query.new( + 'Some Intersection', + mapview: [[40.0, -120.0], [39.0, -121.0]] + ) + ) + assert_match(/mapview=40.0+%2C-120.0+%3B39.0+%2C-121.0+/, url) + end end From 1d7d53690ce2c32c1b8a7ea87a6e72bcb13fdae1 Mon Sep 17 00:00:00 2001 From: Blaine Schanfeldt <git@blaines.me> Date: Tue, 15 Jan 2019 15:38:58 -0800 Subject: [PATCH 142/248] Suggestion to not log full response body as a warning (#1377) Don't log full response body as a warning. --- lib/geocoder/lookups/base.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb index c23c9e667..81699605d 100644 --- a/lib/geocoder/lookups/base.rb +++ b/lib/geocoder/lookups/base.rb @@ -209,7 +209,10 @@ def parse_json(data) JSON.parse(data) end rescue - raise_error(ResponseParseError.new(data)) or Geocoder.log(:warn, "Geocoding API's response was not valid JSON: #{data}") + unless raise_error(ResponseParseError.new(data)) + Geocoder.log(:warn, "Geocoding API's response was not valid JSON") + Geocoder.log(:debug, "Raw response: #{data}") + end end ## From 0a469463e8955fb5a0f03fa709a858954626082f Mon Sep 17 00:00:00 2001 From: Anders Eriksson <aeri3@kth.se> Date: Wed, 16 Jan 2019 01:25:03 +0100 Subject: [PATCH 143/248] add error handling for Tencent status code 199 --- lib/geocoder/lookups/tencent.rb | 3 +++ lib/geocoder/results/tencent.rb | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/geocoder/lookups/tencent.rb b/lib/geocoder/lookups/tencent.rb index 2dade5187..1fef32abe 100644 --- a/lib/geocoder/lookups/tencent.rb +++ b/lib/geocoder/lookups/tencent.rb @@ -31,6 +31,9 @@ def results(query, reverse = false) case doc['status'] when 0 return [doc[content_key]] + when 199 + raise error(Geocoder::InvalidApiKey, "invalid api key") || + Geocoder.log(:warn, "#{name} Geocoding API error: key is not enabled for web service usage.") when 311 raise_error(Geocoder::RequestDenied, "request denied") || Geocoder.log(:warn, "#{name} Geocoding API error: request denied.") diff --git a/lib/geocoder/results/tencent.rb b/lib/geocoder/results/tencent.rb index d546bad6a..c8bb23130 100644 --- a/lib/geocoder/results/tencent.rb +++ b/lib/geocoder/results/tencent.rb @@ -13,10 +13,9 @@ def address #@data['title'] or @data['address'] end - # The Tencent reverse reverse geocoding API has the field named + # NOTE: The Tencent reverse geocoding API has the field named # 'address_component' compared to 'address_components' in the # regular geocoding API. - def province @data['address_components'] and (@data['address_components']['province']) or (@data['address_component'] and @data['address_component']['province']) or From e005d6c9e400697cfeada85960bed9c5868521aa Mon Sep 17 00:00:00 2001 From: Anders Eriksson <aeri3@kth.se> Date: Wed, 16 Jan 2019 13:35:09 +0100 Subject: [PATCH 144/248] update faulty Tencent SSL information in API Guide --- README_API_GUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index d278a85e6..571c9ab0c 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -249,7 +249,7 @@ Data Science Toolkit provides an API whose response format is like Google's but * **Key signup**: http://lbs.qq.com/console/mykey.html * **Quota**: 10,000 free requests per day per key. 5 requests per second per key. For increased quota, one must first apply to become a corporate developer and then apply for increased quota. * **Region**: China -* **SSL support**: no +* **SSL support**: yes * **Languages**: Chinese (Simplified) * **Documentation**: http://lbs.qq.com/webservice_v1/guide-geocoder.html (Standard) & http://lbs.qq.com/webservice_v1/guide-gcoder.html (Reverse) * **Terms of Service**: http://lbs.qq.com/terms.html From a575ec2fa4dc9c8ab374cfe49261c57d324c5ab0 Mon Sep 17 00:00:00 2001 From: Francisco Caiceo <jfcaiceo55@gmail.com> Date: Wed, 16 Jan 2019 11:39:37 -0300 Subject: [PATCH 145/248] Replace Here mapview option to bounds --- README_API_GUIDE.md | 2 +- lib/geocoder/lookups/here.rb | 2 +- test/unit/lookups/here_test.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 94f023c47..bca264a0b 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -178,7 +178,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **SSL support**: yes * **Languages**: The preferred language of address elements in the result. Language code must be provided according to RFC 4647 standard. * **Extra params**: - * `:mapview` - pass NW and SE coordinates as an array of two arrays to bias results towards a viewport + * `:bounds` - pass NW and SE coordinates as an array of two arrays to bias results towards a viewport * `:country` - pass the country or list of countries using the country code (3 bytes, ISO 3166-1-alpha-3) or the country name, to filter the results * **Documentation**: http://developer.here.com/rest-apis/documentation/geocoder * **Terms of Service**: http://developer.here.com/faqs#l&t diff --git a/lib/geocoder/lookups/here.rb b/lib/geocoder/lookups/here.rb index f15104239..e302ef68a 100644 --- a/lib/geocoder/lookups/here.rb +++ b/lib/geocoder/lookups/here.rb @@ -44,7 +44,7 @@ def query_url_here_options(query, reverse_geocode) options[:country] = country end - unless (mapview = query.options[:mapview]).nil? + unless (mapview = query.options[:bounds]).nil? options[:mapview] = mapview.map{ |point| "%f,%f" % point }.join(';') end options diff --git a/test/unit/lookups/here_test.rb b/test/unit/lookups/here_test.rb index 153cebf8e..0e57005ef 100644 --- a/test/unit/lookups/here_test.rb +++ b/test/unit/lookups/here_test.rb @@ -30,7 +30,7 @@ def test_here_query_url_contains_mapview url = lookup.query_url( Geocoder::Query.new( 'Some Intersection', - mapview: [[40.0, -120.0], [39.0, -121.0]] + bounds: [[40.0, -120.0], [39.0, -121.0]] ) ) assert_match(/mapview=40.0+%2C-120.0+%3B39.0+%2C-121.0+/, url) From f9d16c4aababc9b3c64966e294dda4fc9d260722 Mon Sep 17 00:00:00 2001 From: Viren Negi <meetme2meat@gmail.com> Date: Mon, 21 Jan 2019 17:11:38 +0530 Subject: [PATCH 146/248] Rescue the Geocoder::NetworkError to stay consistent with the README.md --- lib/geocoder/lookups/base.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb index 81699605d..3247486bf 100644 --- a/lib/geocoder/lookups/base.rb +++ b/lib/geocoder/lookups/base.rb @@ -197,6 +197,8 @@ def fetch_data(query) raise_error(err) or Geocoder.log(:warn, "Geocoding API connection cannot be established.") rescue Errno::ECONNREFUSED => err raise_error(err) or Geocoder.log(:warn, "Geocoding API connection refused.") + rescue Geocoder::NetworkError => err + raise_error(err) or Geocoder.log(:warn, "Geocoding API connection is either unreacheable or reset by the peer") rescue Timeout::Error => err raise_error(err) or Geocoder.log(:warn, "Geocoding API not responding fast enough " + "(use Geocoder.configure(:timeout => ...) to set limit).") From f1b9fa3e3832cba159d757f02d32336f779baf59 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 23 Jan 2019 11:25:40 -0800 Subject: [PATCH 147/248] Prepare for release of gem version 1.5.1. --- CHANGELOG.md | 6 ++++++ lib/geocoder/version.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dc21450f..5cf518a53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ Changelog Major changes to Geocoder for each release. Please see the Git log for complete list of changes. +1.5.1 (2019 Jan 23) +------------------- +* Add support for :tencent lookup (thanks github.com/Anders-E). +* Add support for :smarty_streets international API (thanks github.com/ankane). +* Remove :mapzen lookup. + 1.5.0 (2018 Jul 31) ------------------- * Drop support for Ruby <2.0. diff --git a/lib/geocoder/version.rb b/lib/geocoder/version.rb index 12905f099..14ea8f91c 100644 --- a/lib/geocoder/version.rb +++ b/lib/geocoder/version.rb @@ -1,3 +1,3 @@ module Geocoder - VERSION = "1.5.0" + VERSION = "1.5.1" end From e81a62602a263baf3b2b041a0b519b5ae9b4aa15 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 23 Jan 2019 16:01:07 -0800 Subject: [PATCH 148/248] Bundler 2.0+ causing issues w/ old Rails. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ae2020d65..ee4498d5b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,8 +23,8 @@ gemfile: - gemfiles/Gemfile.rails4.1 - gemfiles/Gemfile.rails5.0 before_install: - - which bundle >/dev/null 2>&1 || gem install bundler - - gem update --system + - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true + - gem install bundler -v '< 2' matrix: exclude: - env: DB= From 864ca22a3a977b735eaa28fd3db1c94f22e07260 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 23 Jan 2019 16:06:55 -0800 Subject: [PATCH 149/248] Specify Rails version correctly. --- gemfiles/Gemfile.rails3.2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gemfiles/Gemfile.rails3.2 b/gemfiles/Gemfile.rails3.2 index 31cceacd0..4a0fd8b8b 100644 --- a/gemfiles/Gemfile.rails3.2 +++ b/gemfiles/Gemfile.rails3.2 @@ -6,7 +6,7 @@ group :development, :test do gem 'bson_ext', platforms: :ruby gem 'geoip' gem 'rubyzip' - gem 'rails', '>= 3.2' + gem 'rails', '~> 3.2' gem 'test-unit' # needed for Ruby >=2.2.0 platforms :jruby do From 7f3f7c826386c90be1638aee019979087f151b2a Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 23 Jan 2019 16:18:56 -0800 Subject: [PATCH 150/248] Cache bundle to speed things up. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ee4498d5b..04862d011 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: ruby +cache: bundler sudo: false env: global: From 41839d6201e7725b46cf090c35054235556508bd Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 23 Jan 2019 17:08:19 -0800 Subject: [PATCH 151/248] Skip JRuby/Rails 4.1. During database tests: "File does not exist: bson/integer" Not important enough to spend time fixing, so omitting for now. --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 04862d011..85d3e4ef8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,5 +54,7 @@ matrix: gemfile: gemfiles/Gemfile.rails3.2 - rvm: jruby-19mode gemfile: gemfiles/Gemfile.rails5.0 + - rvm: jruby-19mode + gemfile: gemfiles/Gemfile.rails4.1 - env: DB=sqlite USE_SQLITE_EXT=1 rvm: jruby-19mode From c47b97b15ded8b6a02bb48687e74b3eb345630f9 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 27 May 2018 14:42:28 -0600 Subject: [PATCH 152/248] Remove post-install message. --- geocoder.gemspec | 7 ------- 1 file changed, 7 deletions(-) diff --git a/geocoder.gemspec b/geocoder.gemspec index 40c812fe7..c2c8aba26 100644 --- a/geocoder.gemspec +++ b/geocoder.gemspec @@ -18,13 +18,6 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.executables = ["geocode"] s.license = 'MIT' - - s.post_install_message = %q{ - -NOTE: Geocoder's default IP address lookup has changed from FreeGeoIP.net to IPInfo.io. If you explicitly specify :freegeoip in your configuration you must choose a different IP lookup before FreeGeoIP is discontinued on July 1, 2018. If you do not explicitly specify :freegeoip you do not need to change anything. - -} - s.metadata = { 'source_code_uri' => 'https://github.com/alexreisner/geocoder', 'changelog_uri' => 'https://github.com/alexreisner/geocoder/blob/master/CHANGELOG.md' From d94a714a299f29f458f44baefc48150711f77466 Mon Sep 17 00:00:00 2001 From: Mixer Gutierrez <mixergutierrez@gmail.com> Date: Mon, 4 Feb 2019 23:21:33 -0600 Subject: [PATCH 153/248] Add adjustment to freegeoip to use freegeoip.app --- lib/geocoder/lookups/freegeoip.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/geocoder/lookups/freegeoip.rb b/lib/geocoder/lookups/freegeoip.rb index 6b551a22f..f16c24281 100644 --- a/lib/geocoder/lookups/freegeoip.rb +++ b/lib/geocoder/lookups/freegeoip.rb @@ -10,7 +10,7 @@ def name def supported_protocols if configuration[:host] - [:http, :https] + [:https] else # use https for default host [:https] @@ -44,8 +44,8 @@ def reserved_result(ip) "city" => "", "region_code" => "", "region_name" => "", - "metrocode" => "", - "zipcode" => "", + "metro_code" => "", + "zip_code" => "", "latitude" => "0", "longitude" => "0", "country_name" => "Reserved", @@ -54,7 +54,7 @@ def reserved_result(ip) end def host - configuration[:host] || "freegeoip.net" + configuration[:host] || "freegeoip.app" end end end From b89bd0d0cc9b4a09da9b4f8b584b2af239d45660 Mon Sep 17 00:00:00 2001 From: Mixer Gutierrez <mixergutierrez@gmail.com> Date: Tue, 5 Feb 2019 18:23:47 -0600 Subject: [PATCH 154/248] Update freegeoip test as https is required now --- test/unit/lookups/freegeoip_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/lookups/freegeoip_test.rb b/test/unit/lookups/freegeoip_test.rb index 766e000a8..1ce62b4d3 100644 --- a/test/unit/lookups/freegeoip_test.rb +++ b/test/unit/lookups/freegeoip_test.rb @@ -35,6 +35,6 @@ def test_host_config Geocoder.configure(freegeoip: {host: "local.com"}) lookup = Geocoder::Lookup::Freegeoip.new query = Geocoder::Query.new("24.24.24.23") - assert_match %r(http://local\.com), lookup.query_url(query) + assert_match %r(https://local\.com), lookup.query_url(query) end end From eeb898b1ab6e7c072efe9618042988e6439cfbc7 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 6 Feb 2019 15:59:48 -0700 Subject: [PATCH 155/248] Lock sqlite3 gem version. --- Gemfile | 2 +- gemfiles/Gemfile.rails3.2 | 2 +- gemfiles/Gemfile.rails4.1 | 2 +- gemfiles/Gemfile.rails5.0 | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index d514f4bee..51a8fcfe6 100644 --- a/Gemfile +++ b/Gemfile @@ -22,7 +22,7 @@ end group :test do platforms :ruby, :mswin, :mingw do - gem 'sqlite3' + gem 'sqlite3', '~> 1.3.5' gem 'sqlite_ext', '~> 1.5.0' end diff --git a/gemfiles/Gemfile.rails3.2 b/gemfiles/Gemfile.rails3.2 index 4a0fd8b8b..9bf62c89e 100644 --- a/gemfiles/Gemfile.rails3.2 +++ b/gemfiles/Gemfile.rails3.2 @@ -22,7 +22,7 @@ end group :test do platforms :ruby do - gem 'sqlite3' + gem 'sqlite3', '~> 1.3.5' gem 'sqlite_ext', '~> 1.5.0' end diff --git a/gemfiles/Gemfile.rails4.1 b/gemfiles/Gemfile.rails4.1 index 9398b2697..b124ddc7f 100644 --- a/gemfiles/Gemfile.rails4.1 +++ b/gemfiles/Gemfile.rails4.1 @@ -22,7 +22,7 @@ end group :test do platforms :ruby, :mswin, :mingw do - gem 'sqlite3' + gem 'sqlite3', '~> 1.3.5' gem 'sqlite_ext', '~> 1.5.0' end diff --git a/gemfiles/Gemfile.rails5.0 b/gemfiles/Gemfile.rails5.0 index 2f127393f..1068091d3 100644 --- a/gemfiles/Gemfile.rails5.0 +++ b/gemfiles/Gemfile.rails5.0 @@ -22,7 +22,7 @@ end group :test do platforms :ruby, :mswin, :mingw do - gem 'sqlite3' + gem 'sqlite3', '~> 1.3.5' gem 'sqlite_ext', '~> 1.5.0' end From df473becf681ccf3a1b68a6279732fb7151b4d0d Mon Sep 17 00:00:00 2001 From: Alexander Khatlamadzhiev <hatlam@hatlam.com> Date: Mon, 22 Apr 2019 22:34:09 +0300 Subject: [PATCH 156/248] Correct param name for api key is "api_key" https://tech.yandex.ru/maps/doc/geocoder/desc/concepts/input_params-docpage/ --- lib/geocoder/lookups/yandex.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/yandex.rb b/lib/geocoder/lookups/yandex.rb index 61a6afee9..7e4186801 100644 --- a/lib/geocoder/lookups/yandex.rb +++ b/lib/geocoder/lookups/yandex.rb @@ -51,7 +51,7 @@ def query_url_params(query) :geocode => q, :format => "json", :plng => "#{query.language || configuration.language}", # supports ru, uk, be - :key => configuration.api_key + :api_key => configuration.api_key } unless (bounds = query.options[:bounds]).nil? params[:bbox] = bounds.map{ |point| "%f,%f" % point }.join('~') From 9374fc49476763f92887bcbd16b2765e952dbf44 Mon Sep 17 00:00:00 2001 From: Alexander Khatlamadzhiev <hatlam@hatlam.com> Date: Tue, 23 Apr 2019 10:31:45 +0300 Subject: [PATCH 157/248] Update yandex.rb --- lib/geocoder/lookups/yandex.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/yandex.rb b/lib/geocoder/lookups/yandex.rb index 7e4186801..1b2345f7f 100644 --- a/lib/geocoder/lookups/yandex.rb +++ b/lib/geocoder/lookups/yandex.rb @@ -51,7 +51,7 @@ def query_url_params(query) :geocode => q, :format => "json", :plng => "#{query.language || configuration.language}", # supports ru, uk, be - :api_key => configuration.api_key + :apikey => configuration.api_key } unless (bounds = query.options[:bounds]).nil? params[:bbox] = bounds.map{ |point| "%f,%f" % point }.join('~') From 70829e69acb4a861c6f398ed9ab91607dcdeb88e Mon Sep 17 00:00:00 2001 From: Ahmed Magdy <ahmedmagdy711@gmail.com> Date: Wed, 12 Jun 2019 13:53:04 +0200 Subject: [PATCH 158/248] Fix here mapping for state and add state_code --- lib/geocoder/results/here.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/geocoder/results/here.rb b/lib/geocoder/results/here.rb index 12f3ab807..843ae4675 100644 --- a/lib/geocoder/results/here.rb +++ b/lib/geocoder/results/here.rb @@ -26,8 +26,15 @@ def street_number address_data['HouseNumber'] end + def state_code + address_data['State'] + end + def state - address_data['County'] + fail unless d = address_data['AdditionalData'] + if v = d.find{|ad| ad['key']=='StateName'} + return v['value'] + end end def province From 331a468f240c73e5e55bf1b54f3a2c9c4aa97155 Mon Sep 17 00:00:00 2001 From: Laurent Pellegrino <laurent.pellegrino@gmail.com> Date: Mon, 19 Aug 2019 21:32:17 +0200 Subject: [PATCH 159/248] Add support for Ipregistry --- README_API_GUIDE.md | 10 + lib/geocoder/lookup.rb | 1 + lib/geocoder/lookups/ipregistry.rb | 68 ++++++ lib/geocoder/results/ipregistry.rb | 308 +++++++++++++++++++++++++++ test/fixtures/ipregistry_8_8_8_8 | 108 ++++++++++ test/fixtures/ipregistry_no_results | 0 test/test_helper.rb | 8 + test/unit/lookup_test.rb | 8 +- test/unit/lookups/ipregistry_test.rb | 32 +++ 9 files changed, 542 insertions(+), 1 deletion(-) create mode 100644 lib/geocoder/lookups/ipregistry.rb create mode 100644 lib/geocoder/results/ipregistry.rb create mode 100644 test/fixtures/ipregistry_8_8_8_8 create mode 100644 test/fixtures/ipregistry_no_results create mode 100644 test/unit/lookups/ipregistry_test.rb diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index cdda11084..20ee0e444 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -341,6 +341,16 @@ Data Science Toolkit provides an API whose response format is like Google's but IP Address Lookups ------------------ +### Ipregistry (`:ipregistry`) + +* **API key**: required (see https://ipregistry.co) +* **Quota**: first 100,000 requests are free, then you pay per request (see https://ipregistry.co/pricing) +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://ipregistry.co/docs +* **Terms of Service**: https://ipregistry.co/terms + ### IPInfo.io (`:ipinfo_io`) * **API key**: optional - see http://ipinfo.io/pricing diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index 485e28c0d..db03b809f 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -69,6 +69,7 @@ def ip_services :pointpin, :maxmind_geoip2, :ipinfo_io, + :ipregistry, :ipapi_com, :ipdata_co, :db_ip_com, diff --git a/lib/geocoder/lookups/ipregistry.rb b/lib/geocoder/lookups/ipregistry.rb new file mode 100644 index 000000000..87beaba49 --- /dev/null +++ b/lib/geocoder/lookups/ipregistry.rb @@ -0,0 +1,68 @@ +require 'geocoder/lookups/base' +require 'geocoder/results/ipregistry' + +module Geocoder::Lookup + class Ipregistry < Base + + ERROR_CODES = { + 400 => Geocoder::InvalidRequest, + 401 => Geocoder::InvalidRequest, + 402 => Geocoder::OverQueryLimitError, + 403 => Geocoder::InvalidApiKey, + 451 => Geocoder::RequestDenied, + 500 => Geocoder::Error + } + ERROR_CODES.default = Geocoder::Error + + def name + "Ipregistry" + end + + def supported_protocols + [:https] + end + + private + + def base_query_url(query) + "#{protocol}://#{host}/#{query.sanitized_text}?" + end + + def cache_key(query) + query_url(query) + end + + def host + configuration[:host] || "api.ipregistry.co" + end + + def query_url_params(query) + { + key: configuration.api_key + }.merge(super) + end + + def results(query) + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? + + return [] unless (doc = fetch_data(query)) + + if (error = doc['error']) + code = error['code'] + msg = error['message'] + raise_error(ERROR_CODES[code], msg ) || Geocoder.log(:warn, "Ipregistry API error: #{msg}") + return [] + end + [doc] + end + + def reserved_result(ip) + { + "ip" => ip, + "country_name" => "Reserved", + "country_code" => "RD" + } + end + end +end diff --git a/lib/geocoder/results/ipregistry.rb b/lib/geocoder/results/ipregistry.rb new file mode 100644 index 000000000..33e3193d1 --- /dev/null +++ b/lib/geocoder/results/ipregistry.rb @@ -0,0 +1,308 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class Ipregistry < Base + + def initialize(data) + super + + @data = flatten_hash(data) + end + + def flatten_hash(hash) + hash.each_with_object({}) do |(k, v), h| + if v.is_a? Hash + flatten_hash(v).map do |h_k, h_v| + h["#{k}_#{h_k}".to_s] = h_v + end + else + h[k] = v + end + end + end + + private :flatten_hash + + def city + @data['location_city'] + end + + def country + @data['location_country_name'] + end + + def country_code + @data['location_country_code'] + end + + def latitude + @data['location_latitude'] + end + + def longitude + @data['location_longitude'] + end + + def postal_code + @data['location_postal'] + end + + def state + @data['location_region_name'] + end + + def state_code + @data['location_region_code'] + end + + # methods for fields specific to Ipregistry + + def ip + @data["ip"] + end + + def type + @data["type"] + end + + def hostname + @data["hostname"] + end + + def carrier_name + @data["carrier_name"] + end + + def carrier_mcc + @data["carrier_mcc"] + end + + def carrier_mnc + @data["carrier_mnc"] + end + + def connection_asn + @data["connection_asn"] + end + + def connection_domain + @data["connection_domain"] + end + + def connection_organization + @data["connection_organization"] + end + + def connection_type + @data["connection_type"] + end + + def currency_code + @data["currency_code"] + end + + def currency_name + @data["currency_name"] + end + + def currency_plural + @data["currency_plural"] + end + + def currency_symbol + @data["currency_symbol"] + end + + def currency_symbol_native + @data["currency_symbol_native"] + end + + def currency_format_negative_prefix + @data["currency_format_negative_prefix"] + end + + def currency_format_negative_suffix + @data["currency_format_negative_suffix"] + end + + def currency_format_positive_prefix + @data["currency_format_positive_prefix"] + end + + def currency_format_positive_suffix + @data["currency_format_positive_suffix"] + end + + def location_continent_code + @data["location_continent_code"] + end + + def location_continent_name + @data["location_continent_name"] + end + + def location_country_area + @data["location_country_area"] + end + + def location_country_borders + @data["location_country_borders"] + end + + def location_country_calling_code + @data["location_country_calling_code"] + end + + def location_country_capital + @data["location_country_capital"] + end + + def location_country_code + @data["location_country_code"] + end + + def location_country_name + @data["location_country_name"] + end + + def location_country_population + @data["location_country_population"] + end + + def location_country_population_density + @data["location_country_population_density"] + end + + def location_country_flag_emoji + @data["location_country_flag_emoji"] + end + + def location_country_flag_emoji_unicode + @data["location_country_flag_emoji_unicode"] + end + + def location_country_flag_emojitwo + @data["location_country_flag_emojitwo"] + end + + def location_country_flag_noto + @data["location_country_flag_noto"] + end + + def location_country_flag_twemoji + @data["location_country_flag_twemoji"] + end + + def location_country_flag_wikimedia + @data["location_country_flag_wikimedia"] + end + + def location_country_languages + @data["location_country_languages"] + end + + def location_country_tld + @data["location_country_tld"] + end + + def location_region_code + @data["location_region_code"] + end + + def location_region_name + @data["location_region_name"] + end + + def location_city + @data["location_city"] + end + + def location_postal + @data["location_postal"] + end + + def location_latitude + @data["location_latitude"] + end + + def location_longitude + @data["location_longitude"] + end + + def location_language_code + @data["location_language_code"] + end + + def location_language_name + @data["location_language_name"] + end + + def location_language_native + @data["location_language_native"] + end + + def location_in_eu + @data["location_in_eu"] + end + + def security_is_bogon + @data["security_is_bogon"] + end + + def security_is_cloud_provider + @data["security_is_cloud_provider"] + end + + def security_is_tor + @data["security_is_tor"] + end + + def security_is_tor_exit + @data["security_is_tor_exit"] + end + + def security_is_proxy + @data["security_is_proxy"] + end + + def security_is_anonymous + @data["security_is_anonymous"] + end + + def security_is_abuser + @data["security_is_abuser"] + end + + def security_is_attacker + @data["security_is_attacker"] + end + + def security_is_threat + @data["security_is_threat"] + end + + def time_zone_id + @data["time_zone_id"] + end + + def time_zone_abbreviation + @data["time_zone_abbreviation"] + end + + def time_zone_current_time + @data["time_zone_current_time"] + end + + def time_zone_name + @data["time_zone_name"] + end + + def time_zone_offset + @data["time_zone_offset"] + end + + def time_zone_in_daylight_saving + @data["time_zone_in_daylight_saving"] + end + end +end diff --git a/test/fixtures/ipregistry_8_8_8_8 b/test/fixtures/ipregistry_8_8_8_8 new file mode 100644 index 000000000..28422626c --- /dev/null +++ b/test/fixtures/ipregistry_8_8_8_8 @@ -0,0 +1,108 @@ +{ + "ip" : "8.8.8.8", + "type" : "IPv4", + "hostname" : null, + "carrier" : { + "name" : null, + "mcc" : null, + "mnc" : null + }, + "connection" : { + "asn" : 15169, + "domain" : "google.com", + "organization" : "Google LLC", + "type" : "hosting" + }, + "currency" : { + "code" : "USD", + "name" : "US Dollar", + "plural" : "US dollars", + "symbol" : "$", + "symbol_native" : "$", + "format" : { + "negative" : { + "prefix" : "-$", + "suffix" : "" + }, + "positive" : { + "prefix" : "$", + "suffix" : "" + } + } + }, + "location" : { + "continent" : { + "code" : "NA", + "name" : "North America" + }, + "country" : { + "area" : 9629091.0, + "borders" : [ "CA", "MX" ], + "calling_code" : "1", + "capital" : "Washington D.C.", + "code" : "US", + "name" : "United States", + "population" : 327167434, + "population_density" : 33.98, + "flag" : { + "emoji" : "🇺🇸", + "emoji_unicode" : "U+1F1FA U+1F1F8", + "emojitwo" : "https://cdn.ipregistry.co/flags/emojitwo/us.svg", + "noto" : "https://cdn.ipregistry.co/flags/noto/us.png", + "twemoji" : "https://cdn.ipregistry.co/flags/twemoji/us.svg", + "wikimedia" : "https://cdn.ipregistry.co/flags/wikimedia/us.svg" + }, + "languages" : [ { + "code" : "en", + "name" : "English", + "native" : "English" + }, { + "code" : "es", + "name" : "Spanish", + "native" : "español" + }, { + "code" : "haw", + "name" : "Hawaiian", + "native" : "ʻŌlelo Hawaiʻi" + }, { + "code" : "fr", + "name" : "French", + "native" : "français" + } ], + "tld" : ".us" + }, + "region" : { + "code" : "CA", + "name" : "California" + }, + "city" : "Mountain View", + "postal" : "94043", + "latitude" : 37.405992, + "longitude" : -122.078515, + "language" : { + "code" : "en", + "name" : "English", + "native" : "English" + }, + "in_eu" : false + }, + "security" : { + "is_bogon" : false, + "is_cloud_provider" : true, + "is_tor" : false, + "is_tor_exit" : false, + "is_proxy" : false, + "is_anonymous" : false, + "is_abuser" : false, + "is_attacker" : false, + "is_threat" : true + }, + "time_zone" : { + "id" : "America/Los_Angeles", + "abbreviation" : "PST", + "current_time" : "2019-08-18T22:09:10-07:00", + "name" : "Pacific Standard Time", + "offset" : -25200, + "in_daylight_saving" : true + } +} \ No newline at end of file diff --git a/test/fixtures/ipregistry_no_results b/test/fixtures/ipregistry_no_results new file mode 100644 index 000000000..e69de29bb diff --git a/test/test_helper.rb b/test/test_helper.rb index 90c4996d4..89499bbfb 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -386,6 +386,14 @@ def default_fixture_filename end end + require 'geocoder/lookups/ipregistry' + class Ipregistry + private + def default_fixture_filename + "ipregistry_8_8_8_8" + end + end + require 'geocoder/lookups/ipapi_com' class IpapiCom private diff --git a/test/unit/lookup_test.rb b/test/unit/lookup_test.rb index d2ba813a0..16428a533 100644 --- a/test/unit/lookup_test.rb +++ b/test/unit/lookup_test.rb @@ -24,7 +24,7 @@ def test_search_returns_empty_array_when_no_results def test_query_url_contains_values_in_params_hash Geocoder::Lookup.all_services_except_test.each do |l| - next if [:freegeoip, :maxmind_local, :telize, :pointpin, :geoip2, :maxmind_geoip2, :mapbox, :ipdata_co, :ipinfo_io, :ipapi_com, :ipstack, :postcodes_io].include? l # does not use query string + next if [:freegeoip, :maxmind_local, :telize, :pointpin, :geoip2, :maxmind_geoip2, :mapbox, :ipdata_co, :ipinfo_io, :ipapi_com, :ipregistry, :ipstack, :postcodes_io].include? l # does not use query string set_api_key!(l) url = Geocoder::Lookup.get(l).query_url(Geocoder::Query.new( "test", :params => {:one_in_the_hand => "two in the bush"} @@ -155,6 +155,12 @@ def test_ipinfo_io_api_key assert_match "token=MY_KEY", g.query_url(Geocoder::Query.new("232.65.123.94")) end + def test_ipregistry_api_key + Geocoder.configure(:api_key => "MY_KEY") + g = Geocoder::Lookup::Ipregistry.new + assert_match "key=MY_KEY", g.query_url(Geocoder::Query.new("232.65.123.94")) + end + def test_amap_api_key Geocoder.configure(:api_key => "MY_KEY") g = Geocoder::Lookup::Amap.new diff --git a/test/unit/lookups/ipregistry_test.rb b/test/unit/lookups/ipregistry_test.rb new file mode 100644 index 000000000..e70dc34ec --- /dev/null +++ b/test/unit/lookups/ipregistry_test.rb @@ -0,0 +1,32 @@ +# encoding: utf-8 +require 'test_helper' + +class IpregistryTest < GeocoderTestCase + def test_lookup_loopback_address + Geocoder.configure(:ip_lookup => :ipregistry) + result = Geocoder.search("127.0.0.1").first + assert_nil result.latitude + assert_nil result.longitude + assert_equal "127.0.0.1", result.ip + end + + def test_lookup_private_address + Geocoder.configure(:ip_lookup => :ipregistry) + result = Geocoder.search("172.19.0.1").first + assert_nil result.latitude + assert_nil result.longitude + assert_equal "172.19.0.1", result.ip + end + + def test_known_ip_address + Geocoder.configure(:ip_lookup => :ipregistry) + result = Geocoder.search("8.8.8.8").first + assert_equal "8.8.8.8", result.ip + assert_equal "California", result.state + assert_equal "USD", result.currency_code + assert_equal "NA", result.location_continent_code + assert_equal "US", result.location_country_code + assert_equal false, result.security_is_tor + assert_equal "America/Los_Angeles", result.time_zone_id + end +end From 12aa07b05093f9bc90779db64388d4868398ce83 Mon Sep 17 00:00:00 2001 From: Laurent Pellegrino <laurent.pellegrino@gmail.com> Date: Tue, 27 Aug 2019 18:02:58 +0200 Subject: [PATCH 160/248] Add HTTP to the list of supported protocols --- lib/geocoder/lookups/ipregistry.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/ipregistry.rb b/lib/geocoder/lookups/ipregistry.rb index 87beaba49..a0591a4f2 100644 --- a/lib/geocoder/lookups/ipregistry.rb +++ b/lib/geocoder/lookups/ipregistry.rb @@ -19,7 +19,7 @@ def name end def supported_protocols - [:https] + [:https, :http] end private From 04b9bc58994e3a8d0a04d2c372abc6d848030282 Mon Sep 17 00:00:00 2001 From: Laurent Pellegrino <laurent.pellegrino@gmail.com> Date: Tue, 27 Aug 2019 18:04:42 +0200 Subject: [PATCH 161/248] Move new entry at the end of the list --- README_API_GUIDE.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 20ee0e444..9a28e3d4e 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -341,16 +341,6 @@ Data Science Toolkit provides an API whose response format is like Google's but IP Address Lookups ------------------ -### Ipregistry (`:ipregistry`) - -* **API key**: required (see https://ipregistry.co) -* **Quota**: first 100,000 requests are free, then you pay per request (see https://ipregistry.co/pricing) -* **Region**: world -* **SSL support**: yes -* **Languages**: English -* **Documentation**: https://ipregistry.co/docs -* **Terms of Service**: https://ipregistry.co/terms - ### IPInfo.io (`:ipinfo_io`) * **API key**: optional - see http://ipinfo.io/pricing @@ -488,6 +478,15 @@ IP Address Lookups * **Terms of Service**: https://www.ip2location.com/web-service * **Notes**: With the non-free version, specify your desired package: `Geocoder.configure(ip2location: {package: "WSX"})` (see API documentation for package details). +### Ipregistry (`:ipregistry`) + +* **API key**: required (see https://ipregistry.co) +* **Quota**: first 100,000 requests are free, then you pay per request (see https://ipregistry.co/pricing) +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://ipregistry.co/docs +* **Terms of Service**: https://ipregistry.co/terms Local IP Address Lookups ------------------------ From 9aab13fd3cf7502a4eb3c8bb12c3c17c000dbc9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3n?= <anton.casais.mera@gmail.com> Date: Sun, 29 Sep 2019 21:10:40 +0200 Subject: [PATCH 162/248] fix yandex language param the plng parameter didn't change the response language in yandex. Look this: https://tech.yandex.com/maps/geocoder/doc/desc/concepts/input_params-docpage/ --- lib/geocoder/lookups/yandex.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/yandex.rb b/lib/geocoder/lookups/yandex.rb index 1b2345f7f..b39a9050a 100644 --- a/lib/geocoder/lookups/yandex.rb +++ b/lib/geocoder/lookups/yandex.rb @@ -50,7 +50,7 @@ def query_url_params(query) params = { :geocode => q, :format => "json", - :plng => "#{query.language || configuration.language}", # supports ru, uk, be + :lang => "#{query.language || configuration.language}", # supports ru, uk, be, default -> ru :apikey => configuration.api_key } unless (bounds = query.options[:bounds]).nil? From af9296401a7f1defc8809d0602ab3bc6163d328d Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Thu, 19 Sep 2019 09:05:17 -0700 Subject: [PATCH 163/248] Move :nominatim to top of lookup list (since it's the default). --- README_API_GUIDE.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 9a28e3d4e..bd65518e6 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -13,6 +13,17 @@ Table of Contents Street Address Lookups ---------------------- +### Nominatim (`:nominatim`) + +* **API key**: none +* **Quota**: 1 request/second +* **Region**: world +* **SSL support**: yes +* **Languages**: ? +* **Documentation**: http://wiki.openstreetmap.org/wiki/Nominatim +* **Terms of Service**: https://operations.osmfoundation.org/policies/nominatim/ +* **Limitations**: Please limit request rate to 1 per second and include your contact information in User-Agent headers (eg: `Geocoder.configure(http_headers: { "User-Agent" => "your contact info" })`). [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) + ### Google (`:google`) * **API key**: required @@ -68,17 +79,6 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Terms of Service**: http://www.microsoft.com/maps/product/terms.html * **Limitations**: No country codes or state names. Must be used on "public-facing, non-password protected web sites," "in conjunction with Bing Maps or an application that integrates Bing Maps." -### Nominatim (`:nominatim`) - -* **API key**: none -* **Quota**: 1 request/second -* **Region**: world -* **SSL support**: yes -* **Languages**: ? -* **Documentation**: http://wiki.openstreetmap.org/wiki/Nominatim -* **Terms of Service**: https://operations.osmfoundation.org/policies/nominatim/ -* **Limitations**: Please limit request rate to 1 per second and include your contact information in User-Agent headers (eg: `Geocoder.configure(http_headers: { "User-Agent" => "your contact info" })`). [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) - ### PickPoint (`:pickpoint`) * **API key**: required From 45def3843bd5a9fb17d4de9135b378054d337a13 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Thu, 3 Oct 2019 13:11:13 -0700 Subject: [PATCH 164/248] Update test (should have been part of aae6b6581c6bd3a752d4a3294bfb8f5feaefc99b). --- test/unit/lookup_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/lookup_test.rb b/test/unit/lookup_test.rb index 16428a533..7281f1718 100644 --- a/test/unit/lookup_test.rb +++ b/test/unit/lookup_test.rb @@ -43,7 +43,7 @@ def test_query_url_contains_values_in_params_hash :mapquest => :key, :maxmind => :l, :nominatim => :"accept-language", - :yandex => :plng + :yandex => :lang }.each do |l,p| define_method "test_passing_param_to_#{l}_query_overrides_configuration_value" do set_api_key!(l) @@ -61,7 +61,7 @@ def test_query_url_contains_values_in_params_hash :google_premier => :language, :here => :language, :nominatim => :"accept-language", - :yandex => :plng + :yandex => :lang }.each do |l,p| define_method "test_passing_language_to_#{l}_query_overrides_configuration_value" do set_api_key!(l) From 84710122eb06e070f1b0bad8083b3ab6e154d0c4 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Thu, 3 Oct 2019 13:20:45 -0700 Subject: [PATCH 165/248] Remove redundant method definition. --- lib/geocoder/results/here.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/geocoder/results/here.rb b/lib/geocoder/results/here.rb index 843ae4675..636c6c194 100644 --- a/lib/geocoder/results/here.rb +++ b/lib/geocoder/results/here.rb @@ -26,10 +26,6 @@ def street_number address_data['HouseNumber'] end - def state_code - address_data['State'] - end - def state fail unless d = address_data['AdditionalData'] if v = d.find{|ad| ad['key']=='StateName'} From d7db18f9de2ddfd6a0986f876cfc3f1fa623ae06 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Thu, 3 Oct 2019 12:50:56 -0700 Subject: [PATCH 166/248] Prepare for release of gem version 1.5.2. --- CHANGELOG.md | 5 +++++ lib/geocoder/version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cf518a53..e39eb710d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ Changelog Major changes to Geocoder for each release. Please see the Git log for complete list of changes. +1.5.2 (2019 Oct 3) +------------------- +* Add support for :ipregistry lookup (thanks github.com/ipregistry). +* Various fixes for Yandex lookup. + 1.5.1 (2019 Jan 23) ------------------- * Add support for :tencent lookup (thanks github.com/Anders-E). diff --git a/lib/geocoder/version.rb b/lib/geocoder/version.rb index 14ea8f91c..f5b2313c1 100644 --- a/lib/geocoder/version.rb +++ b/lib/geocoder/version.rb @@ -1,3 +1,3 @@ module Geocoder - VERSION = "1.5.1" + VERSION = "1.5.2" end From 58995ae8d070a66b060a8f7ee80872e4ef228a8e Mon Sep 17 00:00:00 2001 From: "Kunto Aji. K" <kuntoaji@kaklabs.com> Date: Sun, 6 Oct 2019 10:53:55 +0700 Subject: [PATCH 167/248] Update Documentation for ipinfo.io and ip-api.com (#1413) Update documentation for ipinfo.io and ip-api.com --- README_API_GUIDE.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index bd65518e6..d91201a88 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -343,13 +343,13 @@ IP Address Lookups ### IPInfo.io (`:ipinfo_io`) -* **API key**: optional - see http://ipinfo.io/pricing -* **Quota**: 1,000/day - more with api key +* **API key**: optional - see https://ipinfo.io/pricing +* **Quota**: 50,000/mo - more with api key - see https://ipinfo.io/developers#rate-limits * **Region**: world * **SSL support**: yes * **Languages**: English -* **Documentation**: http://ipinfo.io/developers -* **Terms of Service**: http://ipinfo.io/developers +* **Documentation**: https://ipinfo.io/developers +* **Terms of Service**: https://ipinfo.io/terms-of-service ### FreeGeoIP (`:freegeoip`) - [DISCONTINUED](https://github.com/alexreisner/geocoder/wiki/Freegeoip-Discontinuation) @@ -438,13 +438,13 @@ IP Address Lookups ### IP-API.com (`:ipapi_com`) -* **API key**: optional - see http://ip-api.com/docs/#usage_limits -* **Quota**: 150/minute - unlimited with api key +* **API key**: optional - see https://members.ip-api.com +* **Quota**: 45/minute - unlimited with api key * **Region**: world -* **SSL support**: no (not without access key - see https://signup.ip-api.com/) +* **SSL support**: no (not without access key - see https://members.ip-api.com) * **Languages**: English * **Documentation**: http://ip-api.com/docs/ -* **Terms of Service**: https://signup.ip-api.com/terms +* **Terms of Service**: https://members.ip-api.com/legal ### DB-IP.com (`:db_ip_com`) From 821032aa3bb0bfd7253d024a55ab4484428b0bee Mon Sep 17 00:00:00 2001 From: in7ect <syfr.iqbal@gmail.com> Date: Sun, 6 Oct 2019 12:08:48 +0700 Subject: [PATCH 168/248] chore: copyright to current year --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4e2c2589e..54f245c7a 100644 --- a/README.md +++ b/README.md @@ -703,4 +703,4 @@ For all contributions, please respect the following guidelines: * If your pull request is merged, please do not ask for an immediate release of the gem. There are many factors contributing to when releases occur (remember that they affect thousands of apps with Geocoder in their Gemfiles). If necessary, please install from the Github source until the next official release. -Copyright (c) 2009-18 Alex Reisner, released under the MIT license. +Copyright :copyright: 2009-19 Alex Reisner, released under the MIT license. From 23ec702c2c0c5f044cde94d2b1a1a66316fbd796 Mon Sep 17 00:00:00 2001 From: Evgeny Esaulkov <evg.esaulkov@gmail.com> Date: Wed, 16 Oct 2019 10:38:17 +0700 Subject: [PATCH 169/248] update geolite urls --- lib/maxmind_database.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/maxmind_database.rb b/lib/maxmind_database.rb index 471195a44..9330f03f6 100644 --- a/lib/maxmind_database.rb +++ b/lib/maxmind_database.rb @@ -96,9 +96,9 @@ def archive_url(package) def archive_url_path(package) { - geolite_country_csv: "GeoIPCountryCSV.zip", - geolite_city_csv: "GeoLiteCity_CSV/GeoLiteCity-latest.zip", - geolite_asn_csv: "asnum/GeoIPASNum2.zip" + geolite_country_csv: "GeoLite2-Country-CSV.zip", + geolite_city_csv: "GeoLite2-City-CSV.zip", + geolite_asn_csv: "GeoLite2-ASN-CSV.zip" }[package] end From 6e30ab9157bd905a928b4c32d73aed7a9358d647 Mon Sep 17 00:00:00 2001 From: Mziserman <martinziserman@gmail.com> Date: Tue, 22 Oct 2019 01:41:11 +0200 Subject: [PATCH 170/248] Feature/allow coordinates in ban fr (#1416) * allow lon and lat params in ban_fr * add center in ban_fr result root keys * test ban_fr geocoder with coordinates * fix expected url --- lib/geocoder/lookups/ban_data_gouv_fr.rb | 13 +++++++++++++ lib/geocoder/results/ban_data_gouv_fr.rb | 2 +- test/unit/lookups/ban_data_gouv_fr_test.rb | 7 +++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/ban_data_gouv_fr.rb b/lib/geocoder/lookups/ban_data_gouv_fr.rb index b4b2e81f4..13ee34dc0 100644 --- a/lib/geocoder/lookups/ban_data_gouv_fr.rb +++ b/lib/geocoder/lookups/ban_data_gouv_fr.rb @@ -86,6 +86,12 @@ def search_geocode_ban_fr_params(query) unless (citycode = query.options[:citycode]).nil? || !code_param_is_valid?(citycode) params[:citycode] = citycode.to_s end + unless (lat = query.options[:lat]).nil? || !latitude_is_valid?(lat) + params[:lat] = lat + end + unless (lon = query.options[:lon]).nil? || !longitude_is_valid?(lon) + params[:lon] = lon + end params end @@ -126,5 +132,12 @@ def code_param_is_valid?(param) (1..99999).include?(param.to_i) end + def latitude_is_valid?(param) + param.to_f <= 90 && param.to_f >= -90 + end + + def longitude_is_valid?(param) + param.to_f <= 180 && param.to_f >= -180 + end end end diff --git a/lib/geocoder/results/ban_data_gouv_fr.rb b/lib/geocoder/results/ban_data_gouv_fr.rb index 0b936b043..2ca2b6feb 100644 --- a/lib/geocoder/results/ban_data_gouv_fr.rb +++ b/lib/geocoder/results/ban_data_gouv_fr.rb @@ -7,7 +7,7 @@ class BanDataGouvFr < Base #### BASE METHODS #### def self.response_attributes - %w[limit attribution version licence type features] + %w[limit attribution version licence type features center] end response_attributes.each do |a| diff --git a/test/unit/lookups/ban_data_gouv_fr_test.rb b/test/unit/lookups/ban_data_gouv_fr_test.rb index 8229c9882..b7a70d518 100644 --- a/test/unit/lookups/ban_data_gouv_fr_test.rb +++ b/test/unit/lookups/ban_data_gouv_fr_test.rb @@ -14,6 +14,13 @@ def test_query_for_geocode assert_equal 'https://api-adresse.data.gouv.fr/search/?q=13+rue+yves+toudic%2C+75010+Paris', res end + def test_query_for_geocode_with_geographic_priority + query = Geocoder::Query.new('13 rue yves toudic, 75010 Paris', lat: 48.789, lon: 2.789) + lookup = Geocoder::Lookup.get(:ban_data_gouv_fr) + res = lookup.query_url(query) + assert_equal 'https://api-adresse.data.gouv.fr/search/?lat=48.789&lon=2.789&q=13+rue+yves+toudic%2C+75010+Paris', res + end + def test_query_for_reverse_geocode query = Geocoder::Query.new([48.770639, 2.364375]) lookup = Geocoder::Lookup.get(:ban_data_gouv_fr) From 9799585d7bb4d34868d89c6b667ebf030ae3e1a2 Mon Sep 17 00:00:00 2001 From: Andrey Makovenko <makovenkoandrey@gmail.com> Date: Wed, 23 Oct 2019 10:56:16 +0300 Subject: [PATCH 171/248] Update IPinfo quota information Source: https://ipinfo.io/missingauth --- README_API_GUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index d91201a88..6f6366088 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -344,7 +344,7 @@ IP Address Lookups ### IPInfo.io (`:ipinfo_io`) * **API key**: optional - see https://ipinfo.io/pricing -* **Quota**: 50,000/mo - more with api key - see https://ipinfo.io/developers#rate-limits +* **Quota**: 1,000/day without API key, 50,000/mo with a free account - more with a paid plan - see https://ipinfo.io/developers#rate-limits * **Region**: world * **SSL support**: yes * **Languages**: English From b4f3c4130aabcda1017f97304c02a4dc6ec27578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= <dzm.kov@gmail.com> Date: Fri, 1 Nov 2019 16:12:45 +0300 Subject: [PATCH 172/248] Remove unnecessary variable `o` variable in the `HashRecursiveMerge#rmerge` method definition is not necessary in the result hash calculation --- lib/hash_recursive_merge.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/hash_recursive_merge.rb b/lib/hash_recursive_merge.rb index 163566ee1..49d648ce3 100644 --- a/lib/hash_recursive_merge.rb +++ b/lib/hash_recursive_merge.rb @@ -60,9 +60,8 @@ def rmerge!(other_hash) # h1.merge(h2) #=> {"a" => 100, "b" = >254, "c" => {"c1" => 16, "c3" => 94}} # def rmerge(other_hash) - r = {} merge(other_hash) do |key, oldval, newval| - r[key] = oldval.class == self.class ? oldval.rmerge(newval) : newval + oldval.class == self.class ? oldval.rmerge(newval) : newval end end From 6abfc3402bf40789e0351fd7b71efcea31dcb6a4 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 8 Nov 2019 13:45:31 -0800 Subject: [PATCH 173/248] Add note about inheriting from Redis. Fixes #1421. --- examples/autoexpire_cache_redis.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/autoexpire_cache_redis.rb b/examples/autoexpire_cache_redis.rb index 395a71e5e..e15c5f546 100644 --- a/examples/autoexpire_cache_redis.rb +++ b/examples/autoexpire_cache_redis.rb @@ -1,6 +1,8 @@ # This class implements a cache with simple delegation to the Redis store, but # when it creates a key/value pair, it also sends an EXPIRE command with a TTL. # It should be fairly simple to do the same thing with Memcached. +# Alternatively, this class could inherit from Redis, which would make most +# of the below methods unnecessary. class AutoexpireCacheRedis def initialize(store, ttl = 86400) @store = store From 773ac0fb67ffc18172573e9c5b052126276e01c1 Mon Sep 17 00:00:00 2001 From: Stephan Pavlovic <stephan@railslove.com> Date: Mon, 16 Dec 2019 00:26:23 +0100 Subject: [PATCH 174/248] Use the Here lookup with the new Here url and the new authentication method (#1430) --- lib/geocoder/lookups/here.rb | 23 +++++++---------------- test/unit/lookups/here_test.rb | 10 ++++++++++ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/geocoder/lookups/here.rb b/lib/geocoder/lookups/here.rb index e302ef68a..27558682f 100644 --- a/lib/geocoder/lookups/here.rb +++ b/lib/geocoder/lookups/here.rb @@ -9,13 +9,17 @@ def name end def required_api_key_parts - ["app_id", "app_code"] + ['api_key'] + end + + def supported_protocols + [:https] end private # --------------------------------------------------------------- def base_query_url(query) - "#{protocol}://#{if query.reverse_geocode? then 'reverse.' end}geocoder.api.here.com/6.2/#{if query.reverse_geocode? then 'reverse' end}geocode.json?" + "#{protocol}://#{if query.reverse_geocode? then 'reverse.' end}geocoder.ls.hereapi.com/6.2/#{if query.reverse_geocode? then 'reverse' end}geocode.json?" end def results(query) @@ -31,8 +35,7 @@ def results(query) def query_url_here_options(query, reverse_geocode) options = { gen: 9, - app_id: api_key, - app_code: api_code, + apikey: configuration.api_key, language: (query.language || configuration.language) } if reverse_geocode @@ -61,17 +64,5 @@ def query_url_params(query) ) end end - - def api_key - if (a = configuration.api_key) - return a.first if a.is_a?(Array) - end - end - - def api_code - if (a = configuration.api_key) - return a.last if a.is_a?(Array) - end - end end end diff --git a/test/unit/lookups/here_test.rb b/test/unit/lookups/here_test.rb index 0e57005ef..b0be288b9 100644 --- a/test/unit/lookups/here_test.rb +++ b/test/unit/lookups/here_test.rb @@ -35,4 +35,14 @@ def test_here_query_url_contains_mapview ) assert_match(/mapview=40.0+%2C-120.0+%3B39.0+%2C-121.0+/, url) end + + def test_here_query_url_contains_api_key + lookup = Geocoder::Lookup::Here.new + url = lookup.query_url( + Geocoder::Query.new( + 'Some Intersection' + ) + ) + assert_match(/apikey=+/, url) + end end From d6649ea05bf20ee3c3d791b24195b7360fb36b89 Mon Sep 17 00:00:00 2001 From: ahsannawaz111 <41775747+ahsannawaz111@users.noreply.github.com> Date: Tue, 31 Dec 2019 04:10:49 +0500 Subject: [PATCH 175/248] add ipgeolocation (#1390) --- README_API_GUIDE.md | 11 ++ lib/geocoder/lookup.rb | 3 +- lib/geocoder/lookups/ipgeolocation.rb | 62 +++++++++++ lib/geocoder/results/ipgeolocation.rb | 54 +++++++++ test/fixtures/ipgeolocation_103_217_177_217 | 37 +++++++ test/test_helper.rb | 8 ++ test/unit/lookups/ipgeolocation_test.rb | 117 ++++++++++++++++++++ 7 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 lib/geocoder/lookups/ipgeolocation.rb create mode 100644 lib/geocoder/results/ipgeolocation.rb create mode 100644 test/fixtures/ipgeolocation_103_217_177_217 create mode 100644 test/unit/lookups/ipgeolocation_test.rb diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 6f6366088..177c80fba 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -488,6 +488,17 @@ IP Address Lookups * **Documentation**: https://ipregistry.co/docs * **Terms of Service**: https://ipregistry.co/terms +### Ipgeolocation (`:ipgeolocation`) + +* **API key**: required (see https://ipgeolocation.io/pricing) +* **Quota**: 1500/day (with free API Key) +* **Region**: world +* **SSL support**: yes +* **Languages**: English, German, Russian, Japanese, French, Chinese, Spanish, Czech, Italian +* **Documentation**: https://ipgeolocation.io/documentation +* **Terms of Service**: https://ipgeolocation/tos +* **Notes**: To use Ipgeolocation set `Geocoder.configure(ip_lookup: :ipgeolocation, api_key: "your_ipgeolocation_api_key", use_https:true)`. Supports the optional params: { excludes: "continent_code"}, {fields: "geo"}, {lang: "ru"}, {output: "xml"}, {include: "hostname"}, {ip: "174.7.116.0"}) (see API documentation for details). + Local IP Address Lookups ------------------------ diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index db03b809f..8874f32d7 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -74,7 +74,8 @@ def ip_services :ipdata_co, :db_ip_com, :ipstack, - :ip2location + :ip2location, + :ipgeolocation ] end diff --git a/lib/geocoder/lookups/ipgeolocation.rb b/lib/geocoder/lookups/ipgeolocation.rb new file mode 100644 index 000000000..008b8011e --- /dev/null +++ b/lib/geocoder/lookups/ipgeolocation.rb @@ -0,0 +1,62 @@ +require 'geocoder/lookups/base' +require 'geocoder/results/ipgeolocation' + + +module Geocoder::Lookup + class Ipgeolocation < Base + + ERROR_CODES = { + 404 => Geocoder::InvalidRequest, + 101 => Geocoder::InvalidApiKey, + 102 => Geocoder::Error, + 103 => Geocoder::InvalidRequest, + 104 => Geocoder::OverQueryLimitError, + 105 => Geocoder::RequestDenied, + 301 => Geocoder::InvalidRequest, + 302 => Geocoder::InvalidRequest, + 303 => Geocoder::RequestDenied, + } + ERROR_CODES.default = Geocoder::Error + + def name + "Ipgeolocation" + end + + private # ---------------------------------------------------------------- + + def base_query_url(query) + "#{protocol}://#{host}/ipgeo?" + end + def query_url_params(query) + { + ip: query.sanitized_text, + apiKey: configuration.api_key + }.merge(super) + end + + def results(query) + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? + return [] unless doc = fetch_data(query) + if error = doc['error'] + code = error['code'] + msg = error['info'] + raise_error(ERROR_CODES[code], msg ) || Geocoder.log(:warn, "Ipgeolocation Geocoding API error: #{msg}") + return [] + end + [doc] + end + + def reserved_result(ip) + { + "ip" => ip, + "country_name" => "Reserved", + "country_code2" => "RD" + } + end + + def host + configuration[:host] || "api.ipgeolocation.io" + end + end +end \ No newline at end of file diff --git a/lib/geocoder/results/ipgeolocation.rb b/lib/geocoder/results/ipgeolocation.rb new file mode 100644 index 000000000..9b44145b0 --- /dev/null +++ b/lib/geocoder/results/ipgeolocation.rb @@ -0,0 +1,54 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class Ipgeolocation < Base + + def address(format = :full) + s = region_code.empty? ? "" : ", #{region_code}" + "#{city}#{s} #{zip}, #{country_name}".sub(/^[ ,]*/, "") + end + + def state + @data['region_name'] + end + + def state_code + @data['region_code'] + end + + def country + @data['country_name'] + end + + def postal_code + @data['zip'] || @data['zipcode'] || @data['zip_code'] + end + + def self.response_attributes + [ + ['ip', ''], + ['hostname', ''], + ['continent_code', ''], + ['continent_name', ''], + ['country_code2', ''], + ['country_code3', ''], + ['country_name', ''], + ['country_capital',''], + ['district',''], + ['state_prov',''], + ['city', ''], + ['zipcode', ''], + ['latitude', 0], + ['longitude', 0], + ['time_zone', {}], + ['currency', {}] + ] + end + + response_attributes.each do |attr, default| + define_method attr do + @data[attr] || default + end + end + end +end \ No newline at end of file diff --git a/test/fixtures/ipgeolocation_103_217_177_217 b/test/fixtures/ipgeolocation_103_217_177_217 new file mode 100644 index 000000000..d4e6e04ca --- /dev/null +++ b/test/fixtures/ipgeolocation_103_217_177_217 @@ -0,0 +1,37 @@ +{ + "ip": "103.217.177.217", + "continent_code": "AS", + "continent_name": "Asia", + "country_code2": "PK", + "country_code3": "PAK", + "country_name": "Pakistan", + "country_capital": "Islamabad", + "state_prov": "Islamabad", + "district": "Islamabad", + "city": "Islamabad", + "zipcode": "44000", + "latitude": "33.7334", + "longitude": "73.0785", + "is_eu": false, + "calling_code": "+92", + "country_tld": ".pk", + "languages": "ur-PK,en-PK,pa,sd,ps,brh", + "country_flag": "https://ipgeolocation.io/static/flags/pk_64.png", + "isp": "TES", + "connection_type": "", + "organization": "Trans World Enterprise Services (Private) Limited", + "geoname_id": "1162015", + "currency": { + "code": "PKR", + "name": "Pakistan Rupee", + "symbol": "₨" + }, + "time_zone": { + "name": "Asia/Karachi", + "offset": 5, + "current_time": "2019-03-18 19:28:33.837+0500", + "current_time_unix": 1552919313.837, + "is_dst": false, + "dst_savings": 0 + } +} \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 89499bbfb..ebac21d62 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -225,6 +225,14 @@ def default_fixture_filename end end + require 'geocoder/lookups/ipgeolocation' + class Ipgeolocation + private + def default_fixture_filename + "ipgeolocation_103_217_177_217" + end + end + require 'geocoder/lookups/ipstack' class Ipstack private diff --git a/test/unit/lookups/ipgeolocation_test.rb b/test/unit/lookups/ipgeolocation_test.rb new file mode 100644 index 000000000..97b5b28cb --- /dev/null +++ b/test/unit/lookups/ipgeolocation_test.rb @@ -0,0 +1,117 @@ +# encoding: utf-8 +require 'test_helper' + +class IpgeolocationTest < GeocoderTestCase + + def setup + Geocoder::Configuration.instance.data.clear + Geocoder::Configuration.set_defaults + Geocoder.configure( + :api_key => 'ea91e4a4159247fdb0926feae70c2911', + :ip_lookup => :ipgeolocation, + :always_raise => :all + ) + end + + def test_result_on_ip_address_search + result = Geocoder.search("103.217.177.217").first + assert result.is_a?(Geocoder::Result::Ipgeolocation) + end + + def test_result_components + result = Geocoder.search("103.217.177.217").first + assert_equal "Pakistan", result.country_name + end + + def test_all_top_level_api_fields + result = Geocoder.search("103.217.177.217").first + assert_equal "103.217.177.217", result.ip + assert_equal "AS", result.continent_code + assert_equal "Asia", result.continent_name + assert_equal "PK", result.country_code2 + assert_equal "Pakistan", result.country_name + assert_equal "Islamabad", result.city + assert_equal "44000", result.zipcode + assert_equal "33.7334", result.latitude + assert_equal "73.0785", result.longitude + end + + def test_nested_api_fields + result = Geocoder.search("103.217.177.217").first + + assert result.time_zone.is_a?(Hash) + assert_equal "Asia/Karachi", result.time_zone['name'] + + assert result.currency.is_a?(Hash) + assert_equal "PKR", result.currency['code'] + end + + def test_required_base_fields + result = Geocoder.search("103.217.177.217").first + + assert_equal "Islamabad", result.country_capital + assert_equal "Islamabad", result.state_prov + assert_equal "Islamabad", result.city + assert_equal "44000", result.zipcode + assert_equal [33.7334, 73.0785], result.coordinates + end + + def test_localhost_loopback + result = Geocoder.search("127.0.0.1").first + assert_equal "127.0.0.1", result.ip + assert_equal "RD", result.country_code2 + assert_equal "Reserved", result.country_name + end + + def test_localhost_loopback_defaults + result = Geocoder.search("127.0.0.1").first + + assert_equal "127.0.0.1", result.ip + assert_equal "", result.continent_code + assert_equal "", result.continent_name + assert_equal "RD", result.country_code2 + assert_equal "Reserved", result.country_name + assert_equal "", result.city + assert_equal "", result.zipcode + assert_equal 0, result.latitude + assert_equal 0, result.longitude + assert_equal({}, result.time_zone) + assert_equal({}, result.currency) + end + + def test_localhost_private + result = Geocoder.search("172.19.0.1").first + assert_equal "172.19.0.1", result.ip + assert_equal "RD", result.country_code2 + assert_equal "Reserved", result.country_name + end + + def test_api_request_adds_access_key + lookup = Geocoder::Lookup.get(:ipgeolocation) + assert_match 'http://api.ipgeolocation.io/ipgeo?apiKey=ea91e4a4159247fdb0926feae70c2911&ip=74.200.247.59', lookup.query_url(Geocoder::Query.new("74.200.247.59")) + end + + def test_api_request_adds_security_when_specified + lookup = Geocoder::Lookup.get(:ipgeolocation) + query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { security: '1' })) + assert_match(/&security=1/, query_url) + end + + def test_api_request_adds_hostname_when_specified + lookup = Geocoder::Lookup.get(:ipgeolocation) + query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { hostname: '1' })) + assert_match(/&hostname=1/, query_url) + end + + def test_api_request_adds_language_when_specified + lookup = Geocoder::Lookup.get(:ipgeolocation) + query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { language: 'es' })) + assert_match(/&language=es/, query_url) + end + + def test_api_request_adds_fields_when_specified + lookup = Geocoder::Lookup.get(:ipgeolocation) + query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { fields: 'foo,bar' })) + assert_match(/&fields=foo%2Cbar/, query_url) + end +end \ No newline at end of file From 968809030ea512fd3f1a064b13a90393b201de5d Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 30 Dec 2019 14:52:04 -0800 Subject: [PATCH 176/248] Fix: lookup only supports HTTPS. HTTP requests were receiving 301 redirect. --- lib/geocoder/lookups/ipgeolocation.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/ipgeolocation.rb b/lib/geocoder/lookups/ipgeolocation.rb index 008b8011e..24bdddff2 100644 --- a/lib/geocoder/lookups/ipgeolocation.rb +++ b/lib/geocoder/lookups/ipgeolocation.rb @@ -22,6 +22,10 @@ def name "Ipgeolocation" end + def supported_protocols + [:https] + end + private # ---------------------------------------------------------------- def base_query_url(query) @@ -59,4 +63,4 @@ def host configuration[:host] || "api.ipgeolocation.io" end end -end \ No newline at end of file +end From 91c3ec02a226bfe818a44544803494b1ba5fd49f Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 30 Dec 2019 14:53:38 -0800 Subject: [PATCH 177/248] Hard code host. API is only served by one host, so this can only cause problems. --- lib/geocoder/lookups/ipgeolocation.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/geocoder/lookups/ipgeolocation.rb b/lib/geocoder/lookups/ipgeolocation.rb index 24bdddff2..32d80f888 100644 --- a/lib/geocoder/lookups/ipgeolocation.rb +++ b/lib/geocoder/lookups/ipgeolocation.rb @@ -29,7 +29,7 @@ def supported_protocols private # ---------------------------------------------------------------- def base_query_url(query) - "#{protocol}://#{host}/ipgeo?" + "#{protocol}://api.ipgeolocation.io/ipgeo?" end def query_url_params(query) { @@ -58,9 +58,5 @@ def reserved_result(ip) "country_code2" => "RD" } end - - def host - configuration[:host] || "api.ipgeolocation.io" - end end end From 48432270fd6b1dc6a61a70dbf242518de43024d7 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 30 Dec 2019 14:59:46 -0800 Subject: [PATCH 178/248] Add exception for specific error code. --- lib/geocoder/lookups/ipgeolocation.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/geocoder/lookups/ipgeolocation.rb b/lib/geocoder/lookups/ipgeolocation.rb index 32d80f888..4317e865f 100644 --- a/lib/geocoder/lookups/ipgeolocation.rb +++ b/lib/geocoder/lookups/ipgeolocation.rb @@ -7,6 +7,7 @@ class Ipgeolocation < Base ERROR_CODES = { 404 => Geocoder::InvalidRequest, + 401 => Geocoder::RequestDenied, # missing/invalid API key 101 => Geocoder::InvalidApiKey, 102 => Geocoder::Error, 103 => Geocoder::InvalidRequest, From a2b1bc725d1d7ca79badd125472b3dc0940c2ca7 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 30 Dec 2019 15:04:57 -0800 Subject: [PATCH 179/248] Fix references to invalid hash keys. --- lib/geocoder/results/ipgeolocation.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/geocoder/results/ipgeolocation.rb b/lib/geocoder/results/ipgeolocation.rb index 9b44145b0..e4eef8198 100644 --- a/lib/geocoder/results/ipgeolocation.rb +++ b/lib/geocoder/results/ipgeolocation.rb @@ -4,16 +4,15 @@ module Geocoder::Result class Ipgeolocation < Base def address(format = :full) - s = region_code.empty? ? "" : ", #{region_code}" - "#{city}#{s} #{zip}, #{country_name}".sub(/^[ ,]*/, "") + "#{city}, #{state} #{postal_code}, #{country_name}".sub(/^[ ,]*/, "") end def state - @data['region_name'] + @data['state_prov'] end def state_code - @data['region_code'] + @data['state_prov'] end def country @@ -21,7 +20,7 @@ def country end def postal_code - @data['zip'] || @data['zipcode'] || @data['zip_code'] + @data['zipcode'] end def self.response_attributes @@ -51,4 +50,4 @@ def self.response_attributes end end end -end \ No newline at end of file +end From 3abd9d7871dfb2881aaa23b621aa9e446fd7fef5 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Fri, 3 Jan 2020 23:22:09 -0800 Subject: [PATCH 180/248] Add missing methods and fix test failures for :ipgeolocation IP lookup. --- lib/geocoder/results/ipgeolocation.rb | 10 ++++++++-- test/unit/lookup_test.rb | 1 + test/unit/lookups/ipgeolocation_test.rb | 8 ++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/geocoder/results/ipgeolocation.rb b/lib/geocoder/results/ipgeolocation.rb index e4eef8198..15dd05b13 100644 --- a/lib/geocoder/results/ipgeolocation.rb +++ b/lib/geocoder/results/ipgeolocation.rb @@ -3,6 +3,10 @@ module Geocoder::Result class Ipgeolocation < Base + def coordinates + [@data['latitude'].to_f, @data['longitude'].to_f] + end + def address(format = :full) "#{city}, #{state} #{postal_code}, #{country_name}".sub(/^[ ,]*/, "") end @@ -19,6 +23,10 @@ def country @data['country_name'] end + def country_code + @data['country_code2'] + end + def postal_code @data['zipcode'] end @@ -37,8 +45,6 @@ def self.response_attributes ['state_prov',''], ['city', ''], ['zipcode', ''], - ['latitude', 0], - ['longitude', 0], ['time_zone', {}], ['currency', {}] ] diff --git a/test/unit/lookup_test.rb b/test/unit/lookup_test.rb index 7281f1718..b8187f903 100644 --- a/test/unit/lookup_test.rb +++ b/test/unit/lookup_test.rb @@ -13,6 +13,7 @@ def test_responds_to_name_method def test_search_returns_empty_array_when_no_results Geocoder::Lookup.all_services_except_test.each do |l| + next if l == :ipgeolocation # always returns one result lookup = Geocoder::Lookup.get(l) set_api_key!(l) silence_warnings do diff --git a/test/unit/lookups/ipgeolocation_test.rb b/test/unit/lookups/ipgeolocation_test.rb index 97b5b28cb..db4b08a95 100644 --- a/test/unit/lookups/ipgeolocation_test.rb +++ b/test/unit/lookups/ipgeolocation_test.rb @@ -32,8 +32,8 @@ def test_all_top_level_api_fields assert_equal "Pakistan", result.country_name assert_equal "Islamabad", result.city assert_equal "44000", result.zipcode - assert_equal "33.7334", result.latitude - assert_equal "73.0785", result.longitude + assert_equal 33.7334, result.latitude + assert_equal 73.0785, result.longitude end def test_nested_api_fields @@ -88,7 +88,7 @@ def test_localhost_private def test_api_request_adds_access_key lookup = Geocoder::Lookup.get(:ipgeolocation) - assert_match 'http://api.ipgeolocation.io/ipgeo?apiKey=ea91e4a4159247fdb0926feae70c2911&ip=74.200.247.59', lookup.query_url(Geocoder::Query.new("74.200.247.59")) + assert_match /apiKey=\w+/, lookup.query_url(Geocoder::Query.new("74.200.247.59")) end def test_api_request_adds_security_when_specified @@ -114,4 +114,4 @@ def test_api_request_adds_fields_when_specified query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { fields: 'foo,bar' })) assert_match(/&fields=foo%2Cbar/, query_url) end -end \ No newline at end of file +end From 957f483a1bbc43266dee34d11a59fb13094101d1 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 4 Jan 2020 13:18:30 -0800 Subject: [PATCH 181/248] Don't lock mongoid gem to old version. Fixes #1433 (bundler hangs on resolving dependencies). --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 51a8fcfe6..d80825dce 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" group :development, :test do gem 'rake' - gem 'mongoid', '2.6.0' + gem 'mongoid' gem 'bson_ext', platforms: :ruby gem 'geoip' gem 'rubyzip' From 2f0a455a4b2fd4acd93137b08f8a337d9e01bccd Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 4 Jan 2020 13:19:39 -0800 Subject: [PATCH 182/248] Remove buggy tests. --- test/unit/rake_task_test.rb | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 test/unit/rake_task_test.rb diff --git a/test/unit/rake_task_test.rb b/test/unit/rake_task_test.rb deleted file mode 100644 index 25b46e0f1..000000000 --- a/test/unit/rake_task_test.rb +++ /dev/null @@ -1,22 +0,0 @@ -# encoding: utf-8 -require 'test_helper' - -class RakeTaskTest < GeocoderTestCase - def setup - Rake.application.rake_require "tasks/geocoder" - Rake::Task.define_task(:environment) - end - - def test_rake_task_geocode_raise_specify_class_message - omit("Errors on Travis") if ENV['TRAVIS'] # TODO: figure out why - assert_raise(RuntimeError, "Please specify a CLASS (model)") do - Rake.application.invoke_task("geocode:all") - end - end - - def test_rake_task_geocode_specify_class - omit("Errors on Travis") if ENV['TRAVIS'] # TODO: figure out why - ENV['CLASS'] = 'Place' - assert_nil Rake.application.invoke_task("geocode:all") - end -end From 6ca92f1ef748365217da78f1caf77ff23fcc9022 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Thu, 3 Oct 2019 13:06:18 -0700 Subject: [PATCH 183/248] Add PosgreSQL and MySQL to Travis. --- .travis.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 85d3e4ef8..89f35912c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,17 @@ language: ruby cache: bundler sudo: false + +services: + - postgresql + - mysql +before_script: + - psql -c 'create database geocoder_test;' -U postgres + +before_install: + - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true + - gem install bundler -v '< 2' + env: global: - JRUBY_OPTS=--2.0 @@ -23,9 +34,6 @@ gemfile: - gemfiles/Gemfile.rails3.2 - gemfiles/Gemfile.rails4.1 - gemfiles/Gemfile.rails5.0 -before_install: - - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true - - gem install bundler -v '< 2' matrix: exclude: - env: DB= From 84aa6d25b2a14228c84b1e4b6864566ebc42b680 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Thu, 3 Oct 2019 13:58:00 -0700 Subject: [PATCH 184/248] Set pg db name and username. --- test/database.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/database.yml b/test/database.yml index 63232ed58..f5f96de5f 100644 --- a/test/database.yml +++ b/test/database.yml @@ -11,4 +11,4 @@ mysql: postgres: adapter: postgresql database: geocoder_test - username: + username: postgres From 3be826b4e2575eb07444fe26d65458626cea49b5 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 4 Jan 2020 18:28:46 -0800 Subject: [PATCH 185/248] Migrate properly w/ ActiveRecord >=5.2. --- test/test_helper.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index ebac21d62..466c43ae6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -23,7 +23,13 @@ ActiveRecord::Base.establish_connection(db_name.to_sym) ActiveRecord::Base.default_timezone = :utc - ActiveRecord::Migrator.migrate('test/db/migrate', nil) + if defined? ActiveRecord::MigrationContext + # ActiveRecord >=5.2 + ActiveRecord::MigrationContext.new('test/db/migrate').migrate + else + ActiveRecord::Migrator.migrate('test/db/migrate', nil) + end + else class MysqlConnection def adapter_name From b78b5266dbb3edcafac64b78de50b125412333ed Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 4 Jan 2020 20:39:36 -0800 Subject: [PATCH 186/248] Upgrade sqlite3 gem. Was getting: Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? can't activate sqlite3 (~> 1.4), already activated sqlite3-1.3.13. --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index d80825dce..f04dc0ff2 100644 --- a/Gemfile +++ b/Gemfile @@ -22,7 +22,7 @@ end group :test do platforms :ruby, :mswin, :mingw do - gem 'sqlite3', '~> 1.3.5' + gem 'sqlite3', '~> 1.4.2' gem 'sqlite_ext', '~> 1.5.0' end From e9d352dfd74858ca7ab29f7b14e13189ee2eb0cc Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 4 Jan 2020 21:02:21 -0800 Subject: [PATCH 187/248] No need to exclude unused gemfile. --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 89f35912c..3925d2d9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,8 +48,6 @@ matrix: gemfile: gemfiles/Gemfile.rails5.0 - rvm: 2.1.10 gemfile: Gemfile - - rvm: 2.1.10 - gemfile: gemfiles/Gemfile.ruby1.9.3 - rvm: 2.1.10 gemfile: gemfiles/Gemfile.rails5.0 - rvm: 2.4.4 From 1c3e7b887ef1c8ab362a1285527d619924d45373 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 4 Jan 2020 21:11:50 -0800 Subject: [PATCH 188/248] Provide corrct number of args for ea version. (second is @schema_migration) --- test/test_helper.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 466c43ae6..8d78b1a62 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -24,8 +24,13 @@ ActiveRecord::Base.default_timezone = :utc if defined? ActiveRecord::MigrationContext - # ActiveRecord >=5.2 - ActiveRecord::MigrationContext.new('test/db/migrate').migrate + if ActiveRecord.version.release < Gem::Version.new('6.0.0') + # ActiveRecord >=5.2, takes one argument + ActiveRecord::MigrationContext.new('test/db/migrate').migrate + else + # ActiveRecord >=6.0, takes two arguments + ActiveRecord::MigrationContext.new('test/db/migrate', nil).migrate + end else ActiveRecord::Migrator.migrate('test/db/migrate', nil) end From 2c32dadcda3b82414ba7078349c9bbc4b24ecc4a Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 4 Jan 2020 22:17:45 -0800 Subject: [PATCH 189/248] Remove first method definition. Was being overwritten by second. --- lib/geocoder/lookups/ip2location.rb | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/geocoder/lookups/ip2location.rb b/lib/geocoder/lookups/ip2location.rb index 3e29a799e..3b6481041 100644 --- a/lib/geocoder/lookups/ip2location.rb +++ b/lib/geocoder/lookups/ip2location.rb @@ -19,11 +19,11 @@ def base_query_url(query) end def query_url_params(query) - { - key: configuration.api_key ? configuration.api_key : "demo", - format: "json", - ip: query.sanitized_text - }.merge(super) + params = super + if configuration.has_key?(:package) + params.merge!(package: configuration[:package]) + end + params end def results(query) @@ -63,13 +63,5 @@ def reserved_result(query) } end - def query_url_params(query) - params = super - if configuration.has_key?(:package) - params.merge!(package: configuration[:package]) - end - params - end - end end From 62d94136ae3d5531546e5309e02c3602fb3051cd Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 4 Jan 2020 22:19:52 -0800 Subject: [PATCH 190/248] Remove duplicated method. --- lib/geocoder/results/baidu.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/geocoder/results/baidu.rb b/lib/geocoder/results/baidu.rb index b30265e56..c6fd36ea8 100644 --- a/lib/geocoder/results/baidu.rb +++ b/lib/geocoder/results/baidu.rb @@ -7,10 +7,6 @@ def coordinates ['lat', 'lng'].map{ |i| @data['location'][i] } end - def address - @data['formatted_address'] - end - def province @data['addressComponent'] and @data['addressComponent']['province'] or "" end From fb4e2ec383ec211394b8bdef8c20843be4309eb4 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 4 Jan 2020 22:20:07 -0800 Subject: [PATCH 191/248] Add parenthesis to fix ambiguous argument warnings. --- lib/geocoder/lookups/pickpoint.rb | 2 +- test/unit/geocoder_test.rb | 4 +-- test/unit/lookups/ipapi_com_test.rb | 48 ++++++++++++------------- test/unit/lookups/ipgeolocation_test.rb | 2 +- test/unit/lookups/location_iq_test.rb | 2 +- test/unit/lookups/pickpoint_test.rb | 2 +- test/unit/method_aliases_test.rb | 2 +- test/unit/model_test.rb | 2 +- test/unit/mongoid_test.rb | 4 +-- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/lib/geocoder/lookups/pickpoint.rb b/lib/geocoder/lookups/pickpoint.rb index e298e8951..b5863ee99 100644 --- a/lib/geocoder/lookups/pickpoint.rb +++ b/lib/geocoder/lookups/pickpoint.rb @@ -23,7 +23,7 @@ def base_query_url(query) end def query_url_params(query) - params = { + { key: configuration.api_key }.merge(super) end diff --git a/test/unit/geocoder_test.rb b/test/unit/geocoder_test.rb index a73c92032..a371cee80 100644 --- a/test/unit/geocoder_test.rb +++ b/test/unit/geocoder_test.rb @@ -40,8 +40,8 @@ def test_geocode_block_executed_when_no_results def test_reverse_geocode_assigns_and_returns_address v = PlaceReverseGeocoded.new(*reverse_geocoded_object_params(:msg)) - assert_match /New York/, v.reverse_geocode - assert_match /New York/, v.address + assert_match(/New York/, v.reverse_geocode) + assert_match(/New York/, v.address) end def test_forward_and_reverse_geocoding_on_same_model_works diff --git a/test/unit/lookups/ipapi_com_test.rb b/test/unit/lookups/ipapi_com_test.rb index e7c92a4c1..9d35653bd 100644 --- a/test/unit/lookups/ipapi_com_test.rb +++ b/test/unit/lookups/ipapi_com_test.rb @@ -21,34 +21,34 @@ def test_result_components def test_all_api_fields result = Geocoder.search("74.200.247.59").first - assert_equal "United States", result.country - assert_equal "US", result.country_code - assert_equal "NJ", result.region - assert_equal "New Jersey", result.region_name - assert_equal "Jersey City", result.city - assert_equal "07302", result.zip - assert_equal 40.7209, result.lat - assert_equal -74.0468, result.lon - assert_equal "America/New_York", result.timezone - assert_equal "DataPipe", result.isp - assert_equal "DataPipe", result.org - assert_equal "AS22576 DataPipe, Inc.", result.as - assert_equal "", result.reverse - assert_equal false, result.mobile - assert_equal false, result.proxy - assert_equal "74.200.247.59", result.query - assert_equal "success", result.status - assert_equal nil, result.message + assert_equal("United States", result.country) + assert_equal("US", result.country_code) + assert_equal("NJ", result.region) + assert_equal("New Jersey", result.region_name) + assert_equal("Jersey City", result.city) + assert_equal("07302", result.zip) + assert_equal(40.7209, result.lat) + assert_equal(-74.0468, result.lon) + assert_equal("America/New_York", result.timezone) + assert_equal("DataPipe", result.isp) + assert_equal("DataPipe", result.org) + assert_equal("AS22576 DataPipe, Inc.", result.as) + assert_equal("", result.reverse) + assert_equal(false, result.mobile) + assert_equal(false, result.proxy) + assert_equal("74.200.247.59", result.query) + assert_equal("success", result.status) + assert_equal(nil, result.message) end def test_loopback result = Geocoder.search("::1").first - assert_equal nil, result.lat - assert_equal nil, result.lon - assert_equal [nil, nil], result.coordinates - assert_equal nil, result.reverse - assert_equal "::1", result.query - assert_equal "fail", result.status + assert_equal(nil, result.lat) + assert_equal(nil, result.lon) + assert_equal([nil, nil], result.coordinates) + assert_equal(nil, result.reverse) + assert_equal("::1", result.query) + assert_equal("fail", result.status) end def test_private diff --git a/test/unit/lookups/ipgeolocation_test.rb b/test/unit/lookups/ipgeolocation_test.rb index db4b08a95..880f35ec8 100644 --- a/test/unit/lookups/ipgeolocation_test.rb +++ b/test/unit/lookups/ipgeolocation_test.rb @@ -88,7 +88,7 @@ def test_localhost_private def test_api_request_adds_access_key lookup = Geocoder::Lookup.get(:ipgeolocation) - assert_match /apiKey=\w+/, lookup.query_url(Geocoder::Query.new("74.200.247.59")) + assert_match(/apiKey=\w+/, lookup.query_url(Geocoder::Query.new("74.200.247.59"))) end def test_api_request_adds_security_when_specified diff --git a/test/unit/lookups/location_iq_test.rb b/test/unit/lookups/location_iq_test.rb index bfb3fc7ad..f3739ecd5 100644 --- a/test/unit/lookups/location_iq_test.rb +++ b/test/unit/lookups/location_iq_test.rb @@ -12,7 +12,7 @@ def setup def test_url_contains_api_key Geocoder.configure(location_iq: {api_key: "abc123"}) query = Geocoder::Query.new("Leadville, CO") - assert_match /key=abc123/, query.url + assert_match(/key=abc123/, query.url) end def test_raises_exception_with_invalid_api_key diff --git a/test/unit/lookups/pickpoint_test.rb b/test/unit/lookups/pickpoint_test.rb index 77d5532d6..be3facac0 100644 --- a/test/unit/lookups/pickpoint_test.rb +++ b/test/unit/lookups/pickpoint_test.rb @@ -20,7 +20,7 @@ def test_result_viewport def test_url_contains_api_key Geocoder.configure(pickpoint: {api_key: "pickpoint-api-key"}) query = Geocoder::Query.new("Leadville, CO") - assert_match /key=pickpoint-api-key/, query.url + assert_match(/key=pickpoint-api-key/, query.url) end def test_raises_exception_with_invalid_api_key diff --git a/test/unit/method_aliases_test.rb b/test/unit/method_aliases_test.rb index bd2f1c66f..c0a0ba7be 100644 --- a/test/unit/method_aliases_test.rb +++ b/test/unit/method_aliases_test.rb @@ -16,6 +16,6 @@ def test_fetch_coordinates_is_alias_for_geocode def test_fetch_address_is_alias_for_reverse_geocode v = PlaceReverseGeocoded.new(*reverse_geocoded_object_params(:msg)) - assert_match /New York/, v.fetch_address + assert_match(/New York/, v.fetch_address) end end diff --git a/test/unit/model_test.rb b/test/unit/model_test.rb index ed1dae046..39612fd73 100644 --- a/test/unit/model_test.rb +++ b/test/unit/model_test.rb @@ -6,7 +6,7 @@ class ModelTest < GeocoderTestCase def test_geocode_with_block_runs_block e = PlaceWithCustomResultsHandling.new(*geocoded_object_params(:msg)) e.geocode - assert_match /[0-9\.,\-]+/, e.coords_string + assert_match(/[0-9\.,\-]+/, e.coords_string) end def test_geocode_with_block_doesnt_auto_assign_coordinates diff --git a/test/unit/mongoid_test.rb b/test/unit/mongoid_test.rb index d2a662ec8..8a9ca1aca 100644 --- a/test/unit/mongoid_test.rb +++ b/test/unit/mongoid_test.rb @@ -44,13 +44,13 @@ def test_geocoded_with_custom_handling p = PlaceUsingMongoidWithCustomResultsHandling.new(*geocoded_object_params(:msg)) p.location = [40.750354, -73.993371] p.geocode - assert_match /[0-9\.,\-]+/, p.coords_string + assert_match(/[0-9\.,\-]+/, p.coords_string) end def test_reverse_geocoded p = PlaceUsingMongoidReverseGeocoded.new(*reverse_geocoded_object_params(:msg)) p.reverse_geocode - assert_match /New York/, p.address + assert_match(/New York/, p.address) end def test_reverse_geocoded_with_custom_handling From fc9dc2e50c0ce1e456e4e142ff5f5d4c5b82ae78 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 5 Jan 2020 00:01:31 -0800 Subject: [PATCH 192/248] Remove defunct service Geocoder.us. --- lib/geocoder/lookup.rb | 1 - lib/geocoder/lookups/geocoder_us.rb | 51 ------------------- lib/geocoder/results/geocoder_us.rb | 39 -------------- .../geocoder_us_madison_square_garden | 1 - test/fixtures/geocoder_us_no_results | 1 - 5 files changed, 93 deletions(-) delete mode 100644 lib/geocoder/lookups/geocoder_us.rb delete mode 100644 lib/geocoder/results/geocoder_us.rb delete mode 100644 test/fixtures/geocoder_us_madison_square_garden delete mode 100644 test/fixtures/geocoder_us_no_results diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index 8874f32d7..e4fc5e5cc 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -32,7 +32,6 @@ def street_services :google_places_search, :bing, :geocoder_ca, - :geocoder_us, :yandex, :nominatim, :mapbox, diff --git a/lib/geocoder/lookups/geocoder_us.rb b/lib/geocoder/lookups/geocoder_us.rb deleted file mode 100644 index cc9869cb3..000000000 --- a/lib/geocoder/lookups/geocoder_us.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'geocoder/lookups/base' -require "geocoder/results/geocoder_us" - -module Geocoder::Lookup - class GeocoderUs < Base - - def name - "Geocoder.us" - end - - def supported_protocols - [:http] - end - - private # ---------------------------------------------------------------- - - def base_query_url(query) - base_query_url_with_optional_key(configuration.api_key) - end - - def cache_key(query) - base_query_url_with_optional_key(nil) + url_query_string(query) - end - - def base_query_url_with_optional_key(key = nil) - base = "#{protocol}://" - if configuration.api_key - base << "#{configuration.api_key}@" - end - base + "geocoder.us/member/service/csv/geocode?" - end - - def results(query) - return [] unless doc = fetch_data(query) - if doc[0].to_s =~ /^(\d+)\:/ - return [] - else - return [doc.size == 5 ? ((doc[0..1] << nil) + doc[2..4]) : doc] - end - end - - def query_url_params(query) - (query.text =~ /^\d{5}(?:-\d{4})?$/ ? {:zip => query} : {:address => query.sanitized_text}).merge(super) - end - - def parse_raw_data(raw_data) - raw_data.chomp.split(',') - end - end -end - diff --git a/lib/geocoder/results/geocoder_us.rb b/lib/geocoder/results/geocoder_us.rb deleted file mode 100644 index ca20ad418..000000000 --- a/lib/geocoder/results/geocoder_us.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'geocoder/results/base' - -module Geocoder::Result - class GeocoderUs < Base - def coordinates - [@data[0].to_f, @data[1].to_f] - end - - def address(format = :full) - "#{street_address}, #{city}, #{state} #{postal_code}, #{country}".sub(/^[ ,]*/, "") - end - - def street_address - @data[2] - end - - def city - @data[3] - end - - def state - @data[4] - end - - alias_method :state_code, :state - - def postal_code - @data[5] - end - - def country - 'United States' - end - - def country_code - 'US' - end - end -end diff --git a/test/fixtures/geocoder_us_madison_square_garden b/test/fixtures/geocoder_us_madison_square_garden deleted file mode 100644 index 546df3682..000000000 --- a/test/fixtures/geocoder_us_madison_square_garden +++ /dev/null @@ -1 +0,0 @@ -40.678107, -73.897460, 4 Pennsylvania Ave, New York, NY, 11207 \ No newline at end of file diff --git a/test/fixtures/geocoder_us_no_results b/test/fixtures/geocoder_us_no_results deleted file mode 100644 index d349a8f91..000000000 --- a/test/fixtures/geocoder_us_no_results +++ /dev/null @@ -1 +0,0 @@ -2: couldn't find this address! sorry \ No newline at end of file From 4debbe72c18403b883daf50be6ac32047277a354 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 4 Jan 2020 23:54:48 -0800 Subject: [PATCH 193/248] Lock dev Gemfile to Rails 5.1.x. On 5.2+, getting argument errors for initializers on STI models. --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index f04dc0ff2..52ddae66c 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ group :development, :test do gem 'bson_ext', platforms: :ruby gem 'geoip' gem 'rubyzip' - gem 'rails' + gem 'rails', '~>5.1.0' gem 'test-unit' # needed for Ruby >=2.2.0 platforms :jruby do From 317f936acb68572ea08a3483e976671cd0e231d4 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 5 Jan 2020 07:10:03 -0800 Subject: [PATCH 194/248] Update activerecord-jdbcpostgresql-adapter gem. --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 52ddae66c..02d9c6bf1 100644 --- a/Gemfile +++ b/Gemfile @@ -36,7 +36,7 @@ group :test do platforms :jruby do gem 'jdbc-mysql' gem 'jdbc-sqlite3' - gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.0' + gem 'activerecord-jdbcpostgresql-adapter' end end From 642f8872a3884e2f8787094fcfdebbab9711df04 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 5 Jan 2020 15:34:10 -0800 Subject: [PATCH 195/248] Don't lock gem versions w/ Rails 3. Gems getting too old to find compatible combos. --- gemfiles/Gemfile.rails3.2 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gemfiles/Gemfile.rails3.2 b/gemfiles/Gemfile.rails3.2 index 9bf62c89e..2d5d714ee 100644 --- a/gemfiles/Gemfile.rails3.2 +++ b/gemfiles/Gemfile.rails3.2 @@ -2,7 +2,7 @@ source "https://rubygems.org" group :development, :test do gem 'rake' - gem 'mongoid', '2.6.0' + gem 'mongoid' gem 'bson_ext', platforms: :ruby gem 'geoip' gem 'rubyzip' @@ -22,13 +22,13 @@ end group :test do platforms :ruby do - gem 'sqlite3', '~> 1.3.5' - gem 'sqlite_ext', '~> 1.5.0' + gem 'sqlite3' + gem 'sqlite_ext' end - gem 'public_suffix', '2.0.5' # webmock dependency - gem 'addressable', '2.5.2' # webmock dependency - gem 'webmock', '3.3.0' + gem 'public_suffix' # webmock dependency + gem 'addressable' # webmock dependency + gem 'webmock' platforms :ruby do gem 'pg', '~> 0.11' @@ -38,6 +38,6 @@ group :test do platforms :jruby do gem 'jdbc-mysql' gem 'jdbc-sqlite3' - gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.0' + gem 'activerecord-jdbcpostgresql-adapter' end end From 9191f97fb1ed4c5682045e4f5ffed63bf7341c7b Mon Sep 17 00:00:00 2001 From: Anders Eriksson <aeri3@kth.se> Date: Mon, 6 Jan 2020 01:28:55 +0100 Subject: [PATCH 196/248] update Tencent status codes --- lib/geocoder/lookups/tencent.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/geocoder/lookups/tencent.rb b/lib/geocoder/lookups/tencent.rb index 1fef32abe..39dcdbfbd 100644 --- a/lib/geocoder/lookups/tencent.rb +++ b/lib/geocoder/lookups/tencent.rb @@ -31,18 +31,18 @@ def results(query, reverse = false) case doc['status'] when 0 return [doc[content_key]] - when 199 - raise error(Geocoder::InvalidApiKey, "invalid api key") || - Geocoder.log(:warn, "#{name} Geocoding API error: key is not enabled for web service usage.") - when 311 - raise_error(Geocoder::RequestDenied, "request denied") || - Geocoder.log(:warn, "#{name} Geocoding API error: request denied.") - when 310, 306 - raise_error(Geocoder::InvalidRequest, "invalid request.") || - Geocoder.log(:warn, "#{name} Geocoding API error: invalid request.") when 311 raise_error(Geocoder::InvalidApiKey, "invalid api key") || Geocoder.log(:warn, "#{name} Geocoding API error: invalid api key.") + when 310 + raise_error(Geocoder::InvalidRequest, "invalid request.") || + Geocoder.log(:warn, "#{name} Geocoding API error: invalid request, invalid parameters.") + when 306 + raise_error(Geocoder::InvalidRequest, "invalid request.") || + Geocoder.log(:warn, "#{name} Geocoding API error: invalid request, check response for more info.") + when 110 + raise_error(Geocoder::RequestDenied, "request denied.") || + Geocoder.log(:warn, "#{name} Geocoding API error: request source is not authorized.") end return [] end From 72b51ef875ea80fc1761e7d83e0eae2fe2e07508 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 5 Jan 2020 19:24:24 -0800 Subject: [PATCH 197/248] Remove reference to :geocoder_us lookup. (should have been part of fc9dc2e50c0ce1e456e4e142ff5f5d4c5b82ae78) --- test/unit/result_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/result_test.rb b/test/unit/result_test.rb index eeb579ee8..007074bed 100644 --- a/test/unit/result_test.rb +++ b/test/unit/result_test.rb @@ -37,7 +37,7 @@ def test_result_has_coords_in_reasonable_range_for_madison_square_garden def test_result_accepts_reverse_coords_in_reasonable_range_for_madison_square_garden Geocoder::Lookup.street_services.each do |l| next unless File.exist?(File.join("test", "fixtures", "#{l.to_s}_madison_square_garden")) - next if [:bing, :esri, :geocoder_ca, :google_places_search, :geocoder_us, :geoportail_lu].include? l # Reverse fixture does not match forward + next if [:bing, :esri, :geocoder_ca, :google_places_search, :geoportail_lu].include? l # Reverse fixture does not match forward Geocoder.configure(:lookup => l) set_api_key!(l) result = Geocoder.search([40.750354, -73.993371]).first From bb19cda924997b0e8a343964a17bba6c6c574a1f Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 5 Jan 2020 19:25:06 -0800 Subject: [PATCH 198/248] Remove obsolete integration tests. --- test/integration/http_client_test.rb | 30 ---------------------------- 1 file changed, 30 deletions(-) delete mode 100644 test/integration/http_client_test.rb diff --git a/test/integration/http_client_test.rb b/test/integration/http_client_test.rb deleted file mode 100644 index 21ffe5611..000000000 --- a/test/integration/http_client_test.rb +++ /dev/null @@ -1,30 +0,0 @@ -# encoding: utf-8 -require 'pathname' -require 'rubygems' -require 'test/unit' -require 'geocoder' -require 'yaml' - -class HttpClientTest < Test::Unit::TestCase - def setup - @api_keys = YAML.load_file("api_keys.yml") - end - - def test_http_basic_auth - Geocoder.configure(lookup: :geocoder_us, api_key: @api_keys["geocoder_us"]) - results = Geocoder.search "27701" - assert_not_nil results.first - end - - def test_ssl - Geocoder.configure(lookup: :esri, use_https: true) - results = Geocoder.search "27701" - assert_not_nil results.first - end - - def test_ssl_opt_out - Geocoder.configure(ip_lookup: :telize, use_https: true) - results = Geocoder.search "74.200.247.59" - assert_not_nil results.first - end -end From 89c2b98f715d626aaf18d3105cdd6976067cf717 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 5 Jan 2020 21:59:09 -0800 Subject: [PATCH 199/248] Move lookup-specific tests to appropriate files. --- test/unit/lookups/mapbox_test.rb | 7 ++++ test/unit/lookups/yandex_test.rb | 41 ++++++++++++++++++++++++ test/unit/result_test.rb | 55 -------------------------------- 3 files changed, 48 insertions(+), 55 deletions(-) diff --git a/test/unit/lookups/mapbox_test.rb b/test/unit/lookups/mapbox_test.rb index e283bbf8c..7610081bb 100644 --- a/test/unit/lookups/mapbox_test.rb +++ b/test/unit/lookups/mapbox_test.rb @@ -49,4 +49,11 @@ def test_truncates_query_at_semicolon result = Geocoder.search("Madison Square Garden, New York, NY;123 Another St").first assert_equal [40.749688, -73.991566], result.coordinates end + + def test_mapbox_result_without_context + assert_nothing_raised do + result = Geocoder.search("Shanghai, China")[0] + assert_equal nil, result.city + end + end end diff --git a/test/unit/lookups/yandex_test.rb b/test/unit/lookups/yandex_test.rb index b4ca20941..9a02a400a 100644 --- a/test/unit/lookups/yandex_test.rb +++ b/test/unit/lookups/yandex_test.rb @@ -32,4 +32,45 @@ def test_yandex_query_url_contains_bbox assert_match(/bbox=40.0+%2C-120.0+~39.0+%2C-121.0+/, url) end end + + def test_yandex_result_without_city_does_not_raise_exception + assert_nothing_raised do + set_api_key!(:yandex) + result = Geocoder.search("no city and town").first + assert_equal "", result.city + end + end + + def test_yandex_result_without_admin_area_no_exception + assert_nothing_raised do + set_api_key!(:yandex) + result = Geocoder.search("no administrative area").first + assert_equal "", result.city + end + end + + def test_yandex_result_new_york + assert_nothing_raised do + set_api_key!(:yandex) + result = Geocoder.search("new york").first + assert_equal "", result.city + end + end + + def test_yandex_result_kind + assert_nothing_raised do + set_api_key!(:yandex) + ["new york", [45.423733, -75.676333], "no city and town"].each do |query| + Geocoder.search("new york").first.kind + end + end + end + + def test_yandex_result_without_locality_name + assert_nothing_raised do + set_api_key!(:yandex) + result = Geocoder.search("canada rue dupuis 14")[6] + assert_equal "", result.city + end + end end diff --git a/test/unit/result_test.rb b/test/unit/result_test.rb index 007074bed..caa573556 100644 --- a/test/unit/result_test.rb +++ b/test/unit/result_test.rb @@ -47,61 +47,6 @@ def test_result_accepts_reverse_coords_in_reasonable_range_for_madison_square_ga end end - def test_yandex_result_without_city_does_not_raise_exception - assert_nothing_raised do - Geocoder.configure(:lookup => :yandex) - set_api_key!(:yandex) - result = Geocoder.search("no city and town").first - assert_equal "", result.city - end - end - - def test_yandex_result_without_admin_area_no_exception - assert_nothing_raised do - Geocoder.configure(:lookup => :yandex) - set_api_key!(:yandex) - result = Geocoder.search("no administrative area").first - assert_equal "", result.city - end - end - - def test_yandex_result_new_york - assert_nothing_raised do - Geocoder.configure(:lookup => :yandex) - set_api_key!(:yandex) - result = Geocoder.search("new york").first - assert_equal "", result.city - end - end - - def test_yandex_result_kind - assert_nothing_raised do - Geocoder.configure(:lookup => :yandex) - set_api_key!(:yandex) - ["new york", [45.423733, -75.676333], "no city and town"].each do |query| - Geocoder.search("new york").first.kind - end - end - end - - def test_yandex_result_without_locality_name - assert_nothing_raised do - Geocoder.configure(:lookup => :yandex) - set_api_key!(:yandex) - result = Geocoder.search("canada rue dupuis 14")[6] - assert_equal "", result.city - end - end - - def test_mapbox_result_without_context - assert_nothing_raised do - Geocoder.configure(:lookup => :mapbox) - set_api_key!(:mapbox) - result = Geocoder.search("Shanghai, China")[0] - assert_equal nil, result.city - end - end - private # ------------------------------------------------------------------ def assert_result_has_required_attributes(result) From 5f35252508f5430e9631d5b48a7c4cf087dfad96 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 5 Jan 2020 21:59:29 -0800 Subject: [PATCH 200/248] Remove tests that aren't really useful. --- test/unit/result_test.rb | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/test/unit/result_test.rb b/test/unit/result_test.rb index caa573556..d5854fed4 100644 --- a/test/unit/result_test.rb +++ b/test/unit/result_test.rb @@ -23,30 +23,6 @@ def test_reverse_geocoding_result_has_required_attributes end end - def test_result_has_coords_in_reasonable_range_for_madison_square_garden - Geocoder::Lookup.street_services.each do |l| - next unless File.exist?(File.join("test", "fixtures", "#{l.to_s}_madison_square_garden")) - Geocoder.configure(:lookup => l) - set_api_key!(l) - result = Geocoder.search("Madison Square Garden, New York, NY 10001, United States").first - assert (result.latitude > 40 and result.latitude < 41), "Lookup #{l} latitude out of range" - assert (result.longitude > -74 and result.longitude < -73), "Lookup #{l} longitude out of range" - end - end - - def test_result_accepts_reverse_coords_in_reasonable_range_for_madison_square_garden - Geocoder::Lookup.street_services.each do |l| - next unless File.exist?(File.join("test", "fixtures", "#{l.to_s}_madison_square_garden")) - next if [:bing, :esri, :geocoder_ca, :google_places_search, :geoportail_lu].include? l # Reverse fixture does not match forward - Geocoder.configure(:lookup => l) - set_api_key!(l) - result = Geocoder.search([40.750354, -73.993371]).first - assert (["New York", "New York City"].include? result.city), "Reverse lookup #{l} City does not match" - assert (result.latitude > 40 and result.latitude < 41), "Reverse lookup #{l} latitude out of range" - assert (result.longitude > -74 and result.longitude < -73), "Reverse lookup #{l} longitude out of range" - end - end - private # ------------------------------------------------------------------ def assert_result_has_required_attributes(result) From 6e4af7e7b7a0328aadd33ae5bdd2cc2d9cc4fe47 Mon Sep 17 00:00:00 2001 From: zacviandier <zacviandier@gmail.com> Date: Fri, 9 Feb 2018 20:20:45 +0800 Subject: [PATCH 201/248] OSMNames Lookup --- lib/geocoder/lookup.rb | 3 +- lib/geocoder/lookups/osmnames.rb | 55 +++++++++++++++++ lib/geocoder/results/osmnames.rb | 56 +++++++++++++++++ test/fixtures/osmnames_invalid_request | 7 +++ test/fixtures/osmnames_madison_square_garden | 40 +++++++++++++ test/fixtures/osmnames_no_results | 6 ++ test/unit/lookups/osmnames_test.rb | 63 ++++++++++++++++++++ 7 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 lib/geocoder/lookups/osmnames.rb create mode 100644 lib/geocoder/results/osmnames.rb create mode 100644 test/fixtures/osmnames_invalid_request create mode 100644 test/fixtures/osmnames_madison_square_garden create mode 100644 test/fixtures/osmnames_no_results create mode 100644 test/unit/lookups/osmnames_test.rb diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index e4fc5e5cc..732e19eac 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -50,7 +50,8 @@ def street_services :ban_data_gouv_fr, :test, :latlon, - :amap + :amap, + :osmnames ] end diff --git a/lib/geocoder/lookups/osmnames.rb b/lib/geocoder/lookups/osmnames.rb new file mode 100644 index 000000000..aff34de65 --- /dev/null +++ b/lib/geocoder/lookups/osmnames.rb @@ -0,0 +1,55 @@ +require 'geocoder/lookups/base' +require 'geocoder/results/osmnames' + +module Geocoder::Lookup + class Osmnames < Base + def name + 'osmnames' + end + + def required_api_key_parts + ['key'] + end + + def query_url(query) + "#{base_url(query)}/#{params_url(query)}.js?#{url_query_string(query)}" + end + + def supported_protocols + [:https] + end + + private + + def base_url(query) + host = configuration[:host] || 'geocoder.tilehosting.com' + "#{protocol}://#{host}" + end + + def params_url(query) + method, args = 'q', URI.escape(query.sanitized_text) + method, args = 'r', query.coordinates.join('/') if query.reverse_geocode? + "#{country_limited(query)}#{method}/#{args}" + end + + def results(query) + return [] unless doc = fetch_data(query) + if (error = doc['message']) + raise_error(Geocoder::InvalidRequest, error) || + Geocoder.log(:warn, "OSMNames Geocoding API error: #{error}") + else + return doc['results'] + end + end + + def query_url_params(query) + { + key: configuration.api_key + }.merge(super) + end + + def country_limited(query) + "#{query.options[:country_code].downcase}/" if query.options[:country_code] && !query.reverse_geocode? + end + end +end diff --git a/lib/geocoder/results/osmnames.rb b/lib/geocoder/results/osmnames.rb new file mode 100644 index 000000000..5954e75cb --- /dev/null +++ b/lib/geocoder/results/osmnames.rb @@ -0,0 +1,56 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class Osmnames < Base + def address + @data['display_name'] + end + + def coordinates + [@data['lat'].to_f, @data['lon'].to_f] + end + + def viewport + west, south, east, north = @data['boundingbox'].map(&:to_f) + [south, west, north, east] + end + + def state + @data['state'] + end + alias_method :state_code, :state + + def place_class + @data['class'] + end + + def place_type + @data['type'] + end + + def postal_code + '' + end + + def country_code + @data['country_code'] + end + + def country + @data['country'] + end + + def self.response_attributes + %w[house_number street city name osm_id osm_type boundingbox place_rank + importance county rank name_suffix] + end + + response_attributes.each do |a| + unless method_defined?(a) + define_method a do + @data[a] + end + end + end + end +end diff --git a/test/fixtures/osmnames_invalid_request b/test/fixtures/osmnames_invalid_request new file mode 100644 index 000000000..520d58af3 --- /dev/null +++ b/test/fixtures/osmnames_invalid_request @@ -0,0 +1,7 @@ +{ + "count": 20, + "startIndex": 0, + "message": "Invalid attribute value.", + "totalResults": 0, + "results": [] +} diff --git a/test/fixtures/osmnames_madison_square_garden b/test/fixtures/osmnames_madison_square_garden new file mode 100644 index 000000000..d6b7be015 --- /dev/null +++ b/test/fixtures/osmnames_madison_square_garden @@ -0,0 +1,40 @@ +{ + "count": 20, + "nextIndex": 20, + "startIndex": 0, + "totalResults": 8000, + "results": [ + { + "wikipedia": "en:New York City", + "rank": 628616.9375, + "county": "", + "street": "", + "wikidata": "Q60", + "country_code": "us", + "osm_id": "175905", + "housenumbers": "", + "id": 64, + "city": "New York City", + "display_name": "New York City, New York, United States of America", + "lon": -73.878418, + "state": "New York", + "boundingbox": [ + -74.259087, + 40.477398, + -73.70018, + 40.91618 + ], + "type": "city", + "importance": 0.782928, + "lat": 40.693073, + "class": "place", + "name": "New York City", + "country": "United States of America", + "name_suffix": "New York, US", + "osm_type": "relation", + "place_rank": 16, + "alternative_names": "New York,Nova York,Nueva York,NYC" + } + + ] +} diff --git a/test/fixtures/osmnames_no_results b/test/fixtures/osmnames_no_results new file mode 100644 index 000000000..df5cfe5db --- /dev/null +++ b/test/fixtures/osmnames_no_results @@ -0,0 +1,6 @@ +{ + "count": 20, + "startIndex": 0, + "totalResults": 0, + "results": [] +} diff --git a/test/unit/lookups/osmnames_test.rb b/test/unit/lookups/osmnames_test.rb new file mode 100644 index 000000000..19c1c296c --- /dev/null +++ b/test/unit/lookups/osmnames_test.rb @@ -0,0 +1,63 @@ +# encoding: utf-8 +require 'test_helper' + +class OsmnamesTest < GeocoderTestCase + def setup + Geocoder.configure(lookup: :osmnames) + set_api_key!(:osmnames) + end + + def test_url_contains_api_key + Geocoder.configure(osmnames: {api_key: 'abc123'}) + query = Geocoder::Query.new('test') + assert_includes query.url, 'key=abc123' + end + + def test_url_contains_query_base + query = Geocoder::Query.new("Madison Square Garden, New York, NY") + assert_includes query.url, 'https://geocoder.tilehosting.com/q/Madison%20Square%20Garden,%20New%20York,%20NY.js' + end + + def test_url_contains_country_code + query = Geocoder::Query.new("test", country_code: 'US') + assert_includes query.url, 'https://geocoder.tilehosting.com/us/q/' + end + + def test_result_components + result = Geocoder.search('Madison Square Garden, New York, NY').first + assert_equal [40.693073, -73.878418], result.coordinates + assert_equal 'New York City, New York, United States of America', result.address + assert_equal 'New York', result.state + assert_equal 'New York City', result.city + assert_equal 'us', result.country_code + end + + def test_result_for_reverse_geocode + result = Geocoder.search('-73.878418, 40.693073').first + assert_equal 'New York City, New York, United States of America', result.address + assert_equal 'New York', result.state + assert_equal 'New York City', result.city + assert_equal 'us', result.country_code + end + + def test_url_for_reverse_geocode + query = Geocoder::Query.new("-73.878418, 40.693073") + assert_includes query.url, 'https://geocoder.tilehosting.com/r/-73.878418/40.693073.js' + end + + def test_result_viewport + result = Geocoder.search("Madison Square Garden, New York, NY").first + assert_equal [40.477398, -74.259087, 40.91618, -73.70018], result.viewport + end + + def test_no_results + assert_equal [], Geocoder.search("no results") + end + + def test_raises_exception_when_return_message_error + Geocoder.configure(always_raise: [Geocoder::InvalidRequest]) + assert_raises Geocoder::InvalidRequest.new("Invalid attribute value.") do + Geocoder.search("invalid request") + end + end +end From 7ed988a37815525031ff2cfb9f4d741948f7fd0a Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 5 Jan 2020 22:55:05 -0800 Subject: [PATCH 202/248] Properly define base_query_url in lookup. --- lib/geocoder/lookups/osmnames.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/geocoder/lookups/osmnames.rb b/lib/geocoder/lookups/osmnames.rb index aff34de65..7374f9c05 100644 --- a/lib/geocoder/lookups/osmnames.rb +++ b/lib/geocoder/lookups/osmnames.rb @@ -11,16 +11,16 @@ def required_api_key_parts ['key'] end - def query_url(query) - "#{base_url(query)}/#{params_url(query)}.js?#{url_query_string(query)}" - end - def supported_protocols [:https] end private + def base_query_url(query) + "#{base_url(query)}/#{params_url(query)}.js?" + end + def base_url(query) host = configuration[:host] || 'geocoder.tilehosting.com' "#{protocol}://#{host}" From 487e9189c8fb9ef24f6850937b422df5ac9de70b Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 5 Jan 2020 22:55:22 -0800 Subject: [PATCH 203/248] Use CGI.escape instead of obsolete URI.escape. --- lib/geocoder/lookups/osmnames.rb | 3 ++- test/unit/lookups/osmnames_test.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/geocoder/lookups/osmnames.rb b/lib/geocoder/lookups/osmnames.rb index 7374f9c05..b366c0699 100644 --- a/lib/geocoder/lookups/osmnames.rb +++ b/lib/geocoder/lookups/osmnames.rb @@ -1,3 +1,4 @@ +require 'cgi' require 'geocoder/lookups/base' require 'geocoder/results/osmnames' @@ -27,7 +28,7 @@ def base_url(query) end def params_url(query) - method, args = 'q', URI.escape(query.sanitized_text) + method, args = 'q', CGI.escape(query.sanitized_text) method, args = 'r', query.coordinates.join('/') if query.reverse_geocode? "#{country_limited(query)}#{method}/#{args}" end diff --git a/test/unit/lookups/osmnames_test.rb b/test/unit/lookups/osmnames_test.rb index 19c1c296c..dbb2cee39 100644 --- a/test/unit/lookups/osmnames_test.rb +++ b/test/unit/lookups/osmnames_test.rb @@ -15,7 +15,7 @@ def test_url_contains_api_key def test_url_contains_query_base query = Geocoder::Query.new("Madison Square Garden, New York, NY") - assert_includes query.url, 'https://geocoder.tilehosting.com/q/Madison%20Square%20Garden,%20New%20York,%20NY.js' + assert_includes query.url, 'geocoder.tilehosting.com/q/Madison' end def test_url_contains_country_code From 692d62eabfdcd776f86dd0ca468bdae6bb5a883f Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 5 Jan 2020 23:03:50 -0800 Subject: [PATCH 204/248] Add :osmnames to README API guide. --- README_API_GUIDE.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 177c80fba..d58c4ad11 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -337,6 +337,19 @@ Data Science Toolkit provides an API whose response format is like Google's but - **Limitations**: Only good for non-commercial use. For commercial usage please check http://lbs.amap.com/home/terms/ - **Notes**: To use AMap set `Geocoder.configure(lookup: :amap, api_key: "your_api_key")`. +### OSM Names (`:osmnames`) + +Open source geocoding engine which can be self-hosted. MapTiler.com hosts an installation for use with API key. + +* **API key**: required if not self-hosting (see https://www.maptiler.com/cloud/plans/) +* **Quota**: none if self-hosting; 100,000/mo with MapTiler free plan (more with paid) +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://osmnames.org/ (open source project), https://cloud.maptiler.com/geocoding/ (MapTiler) +* **Terms of Service**: https://www.maptiler.com/terms/ +* **Notes**: To use self-hosted service, set the `:host` option in `Geocoder.configure`. + IP Address Lookups ------------------ From 39b8e3143a6ff98918218dcd1b52069f50ca313a Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 6 Jan 2020 09:10:33 -0800 Subject: [PATCH 205/248] Use lookup's human-readable name. --- lib/geocoder/lookups/osmnames.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/osmnames.rb b/lib/geocoder/lookups/osmnames.rb index b366c0699..f2221108c 100644 --- a/lib/geocoder/lookups/osmnames.rb +++ b/lib/geocoder/lookups/osmnames.rb @@ -4,8 +4,9 @@ module Geocoder::Lookup class Osmnames < Base + def name - 'osmnames' + 'OSM Names' end def required_api_key_parts From 506c42e479d05cdbc1b6ff047b48560093bc4f1f Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 6 Jan 2020 09:34:17 -0800 Subject: [PATCH 206/248] API key not required if self-hosting. --- lib/geocoder/lookups/osmnames.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/lookups/osmnames.rb b/lib/geocoder/lookups/osmnames.rb index f2221108c..7a781986f 100644 --- a/lib/geocoder/lookups/osmnames.rb +++ b/lib/geocoder/lookups/osmnames.rb @@ -10,7 +10,7 @@ def name end def required_api_key_parts - ['key'] + configuration[:host] ? [] : ['key'] end def supported_protocols From 877ad6fe2ab9b5f54e8502073ef2273dc7cb7281 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 6 Jan 2020 09:55:21 -0800 Subject: [PATCH 207/248] Move assertions into separate tests. --- test/unit/query_test.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 862e1b072..5675461b4 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -3,9 +3,15 @@ class QueryTest < GeocoderTestCase - def test_ip_address_detection + def test_detect_ipv4 assert Geocoder::Query.new("232.65.123.94").ip_address? + end + + def test_detect_ipv6 assert Geocoder::Query.new("3ffe:0b00:0000:0000:0001:0000:0000:000a").ip_address? + end + + def test_detect_non_ip_address assert !Geocoder::Query.new("232.65.123.94.43").ip_address? assert !Geocoder::Query.new("::ffff:123.456.789").ip_address? end From 8f6f850893c2d9c64d90d05171f55aa5d3e6750f Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 4 Jan 2020 21:01:11 -0800 Subject: [PATCH 208/248] Remove Rails 3.2 from Travis matrix. --- .travis.yml | 7 ------- gemfiles/Gemfile.rails3.2 | 43 --------------------------------------- 2 files changed, 50 deletions(-) delete mode 100644 gemfiles/Gemfile.rails3.2 diff --git a/.travis.yml b/.travis.yml index 3925d2d9e..8aa85f633 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,13 +31,10 @@ rvm: - jruby-19mode gemfile: - Gemfile - - gemfiles/Gemfile.rails3.2 - gemfiles/Gemfile.rails4.1 - gemfiles/Gemfile.rails5.0 matrix: exclude: - - env: DB= - gemfile: gemfiles/Gemfile.rails3.2 - env: DB= gemfile: gemfiles/Gemfile.rails4.1 - env: DB= @@ -54,10 +51,6 @@ matrix: gemfile: gemfiles/Gemfile.rails4.1 - rvm: 2.5.1 gemfile: gemfiles/Gemfile.rails4.1 - - rvm: 2.4.4 - gemfile: gemfiles/Gemfile.rails3.2 - - rvm: 2.5.1 - gemfile: gemfiles/Gemfile.rails3.2 - rvm: jruby-19mode gemfile: gemfiles/Gemfile.rails5.0 - rvm: jruby-19mode diff --git a/gemfiles/Gemfile.rails3.2 b/gemfiles/Gemfile.rails3.2 deleted file mode 100644 index 2d5d714ee..000000000 --- a/gemfiles/Gemfile.rails3.2 +++ /dev/null @@ -1,43 +0,0 @@ -source "https://rubygems.org" - -group :development, :test do - gem 'rake' - gem 'mongoid' - gem 'bson_ext', platforms: :ruby - gem 'geoip' - gem 'rubyzip' - gem 'rails', '~> 3.2' - gem 'test-unit' # needed for Ruby >=2.2.0 - - platforms :jruby do - gem 'jruby-openssl' - gem 'jgeoip' - end - - platforms :rbx do - gem 'rubysl', '~> 2.0' - gem 'rubysl-test-unit' - end -end - -group :test do - platforms :ruby do - gem 'sqlite3' - gem 'sqlite_ext' - end - - gem 'public_suffix' # webmock dependency - gem 'addressable' # webmock dependency - gem 'webmock' - - platforms :ruby do - gem 'pg', '~> 0.11' - gem 'mysql2', '~> 0.3.11' - end - - platforms :jruby do - gem 'jdbc-mysql' - gem 'jdbc-sqlite3' - gem 'activerecord-jdbcpostgresql-adapter' - end -end From 0d425fd055570ee176ccf662c6891b228e6566c3 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sat, 4 Jan 2020 21:06:24 -0800 Subject: [PATCH 209/248] Update Rails version compatibility. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 54f245c7a..564fbb2f1 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,8 @@ Compatibility: * Supports multiple Ruby versions: Ruby 2.x, and JRuby. * Supports multiple databases: MySQL, PostgreSQL, SQLite, and MongoDB (1.7.0 and higher). -* Supports Rails 3, 4, and 5. If you need to use it with Rails 2 please see the `rails2` branch (no longer maintained, limited feature set). -* Works very well outside of Rails, you just need to install either the `json` (for MRI) or `json_pure` (for JRuby) gem. +* Supports Rails 4, 5, and 6. +* Works very well outside of Rails, just install the `json` (for MRI) or `json_pure` (for JRuby) gem. Table of Contents From a3189e0cfb13d722fdec8a09de397118af5420f8 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 5 Jan 2020 19:30:56 -0800 Subject: [PATCH 210/248] More concise language. --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 564fbb2f1..87c34ed5b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Geocoder ======== -**A complete geocoding solution for Ruby.** +**Complete geocoding solution for Ruby.** [![Gem Version](https://badge.fury.io/rb/geocoder.svg)](http://badge.fury.io/rb/geocoder) [![Code Climate](https://codeclimate.com/github/alexreisner/geocoder/badges/gpa.svg)](https://codeclimate.com/github/alexreisner/geocoder) @@ -11,19 +11,19 @@ Geocoder Key features: -* Forward and reverse geocoding, and IP address geocoding. +* Forward and reverse geocoding. +* IP address geocoding. * Connects to more than 40 APIs worldwide. * Performance-enhancing features like caching. -* Advanced configuration allows different parameters and APIs to be used in different conditions. * Integrates with ActiveRecord and Mongoid. * Basic geospatial queries: search within radius (or rectangle, or ring). Compatibility: -* Supports multiple Ruby versions: Ruby 2.x, and JRuby. -* Supports multiple databases: MySQL, PostgreSQL, SQLite, and MongoDB (1.7.0 and higher). -* Supports Rails 4, 5, and 6. -* Works very well outside of Rails, just install the `json` (for MRI) or `json_pure` (for JRuby) gem. +* Ruby versions: 2.x, and JRuby. +* Databases: MySQL, PostgreSQL, SQLite, and MongoDB. +* Rails: 4, 5, and 6. +* Works outside of Rails with the `json` (for MRI) or `json_pure` (for JRuby) gem. Table of Contents From 884befd22a4b899be60f238629adc02ee1a1b7b3 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 6 Jan 2020 10:02:24 -0800 Subject: [PATCH 211/248] Prepare for gem release 1.6.0. --- CHANGELOG.md | 6 ++++++ LICENSE | 2 +- README.md | 2 +- README_API_GUIDE.md | 2 +- lib/geocoder/version.rb | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e39eb710d..748108c87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ Changelog Major changes to Geocoder for each release. Please see the Git log for complete list of changes. +1.6.0 (2020 Jan 6) +------------------- +* Drop support for Rails 3.x. +* Add support for :osmnames lookup (thanks github.com/zacviandier). +* Add support for :ipgeolocation IP lookup (thanks github.com/ahsannawaz111). + 1.5.2 (2019 Oct 3) ------------------- * Add support for :ipregistry lookup (thanks github.com/ipregistry). diff --git a/LICENSE b/LICENSE index 767580ccd..21dd3a0a2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009-11 Alex Reisner +Copyright (c) 2009-2020 Alex Reisner Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index 87c34ed5b..f91258ed1 100644 --- a/README.md +++ b/README.md @@ -703,4 +703,4 @@ For all contributions, please respect the following guidelines: * If your pull request is merged, please do not ask for an immediate release of the gem. There are many factors contributing to when releases occur (remember that they affect thousands of apps with Geocoder in their Gemfiles). If necessary, please install from the Github source until the next official release. -Copyright :copyright: 2009-19 Alex Reisner, released under the MIT license. +Copyright :copyright: 2009-2020 Alex Reisner, released under the MIT license. diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index d58c4ad11..a21c0aea8 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -579,4 +579,4 @@ You must add either the *[hive_geoip2](https://rubygems.org/gems/hive_geoip2)* g ) -Copyright (c) 2009-18 Alex Reisner, released under the MIT license. +Copyright (c) 2009-2020 Alex Reisner, released under the MIT license. diff --git a/lib/geocoder/version.rb b/lib/geocoder/version.rb index f5b2313c1..9f29246ca 100644 --- a/lib/geocoder/version.rb +++ b/lib/geocoder/version.rb @@ -1,3 +1,3 @@ module Geocoder - VERSION = "1.5.2" + VERSION = "1.6.0" end From 5f136e3fc9d4d560314279aee51262e689966490 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 6 Jan 2020 11:36:31 -0800 Subject: [PATCH 212/248] Remove issues and license badges. (Don't add much useful info.) --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index f91258ed1..27c8b7010 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,6 @@ Geocoder [![Gem Version](https://badge.fury.io/rb/geocoder.svg)](http://badge.fury.io/rb/geocoder) [![Code Climate](https://codeclimate.com/github/alexreisner/geocoder/badges/gpa.svg)](https://codeclimate.com/github/alexreisner/geocoder) [![Build Status](https://travis-ci.org/alexreisner/geocoder.svg?branch=master)](https://travis-ci.org/alexreisner/geocoder) -[![GitHub Issues](https://img.shields.io/github/issues/alexreisner/geocoder.svg)](https://github.com/alexreisner/geocoder/issues) -[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT) Key features: From 94c00100252adaf6911b3676298451b14d0de355 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 6 Jan 2020 18:42:00 -0800 Subject: [PATCH 213/248] Fix incorrect status codes. See https://ipgeolocation.io/documentation/ip-geolocation-api.html --- lib/geocoder/lookups/ipgeolocation.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/geocoder/lookups/ipgeolocation.rb b/lib/geocoder/lookups/ipgeolocation.rb index 4317e865f..56d763cce 100644 --- a/lib/geocoder/lookups/ipgeolocation.rb +++ b/lib/geocoder/lookups/ipgeolocation.rb @@ -6,16 +6,11 @@ module Geocoder::Lookup class Ipgeolocation < Base ERROR_CODES = { - 404 => Geocoder::InvalidRequest, - 401 => Geocoder::RequestDenied, # missing/invalid API key - 101 => Geocoder::InvalidApiKey, - 102 => Geocoder::Error, - 103 => Geocoder::InvalidRequest, - 104 => Geocoder::OverQueryLimitError, - 105 => Geocoder::RequestDenied, - 301 => Geocoder::InvalidRequest, - 302 => Geocoder::InvalidRequest, - 303 => Geocoder::RequestDenied, + 400 => Geocoder::RequestDenied, # subscription is paused + 401 => Geocoder::InvalidApiKey, # missing/invalid API key + 403 => Geocoder::InvalidRequest, # invalid IP address + 404 => Geocoder::InvalidRequest, # not found + 423 => Geocoder::InvalidRequest # bogon/reserved IP address } ERROR_CODES.default = Geocoder::Error From c8b1d480e81bc9757740eec137bc0b5ad948d59f Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 6 Jan 2020 19:02:23 -0800 Subject: [PATCH 214/248] Add fixture for invalid key response. --- test/fixtures/ipgeolocation_invalid_api_key | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/fixtures/ipgeolocation_invalid_api_key diff --git a/test/fixtures/ipgeolocation_invalid_api_key b/test/fixtures/ipgeolocation_invalid_api_key new file mode 100644 index 000000000..09ae15f77 --- /dev/null +++ b/test/fixtures/ipgeolocation_invalid_api_key @@ -0,0 +1 @@ +{"message":"Provided API key is not valid."} From 26a0c963e6fc3daecbb9cf47263ced1dc2babaef Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 6 Jan 2020 19:02:38 -0800 Subject: [PATCH 215/248] Remove irrelevant code. Appears to be copied from another lookup. Will not work with :ipgeolocation. --- lib/geocoder/lookups/ipgeolocation.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/geocoder/lookups/ipgeolocation.rb b/lib/geocoder/lookups/ipgeolocation.rb index 56d763cce..adfc655d3 100644 --- a/lib/geocoder/lookups/ipgeolocation.rb +++ b/lib/geocoder/lookups/ipgeolocation.rb @@ -37,14 +37,7 @@ def query_url_params(query) def results(query) # don't look up a loopback or private address, just return the stored result return [reserved_result(query.text)] if query.internal_ip_address? - return [] unless doc = fetch_data(query) - if error = doc['error'] - code = error['code'] - msg = error['info'] - raise_error(ERROR_CODES[code], msg ) || Geocoder.log(:warn, "Ipgeolocation Geocoding API error: #{msg}") - return [] - end - [doc] + [fetch_data(query)] end def reserved_result(ip) From 1d520eee14c20a40dc83262417dcdba0cd819268 Mon Sep 17 00:00:00 2001 From: Vesa Laakso <482561+valscion@users.noreply.github.com> Date: Tue, 14 Jan 2020 14:20:59 +0200 Subject: [PATCH 216/248] Remove bad information from HERE API docs --- README_API_GUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index a21c0aea8..2c22ff3e0 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -172,7 +172,7 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ ### Here/Nokia (`:here`) -* **API key**: required (set `Geocoder.configure(api_key: [app_id, app_code])`) +* **API key**: required * **Quota**: Depending on the API key * **Region**: world * **SSL support**: yes From dcdc3d8675411edce3965941a2ca7c441ca48613 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Thu, 23 Jan 2020 09:08:45 -0700 Subject: [PATCH 217/248] Sanitize lat/lon for SQL query. --- lib/geocoder/sql.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/geocoder/sql.rb b/lib/geocoder/sql.rb index 71ea96f8a..6bca8a65a 100644 --- a/lib/geocoder/sql.rb +++ b/lib/geocoder/sql.rb @@ -44,13 +44,13 @@ def approx_distance(latitude, longitude, lat_attr, lon_attr, options = {}) end def within_bounding_box(sw_lat, sw_lng, ne_lat, ne_lng, lat_attr, lon_attr) - spans = "#{lat_attr} BETWEEN #{sw_lat} AND #{ne_lat} AND " + spans = "#{lat_attr} BETWEEN #{sw_lat.to_f} AND #{ne_lat.to_f} AND " # handle box that spans 180 longitude if sw_lng.to_f > ne_lng.to_f - spans + "(#{lon_attr} BETWEEN #{sw_lng} AND 180 OR " + - "#{lon_attr} BETWEEN -180 AND #{ne_lng})" + spans + "(#{lon_attr} BETWEEN #{sw_lng.to_f} AND 180 OR " + + "#{lon_attr} BETWEEN -180 AND #{ne_lng.to_f})" else - spans + "#{lon_attr} BETWEEN #{sw_lng} AND #{ne_lng}" + spans + "#{lon_attr} BETWEEN #{sw_lng.to_f} AND #{ne_lng.to_f}" end end From dfba0ceb86731c1e58ea963d0a6dca3b15c87580 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Thu, 23 Jan 2020 09:17:03 -0700 Subject: [PATCH 218/248] Prepare for gem release 1.6.1. --- CHANGELOG.md | 4 ++++ lib/geocoder/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 748108c87..15104f65a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ Changelog Major changes to Geocoder for each release. Please see the Git log for complete list of changes. +1.6.1 (2020 Jan 23) +------------------- +* Sanitize lat/lon values passed to within_bounding_box to prevent SQL injection. + 1.6.0 (2020 Jan 6) ------------------- * Drop support for Rails 3.x. diff --git a/lib/geocoder/version.rb b/lib/geocoder/version.rb index 9f29246ca..092dec535 100644 --- a/lib/geocoder/version.rb +++ b/lib/geocoder/version.rb @@ -1,3 +1,3 @@ module Geocoder - VERSION = "1.6.0" + VERSION = "1.6.1" end From dbb9788ab366c6543ba4767565cec455ab5f9954 Mon Sep 17 00:00:00 2001 From: Evgrafov Denis <stereodenis@gmail.com> Date: Sun, 15 Mar 2020 02:21:47 +0300 Subject: [PATCH 219/248] failing test --- test/unit/lookups/yandex_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/unit/lookups/yandex_test.rb b/test/unit/lookups/yandex_test.rb index 9a02a400a..91d0c63ce 100644 --- a/test/unit/lookups/yandex_test.rb +++ b/test/unit/lookups/yandex_test.rb @@ -73,4 +73,20 @@ def test_yandex_result_without_locality_name assert_equal "", result.city end end + + def test_yandex_result_returns_street_name + assert_nothing_raised do + set_api_key!(:yandex) + result = Geocoder.search("canada rue dupuis 14")[6] + assert_equal "Rue Hormidas-Dupuis", result.street + end + end + + def test_yandex_result_returns_street_number + assert_nothing_raised do + set_api_key!(:yandex) + result = Geocoder.search("canada rue dupuis 14")[6] + assert_equal "14", result.street_number + end + end end From 0bdf88a034ab3d077384e213f0751a6c598927f2 Mon Sep 17 00:00:00 2001 From: Evgrafov Denis <stereodenis@gmail.com> Date: Sun, 15 Mar 2020 02:22:07 +0300 Subject: [PATCH 220/248] [Yandex] Wrong condition for locality data --- lib/geocoder/results/yandex.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/results/yandex.rb b/lib/geocoder/results/yandex.rb index 524353309..9407df5e2 100644 --- a/lib/geocoder/results/yandex.rb +++ b/lib/geocoder/results/yandex.rb @@ -98,7 +98,7 @@ def thoroughfare_data end def locality_data - dependent_locality && subadmin_locality && admin_locality + dependent_locality || subadmin_locality || admin_locality end def admin_locality From 21904ceec41cb651568724b8115d0ae27623ac52 Mon Sep 17 00:00:00 2001 From: Yaroslav Litvinov <beyondthemkad@gmail.com> Date: Mon, 2 Jul 2018 16:12:05 +0300 Subject: [PATCH 221/248] add bin/console --- bin/console | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 bin/console diff --git a/bin/console b/bin/console new file mode 100755 index 000000000..c5867d3dc --- /dev/null +++ b/bin/console @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby + +require 'bundler/setup' +require 'geocoder' + +require 'irb' +IRB.start From d7582d3ea317f173e918ecd58d9c315db664fb9a Mon Sep 17 00:00:00 2001 From: Yaroslav Litvinov <beyondthemkad@gmail.com> Date: Wed, 6 Jun 2018 16:50:13 +0300 Subject: [PATCH 222/248] fix-yandex-result-data-extraction --- lib/geocoder/results/yandex.rb | 18 ++-- .../yandex_putilkovo_novotushinskaya_5 | 97 +++++++++++++++++++ test/unit/lookups/yandex_test.rb | 16 ++- 3 files changed, 120 insertions(+), 11 deletions(-) create mode 100644 test/fixtures/yandex_putilkovo_novotushinskaya_5 diff --git a/lib/geocoder/results/yandex.rb b/lib/geocoder/results/yandex.rb index 9407df5e2..a2221c722 100644 --- a/lib/geocoder/results/yandex.rb +++ b/lib/geocoder/results/yandex.rb @@ -60,20 +60,16 @@ def state_code "" end - def postal_code - "" - end - - def premise_name - address_details['Locality']['Premise']['PremiseName'] - end - def street thoroughfare_data && thoroughfare_data['ThoroughfareName'] end def street_number - thoroughfare_data && thoroughfare_data['Premise'] && thoroughfare_data['Premise']['PremiseNumber'] + premise && premise['PremiseNumber'] + end + + def postal_code + premise && premise['PostalCode'] && premise['PostalCode']['PostalCodeNumber'] end def kind @@ -93,6 +89,10 @@ def viewport private # ---------------------------------------------------------------- + def premise + thoroughfare_data && thoroughfare_data['Premise'] + end + def thoroughfare_data locality_data && locality_data['Thoroughfare'] end diff --git a/test/fixtures/yandex_putilkovo_novotushinskaya_5 b/test/fixtures/yandex_putilkovo_novotushinskaya_5 new file mode 100644 index 000000000..4b6411880 --- /dev/null +++ b/test/fixtures/yandex_putilkovo_novotushinskaya_5 @@ -0,0 +1,97 @@ +{ + "response": { + "GeoObjectCollection": { + "metaDataProperty": { + "GeocoderResponseMetaData": { + "request": "putilkovo novotushinskaya 5", + "found": "1", + "results": "10" + } + }, + "featureMember": [ + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "house", + "text": "Россия, Московская область, городской округ Красногорск, деревня Путилково, Новотушинская улица, 5", + "precision": "exact", + "Address": { + "country_code": "RU", + "postal_code": "143441", + "formatted": "Московская область, городской округ Красногорск, деревня Путилково, Новотушинская улица, 5", + "Components": [ + { + "kind": "country", + "name": "Россия" + }, + { + "kind": "province", + "name": "Центральный федеральный округ" + }, + { + "kind": "province", + "name": "Московская область" + }, + { + "kind": "area", + "name": "городской округ Красногорск" + }, + { + "kind": "locality", + "name": "деревня Путилково" + }, + { + "kind": "street", + "name": "Новотушинская улица" + }, + { + "kind": "house", + "name": "5" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Московская область, городской округ Красногорск, деревня Путилково, Новотушинская улица, 5", + "CountryNameCode": "RU", + "CountryName": "Россия", + "AdministrativeArea": { + "AdministrativeAreaName": "Московская область", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "городской округ Красногорск", + "Locality": { + "LocalityName": "деревня Путилково", + "Thoroughfare": { + "ThoroughfareName": "Новотушинская улица", + "Premise": { + "PremiseNumber": "5", + "PostalCode": { + "PostalCodeNumber": "143441" + } + } + } + } + } + } + } + } + } + }, + "description": "деревня Путилково, городской округ Красногорск, Московская область, Россия", + "name": "Новотушинская улица, 5", + "boundedBy": { + "Envelope": { + "lowerCorner": "37.399416 55.86995", + "upperCorner": "37.407627 55.874567" + } + }, + "Point": { + "pos": "37.403522 55.872258" + } + } + } + ] + } + } +} diff --git a/test/unit/lookups/yandex_test.rb b/test/unit/lookups/yandex_test.rb index 91d0c63ce..78c84e2c7 100644 --- a/test/unit/lookups/yandex_test.rb +++ b/test/unit/lookups/yandex_test.rb @@ -3,9 +3,8 @@ require 'test_helper' class YandexTest < GeocoderTestCase - def setup - Geocoder.configure(lookup: :yandex) + Geocoder.configure(lookup: :yandex, language: :ru) end def test_yandex_viewport @@ -89,4 +88,17 @@ def test_yandex_result_returns_street_number assert_equal "14", result.street_number end end + + def test_yandex_maximum_precision_on_russian_address + result = Geocoder.search('putilkovo novotushinskaya 5').first + + assert_equal "exact", result.precision + assert_equal "Россия", result.country + assert_equal "Московская область", result.state + assert_equal "городской округ Красногорск" , result.sub_state + assert_equal "деревня Путилково", result.city + assert_equal "Новотушинская улица", result.street + assert_equal "5", result.street_number + assert_equal "143441", result.postal_code + end end From c43939c9782cec9b79d1d1a14793b5bc79d73f57 Mon Sep 17 00:00:00 2001 From: Yaroslav Litvinov <beyondthemkad@gmail.com> Date: Wed, 6 Jun 2018 18:03:45 +0300 Subject: [PATCH 223/248] make yandex postal_code fit result data specification --- lib/geocoder/results/yandex.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/geocoder/results/yandex.rb b/lib/geocoder/results/yandex.rb index a2221c722..d099ebceb 100644 --- a/lib/geocoder/results/yandex.rb +++ b/lib/geocoder/results/yandex.rb @@ -61,15 +61,27 @@ def state_code end def street - thoroughfare_data && thoroughfare_data['ThoroughfareName'] + if thoroughfare_data + thoroughfare_data['ThoroughfareName'] + else + "" + end end def street_number - premise && premise['PremiseNumber'] + if premise + premise['PremiseNumber'] + else + "" + end end def postal_code - premise && premise['PostalCode'] && premise['PostalCode']['PostalCodeNumber'] + if premise && premise['PostalCode'] + premise['PostalCode']['PostalCodeNumber'] + else + "" + end end def kind From c5c4be3800ab82a8e49fb6b91adcbe2fd2911d03 Mon Sep 17 00:00:00 2001 From: Yaroslav Litvinov <beyondthemkad@gmail.com> Date: Mon, 2 Jul 2018 16:12:38 +0300 Subject: [PATCH 224/248] Yandex Result Rewrite --- lib/geocoder/results/yandex.rb | 158 ++++++++------ test/fixtures/yandex_new_york | 387 ++++++++++++++++++++++++++++++++- 2 files changed, 474 insertions(+), 71 deletions(-) diff --git a/lib/geocoder/results/yandex.rb b/lib/geocoder/results/yandex.rb index d099ebceb..e8900fac1 100644 --- a/lib/geocoder/results/yandex.rb +++ b/lib/geocoder/results/yandex.rb @@ -2,58 +2,80 @@ module Geocoder::Result class Yandex < Base + ADDRESS_DETAILS = %w[ + GeoObject metaDataProperty GeocoderMetaData + AddressDetails + ].freeze + + COUNTRY_LEVEL = %w[ + GeoObject metaDataProperty GeocoderMetaData + AddressDetails Country + ].freeze + + ADMIN_LEVEL = %w[ + GeoObject metaDataProperty GeocoderMetaData + AddressDetails Country + AdministrativeArea + ].freeze + + SUBADMIN_LEVEL = %w[ + GeoObject metaDataProperty GeocoderMetaData + AddressDetails Country + AdministrativeArea + SubAdministrativeArea + ].freeze + + DEPENDENT_LOCALITY_1 = %w[ + GeoObject metaDataProperty GeocoderMetaData + AddressDetails Country + AdministrativeArea Locality + DependentLocality + ].freeze + + DEPENDENT_LOCALITY_2 = %w[ + GeoObject metaDataProperty GeocoderMetaData + AddressDetails Country + AdministrativeArea + SubAdministrativeArea Locality + DependentLocality + ].freeze def coordinates @data['GeoObject']['Point']['pos'].split(' ').reverse.map(&:to_f) end - def address(format = :full) + def address(_format = :full) @data['GeoObject']['metaDataProperty']['GeocoderMetaData']['text'] end def city - if state.empty? and address_details and address_details.has_key? 'Locality' - address_details['Locality']['LocalityName'] - elsif sub_state.empty? and address_details and address_details.has_key? 'AdministrativeArea' and - address_details['AdministrativeArea'].has_key? 'Locality' - address_details['AdministrativeArea']['Locality']['LocalityName'] - elsif not sub_state_city.empty? - sub_state_city - else - "" - end + result = + if state.empty? + dig_data(@data, *COUNTRY_LEVEL, 'Locality', 'LocalityName') + elsif sub_state.empty? + dig_data(@data, *ADMIN_LEVEL, 'Locality', 'LocalityName') + else + dig_data(@data, *SUBADMIN_LEVEL, 'Locality', 'LocalityName') + end + + result || "" end def country - if address_details - address_details['CountryName'] - else - "" - end + dig_data(@data, *COUNTRY_LEVEL, 'CountryName') || "" end def country_code - if address_details - address_details['CountryNameCode'] - else - "" - end + dig_data(@data, *COUNTRY_LEVEL, 'CountryNameCode') || "" end def state - if address_details and address_details['AdministrativeArea'] - address_details['AdministrativeArea']['AdministrativeAreaName'] - else - "" - end + dig_data(@data, *ADMIN_LEVEL, 'AdministrativeAreaName') || "" end def sub_state - if !state.empty? and address_details and address_details['AdministrativeArea']['SubAdministrativeArea'] - address_details['AdministrativeArea']['SubAdministrativeArea']['SubAdministrativeAreaName'] - else - "" - end + return "" if state.empty? + dig_data(@data, *SUBADMIN_LEVEL, 'SubAdministrativeAreaName') || "" end def state_code @@ -61,27 +83,20 @@ def state_code end def street - if thoroughfare_data - thoroughfare_data['ThoroughfareName'] - else - "" - end + thoroughfare_data.is_a?(Hash) ? thoroughfare_data['ThoroughfareName'] : "" end def street_number - if premise - premise['PremiseNumber'] - else - "" - end + premise.is_a?(Hash) ? premise.fetch('PremiseNumber', "") : "" + end + + def premise_name + premise.is_a?(Hash) ? premise.fetch('PremiseName', "") : "" end def postal_code - if premise && premise['PostalCode'] - premise['PostalCode']['PostalCodeNumber'] - else - "" - end + return "" unless premise.is_a?(Hash) + dig_data(premise, 'PostalCode', 'PostalCodeNumber') || "" end def kind @@ -101,46 +116,49 @@ def viewport private # ---------------------------------------------------------------- - def premise - thoroughfare_data && thoroughfare_data['Premise'] + def top_level_locality + dig_data(@data, *ADDRESS_DETAILS, 'Locality') end - def thoroughfare_data - locality_data && locality_data['Thoroughfare'] - end - - def locality_data - dependent_locality || subadmin_locality || admin_locality + def country_level_locality + dig_data(@data, *COUNTRY_LEVEL, 'Locality') end def admin_locality - address_details && address_details['AdministrativeArea'] && - address_details['AdministrativeArea']['Locality'] + dig_data(@data, *ADMIN_LEVEL, 'Locality') end def subadmin_locality - address_details && address_details['AdministrativeArea'] && - address_details['AdministrativeArea']['SubAdministrativeArea'] && - address_details['AdministrativeArea']['SubAdministrativeArea']['Locality'] + dig_data(@data, *SUBADMIN_LEVEL, 'Locality') end def dependent_locality - address_details && address_details['AdministrativeArea'] && - address_details['AdministrativeArea']['SubAdministrativeArea'] && - address_details['AdministrativeArea']['SubAdministrativeArea']['Locality'] && - address_details['AdministrativeArea']['SubAdministrativeArea']['Locality']['DependentLocality'] + dig_data(@data, *DEPENDENT_LOCALITY_1) || + dig_data(@data, *DEPENDENT_LOCALITY_2) end - def address_details - @data['GeoObject']['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country'] + def locality_data + dependent_locality || subadmin_locality || admin_locality || + country_level_locality || top_level_locality end - def sub_state_city - if !sub_state.empty? and address_details and address_details['AdministrativeArea']['SubAdministrativeArea'].has_key? 'Locality' - address_details['AdministrativeArea']['SubAdministrativeArea']['Locality']['LocalityName'] || "" - else - "" + def thoroughfare_data + locality_data['Thoroughfare'] if locality_data.is_a?(Hash) + end + + def premise + if thoroughfare_data.is_a?(Hash) + thoroughfare_data['Premise'] + elsif locality_data.is_a?(Hash) + locality_data['Premise'] end end + + def dig_data(source, *keys) + key = keys.shift + result = source.fetch(key, nil) + return result unless result.is_a?(Hash) + keys.any? ? dig_data(result, *keys) : result + end end end diff --git a/test/fixtures/yandex_new_york b/test/fixtures/yandex_new_york index e48bb5370..3c0bd3afa 100644 --- a/test/fixtures/yandex_new_york +++ b/test/fixtures/yandex_new_york @@ -1 +1,386 @@ -{"response":{"Attribution":"","GeoObjectCollection":{"metaDataProperty":{"GeocoderResponseMetaData":{"request":"New York, NY","found":"21","results":"10"}},"featureMember":[{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"province","text":"United States, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"New York"}}}}},"description":"United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-79.762115 40.477414","upperCorner":"-71.668635 45.016078"}},"Point":{"pos":"-74.007112 40.714545"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, New York, Bronx, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"New York, Bronx, New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"New York","SubAdministrativeArea":{"SubAdministrativeAreaName":"Bronx","Locality":{"LocalityName":"New York"}}}}}}},"description":"Bronx, New York, United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-74.258892 40.477414","upperCorner":"-73.700373 40.917616"}},"Point":{"pos":"-74.007112 40.714545"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"hydro","text":"United States, Upper New York Bay","precision":"other","AddressDetails":{"Country":{"AddressLine":"Upper New York Bay","CountryNameCode":"US","CountryName":"United States","Locality":{"Premise":{"PremiseName":"Upper New York Bay"}}}}}},"description":"United States","name":"Upper New York Bay","boundedBy":{"Envelope":{"lowerCorner":"-74.107633 40.604124","upperCorner":"-73.998434 40.706697"}},"Point":{"pos":"-74.048758 40.660893"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, New Jersey, Hudson, West New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"New Jersey, Hudson, West New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"New Jersey","SubAdministrativeArea":{"SubAdministrativeAreaName":"Hudson","Locality":{"LocalityName":"West New York"}}}}}}},"description":"Hudson, New Jersey, United States","name":"West New York","boundedBy":{"Envelope":{"lowerCorner":"-74.023569 40.7746","upperCorner":"-73.992936 40.796565"}},"Point":{"pos":"-74.015260 40.788325"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United Kingdom of Great Britain and Northern Ireland, England, Lincolnshire, East Lindsey, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"England, Lincolnshire, East Lindsey, New York","CountryNameCode":"GB","CountryName":"United Kingdom of Great Britain and Northern Ireland","AdministrativeArea":{"AdministrativeAreaName":"England","SubAdministrativeArea":{"SubAdministrativeAreaName":"Lincolnshire","Locality":{"LocalityName":"New York"}}}}}}},"description":"East Lindsey, Lincolnshire, England, United Kingdom of Great Britain and Northern Ireland","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-0.205993 53.039103","upperCorner":"-0.074192 53.11847"}},"Point":{"pos":"-0.140092 53.078805"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"South Africa, North West, Bophirima, Naledi, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"North West, Bophirima, Naledi, New York","CountryNameCode":"ZA","CountryName":"South Africa","AdministrativeArea":{"AdministrativeAreaName":"North West","SubAdministrativeArea":{"SubAdministrativeAreaName":"Bophirima","Locality":{"LocalityName":"New York"}}}}}}},"description":"Naledi, Bophirima, North West, South Africa","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"24.454037 -26.943742","upperCorner":"24.585838 -26.825556"}},"Point":{"pos":"24.519938 -26.884665"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, New Mexico, Cibola, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"New Mexico, Cibola, New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"New Mexico","SubAdministrativeArea":{"SubAdministrativeAreaName":"Cibola","Locality":{"LocalityName":"New York"}}}}}}},"description":"Cibola, New Mexico, United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-107.592515 35.00522","upperCorner":"-107.460714 35.113594"}},"Point":{"pos":"-107.526615 35.059425"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, Iowa, Wayne, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"Iowa, Wayne, New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"Iowa","SubAdministrativeArea":{"SubAdministrativeAreaName":"Wayne","Locality":{"LocalityName":"New York"}}}}}}},"description":"Wayne, Iowa, United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-93.32337 40.801487","upperCorner":"-93.191569 40.901567"}},"Point":{"pos":"-93.257469 40.851546"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, Missouri, Caldwell, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"Missouri, Caldwell, New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"Missouri","SubAdministrativeArea":{"SubAdministrativeAreaName":"Caldwell","Locality":{"LocalityName":"New York"}}}}}}},"description":"Caldwell, Missouri, United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-93.97525 39.633979","upperCorner":"-93.843449 39.735813"}},"Point":{"pos":"-93.909350 39.684915"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, Texas, Henderson, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"Texas, Henderson, New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"Texas","SubAdministrativeArea":{"SubAdministrativeAreaName":"Henderson","Locality":{"LocalityName":"New York"}}}}}}},"description":"Henderson, Texas, United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-95.735086 32.112428","upperCorner":"-95.603285 32.224535"}},"Point":{"pos":"-95.669185 32.168499"}}}]}}} +{ + "response": { + "Attribution": "", + "GeoObjectCollection": { + "metaDataProperty": { + "GeocoderResponseMetaData": { + "request": "New York, NY", + "found": "21", + "results": "10" + } + }, + "featureMember": [ + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "province", + "text": "United States, New York", + "precision": "other", + "AddressDetails": { + "Country": { + "AddressLine": "New York", + "CountryNameCode": "US", + "CountryName": "United States", + "AdministrativeArea": { + "AdministrativeAreaName": "New York" + } + } + } + } + }, + "description": "United States", + "name": "New York", + "boundedBy": { + "Envelope": { + "lowerCorner": "-79.762115 40.477414", + "upperCorner": "-71.668635 45.016078" + } + }, + "Point": { + "pos": "-74.007112 40.714545" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "locality", + "text": "United States, New York, Bronx, New York", + "precision": "other", + "AddressDetails": { + "Country": { + "AddressLine": "New York, Bronx, New York", + "CountryNameCode": "US", + "CountryName": "United States", + "AdministrativeArea": { + "AdministrativeAreaName": "New York", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Bronx", + "Locality": { + "LocalityName": "New York" + } + } + } + } + } + } + }, + "description": "Bronx, New York, United States", + "name": "New York", + "boundedBy": { + "Envelope": { + "lowerCorner": "-74.258892 40.477414", + "upperCorner": "-73.700373 40.917616" + } + }, + "Point": { + "pos": "-74.007112 40.714545" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "hydro", + "text": "United States, Upper New York Bay", + "precision": "other", + "AddressDetails": { + "Country": { + "AddressLine": "Upper New York Bay", + "CountryNameCode": "US", + "CountryName": "United States", + "Locality": { + "Premise": { + "PremiseName": "Upper New York Bay" + } + } + } + } + } + }, + "description": "United States", + "name": "Upper New York Bay", + "boundedBy": { + "Envelope": { + "lowerCorner": "-74.107633 40.604124", + "upperCorner": "-73.998434 40.706697" + } + }, + "Point": { + "pos": "-74.048758 40.660893" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "locality", + "text": "United States, New Jersey, Hudson, West New York", + "precision": "other", + "AddressDetails": { + "Country": { + "AddressLine": "New Jersey, Hudson, West New York", + "CountryNameCode": "US", + "CountryName": "United States", + "AdministrativeArea": { + "AdministrativeAreaName": "New Jersey", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Hudson", + "Locality": { + "LocalityName": "West New York" + } + } + } + } + } + } + }, + "description": "Hudson, New Jersey, United States", + "name": "West New York", + "boundedBy": { + "Envelope": { + "lowerCorner": "-74.023569 40.7746", + "upperCorner": "-73.992936 40.796565" + } + }, + "Point": { + "pos": "-74.015260 40.788325" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "locality", + "text": "United Kingdom of Great Britain and Northern Ireland, England, Lincolnshire, East Lindsey, New York", + "precision": "other", + "AddressDetails": { + "Country": { + "AddressLine": "England, Lincolnshire, East Lindsey, New York", + "CountryNameCode": "GB", + "CountryName": "United Kingdom of Great Britain and Northern Ireland", + "AdministrativeArea": { + "AdministrativeAreaName": "England", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Lincolnshire", + "Locality": { + "LocalityName": "New York" + } + } + } + } + } + } + }, + "description": "East Lindsey, Lincolnshire, England, United Kingdom of Great Britain and Northern Ireland", + "name": "New York", + "boundedBy": { + "Envelope": { + "lowerCorner": "-0.205993 53.039103", + "upperCorner": "-0.074192 53.11847" + } + }, + "Point": { + "pos": "-0.140092 53.078805" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "locality", + "text": "South Africa, North West, Bophirima, Naledi, New York", + "precision": "other", + "AddressDetails": { + "Country": { + "AddressLine": "North West, Bophirima, Naledi, New York", + "CountryNameCode": "ZA", + "CountryName": "South Africa", + "AdministrativeArea": { + "AdministrativeAreaName": "North West", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Bophirima", + "Locality": { + "LocalityName": "New York" + } + } + } + } + } + } + }, + "description": "Naledi, Bophirima, North West, South Africa", + "name": "New York", + "boundedBy": { + "Envelope": { + "lowerCorner": "24.454037 -26.943742", + "upperCorner": "24.585838 -26.825556" + } + }, + "Point": { + "pos": "24.519938 -26.884665" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "locality", + "text": "United States, New Mexico, Cibola, New York", + "precision": "other", + "AddressDetails": { + "Country": { + "AddressLine": "New Mexico, Cibola, New York", + "CountryNameCode": "US", + "CountryName": "United States", + "AdministrativeArea": { + "AdministrativeAreaName": "New Mexico", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Cibola", + "Locality": { + "LocalityName": "New York" + } + } + } + } + } + } + }, + "description": "Cibola, New Mexico, United States", + "name": "New York", + "boundedBy": { + "Envelope": { + "lowerCorner": "-107.592515 35.00522", + "upperCorner": "-107.460714 35.113594" + } + }, + "Point": { + "pos": "-107.526615 35.059425" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "locality", + "text": "United States, Iowa, Wayne, New York", + "precision": "other", + "AddressDetails": { + "Country": { + "AddressLine": "Iowa, Wayne, New York", + "CountryNameCode": "US", + "CountryName": "United States", + "AdministrativeArea": { + "AdministrativeAreaName": "Iowa", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Wayne", + "Locality": { + "LocalityName": "New York" + } + } + } + } + } + } + }, + "description": "Wayne, Iowa, United States", + "name": "New York", + "boundedBy": { + "Envelope": { + "lowerCorner": "-93.32337 40.801487", + "upperCorner": "-93.191569 40.901567" + } + }, + "Point": { + "pos": "-93.257469 40.851546" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "locality", + "text": "United States, Missouri, Caldwell, New York", + "precision": "other", + "AddressDetails": { + "Country": { + "AddressLine": "Missouri, Caldwell, New York", + "CountryNameCode": "US", + "CountryName": "United States", + "AdministrativeArea": { + "AdministrativeAreaName": "Missouri", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Caldwell", + "Locality": { + "LocalityName": "New York" + } + } + } + } + } + } + }, + "description": "Caldwell, Missouri, United States", + "name": "New York", + "boundedBy": { + "Envelope": { + "lowerCorner": "-93.97525 39.633979", + "upperCorner": "-93.843449 39.735813" + } + }, + "Point": { + "pos": "-93.909350 39.684915" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "locality", + "text": "United States, Texas, Henderson, New York", + "precision": "other", + "AddressDetails": { + "Country": { + "AddressLine": "Texas, Henderson, New York", + "CountryNameCode": "US", + "CountryName": "United States", + "AdministrativeArea": { + "AdministrativeAreaName": "Texas", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Henderson", + "Locality": { + "LocalityName": "New York" + } + } + } + } + } + } + }, + "description": "Henderson, Texas, United States", + "name": "New York", + "boundedBy": { + "Envelope": { + "lowerCorner": "-95.735086 32.112428", + "upperCorner": "-95.603285 32.224535" + } + }, + "Point": { + "pos": "-95.669185 32.168499" + } + } + } + ] + } + } +} From 65d9776fe8690f66edadf7f677d2ad548d9d8c69 Mon Sep 17 00:00:00 2001 From: Yaroslav Litvinov <beyondthemkad@gmail.com> Date: Sat, 29 Sep 2018 13:27:25 +0300 Subject: [PATCH 225/248] add yandex tests --- test/fixtures/yandex_kremlin | 588 ++++++++++++++++-- test/fixtures/yandex_ontario | 571 +++++++++++++++++ .../yandex_putilkovo_novotushinskaya_5 | 32 +- test/fixtures/yandex_volga_river | 63 ++ test/unit/lookups/yandex_test.rb | 70 ++- 5 files changed, 1255 insertions(+), 69 deletions(-) create mode 100644 test/fixtures/yandex_ontario create mode 100644 test/fixtures/yandex_volga_river diff --git a/test/fixtures/yandex_kremlin b/test/fixtures/yandex_kremlin index f08b6ea3a..d73fdff14 100644 --- a/test/fixtures/yandex_kremlin +++ b/test/fixtures/yandex_kremlin @@ -1,48 +1,548 @@ { - "response": { - "GeoObjectCollection": { - "metaDataProperty": { - "GeocoderResponseMetaData": { - "request": "Кремль, Moscow, Russia", - "found": "1", - "results": "10" - } - }, - "featureMember": [ - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "vegetation", - "text": "Россия, Москва, Московский Кремль", - "precision": "other", - "AddressDetails": { - "Country": { - "CountryNameCode": "RU", - "CountryName": "Россия", - "Locality": { - "LocalityName": "Москва", - "Premise": { - "PremiseName": "Московский Кремль" - } - } - } - } - } - }, - "name": "Московский Кремль", - "boundedBy": { - "Envelope": { - "lowerCorner": "37.584182 55.733361", - "upperCorner": "37.650064 55.770517" - } - }, - "Point": { - "pos": "37.617123 55.751943" - } - } - } - ] + "response": { + "GeoObjectCollection": { + "metaDataProperty": { + "GeocoderResponseMetaData": { + "request": "Kremlin, Moscow, Russia", + "found": "8", + "results": "10" } + }, + "featureMember": [ + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "district", + "text": "Russia, Moscow, Moscow Kremlin", + "precision": "other", + "Address": { + "country_code": "RU", + "formatted": "Moscow, Moscow Kremlin", + "Components": [ + { + "kind": "country", + "name": "Russia" + }, + { + "kind": "province", + "name": "Tsentralny federalny okrug" + }, + { + "kind": "province", + "name": "Moscow" + }, + { + "kind": "locality", + "name": "Moscow" + }, + { + "kind": "district", + "name": "Moscow Kremlin" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Moscow, Moscow Kremlin", + "CountryNameCode": "RU", + "CountryName": "Russia", + "AdministrativeArea": { + "AdministrativeAreaName": "Moscow", + "Locality": { + "LocalityName": "Moscow", + "DependentLocality": { + "DependentLocalityName": "Moscow Kremlin" + } + } + } + } + } + } + }, + "description": "Moscow, Russia", + "name": "Moscow Kremlin", + "boundedBy": { + "Envelope": { + "lowerCorner": "37.612587 55.748189", + "upperCorner": "37.623187 55.755044" + } + }, + "Point": { + "pos": "37.617734 55.751999" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "other", + "text": "Russia, Moscow, Kremlin Wall Necropolis", + "precision": "other", + "Address": { + "country_code": "RU", + "formatted": "Moscow, Kremlin Wall Necropolis", + "Components": [ + { + "kind": "country", + "name": "Russia" + }, + { + "kind": "province", + "name": "Tsentralny federalny okrug" + }, + { + "kind": "province", + "name": "Moscow" + }, + { + "kind": "locality", + "name": "Moscow" + }, + { + "kind": "other", + "name": "Kremlin Wall Necropolis" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Moscow, Kremlin Wall Necropolis", + "CountryNameCode": "RU", + "CountryName": "Russia", + "AdministrativeArea": { + "AdministrativeAreaName": "Moscow", + "Locality": { + "LocalityName": "Moscow", + "Premise": { + "PremiseName": "Kremlin Wall Necropolis" + } + } + } + } + } + } + }, + "description": "Moscow, Russia", + "name": "Kremlin Wall Necropolis", + "boundedBy": { + "Envelope": { + "lowerCorner": "37.617824 55.752708", + "upperCorner": "37.621264 55.754487" + } + }, + "Point": { + "pos": "37.619576 55.753559" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "vegetation", + "text": "Russia, Moscow, Small Kremlin Public Garden", + "precision": "other", + "Address": { + "country_code": "RU", + "formatted": "Moscow, Small Kremlin Public Garden", + "Components": [ + { + "kind": "country", + "name": "Russia" + }, + { + "kind": "province", + "name": "Tsentralny federalny okrug" + }, + { + "kind": "province", + "name": "Moscow" + }, + { + "kind": "locality", + "name": "Moscow" + }, + { + "kind": "vegetation", + "name": "Small Kremlin Public Garden" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Moscow, Small Kremlin Public Garden", + "CountryNameCode": "RU", + "CountryName": "Russia", + "AdministrativeArea": { + "AdministrativeAreaName": "Moscow", + "Locality": { + "LocalityName": "Moscow", + "Premise": { + "PremiseName": "Small Kremlin Public Garden" + } + } + } + } + } + } + }, + "description": "Moscow, Russia", + "name": "Small Kremlin Public Garden", + "boundedBy": { + "Envelope": { + "lowerCorner": "37.616467 55.751452", + "upperCorner": "37.617788 55.752004" + } + }, + "Point": { + "pos": "37.61706 55.751731" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "vegetation", + "text": "Russia, Moscow, Grand Kremlin Public Garden", + "precision": "other", + "Address": { + "country_code": "RU", + "formatted": "Moscow, Grand Kremlin Public Garden", + "Components": [ + { + "kind": "country", + "name": "Russia" + }, + { + "kind": "province", + "name": "Tsentralny federalny okrug" + }, + { + "kind": "province", + "name": "Moscow" + }, + { + "kind": "locality", + "name": "Moscow" + }, + { + "kind": "vegetation", + "name": "Grand Kremlin Public Garden" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Moscow, Grand Kremlin Public Garden", + "CountryNameCode": "RU", + "CountryName": "Russia", + "AdministrativeArea": { + "AdministrativeAreaName": "Moscow", + "Locality": { + "LocalityName": "Moscow", + "Premise": { + "PremiseName": "Grand Kremlin Public Garden" + } + } + } + } + } + } + }, + "description": "Moscow, Russia", + "name": "Grand Kremlin Public Garden", + "boundedBy": { + "Envelope": { + "lowerCorner": "37.618336 55.749922", + "upperCorner": "37.621956 55.75246" + } + }, + "Point": { + "pos": "37.620447 55.751031" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "street", + "text": "Russia, Moscow, Kremlyovsky Drive", + "precision": "street", + "Address": { + "country_code": "RU", + "formatted": "Moscow, Kremlyovsky Drive", + "Components": [ + { + "kind": "country", + "name": "Russia" + }, + { + "kind": "province", + "name": "Tsentralny federalny okrug" + }, + { + "kind": "province", + "name": "Moscow" + }, + { + "kind": "locality", + "name": "Moscow" + }, + { + "kind": "street", + "name": "Kremlyovsky Drive" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Moscow, Kremlyovsky Drive", + "CountryNameCode": "RU", + "CountryName": "Russia", + "AdministrativeArea": { + "AdministrativeAreaName": "Moscow", + "Locality": { + "LocalityName": "Moscow", + "Thoroughfare": { + "ThoroughfareName": "Kremlyovsky Drive" + } + } + } + } + } + } + }, + "description": "Moscow, Russia", + "name": "Kremlyovsky Drive", + "boundedBy": { + "Envelope": { + "lowerCorner": "37.616566 55.754649", + "upperCorner": "37.61812 55.755469" + } + }, + "Point": { + "pos": "37.61733 55.755044" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "street", + "text": "Russia, Republic of Tatarstan, City of Kazan, Kremlevskaya Street", + "precision": "street", + "Address": { + "country_code": "RU", + "formatted": "Republic of Tatarstan, City of Kazan, Kremlevskaya Street", + "Components": [ + { + "kind": "country", + "name": "Russia" + }, + { + "kind": "province", + "name": "Privolzhskiy federalny okrug" + }, + { + "kind": "province", + "name": "Republic of Tatarstan" + }, + { + "kind": "area", + "name": "Kazan City District" + }, + { + "kind": "locality", + "name": "City of Kazan" + }, + { + "kind": "street", + "name": "Kremlevskaya Street" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Republic of Tatarstan, City of Kazan, Kremlevskaya Street", + "CountryNameCode": "RU", + "CountryName": "Russia", + "AdministrativeArea": { + "AdministrativeAreaName": "Republic of Tatarstan", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Kazan City District", + "Locality": { + "LocalityName": "City of Kazan", + "Thoroughfare": { + "ThoroughfareName": "Kremlevskaya Street" + } + } + } + } + } + } + } + }, + "description": "City of Kazan, Republic of Tatarstan, Russia", + "name": "Kremlevskaya Street", + "boundedBy": { + "Envelope": { + "lowerCorner": "49.108372 55.790651", + "upperCorner": "49.123105 55.796653" + } + }, + "Point": { + "pos": "49.11573 55.793637" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "street", + "text": "Russia, Republic of Tatarstan, City of Kazan, Kremlevskiy Bridge", + "precision": "street", + "Address": { + "country_code": "RU", + "formatted": "Republic of Tatarstan, City of Kazan, Kremlevskiy Bridge", + "Components": [ + { + "kind": "country", + "name": "Russia" + }, + { + "kind": "province", + "name": "Privolzhskiy federalny okrug" + }, + { + "kind": "province", + "name": "Republic of Tatarstan" + }, + { + "kind": "area", + "name": "Kazan City District" + }, + { + "kind": "locality", + "name": "City of Kazan" + }, + { + "kind": "street", + "name": "Kremlevskiy Bridge" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Republic of Tatarstan, City of Kazan, Kremlevskiy Bridge", + "CountryNameCode": "RU", + "CountryName": "Russia", + "AdministrativeArea": { + "AdministrativeAreaName": "Republic of Tatarstan", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Kazan City District", + "Locality": { + "LocalityName": "City of Kazan", + "Thoroughfare": { + "ThoroughfareName": "Kremlevskiy Bridge" + } + } + } + } + } + } + } + }, + "description": "City of Kazan, Republic of Tatarstan, Russia", + "name": "Kremlevskiy Bridge", + "boundedBy": { + "Envelope": { + "lowerCorner": "49.101374 55.79973", + "upperCorner": "49.102291 55.802664" + } + }, + "Point": { + "pos": "49.101913 55.801217" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "street", + "text": "Russia, Republic of Tatarstan, City of Kazan, Kremlevskaya Embankment", + "precision": "street", + "Address": { + "country_code": "RU", + "formatted": "Republic of Tatarstan, City of Kazan, Kremlevskaya Embankment", + "Components": [ + { + "kind": "country", + "name": "Russia" + }, + { + "kind": "province", + "name": "Privolzhskiy federalny okrug" + }, + { + "kind": "province", + "name": "Republic of Tatarstan" + }, + { + "kind": "area", + "name": "Kazan City District" + }, + { + "kind": "locality", + "name": "City of Kazan" + }, + { + "kind": "street", + "name": "Kremlevskaya Embankment" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Republic of Tatarstan, City of Kazan, Kremlevskaya Embankment", + "CountryNameCode": "RU", + "CountryName": "Russia", + "AdministrativeArea": { + "AdministrativeAreaName": "Republic of Tatarstan", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Kazan City District", + "Locality": { + "LocalityName": "City of Kazan", + "Thoroughfare": { + "ThoroughfareName": "Kremlevskaya Embankment" + } + } + } + } + } + } + } + }, + "description": "City of Kazan, Republic of Tatarstan, Russia", + "name": "Kremlevskaya Embankment", + "boundedBy": { + "Envelope": { + "lowerCorner": "49.091358 55.795454", + "upperCorner": "49.102021 55.800858" + } + }, + "Point": { + "pos": "49.096676 55.798191" + } + } + } + ] } + } } diff --git a/test/fixtures/yandex_ontario b/test/fixtures/yandex_ontario new file mode 100644 index 000000000..6afca1bb2 --- /dev/null +++ b/test/fixtures/yandex_ontario @@ -0,0 +1,571 @@ +{ + "response": { + "GeoObjectCollection": { + "metaDataProperty": { + "GeocoderResponseMetaData": { + "request": "ontario", + "found": "57", + "results": "10" + } + }, + "featureMember": [ + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "province", + "text": "Canada, Ontario", + "precision": "other", + "Address": { + "country_code": "CA", + "formatted": "Ontario", + "Components": [ + { + "kind": "country", + "name": "Canada" + }, + { + "kind": "province", + "name": "Ontario" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Ontario", + "CountryNameCode": "CA", + "CountryName": "Canada", + "AdministrativeArea": { + "AdministrativeAreaName": "Ontario" + } + } + } + } + }, + "description": "Canada", + "name": "Ontario", + "boundedBy": { + "Envelope": { + "lowerCorner": "-95.153382 41.704494", + "upperCorner": "-74.321387 56.88699" + } + }, + "Point": { + "pos": "-87.170557 49.294248" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "locality", + "text": "United States of America, California, San Bernardino County, Ontario", + "precision": "other", + "Address": { + "country_code": "US", + "formatted": "California, San Bernardino County, Ontario", + "Components": [ + { + "kind": "country", + "name": "United States of America" + }, + { + "kind": "province", + "name": "California" + }, + { + "kind": "area", + "name": "San Bernardino County" + }, + { + "kind": "locality", + "name": "Ontario" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "California, San Bernardino County, Ontario", + "CountryNameCode": "US", + "CountryName": "United States of America", + "AdministrativeArea": { + "AdministrativeAreaName": "California", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "San Bernardino County", + "Locality": { + "LocalityName": "Ontario" + } + } + } + } + } + } + }, + "description": "San Bernardino County, California, United States of America", + "name": "Ontario", + "boundedBy": { + "Envelope": { + "lowerCorner": "-117.681844 33.975275", + "upperCorner": "-117.524028 34.093373" + } + }, + "Point": { + "pos": "-117.627586 34.054599" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "hydro", + "text": "Lake Ontario", + "precision": "other", + "Address": { + "formatted": "Lake Ontario", + "Components": [ + { + "kind": "hydro", + "name": "Lake Ontario" + } + ] + }, + "AddressDetails": { + "Locality": { + "Premise": { + "PremiseName": "Lake Ontario" + } + } + } + } + }, + "name": "Lake Ontario", + "boundedBy": { + "Envelope": { + "lowerCorner": "-79.801686 43.1625", + "upperCorner": "-76.008585 44.244197" + } + }, + "Point": { + "pos": "-77.804812 43.6384" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "locality", + "text": "United States of America, State of Oregon, Malheur County, Ontario", + "precision": "other", + "Address": { + "country_code": "US", + "formatted": "State of Oregon, Malheur County, Ontario", + "Components": [ + { + "kind": "country", + "name": "United States of America" + }, + { + "kind": "province", + "name": "State of Oregon" + }, + { + "kind": "area", + "name": "Malheur County" + }, + { + "kind": "locality", + "name": "Ontario" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "State of Oregon, Malheur County, Ontario", + "CountryNameCode": "US", + "CountryName": "United States of America", + "AdministrativeArea": { + "AdministrativeAreaName": "State of Oregon", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Malheur County", + "Locality": { + "LocalityName": "Ontario" + } + } + } + } + } + } + }, + "description": "Malheur County, State of Oregon, United States of America", + "name": "Ontario", + "boundedBy": { + "Envelope": { + "lowerCorner": "-116.970487 44.014537", + "upperCorner": "-116.943744 44.038966" + } + }, + "Point": { + "pos": "-116.962968 44.026639" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "district", + "text": "Canada, City of Montreal, Centre-Ville, Terrasse Ontario", + "precision": "other", + "Address": { + "country_code": "CA", + "formatted": "City of Montreal, Centre-Ville, Terrasse Ontario", + "Components": [ + { + "kind": "country", + "name": "Canada" + }, + { + "kind": "locality", + "name": "City of Montreal" + }, + { + "kind": "district", + "name": "Centre-Ville" + }, + { + "kind": "district", + "name": "Terrasse Ontario" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "City of Montreal, Centre-Ville, Terrasse Ontario", + "CountryNameCode": "CA", + "CountryName": "Canada", + "Locality": { + "LocalityName": "City of Montreal", + "DependentLocality": { + "DependentLocalityName": "Centre-Ville", + "DependentLocality": { + "DependentLocalityName": "Terrasse Ontario" + } + } + } + } + } + } + }, + "description": "Centre-Ville, City of Montreal, Canada", + "name": "Terrasse Ontario", + "boundedBy": { + "Envelope": { + "lowerCorner": "-73.583251 45.507018", + "upperCorner": "-73.550318 45.53017" + } + }, + "Point": { + "pos": "-73.566785 45.518595" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "area", + "text": "United States of America, New York, Ontario County", + "precision": "other", + "Address": { + "country_code": "US", + "formatted": "New York, Ontario County", + "Components": [ + { + "kind": "country", + "name": "United States of America" + }, + { + "kind": "province", + "name": "New York" + }, + { + "kind": "area", + "name": "Ontario County" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "New York, Ontario County", + "CountryNameCode": "US", + "CountryName": "United States of America", + "AdministrativeArea": { + "AdministrativeAreaName": "New York", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Ontario County" + } + } + } + } + } + }, + "description": "New York, United States of America", + "name": "Ontario County", + "boundedBy": { + "Envelope": { + "lowerCorner": "-77.612581 42.576595", + "upperCorner": "-76.964087 43.040597" + } + }, + "Point": { + "pos": "-77.281965 42.807695" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "locality", + "text": "United States of America, Kansas, Nemaha County, Ontario", + "precision": "other", + "Address": { + "country_code": "US", + "formatted": "Kansas, Nemaha County, Ontario", + "Components": [ + { + "kind": "country", + "name": "United States of America" + }, + { + "kind": "province", + "name": "Kansas" + }, + { + "kind": "area", + "name": "Nemaha County" + }, + { + "kind": "locality", + "name": "Ontario" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Kansas, Nemaha County, Ontario", + "CountryNameCode": "US", + "CountryName": "United States of America", + "AdministrativeArea": { + "AdministrativeAreaName": "Kansas", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Nemaha County", + "Locality": { + "LocalityName": "Ontario" + } + } + } + } + } + } + }, + "description": "Nemaha County, Kansas, United States of America", + "name": "Ontario", + "boundedBy": { + "Envelope": { + "lowerCorner": "-95.94849 39.515074", + "upperCorner": "-95.816689 39.617085" + } + }, + "Point": { + "pos": "-95.882589 39.566098" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "locality", + "text": "United States of America, Oklahoma, Ottawa County, Ontario", + "precision": "other", + "Address": { + "country_code": "US", + "formatted": "Oklahoma, Ottawa County, Ontario", + "Components": [ + { + "kind": "country", + "name": "United States of America" + }, + { + "kind": "province", + "name": "Oklahoma" + }, + { + "kind": "area", + "name": "Ottawa County" + }, + { + "kind": "locality", + "name": "Ontario" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Oklahoma, Ottawa County, Ontario", + "CountryNameCode": "US", + "CountryName": "United States of America", + "AdministrativeArea": { + "AdministrativeAreaName": "Oklahoma", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Ottawa County", + "Locality": { + "LocalityName": "Ontario" + } + } + } + } + } + } + }, + "description": "Ottawa County, Oklahoma, United States of America", + "name": "Ontario", + "boundedBy": { + "Envelope": { + "lowerCorner": "-94.823987 36.934211", + "upperCorner": "-94.692187 37.039943" + } + }, + "Point": { + "pos": "-94.758087 36.987095" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "locality", + "text": "United States of America, State of Iowa, Story County, Ontario", + "precision": "other", + "Address": { + "country_code": "US", + "formatted": "State of Iowa, Story County, Ontario", + "Components": [ + { + "kind": "country", + "name": "United States of America" + }, + { + "kind": "province", + "name": "State of Iowa" + }, + { + "kind": "area", + "name": "Story County" + }, + { + "kind": "locality", + "name": "Ontario" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "State of Iowa, Story County, Ontario", + "CountryNameCode": "US", + "CountryName": "United States of America", + "AdministrativeArea": { + "AdministrativeAreaName": "State of Iowa", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Story County", + "Locality": { + "LocalityName": "Ontario" + } + } + } + } + } + } + }, + "description": "Story County, State of Iowa, United States of America", + "name": "Ontario", + "boundedBy": { + "Envelope": { + "lowerCorner": "-93.747384 41.985247", + "upperCorner": "-93.615583 42.083505" + } + }, + "Point": { + "pos": "-93.681483 42.034395" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "locality", + "text": "United States of America, Wisconsin, Vernon County, Ontario", + "precision": "other", + "Address": { + "country_code": "US", + "formatted": "Wisconsin, Vernon County, Ontario", + "Components": [ + { + "kind": "country", + "name": "United States of America" + }, + { + "kind": "province", + "name": "Wisconsin" + }, + { + "kind": "area", + "name": "Vernon County" + }, + { + "kind": "locality", + "name": "Ontario" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Wisconsin, Vernon County, Ontario", + "CountryNameCode": "US", + "CountryName": "United States of America", + "AdministrativeArea": { + "AdministrativeAreaName": "Wisconsin", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "Vernon County", + "Locality": { + "LocalityName": "Ontario" + } + } + } + } + } + } + }, + "description": "Vernon County, Wisconsin, United States of America", + "name": "Ontario", + "boundedBy": { + "Envelope": { + "lowerCorner": "-90.657089 43.678184", + "upperCorner": "-90.525288 43.773766" + } + }, + "Point": { + "pos": "-90.591189 43.725994" + } + } + } + ] + } + } +} diff --git a/test/fixtures/yandex_putilkovo_novotushinskaya_5 b/test/fixtures/yandex_putilkovo_novotushinskaya_5 index 4b6411880..e2626f0bd 100644 --- a/test/fixtures/yandex_putilkovo_novotushinskaya_5 +++ b/test/fixtures/yandex_putilkovo_novotushinskaya_5 @@ -14,36 +14,36 @@ "metaDataProperty": { "GeocoderMetaData": { "kind": "house", - "text": "Россия, Московская область, городской округ Красногорск, деревня Путилково, Новотушинская улица, 5", + "text": "Russia, Moscow Region, gorodskoy okrug Krasnogorsk, derevnya Putilkovo, Novotushinskaya ulitsa, 5", "precision": "exact", "Address": { "country_code": "RU", "postal_code": "143441", - "formatted": "Московская область, городской округ Красногорск, деревня Путилково, Новотушинская улица, 5", + "formatted": "Moscow Region, gorodskoy okrug Krasnogorsk, derevnya Putilkovo, Novotushinskaya ulitsa, 5", "Components": [ { "kind": "country", - "name": "Россия" + "name": "Russia" }, { "kind": "province", - "name": "Центральный федеральный округ" + "name": "Tsentralny federalny okrug" }, { "kind": "province", - "name": "Московская область" + "name": "Moscow Region" }, { "kind": "area", - "name": "городской округ Красногорск" + "name": "gorodskoy okrug Krasnogorsk" }, { "kind": "locality", - "name": "деревня Путилково" + "name": "derevnya Putilkovo" }, { "kind": "street", - "name": "Новотушинская улица" + "name": "Novotushinskaya ulitsa" }, { "kind": "house", @@ -53,17 +53,17 @@ }, "AddressDetails": { "Country": { - "AddressLine": "Московская область, городской округ Красногорск, деревня Путилково, Новотушинская улица, 5", + "AddressLine": "Moscow Region, gorodskoy okrug Krasnogorsk, derevnya Putilkovo, Novotushinskaya ulitsa, 5", "CountryNameCode": "RU", - "CountryName": "Россия", + "CountryName": "Russia", "AdministrativeArea": { - "AdministrativeAreaName": "Московская область", + "AdministrativeAreaName": "Moscow Region", "SubAdministrativeArea": { - "SubAdministrativeAreaName": "городской округ Красногорск", + "SubAdministrativeAreaName": "gorodskoy okrug Krasnogorsk", "Locality": { - "LocalityName": "деревня Путилково", + "LocalityName": "derevnya Putilkovo", "Thoroughfare": { - "ThoroughfareName": "Новотушинская улица", + "ThoroughfareName": "Novotushinskaya ulitsa", "Premise": { "PremiseNumber": "5", "PostalCode": { @@ -78,8 +78,8 @@ } } }, - "description": "деревня Путилково, городской округ Красногорск, Московская область, Россия", - "name": "Новотушинская улица, 5", + "description": "derevnya Putilkovo, gorodskoy okrug Krasnogorsk, Moscow Region, Russia", + "name": "Novotushinskaya ulitsa, 5", "boundedBy": { "Envelope": { "lowerCorner": "37.399416 55.86995", diff --git a/test/fixtures/yandex_volga_river b/test/fixtures/yandex_volga_river new file mode 100644 index 000000000..a314c19b1 --- /dev/null +++ b/test/fixtures/yandex_volga_river @@ -0,0 +1,63 @@ +{ + "response": { + "GeoObjectCollection": { + "metaDataProperty": { + "GeocoderResponseMetaData": { + "request": "volga river", + "found": "1", + "results": "10" + } + }, + "featureMember": [ + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "hydro", + "text": "Russia, Volga River", + "precision": "other", + "Address": { + "country_code": "RU", + "formatted": "Volga River", + "Components": [ + { + "kind": "country", + "name": "Russia" + }, + { + "kind": "hydro", + "name": "Volga River" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Volga River", + "CountryNameCode": "RU", + "CountryName": "Russia", + "Locality": { + "Premise": { + "PremiseName": "Volga River" + } + } + } + } + } + }, + "description": "Russia", + "name": "Volga River", + "boundedBy": { + "Envelope": { + "lowerCorner": "32.468241 45.697053", + "upperCorner": "50.181608 58.194645" + } + }, + "Point": { + "pos": "45.139984 49.550996" + } + } + } + ] + } + } +} diff --git a/test/unit/lookups/yandex_test.rb b/test/unit/lookups/yandex_test.rb index 78c84e2c7..347a3c055 100644 --- a/test/unit/lookups/yandex_test.rb +++ b/test/unit/lookups/yandex_test.rb @@ -4,12 +4,12 @@ class YandexTest < GeocoderTestCase def setup - Geocoder.configure(lookup: :yandex, language: :ru) + Geocoder.configure(lookup: :yandex, language: :en) end def test_yandex_viewport - result = Geocoder.search('Кремль, Moscow, Russia').first - assert_equal [55.733361, 37.584182, 55.770517, 37.650064], + result = Geocoder.search('Kremlin, Moscow, Russia').first + assert_equal [55.748189, 37.612587, 55.755044, 37.623187], result.viewport end @@ -92,13 +92,65 @@ def test_yandex_result_returns_street_number def test_yandex_maximum_precision_on_russian_address result = Geocoder.search('putilkovo novotushinskaya 5').first - assert_equal "exact", result.precision - assert_equal "Россия", result.country - assert_equal "Московская область", result.state - assert_equal "городской округ Красногорск" , result.sub_state - assert_equal "деревня Путилково", result.city - assert_equal "Новотушинская улица", result.street + assert_equal [55.872258, 37.403522], result.coordinates + assert_equal [55.86995, 37.399416, 55.874567, 37.407627], result.viewport + + assert_equal "Russia, Moscow Region, gorodskoy okrug Krasnogorsk, " \ + "derevnya Putilkovo, Novotushinskaya ulitsa, 5", + result.address + assert_equal "derevnya Putilkovo", result.city + assert_equal "Russia", result.country + assert_equal "RU", result.country_code + assert_equal "Moscow Region", result.state + assert_equal "gorodskoy okrug Krasnogorsk", result.sub_state + assert_equal "", result.state_code + assert_equal "Novotushinskaya ulitsa", result.street assert_equal "5", result.street_number + assert_equal "", result.premise_name assert_equal "143441", result.postal_code + assert_equal "house", result.kind + assert_equal "exact", result.precision + end + + def test_yandex_hydro_object + result = Geocoder.search('Volga river').first + + assert_equal [49.550996, 45.139984], result.coordinates + assert_equal [45.697053, 32.468241, 58.194645, 50.181608], result.viewport + + assert_equal "Russia, Volga River", result.address + assert_equal "", result.city + assert_equal "Russia", result.country + assert_equal "RU", result.country_code + assert_equal "", result.state + assert_equal "", result.sub_state + assert_equal "", result.state_code + assert_equal "", result.street + assert_equal "", result.street_number + assert_equal "Volga River", result.premise_name + assert_equal "", result.postal_code + assert_equal "hydro", result.kind + assert_equal "other", result.precision + end + + def test_yandex_province_object + result = Geocoder.search('Ontario').first + + assert_equal [49.294248, -87.170557], result.coordinates + assert_equal [41.704494, -95.153382, 56.88699, -74.321387], result.viewport + + assert_equal "Canada, Ontario", result.address + assert_equal "", result.city + assert_equal "Canada", result.country + assert_equal "CA", result.country_code + assert_equal "Ontario", result.state + assert_equal "", result.sub_state + assert_equal "", result.state_code + assert_equal "", result.street + assert_equal "", result.street_number + assert_equal "", result.premise_name + assert_equal "", result.postal_code + assert_equal "province", result.kind + assert_equal "other", result.precision end end From 7e68e8b0339530a86a6696d4c0faf4d4fff57f27 Mon Sep 17 00:00:00 2001 From: Yaroslav Litvinov <beyondthemkad@gmail.com> Date: Sat, 29 Sep 2018 13:28:34 +0300 Subject: [PATCH 226/248] Geocoder::Result::Yandex: clarify logic with description --- lib/geocoder/results/yandex.rb | 122 +++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/lib/geocoder/results/yandex.rb b/lib/geocoder/results/yandex.rb index e8900fac1..cb95469b9 100644 --- a/lib/geocoder/results/yandex.rb +++ b/lib/geocoder/results/yandex.rb @@ -2,22 +2,93 @@ module Geocoder::Result class Yandex < Base + # Yandex result has difficult tree structure, + # and presence of some nodes depends on exact search case. + + # Also Yandex lacks documentation about it. + # See https://tech.yandex.com/maps/doc/geocoder/desc/concepts/response_structure-docpage/ + + # Ultimatly, we need to find Locality and/or Thoroughfare data. + + # It may resides on the top (ADDRESS_DETAILS) level. + # example: 'Baltic Sea' + # "AddressDetails": { + # "Locality": { + # "Premise": { + # "PremiseName": "Baltic Sea" + # } + # } + # } + ADDRESS_DETAILS = %w[ GeoObject metaDataProperty GeocoderMetaData AddressDetails ].freeze + # On COUNTRY_LEVEL. + # example: 'Potomak' + # "AddressDetails": { + # "Country": { + # "AddressLine": "reka Potomak", + # "CountryNameCode": "US", + # "CountryName": "United States of America", + # "Locality": { + # "Premise": { + # "PremiseName": "reka Potomak" + # } + # } + # } + # } + COUNTRY_LEVEL = %w[ GeoObject metaDataProperty GeocoderMetaData AddressDetails Country ].freeze + # On ADMIN_LEVEL (usually state or city) + # example: 'Moscow, Tverskaya' + # "AddressDetails": { + # "Country": { + # "AddressLine": "Moscow, Tverskaya Street", + # "CountryNameCode": "RU", + # "CountryName": "Russia", + # "AdministrativeArea": { + # "AdministrativeAreaName": "Moscow", + # "Locality": { + # "LocalityName": "Moscow", + # "Thoroughfare": { + # "ThoroughfareName": "Tverskaya Street" + # } + # } + # } + # } + # } + ADMIN_LEVEL = %w[ GeoObject metaDataProperty GeocoderMetaData AddressDetails Country AdministrativeArea ].freeze + # On SUBADMIN_LEVEL (may refer to urban district) + # example: '' + # "AddressDetails": { + # "Country": { + # "AddressLine": "Moscow Region, Krasnogorsk", + # "CountryNameCode": "RU", + # "CountryName": "Russia", + # "AdministrativeArea": { + # "AdministrativeAreaName": "Moscow Region", + # "SubAdministrativeArea": { + # "SubAdministrativeAreaName": "gorodskoy okrug Krasnogorsk", + # "Locality": { + # "LocalityName": "Krasnogorsk" + # } + # } + # } + # } + # } + SUBADMIN_LEVEL = %w[ GeoObject metaDataProperty GeocoderMetaData AddressDetails Country @@ -25,6 +96,28 @@ class Yandex < Base SubAdministrativeArea ].freeze + # On DEPENDENT_LOCALITY_1 (may refer to district of city) + # example: 'Paris, Etienne Marcel' + # "AddressDetails": { + # "Country": { + # "AddressLine": "Île-de-France, Paris, 1er Arrondissement, Rue Étienne Marcel", + # "CountryNameCode": "FR", + # "CountryName": "France", + # "AdministrativeArea": { + # "AdministrativeAreaName": "Île-de-France", + # "Locality": { + # "LocalityName": "Paris", + # "DependentLocality": { + # "DependentLocalityName": "1er Arrondissement", + # "Thoroughfare": { + # "ThoroughfareName": "Rue Étienne Marcel" + # } + # } + # } + # } + # } + # } + DEPENDENT_LOCALITY_1 = %w[ GeoObject metaDataProperty GeocoderMetaData AddressDetails Country @@ -32,6 +125,35 @@ class Yandex < Base DependentLocality ].freeze + # On DEPENDENT_LOCALITY_2 (for special cases like turkish "mahalle") + # https://en.wikipedia.org/wiki/Mahalle + # example: 'Istanbul Mabeyinci Yokuşu 17' + + # "AddressDetails": { + # "Country": { + # "AddressLine": "İstanbul, Fatih, Saraç İshak Mah., Mabeyinci Yokuşu, 17", + # "CountryNameCode": "TR", + # "CountryName": "Turkey", + # "AdministrativeArea": { + # "AdministrativeAreaName": "İstanbul", + # "SubAdministrativeArea": { + # "SubAdministrativeAreaName": "Fatih", + # "Locality": { + # "DependentLocality": { + # "DependentLocalityName": "Saraç İshak Mah.", + # "Thoroughfare": { + # "ThoroughfareName": "Mabeyinci Yokuşu", + # "Premise": { + # "PremiseNumber": "17" + # } + # } + # } + # } + # } + # } + # } + # } + DEPENDENT_LOCALITY_2 = %w[ GeoObject metaDataProperty GeocoderMetaData AddressDetails Country From ebe34b2e6a40295839400d943252309075c3a058 Mon Sep 17 00:00:00 2001 From: Yaroslav Litvinov <beyondthemkad@gmail.com> Date: Sat, 29 Sep 2018 13:36:54 +0300 Subject: [PATCH 227/248] trim some fixtures we don't need all data, just 1 object of each response --- test/fixtures/yandex_kremlin | 469 ------------------------------- test/fixtures/yandex_new_york | 338 ---------------------- test/fixtures/yandex_ontario | 510 ---------------------------------- 3 files changed, 1317 deletions(-) diff --git a/test/fixtures/yandex_kremlin b/test/fixtures/yandex_kremlin index d73fdff14..77ac19451 100644 --- a/test/fixtures/yandex_kremlin +++ b/test/fixtures/yandex_kremlin @@ -72,475 +72,6 @@ "pos": "37.617734 55.751999" } } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "other", - "text": "Russia, Moscow, Kremlin Wall Necropolis", - "precision": "other", - "Address": { - "country_code": "RU", - "formatted": "Moscow, Kremlin Wall Necropolis", - "Components": [ - { - "kind": "country", - "name": "Russia" - }, - { - "kind": "province", - "name": "Tsentralny federalny okrug" - }, - { - "kind": "province", - "name": "Moscow" - }, - { - "kind": "locality", - "name": "Moscow" - }, - { - "kind": "other", - "name": "Kremlin Wall Necropolis" - } - ] - }, - "AddressDetails": { - "Country": { - "AddressLine": "Moscow, Kremlin Wall Necropolis", - "CountryNameCode": "RU", - "CountryName": "Russia", - "AdministrativeArea": { - "AdministrativeAreaName": "Moscow", - "Locality": { - "LocalityName": "Moscow", - "Premise": { - "PremiseName": "Kremlin Wall Necropolis" - } - } - } - } - } - } - }, - "description": "Moscow, Russia", - "name": "Kremlin Wall Necropolis", - "boundedBy": { - "Envelope": { - "lowerCorner": "37.617824 55.752708", - "upperCorner": "37.621264 55.754487" - } - }, - "Point": { - "pos": "37.619576 55.753559" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "vegetation", - "text": "Russia, Moscow, Small Kremlin Public Garden", - "precision": "other", - "Address": { - "country_code": "RU", - "formatted": "Moscow, Small Kremlin Public Garden", - "Components": [ - { - "kind": "country", - "name": "Russia" - }, - { - "kind": "province", - "name": "Tsentralny federalny okrug" - }, - { - "kind": "province", - "name": "Moscow" - }, - { - "kind": "locality", - "name": "Moscow" - }, - { - "kind": "vegetation", - "name": "Small Kremlin Public Garden" - } - ] - }, - "AddressDetails": { - "Country": { - "AddressLine": "Moscow, Small Kremlin Public Garden", - "CountryNameCode": "RU", - "CountryName": "Russia", - "AdministrativeArea": { - "AdministrativeAreaName": "Moscow", - "Locality": { - "LocalityName": "Moscow", - "Premise": { - "PremiseName": "Small Kremlin Public Garden" - } - } - } - } - } - } - }, - "description": "Moscow, Russia", - "name": "Small Kremlin Public Garden", - "boundedBy": { - "Envelope": { - "lowerCorner": "37.616467 55.751452", - "upperCorner": "37.617788 55.752004" - } - }, - "Point": { - "pos": "37.61706 55.751731" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "vegetation", - "text": "Russia, Moscow, Grand Kremlin Public Garden", - "precision": "other", - "Address": { - "country_code": "RU", - "formatted": "Moscow, Grand Kremlin Public Garden", - "Components": [ - { - "kind": "country", - "name": "Russia" - }, - { - "kind": "province", - "name": "Tsentralny federalny okrug" - }, - { - "kind": "province", - "name": "Moscow" - }, - { - "kind": "locality", - "name": "Moscow" - }, - { - "kind": "vegetation", - "name": "Grand Kremlin Public Garden" - } - ] - }, - "AddressDetails": { - "Country": { - "AddressLine": "Moscow, Grand Kremlin Public Garden", - "CountryNameCode": "RU", - "CountryName": "Russia", - "AdministrativeArea": { - "AdministrativeAreaName": "Moscow", - "Locality": { - "LocalityName": "Moscow", - "Premise": { - "PremiseName": "Grand Kremlin Public Garden" - } - } - } - } - } - } - }, - "description": "Moscow, Russia", - "name": "Grand Kremlin Public Garden", - "boundedBy": { - "Envelope": { - "lowerCorner": "37.618336 55.749922", - "upperCorner": "37.621956 55.75246" - } - }, - "Point": { - "pos": "37.620447 55.751031" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "street", - "text": "Russia, Moscow, Kremlyovsky Drive", - "precision": "street", - "Address": { - "country_code": "RU", - "formatted": "Moscow, Kremlyovsky Drive", - "Components": [ - { - "kind": "country", - "name": "Russia" - }, - { - "kind": "province", - "name": "Tsentralny federalny okrug" - }, - { - "kind": "province", - "name": "Moscow" - }, - { - "kind": "locality", - "name": "Moscow" - }, - { - "kind": "street", - "name": "Kremlyovsky Drive" - } - ] - }, - "AddressDetails": { - "Country": { - "AddressLine": "Moscow, Kremlyovsky Drive", - "CountryNameCode": "RU", - "CountryName": "Russia", - "AdministrativeArea": { - "AdministrativeAreaName": "Moscow", - "Locality": { - "LocalityName": "Moscow", - "Thoroughfare": { - "ThoroughfareName": "Kremlyovsky Drive" - } - } - } - } - } - } - }, - "description": "Moscow, Russia", - "name": "Kremlyovsky Drive", - "boundedBy": { - "Envelope": { - "lowerCorner": "37.616566 55.754649", - "upperCorner": "37.61812 55.755469" - } - }, - "Point": { - "pos": "37.61733 55.755044" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "street", - "text": "Russia, Republic of Tatarstan, City of Kazan, Kremlevskaya Street", - "precision": "street", - "Address": { - "country_code": "RU", - "formatted": "Republic of Tatarstan, City of Kazan, Kremlevskaya Street", - "Components": [ - { - "kind": "country", - "name": "Russia" - }, - { - "kind": "province", - "name": "Privolzhskiy federalny okrug" - }, - { - "kind": "province", - "name": "Republic of Tatarstan" - }, - { - "kind": "area", - "name": "Kazan City District" - }, - { - "kind": "locality", - "name": "City of Kazan" - }, - { - "kind": "street", - "name": "Kremlevskaya Street" - } - ] - }, - "AddressDetails": { - "Country": { - "AddressLine": "Republic of Tatarstan, City of Kazan, Kremlevskaya Street", - "CountryNameCode": "RU", - "CountryName": "Russia", - "AdministrativeArea": { - "AdministrativeAreaName": "Republic of Tatarstan", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Kazan City District", - "Locality": { - "LocalityName": "City of Kazan", - "Thoroughfare": { - "ThoroughfareName": "Kremlevskaya Street" - } - } - } - } - } - } - } - }, - "description": "City of Kazan, Republic of Tatarstan, Russia", - "name": "Kremlevskaya Street", - "boundedBy": { - "Envelope": { - "lowerCorner": "49.108372 55.790651", - "upperCorner": "49.123105 55.796653" - } - }, - "Point": { - "pos": "49.11573 55.793637" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "street", - "text": "Russia, Republic of Tatarstan, City of Kazan, Kremlevskiy Bridge", - "precision": "street", - "Address": { - "country_code": "RU", - "formatted": "Republic of Tatarstan, City of Kazan, Kremlevskiy Bridge", - "Components": [ - { - "kind": "country", - "name": "Russia" - }, - { - "kind": "province", - "name": "Privolzhskiy federalny okrug" - }, - { - "kind": "province", - "name": "Republic of Tatarstan" - }, - { - "kind": "area", - "name": "Kazan City District" - }, - { - "kind": "locality", - "name": "City of Kazan" - }, - { - "kind": "street", - "name": "Kremlevskiy Bridge" - } - ] - }, - "AddressDetails": { - "Country": { - "AddressLine": "Republic of Tatarstan, City of Kazan, Kremlevskiy Bridge", - "CountryNameCode": "RU", - "CountryName": "Russia", - "AdministrativeArea": { - "AdministrativeAreaName": "Republic of Tatarstan", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Kazan City District", - "Locality": { - "LocalityName": "City of Kazan", - "Thoroughfare": { - "ThoroughfareName": "Kremlevskiy Bridge" - } - } - } - } - } - } - } - }, - "description": "City of Kazan, Republic of Tatarstan, Russia", - "name": "Kremlevskiy Bridge", - "boundedBy": { - "Envelope": { - "lowerCorner": "49.101374 55.79973", - "upperCorner": "49.102291 55.802664" - } - }, - "Point": { - "pos": "49.101913 55.801217" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "street", - "text": "Russia, Republic of Tatarstan, City of Kazan, Kremlevskaya Embankment", - "precision": "street", - "Address": { - "country_code": "RU", - "formatted": "Republic of Tatarstan, City of Kazan, Kremlevskaya Embankment", - "Components": [ - { - "kind": "country", - "name": "Russia" - }, - { - "kind": "province", - "name": "Privolzhskiy federalny okrug" - }, - { - "kind": "province", - "name": "Republic of Tatarstan" - }, - { - "kind": "area", - "name": "Kazan City District" - }, - { - "kind": "locality", - "name": "City of Kazan" - }, - { - "kind": "street", - "name": "Kremlevskaya Embankment" - } - ] - }, - "AddressDetails": { - "Country": { - "AddressLine": "Republic of Tatarstan, City of Kazan, Kremlevskaya Embankment", - "CountryNameCode": "RU", - "CountryName": "Russia", - "AdministrativeArea": { - "AdministrativeAreaName": "Republic of Tatarstan", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Kazan City District", - "Locality": { - "LocalityName": "City of Kazan", - "Thoroughfare": { - "ThoroughfareName": "Kremlevskaya Embankment" - } - } - } - } - } - } - } - }, - "description": "City of Kazan, Republic of Tatarstan, Russia", - "name": "Kremlevskaya Embankment", - "boundedBy": { - "Envelope": { - "lowerCorner": "49.091358 55.795454", - "upperCorner": "49.102021 55.800858" - } - }, - "Point": { - "pos": "49.096676 55.798191" - } - } } ] } diff --git a/test/fixtures/yandex_new_york b/test/fixtures/yandex_new_york index 3c0bd3afa..5bfa354b3 100644 --- a/test/fixtures/yandex_new_york +++ b/test/fixtures/yandex_new_york @@ -41,344 +41,6 @@ "pos": "-74.007112 40.714545" } } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "locality", - "text": "United States, New York, Bronx, New York", - "precision": "other", - "AddressDetails": { - "Country": { - "AddressLine": "New York, Bronx, New York", - "CountryNameCode": "US", - "CountryName": "United States", - "AdministrativeArea": { - "AdministrativeAreaName": "New York", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Bronx", - "Locality": { - "LocalityName": "New York" - } - } - } - } - } - } - }, - "description": "Bronx, New York, United States", - "name": "New York", - "boundedBy": { - "Envelope": { - "lowerCorner": "-74.258892 40.477414", - "upperCorner": "-73.700373 40.917616" - } - }, - "Point": { - "pos": "-74.007112 40.714545" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "hydro", - "text": "United States, Upper New York Bay", - "precision": "other", - "AddressDetails": { - "Country": { - "AddressLine": "Upper New York Bay", - "CountryNameCode": "US", - "CountryName": "United States", - "Locality": { - "Premise": { - "PremiseName": "Upper New York Bay" - } - } - } - } - } - }, - "description": "United States", - "name": "Upper New York Bay", - "boundedBy": { - "Envelope": { - "lowerCorner": "-74.107633 40.604124", - "upperCorner": "-73.998434 40.706697" - } - }, - "Point": { - "pos": "-74.048758 40.660893" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "locality", - "text": "United States, New Jersey, Hudson, West New York", - "precision": "other", - "AddressDetails": { - "Country": { - "AddressLine": "New Jersey, Hudson, West New York", - "CountryNameCode": "US", - "CountryName": "United States", - "AdministrativeArea": { - "AdministrativeAreaName": "New Jersey", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Hudson", - "Locality": { - "LocalityName": "West New York" - } - } - } - } - } - } - }, - "description": "Hudson, New Jersey, United States", - "name": "West New York", - "boundedBy": { - "Envelope": { - "lowerCorner": "-74.023569 40.7746", - "upperCorner": "-73.992936 40.796565" - } - }, - "Point": { - "pos": "-74.015260 40.788325" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "locality", - "text": "United Kingdom of Great Britain and Northern Ireland, England, Lincolnshire, East Lindsey, New York", - "precision": "other", - "AddressDetails": { - "Country": { - "AddressLine": "England, Lincolnshire, East Lindsey, New York", - "CountryNameCode": "GB", - "CountryName": "United Kingdom of Great Britain and Northern Ireland", - "AdministrativeArea": { - "AdministrativeAreaName": "England", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Lincolnshire", - "Locality": { - "LocalityName": "New York" - } - } - } - } - } - } - }, - "description": "East Lindsey, Lincolnshire, England, United Kingdom of Great Britain and Northern Ireland", - "name": "New York", - "boundedBy": { - "Envelope": { - "lowerCorner": "-0.205993 53.039103", - "upperCorner": "-0.074192 53.11847" - } - }, - "Point": { - "pos": "-0.140092 53.078805" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "locality", - "text": "South Africa, North West, Bophirima, Naledi, New York", - "precision": "other", - "AddressDetails": { - "Country": { - "AddressLine": "North West, Bophirima, Naledi, New York", - "CountryNameCode": "ZA", - "CountryName": "South Africa", - "AdministrativeArea": { - "AdministrativeAreaName": "North West", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Bophirima", - "Locality": { - "LocalityName": "New York" - } - } - } - } - } - } - }, - "description": "Naledi, Bophirima, North West, South Africa", - "name": "New York", - "boundedBy": { - "Envelope": { - "lowerCorner": "24.454037 -26.943742", - "upperCorner": "24.585838 -26.825556" - } - }, - "Point": { - "pos": "24.519938 -26.884665" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "locality", - "text": "United States, New Mexico, Cibola, New York", - "precision": "other", - "AddressDetails": { - "Country": { - "AddressLine": "New Mexico, Cibola, New York", - "CountryNameCode": "US", - "CountryName": "United States", - "AdministrativeArea": { - "AdministrativeAreaName": "New Mexico", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Cibola", - "Locality": { - "LocalityName": "New York" - } - } - } - } - } - } - }, - "description": "Cibola, New Mexico, United States", - "name": "New York", - "boundedBy": { - "Envelope": { - "lowerCorner": "-107.592515 35.00522", - "upperCorner": "-107.460714 35.113594" - } - }, - "Point": { - "pos": "-107.526615 35.059425" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "locality", - "text": "United States, Iowa, Wayne, New York", - "precision": "other", - "AddressDetails": { - "Country": { - "AddressLine": "Iowa, Wayne, New York", - "CountryNameCode": "US", - "CountryName": "United States", - "AdministrativeArea": { - "AdministrativeAreaName": "Iowa", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Wayne", - "Locality": { - "LocalityName": "New York" - } - } - } - } - } - } - }, - "description": "Wayne, Iowa, United States", - "name": "New York", - "boundedBy": { - "Envelope": { - "lowerCorner": "-93.32337 40.801487", - "upperCorner": "-93.191569 40.901567" - } - }, - "Point": { - "pos": "-93.257469 40.851546" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "locality", - "text": "United States, Missouri, Caldwell, New York", - "precision": "other", - "AddressDetails": { - "Country": { - "AddressLine": "Missouri, Caldwell, New York", - "CountryNameCode": "US", - "CountryName": "United States", - "AdministrativeArea": { - "AdministrativeAreaName": "Missouri", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Caldwell", - "Locality": { - "LocalityName": "New York" - } - } - } - } - } - } - }, - "description": "Caldwell, Missouri, United States", - "name": "New York", - "boundedBy": { - "Envelope": { - "lowerCorner": "-93.97525 39.633979", - "upperCorner": "-93.843449 39.735813" - } - }, - "Point": { - "pos": "-93.909350 39.684915" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "locality", - "text": "United States, Texas, Henderson, New York", - "precision": "other", - "AddressDetails": { - "Country": { - "AddressLine": "Texas, Henderson, New York", - "CountryNameCode": "US", - "CountryName": "United States", - "AdministrativeArea": { - "AdministrativeAreaName": "Texas", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Henderson", - "Locality": { - "LocalityName": "New York" - } - } - } - } - } - } - }, - "description": "Henderson, Texas, United States", - "name": "New York", - "boundedBy": { - "Envelope": { - "lowerCorner": "-95.735086 32.112428", - "upperCorner": "-95.603285 32.224535" - } - }, - "Point": { - "pos": "-95.669185 32.168499" - } - } } ] } diff --git a/test/fixtures/yandex_ontario b/test/fixtures/yandex_ontario index 6afca1bb2..478989c38 100644 --- a/test/fixtures/yandex_ontario +++ b/test/fixtures/yandex_ontario @@ -54,516 +54,6 @@ "pos": "-87.170557 49.294248" } } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "locality", - "text": "United States of America, California, San Bernardino County, Ontario", - "precision": "other", - "Address": { - "country_code": "US", - "formatted": "California, San Bernardino County, Ontario", - "Components": [ - { - "kind": "country", - "name": "United States of America" - }, - { - "kind": "province", - "name": "California" - }, - { - "kind": "area", - "name": "San Bernardino County" - }, - { - "kind": "locality", - "name": "Ontario" - } - ] - }, - "AddressDetails": { - "Country": { - "AddressLine": "California, San Bernardino County, Ontario", - "CountryNameCode": "US", - "CountryName": "United States of America", - "AdministrativeArea": { - "AdministrativeAreaName": "California", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "San Bernardino County", - "Locality": { - "LocalityName": "Ontario" - } - } - } - } - } - } - }, - "description": "San Bernardino County, California, United States of America", - "name": "Ontario", - "boundedBy": { - "Envelope": { - "lowerCorner": "-117.681844 33.975275", - "upperCorner": "-117.524028 34.093373" - } - }, - "Point": { - "pos": "-117.627586 34.054599" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "hydro", - "text": "Lake Ontario", - "precision": "other", - "Address": { - "formatted": "Lake Ontario", - "Components": [ - { - "kind": "hydro", - "name": "Lake Ontario" - } - ] - }, - "AddressDetails": { - "Locality": { - "Premise": { - "PremiseName": "Lake Ontario" - } - } - } - } - }, - "name": "Lake Ontario", - "boundedBy": { - "Envelope": { - "lowerCorner": "-79.801686 43.1625", - "upperCorner": "-76.008585 44.244197" - } - }, - "Point": { - "pos": "-77.804812 43.6384" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "locality", - "text": "United States of America, State of Oregon, Malheur County, Ontario", - "precision": "other", - "Address": { - "country_code": "US", - "formatted": "State of Oregon, Malheur County, Ontario", - "Components": [ - { - "kind": "country", - "name": "United States of America" - }, - { - "kind": "province", - "name": "State of Oregon" - }, - { - "kind": "area", - "name": "Malheur County" - }, - { - "kind": "locality", - "name": "Ontario" - } - ] - }, - "AddressDetails": { - "Country": { - "AddressLine": "State of Oregon, Malheur County, Ontario", - "CountryNameCode": "US", - "CountryName": "United States of America", - "AdministrativeArea": { - "AdministrativeAreaName": "State of Oregon", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Malheur County", - "Locality": { - "LocalityName": "Ontario" - } - } - } - } - } - } - }, - "description": "Malheur County, State of Oregon, United States of America", - "name": "Ontario", - "boundedBy": { - "Envelope": { - "lowerCorner": "-116.970487 44.014537", - "upperCorner": "-116.943744 44.038966" - } - }, - "Point": { - "pos": "-116.962968 44.026639" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "district", - "text": "Canada, City of Montreal, Centre-Ville, Terrasse Ontario", - "precision": "other", - "Address": { - "country_code": "CA", - "formatted": "City of Montreal, Centre-Ville, Terrasse Ontario", - "Components": [ - { - "kind": "country", - "name": "Canada" - }, - { - "kind": "locality", - "name": "City of Montreal" - }, - { - "kind": "district", - "name": "Centre-Ville" - }, - { - "kind": "district", - "name": "Terrasse Ontario" - } - ] - }, - "AddressDetails": { - "Country": { - "AddressLine": "City of Montreal, Centre-Ville, Terrasse Ontario", - "CountryNameCode": "CA", - "CountryName": "Canada", - "Locality": { - "LocalityName": "City of Montreal", - "DependentLocality": { - "DependentLocalityName": "Centre-Ville", - "DependentLocality": { - "DependentLocalityName": "Terrasse Ontario" - } - } - } - } - } - } - }, - "description": "Centre-Ville, City of Montreal, Canada", - "name": "Terrasse Ontario", - "boundedBy": { - "Envelope": { - "lowerCorner": "-73.583251 45.507018", - "upperCorner": "-73.550318 45.53017" - } - }, - "Point": { - "pos": "-73.566785 45.518595" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "area", - "text": "United States of America, New York, Ontario County", - "precision": "other", - "Address": { - "country_code": "US", - "formatted": "New York, Ontario County", - "Components": [ - { - "kind": "country", - "name": "United States of America" - }, - { - "kind": "province", - "name": "New York" - }, - { - "kind": "area", - "name": "Ontario County" - } - ] - }, - "AddressDetails": { - "Country": { - "AddressLine": "New York, Ontario County", - "CountryNameCode": "US", - "CountryName": "United States of America", - "AdministrativeArea": { - "AdministrativeAreaName": "New York", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Ontario County" - } - } - } - } - } - }, - "description": "New York, United States of America", - "name": "Ontario County", - "boundedBy": { - "Envelope": { - "lowerCorner": "-77.612581 42.576595", - "upperCorner": "-76.964087 43.040597" - } - }, - "Point": { - "pos": "-77.281965 42.807695" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "locality", - "text": "United States of America, Kansas, Nemaha County, Ontario", - "precision": "other", - "Address": { - "country_code": "US", - "formatted": "Kansas, Nemaha County, Ontario", - "Components": [ - { - "kind": "country", - "name": "United States of America" - }, - { - "kind": "province", - "name": "Kansas" - }, - { - "kind": "area", - "name": "Nemaha County" - }, - { - "kind": "locality", - "name": "Ontario" - } - ] - }, - "AddressDetails": { - "Country": { - "AddressLine": "Kansas, Nemaha County, Ontario", - "CountryNameCode": "US", - "CountryName": "United States of America", - "AdministrativeArea": { - "AdministrativeAreaName": "Kansas", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Nemaha County", - "Locality": { - "LocalityName": "Ontario" - } - } - } - } - } - } - }, - "description": "Nemaha County, Kansas, United States of America", - "name": "Ontario", - "boundedBy": { - "Envelope": { - "lowerCorner": "-95.94849 39.515074", - "upperCorner": "-95.816689 39.617085" - } - }, - "Point": { - "pos": "-95.882589 39.566098" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "locality", - "text": "United States of America, Oklahoma, Ottawa County, Ontario", - "precision": "other", - "Address": { - "country_code": "US", - "formatted": "Oklahoma, Ottawa County, Ontario", - "Components": [ - { - "kind": "country", - "name": "United States of America" - }, - { - "kind": "province", - "name": "Oklahoma" - }, - { - "kind": "area", - "name": "Ottawa County" - }, - { - "kind": "locality", - "name": "Ontario" - } - ] - }, - "AddressDetails": { - "Country": { - "AddressLine": "Oklahoma, Ottawa County, Ontario", - "CountryNameCode": "US", - "CountryName": "United States of America", - "AdministrativeArea": { - "AdministrativeAreaName": "Oklahoma", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Ottawa County", - "Locality": { - "LocalityName": "Ontario" - } - } - } - } - } - } - }, - "description": "Ottawa County, Oklahoma, United States of America", - "name": "Ontario", - "boundedBy": { - "Envelope": { - "lowerCorner": "-94.823987 36.934211", - "upperCorner": "-94.692187 37.039943" - } - }, - "Point": { - "pos": "-94.758087 36.987095" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "locality", - "text": "United States of America, State of Iowa, Story County, Ontario", - "precision": "other", - "Address": { - "country_code": "US", - "formatted": "State of Iowa, Story County, Ontario", - "Components": [ - { - "kind": "country", - "name": "United States of America" - }, - { - "kind": "province", - "name": "State of Iowa" - }, - { - "kind": "area", - "name": "Story County" - }, - { - "kind": "locality", - "name": "Ontario" - } - ] - }, - "AddressDetails": { - "Country": { - "AddressLine": "State of Iowa, Story County, Ontario", - "CountryNameCode": "US", - "CountryName": "United States of America", - "AdministrativeArea": { - "AdministrativeAreaName": "State of Iowa", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Story County", - "Locality": { - "LocalityName": "Ontario" - } - } - } - } - } - } - }, - "description": "Story County, State of Iowa, United States of America", - "name": "Ontario", - "boundedBy": { - "Envelope": { - "lowerCorner": "-93.747384 41.985247", - "upperCorner": "-93.615583 42.083505" - } - }, - "Point": { - "pos": "-93.681483 42.034395" - } - } - }, - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "locality", - "text": "United States of America, Wisconsin, Vernon County, Ontario", - "precision": "other", - "Address": { - "country_code": "US", - "formatted": "Wisconsin, Vernon County, Ontario", - "Components": [ - { - "kind": "country", - "name": "United States of America" - }, - { - "kind": "province", - "name": "Wisconsin" - }, - { - "kind": "area", - "name": "Vernon County" - }, - { - "kind": "locality", - "name": "Ontario" - } - ] - }, - "AddressDetails": { - "Country": { - "AddressLine": "Wisconsin, Vernon County, Ontario", - "CountryNameCode": "US", - "CountryName": "United States of America", - "AdministrativeArea": { - "AdministrativeAreaName": "Wisconsin", - "SubAdministrativeArea": { - "SubAdministrativeAreaName": "Vernon County", - "Locality": { - "LocalityName": "Ontario" - } - } - } - } - } - } - }, - "description": "Vernon County, Wisconsin, United States of America", - "name": "Ontario", - "boundedBy": { - "Envelope": { - "lowerCorner": "-90.657089 43.678184", - "upperCorner": "-90.525288 43.773766" - } - }, - "Point": { - "pos": "-90.591189 43.725994" - } - } } ] } From 67831450999d53c26a6f7009910ffd38393cb6b4 Mon Sep 17 00:00:00 2001 From: Yaroslav Litvinov <beyondthemkad@gmail.com> Date: Sun, 30 Sep 2018 15:01:03 +0300 Subject: [PATCH 228/248] respect register for fixture auto lookup --- test/unit/lookups/yandex_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/lookups/yandex_test.rb b/test/unit/lookups/yandex_test.rb index 347a3c055..a6b711cfe 100644 --- a/test/unit/lookups/yandex_test.rb +++ b/test/unit/lookups/yandex_test.rb @@ -113,7 +113,7 @@ def test_yandex_maximum_precision_on_russian_address end def test_yandex_hydro_object - result = Geocoder.search('Volga river').first + result = Geocoder.search('volga river').first assert_equal [49.550996, 45.139984], result.coordinates assert_equal [45.697053, 32.468241, 58.194645, 50.181608], result.viewport @@ -134,7 +134,7 @@ def test_yandex_hydro_object end def test_yandex_province_object - result = Geocoder.search('Ontario').first + result = Geocoder.search('ontario').first assert_equal [49.294248, -87.170557], result.coordinates assert_equal [41.704494, -95.153382, 56.88699, -74.321387], result.viewport From 2ae4650e950e24d66625de36b281675481dab78f Mon Sep 17 00:00:00 2001 From: Yaroslav Litvinov <beyondthemkad@gmail.com> Date: Wed, 17 Oct 2018 15:19:31 +0300 Subject: [PATCH 229/248] Geocoder::Result::Yandex: test dig_data --- lib/geocoder/results/yandex.rb | 12 +++++++++--- test/unit/lookups/yandex_test.rb | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/geocoder/results/yandex.rb b/lib/geocoder/results/yandex.rb index cb95469b9..57153fc23 100644 --- a/lib/geocoder/results/yandex.rb +++ b/lib/geocoder/results/yandex.rb @@ -278,9 +278,15 @@ def premise def dig_data(source, *keys) key = keys.shift - result = source.fetch(key, nil) - return result unless result.is_a?(Hash) - keys.any? ? dig_data(result, *keys) : result + result = source[key] + + if keys.empty? + return result + elsif !result.is_a?(Hash) + return nil + end + + dig_data(result, *keys) end end end diff --git a/test/unit/lookups/yandex_test.rb b/test/unit/lookups/yandex_test.rb index a6b711cfe..dd22b3a1b 100644 --- a/test/unit/lookups/yandex_test.rb +++ b/test/unit/lookups/yandex_test.rb @@ -89,6 +89,24 @@ def test_yandex_result_returns_street_number end end + def test_yandex_dig_data_method + result = Geocoder::Result::Yandex.new({}) + hash = { + 'root_node' => { + 'node_1' => [1, 2, 3], + 'node_2' => { + 'data' => 'foo' + } + } + } + + assert_equal [1, 2, 3], result.send(:dig_data, hash, 'root_node', 'node_1') + assert_equal "foo", result.send(:dig_data, hash, 'root_node', 'node_2', 'data') + assert_equal nil, result.send(:dig_data, hash, 'root_node', 'node_3') + assert_equal nil, result.send(:dig_data, hash, 'root_node', 'node_2', 'another_data') + assert_equal nil, result.send(:dig_data, hash, 'root_node', 'node_2', 'data', 'x') + end + def test_yandex_maximum_precision_on_russian_address result = Geocoder.search('putilkovo novotushinskaya 5').first From bd792b36485bb3f8f3c86005e87832b64c47c54e Mon Sep 17 00:00:00 2001 From: Yaroslav Litvinov <beyondthemkad@gmail.com> Date: Fri, 19 Oct 2018 13:18:35 +0300 Subject: [PATCH 230/248] fix description --- lib/geocoder/results/yandex.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/geocoder/results/yandex.rb b/lib/geocoder/results/yandex.rb index 57153fc23..6face7c04 100644 --- a/lib/geocoder/results/yandex.rb +++ b/lib/geocoder/results/yandex.rb @@ -71,7 +71,7 @@ class Yandex < Base ].freeze # On SUBADMIN_LEVEL (may refer to urban district) - # example: '' + # example: 'Moscow Region, Krasnogorsk' # "AddressDetails": { # "Country": { # "AddressLine": "Moscow Region, Krasnogorsk", From eeb5d94ba03345d488b20ab3d6d78eb413b2e946 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 16 Mar 2020 08:22:38 -0700 Subject: [PATCH 231/248] Rename dig_data method find_in_hash. Reason: the name `dig_data` implies that the method only works on the @data hash, but it can actually work on any hash. --- lib/geocoder/results/yandex.rb | 32 ++++++++++++++++---------------- test/unit/lookups/yandex_test.rb | 12 ++++++------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/geocoder/results/yandex.rb b/lib/geocoder/results/yandex.rb index 6face7c04..eced22793 100644 --- a/lib/geocoder/results/yandex.rb +++ b/lib/geocoder/results/yandex.rb @@ -173,31 +173,31 @@ def address(_format = :full) def city result = if state.empty? - dig_data(@data, *COUNTRY_LEVEL, 'Locality', 'LocalityName') + find_in_hash(@data, *COUNTRY_LEVEL, 'Locality', 'LocalityName') elsif sub_state.empty? - dig_data(@data, *ADMIN_LEVEL, 'Locality', 'LocalityName') + find_in_hash(@data, *ADMIN_LEVEL, 'Locality', 'LocalityName') else - dig_data(@data, *SUBADMIN_LEVEL, 'Locality', 'LocalityName') + find_in_hash(@data, *SUBADMIN_LEVEL, 'Locality', 'LocalityName') end result || "" end def country - dig_data(@data, *COUNTRY_LEVEL, 'CountryName') || "" + find_in_hash(@data, *COUNTRY_LEVEL, 'CountryName') || "" end def country_code - dig_data(@data, *COUNTRY_LEVEL, 'CountryNameCode') || "" + find_in_hash(@data, *COUNTRY_LEVEL, 'CountryNameCode') || "" end def state - dig_data(@data, *ADMIN_LEVEL, 'AdministrativeAreaName') || "" + find_in_hash(@data, *ADMIN_LEVEL, 'AdministrativeAreaName') || "" end def sub_state return "" if state.empty? - dig_data(@data, *SUBADMIN_LEVEL, 'SubAdministrativeAreaName') || "" + find_in_hash(@data, *SUBADMIN_LEVEL, 'SubAdministrativeAreaName') || "" end def state_code @@ -218,7 +218,7 @@ def premise_name def postal_code return "" unless premise.is_a?(Hash) - dig_data(premise, 'PostalCode', 'PostalCodeNumber') || "" + find_in_hash(premise, 'PostalCode', 'PostalCodeNumber') || "" end def kind @@ -239,24 +239,24 @@ def viewport private # ---------------------------------------------------------------- def top_level_locality - dig_data(@data, *ADDRESS_DETAILS, 'Locality') + find_in_hash(@data, *ADDRESS_DETAILS, 'Locality') end def country_level_locality - dig_data(@data, *COUNTRY_LEVEL, 'Locality') + find_in_hash(@data, *COUNTRY_LEVEL, 'Locality') end def admin_locality - dig_data(@data, *ADMIN_LEVEL, 'Locality') + find_in_hash(@data, *ADMIN_LEVEL, 'Locality') end def subadmin_locality - dig_data(@data, *SUBADMIN_LEVEL, 'Locality') + find_in_hash(@data, *SUBADMIN_LEVEL, 'Locality') end def dependent_locality - dig_data(@data, *DEPENDENT_LOCALITY_1) || - dig_data(@data, *DEPENDENT_LOCALITY_2) + find_in_hash(@data, *DEPENDENT_LOCALITY_1) || + find_in_hash(@data, *DEPENDENT_LOCALITY_2) end def locality_data @@ -276,7 +276,7 @@ def premise end end - def dig_data(source, *keys) + def find_in_hash(source, *keys) key = keys.shift result = source[key] @@ -286,7 +286,7 @@ def dig_data(source, *keys) return nil end - dig_data(result, *keys) + find_in_hash(result, *keys) end end end diff --git a/test/unit/lookups/yandex_test.rb b/test/unit/lookups/yandex_test.rb index dd22b3a1b..9887dfd8b 100644 --- a/test/unit/lookups/yandex_test.rb +++ b/test/unit/lookups/yandex_test.rb @@ -89,7 +89,7 @@ def test_yandex_result_returns_street_number end end - def test_yandex_dig_data_method + def test_yandex_find_in_hash_method result = Geocoder::Result::Yandex.new({}) hash = { 'root_node' => { @@ -100,11 +100,11 @@ def test_yandex_dig_data_method } } - assert_equal [1, 2, 3], result.send(:dig_data, hash, 'root_node', 'node_1') - assert_equal "foo", result.send(:dig_data, hash, 'root_node', 'node_2', 'data') - assert_equal nil, result.send(:dig_data, hash, 'root_node', 'node_3') - assert_equal nil, result.send(:dig_data, hash, 'root_node', 'node_2', 'another_data') - assert_equal nil, result.send(:dig_data, hash, 'root_node', 'node_2', 'data', 'x') + assert_equal [1, 2, 3], result.send(:find_in_hash, hash, 'root_node', 'node_1') + assert_equal "foo", result.send(:find_in_hash, hash, 'root_node', 'node_2', 'data') + assert_equal nil, result.send(:find_in_hash, hash, 'root_node', 'node_3') + assert_equal nil, result.send(:find_in_hash, hash, 'root_node', 'node_2', 'another_data') + assert_equal nil, result.send(:find_in_hash, hash, 'root_node', 'node_2', 'data', 'x') end def test_yandex_maximum_precision_on_russian_address From d3e3f7cb46d1d3b51270186c45fc84d9fbdbfd85 Mon Sep 17 00:00:00 2001 From: David Kelly <david@opensourceame.com> Date: Mon, 16 Mar 2020 21:08:06 +0100 Subject: [PATCH 232/248] Add Netherlands National Geocode Register (#1386) Add the Netherlands National Georegister service. --- lib/geocoder/lookup.rb | 1 + .../lookups/nationaal_georegister_nl.rb | 38 ++ .../results/nationaal_georegister_nl.rb | 64 +++ test/fixtures/nationaal_georegister_nl | 441 ++++++++++++++++++ test/test_helper.rb | 9 + .../lookups/nationaal_georegister_nl_test.rb | 23 + 6 files changed, 576 insertions(+) create mode 100644 lib/geocoder/lookups/nationaal_georegister_nl.rb create mode 100644 lib/geocoder/results/nationaal_georegister_nl.rb create mode 100644 test/fixtures/nationaal_georegister_nl create mode 100644 test/unit/lookups/nationaal_georegister_nl_test.rb diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index 732e19eac..40fa94100 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -33,6 +33,7 @@ def street_services :bing, :geocoder_ca, :yandex, + :nationaal_georegister_nl, :nominatim, :mapbox, :mapquest, diff --git a/lib/geocoder/lookups/nationaal_georegister_nl.rb b/lib/geocoder/lookups/nationaal_georegister_nl.rb new file mode 100644 index 000000000..af1256ba1 --- /dev/null +++ b/lib/geocoder/lookups/nationaal_georegister_nl.rb @@ -0,0 +1,38 @@ +require 'geocoder/lookups/base' +require "geocoder/results/nationaal_georegister_nl" + +module Geocoder::Lookup + class NationaalGeoregisterNl < Base + + def name + 'Nationaal Georegister Nederland' + end + + private # --------------------------------------------------------------- + + def cache_key(query) + base_query_url(query) + hash_to_query(query_url_params(query)) + end + + def base_query_url(query) + "#{protocol}://geodata.nationaalgeoregister.nl/locatieserver/v3/free?" + end + + def valid_response?(response) + json = parse_json(response.body) + super(response) if json + end + + def results(query) + return [] unless doc = fetch_data(query) + return doc['response']['docs'] + end + + def query_url_params(query) + { + fl: '*', + q: query.text + }.merge(super) + end + end +end diff --git a/lib/geocoder/results/nationaal_georegister_nl.rb b/lib/geocoder/results/nationaal_georegister_nl.rb new file mode 100644 index 000000000..d980513aa --- /dev/null +++ b/lib/geocoder/results/nationaal_georegister_nl.rb @@ -0,0 +1,64 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class NationaalGeoregisterNl < Base + + def response_attributes + @data + end + + def coordinates + lat, lng = @data['centroide_ll'][6..-2].split(' ') + + [lat, lng] + end + + def formatted_address + @data['weergavenaam'] + end + + alias_method :address, :formatted_address + + def province + @data['provincienaam'] + end + + alias_method :state, :province + + def city + @data['woonplaatsnaam'] + end + + def district + @data['gemeentenaam'] + end + + def street + @data['straatnaam'] + end + + def street_number + @data['huis_nlt'] + end + + def address_components + @data + end + + def state_code + @data['provinciecode'] + end + + def postal_code + @data['postcode'] + end + + def country + "Netherlands" + end + + def country_code + "NL" + end + end +end diff --git a/test/fixtures/nationaal_georegister_nl b/test/fixtures/nationaal_georegister_nl new file mode 100644 index 000000000..a41c0cad2 --- /dev/null +++ b/test/fixtures/nationaal_georegister_nl @@ -0,0 +1,441 @@ +{ + "response": { + "numFound": 10242, + "start": 0, + "maxScore": 61.028397, + "docs": [ + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "147", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200000218908", + "weergavenaam": "Nieuwezijds Voorburgwal 147, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 147, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 147, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-563f90756e46d1c554b4ab00ac61b932", + "gekoppeld_perceel": [ + "ASD04-F-2749" + ], + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363010000758545-0363200000218908", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89089949 52.37316397)", + "centroide_ll": "POINT(4.89089949 52.37316397)", + "nummeraanduiding_id": "0363200000218908", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363010000758545", + "huisnummer": 147, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121202 487370)", + "geometrie_rd": "POINT(121202 487370)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627309871432990700, + "typesortering": 4, + "sortering": 147, + "shard": "bag" + }, + { + "bron": "BAG", + "suggest": [ + "Nieuwezijds Voorburgwal, 1012 RJ Amsterdam", + "Nieuwezijds Voorburgwal, 1012RJ Amsterdam" + ], + "woonplaatscode": "3594", + "type": "postcode", + "woonplaatsnaam": "Amsterdam", + "openbareruimtetype": "Weg", + "gemeentecode": "0363", + "weergavenaam": "Nieuwezijds Voorburgwal, 1012RJ Amsterdam", + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "pcd-07ad1c9a6086b4ffd4b885b4cc12f513", + "gemeentenaam": "Amsterdam", + "identificatie": "0363300000004690_1012RJ", + "openbareruimte_id": "0363300000004690", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89133064 52.3739109)", + "centroide_ll": "POINT(4.89133064 52.3739109)", + "provincieafkorting": "NH", + "centroide_rd": "POINT(121231.93 487452.904)", + "geometrie_rd": "POINT(121231.93 487452.904)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627316920607834000, + "typesortering": 3.5, + "shard": "bag" + }, + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "125", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200000218874", + "weergavenaam": "Nieuwezijds Voorburgwal 125, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 125, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 125, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-00c3407685fcd67989bb2915acdee929", + "gekoppeld_perceel": [ + "ASD04-F-2732" + ], + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363010000758517-0363200000218874", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89153483 52.37412832)", + "centroide_ll": "POINT(4.89153483 52.37412832)", + "nummeraanduiding_id": "0363200000218874", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363010000758517", + "huisnummer": 125, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121246 487477)", + "geometrie_rd": "POINT(121246 487477)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627309871418310700, + "typesortering": 4, + "sortering": 125, + "shard": "bag" + }, + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "127", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200012076682", + "weergavenaam": "Nieuwezijds Voorburgwal 127, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 127, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 127, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-bb2a9b0c4090656cd8a31e3cdfa26701", + "gekoppeld_perceel": [ + "ASD04-F-2731" + ], + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363010012076291-0363200012076682", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89147613 52.37412482)", + "centroide_ll": "POINT(4.89147613 52.37412482)", + "nummeraanduiding_id": "0363200012076682", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363010012076291", + "huisnummer": 127, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121242 487476.638)", + "geometrie_rd": "POINT(121242 487476.638)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627310053758337000, + "typesortering": 4, + "sortering": 127, + "shard": "bag" + }, + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "129", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200012076683", + "weergavenaam": "Nieuwezijds Voorburgwal 129, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 129, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 129, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-e3339f855fd23024786c719e404fe9e8", + "gekoppeld_perceel": [ + "ASD04-F-2729" + ], + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363010012076292-0363200012076683", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89141948 52.37411589)", + "centroide_ll": "POINT(4.89141948 52.37411589)", + "nummeraanduiding_id": "0363200012076683", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363010012076292", + "huisnummer": 129, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121238.135 487475.671)", + "geometrie_rd": "POINT(121238.135 487475.671)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627310053759385600, + "typesortering": 4, + "sortering": 129, + "shard": "bag" + }, + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "133", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200000218889", + "weergavenaam": "Nieuwezijds Voorburgwal 133, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 133, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 133, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-0c4f985c4b63168eb4327f76774deef1", + "gekoppeld_perceel": [ + "ASD04-F-7847" + ], + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363010000758534-0363200000218889", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89128581 52.37407335)", + "centroide_ll": "POINT(4.89128581 52.37407335)", + "nummeraanduiding_id": "0363200000218889", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363010000758534", + "huisnummer": 133, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121229 487471)", + "geometrie_rd": "POINT(121229 487471)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627309871428796400, + "typesortering": 4, + "sortering": 133, + "shard": "bag" + }, + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "135", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200000218892", + "weergavenaam": "Nieuwezijds Voorburgwal 135, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 135, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 135, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-741c0d7a8cab9ea398e8e5de0fb6e841", + "gekoppeld_perceel": [ + "ASD04-F-7847" + ], + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363010000758537-0363200000218892", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89122747 52.37403716)", + "centroide_ll": "POINT(4.89122747 52.37403716)", + "nummeraanduiding_id": "0363200000218892", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363010000758537", + "huisnummer": 135, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121225 487467)", + "geometrie_rd": "POINT(121225 487467)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627309871429845000, + "typesortering": 4, + "sortering": 135, + "shard": "bag" + }, + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "137", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200000218895", + "weergavenaam": "Nieuwezijds Voorburgwal 137, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 137, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 137, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-49b25fb1d14a09d548beb984452010a8", + "gekoppeld_perceel": [ + "ASD04-F-7847" + ], + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363010000758540-0363200000218895", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89116944 52.373974)", + "centroide_ll": "POINT(4.89116944 52.373974)", + "nummeraanduiding_id": "0363200000218895", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363010000758540", + "huisnummer": 137, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121221 487460)", + "geometrie_rd": "POINT(121221 487460)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627309871430893600, + "typesortering": 4, + "sortering": 137, + "shard": "bag" + }, + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "141", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200000218902", + "weergavenaam": "Nieuwezijds Voorburgwal 141, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 141, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 141, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-2e8a1e522b5cacd766fbe23b58da4f8c", + "gekoppeld_perceel": [ + "ASD04-F-5658" + ], + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363010000758542-0363200000218902", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89108546 52.37390916)", + "centroide_ll": "POINT(4.89108546 52.37390916)", + "nummeraanduiding_id": "0363200000218902", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363010000758542", + "huisnummer": 141, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121215.232 487452.825)", + "geometrie_rd": "POINT(121215.232 487452.825)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627309871430893600, + "typesortering": 4, + "sortering": 141, + "shard": "bag" + }, + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "143", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200012093196", + "weergavenaam": "Nieuwezijds Voorburgwal 143, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 143, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 143, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-5b6658e7817f0c7fcf29b7874b4e396c", + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363200012093196-0363200012093196", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89187769 52.37367138)", + "centroide_ll": "POINT(4.89187769 52.37367138)", + "nummeraanduiding_id": "0363200012093196", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363200012093196", + "huisnummer": 143, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121269 487426)", + "geometrie_rd": "POINT(121269 487426)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627310104285020200, + "typesortering": 4, + "sortering": 143, + "shard": "bag" + } + ] + } +} diff --git a/test/test_helper.rb b/test/test_helper.rb index 8d78b1a62..7b9cf3acc 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -321,6 +321,7 @@ def results query end end + require 'geocoder/lookups/baidu' class Baidu private @@ -329,6 +330,14 @@ def default_fixture_filename end end + require 'geocoder/lookups/nationaal_georegister_nl' + class NationaalGeoregisterNl + private + def default_fixture_filename + "nationaal_georegister_nl" + end + end + require 'geocoder/lookups/baidu_ip' class BaiduIp private diff --git a/test/unit/lookups/nationaal_georegister_nl_test.rb b/test/unit/lookups/nationaal_georegister_nl_test.rb new file mode 100644 index 000000000..d2ac6193a --- /dev/null +++ b/test/unit/lookups/nationaal_georegister_nl_test.rb @@ -0,0 +1,23 @@ +# encoding: utf-8 +require 'test_helper' + +class NationaalGeoregisterNlTest < GeocoderTestCase + + def setup + Geocoder.configure(lookup: :nationaal_georegister_nl) + end + + def test_result_components + result = Geocoder.search('Nieuwezijds Voorburgwal 147, Amsterdam').first + + assert_equal result.street, 'Nieuwezijds Voorburgwal' + assert_equal result.street_number, '147' + assert_equal result.city, 'Amsterdam' + assert_equal result.postal_code, '1012RJ' + assert_equal result.address, 'Nieuwezijds Voorburgwal 147, 1012RJ Amsterdam' + assert_equal result.province, 'Noord-Holland' + assert_equal result.province_code, 'PV27' + assert_equal result.country_code, 'NL' + end + +end From 4fc93d859aeb0429fb2c210e3db971897b0ff754 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 16 Mar 2020 13:03:43 -0700 Subject: [PATCH 233/248] Return coordinates as floats, not strings. --- lib/geocoder/results/nationaal_georegister_nl.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/geocoder/results/nationaal_georegister_nl.rb b/lib/geocoder/results/nationaal_georegister_nl.rb index d980513aa..aa0def236 100644 --- a/lib/geocoder/results/nationaal_georegister_nl.rb +++ b/lib/geocoder/results/nationaal_georegister_nl.rb @@ -8,9 +8,7 @@ def response_attributes end def coordinates - lat, lng = @data['centroide_ll'][6..-2].split(' ') - - [lat, lng] + @data['centroide_ll'][6..-2].split(' ').map(&:to_f) end def formatted_address From 6492bb5b29e1369774fd2a470594695b15e4be66 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 16 Mar 2020 13:03:56 -0700 Subject: [PATCH 234/248] Excuse lookup from irrelevant tests. --- test/unit/lookup_test.rb | 2 +- test/unit/result_test.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit/lookup_test.rb b/test/unit/lookup_test.rb index b8187f903..146fff04c 100644 --- a/test/unit/lookup_test.rb +++ b/test/unit/lookup_test.rb @@ -13,7 +13,7 @@ def test_responds_to_name_method def test_search_returns_empty_array_when_no_results Geocoder::Lookup.all_services_except_test.each do |l| - next if l == :ipgeolocation # always returns one result + next if [:ipgeolocation, :nationaal_georegister_nl].include?(l) # lookups that always return a result lookup = Geocoder::Lookup.get(l) set_api_key!(l) silence_warnings do diff --git a/test/unit/result_test.rb b/test/unit/result_test.rb index d5854fed4..410c31fdc 100644 --- a/test/unit/result_test.rb +++ b/test/unit/result_test.rb @@ -16,6 +16,7 @@ def test_forward_geocoding_result_has_required_attributes def test_reverse_geocoding_result_has_required_attributes Geocoder::Lookup.all_services_except_test.each do |l| next if l == :ip2location # has pay-per-attribute pricing model + next if l == :nationaal_georegister_nl # no reverse geocoding Geocoder.configure(:lookup => l) set_api_key!(l) result = Geocoder.search([45.423733, -75.676333]).first From 911aa359d7b0d15d6e649adaa2407df2037ca750 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 16 Mar 2020 13:04:10 -0700 Subject: [PATCH 235/248] Add NationaalGeoregisterNl to lookup guide. --- README_API_GUIDE.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 2c22ff3e0..a042f3d56 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -350,6 +350,16 @@ Open source geocoding engine which can be self-hosted. MapTiler.com hosts an ins * **Terms of Service**: https://www.maptiler.com/terms/ * **Notes**: To use self-hosted service, set the `:host` option in `Geocoder.configure`. +### Nationaal Georegister Netherlands (`:nationaal_georegister_nl`) + +* **API key**: none +* **Quota**: ? +* **Region**: Netherlands +* **SSL support**: yes +* **Languages**: ? +* **Documentation**: http://geodata.nationaalgeoregister.nl/ +* **Terms of Service**: ? + IP Address Lookups ------------------ From e904ac6fc5b350f9765519e102de157f9e2c91ba Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 16 Mar 2020 13:17:49 -0700 Subject: [PATCH 236/248] Split API list into global and regional sections. --- README_API_GUIDE.md | 60 ++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index a042f3d56..1525e17a5 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -6,12 +6,13 @@ This is a list of geocoding APIs supported by the Geocoder gem. Before using any Table of Contents ----------------- -* [Street Address Lookups](#street-address-lookups) +* [Global Street Address Lookups](#global-street-address-lookups) +* [Regional Street Address Lookups](#regional-street-address-lookups) * [IP Address Lookups](#ip-address-lookups) * [Local IP Address Lookups](#local-ip-address-lookups) -Street Address Lookups ----------------------- +Global Street Address Lookups +----------------------------- ### Nominatim (`:nominatim`) @@ -90,7 +91,6 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Documentation**: [https://pickpoint.io/api-reference](https://pickpoint.io/api-reference) * **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) - ### LocationIQ (`:location_iq`) * **API key**: required @@ -124,17 +124,6 @@ The [Google Places Search API](https://developers.google.com/places/web-service/ * **Terms of Service**: http://api.yandex.com.tr/maps/doc/intro/concepts/intro.xml#rules * **Limitations**: ? -### Geocoder.ca (`:geocoder_ca`) - -* **API key**: none -* **Quota**: ? -* **Region**: US, Canada, Mexico -* **SSL support**: no -* **Languages**: English -* **Documentation**: https://geocoder.ca/?premium_api=1 -* **Terms of Service**: http://geocoder.ca/?terms=1 -* **Limitations**: "Under no circumstances can our data be re-distributed or re-sold by anyone to other parties without our written permission." - ### Mapbox (`:mapbox`) * **API key**: required @@ -222,6 +211,23 @@ Data Science Toolkit provides an API whose response format is like Google's but * **Limitations**: No reverse geocoding. * **Notes**: If you are hosting your own DSTK server you will need to configure the host name, eg: `Geocoder.configure(lookup: :dstk, dstk: {host: "localhost:4567"})`. +### OSM Names (`:osmnames`) + +Open source geocoding engine which can be self-hosted. MapTiler.com hosts an installation for use with API key. + +* **API key**: required if not self-hosting (see https://www.maptiler.com/cloud/plans/) +* **Quota**: none if self-hosting; 100,000/mo with MapTiler free plan (more with paid) +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://osmnames.org/ (open source project), https://cloud.maptiler.com/geocoding/ (MapTiler) +* **Terms of Service**: https://www.maptiler.com/terms/ +* **Notes**: To use self-hosted service, set the `:host` option in `Geocoder.configure`. + + +Regional Street Address Lookups +------------------------------- + ### Baidu (`:baidu`) * **API key**: required @@ -247,6 +253,17 @@ Data Science Toolkit provides an API whose response format is like Google's but * **Limitations**: Only works for locations in Greater China (mainland China, Hong Kong, Macau, and Taiwan). * **Notes**: To use Tencent, set `Geocoder.configure(lookup: :tencent, api_key: "your_api_key")`. +### Geocoder.ca (`:geocoder_ca`) + +* **API key**: none +* **Quota**: ? +* **Region**: US, Canada, Mexico +* **SSL support**: no +* **Languages**: English +* **Documentation**: https://geocoder.ca/?premium_api=1 +* **Terms of Service**: http://geocoder.ca/?terms=1 +* **Limitations**: "Under no circumstances can our data be re-distributed or re-sold by anyone to other parties without our written permission." + ### Geocodio (`:geocodio`) * **API key**: required @@ -337,19 +354,6 @@ Data Science Toolkit provides an API whose response format is like Google's but - **Limitations**: Only good for non-commercial use. For commercial usage please check http://lbs.amap.com/home/terms/ - **Notes**: To use AMap set `Geocoder.configure(lookup: :amap, api_key: "your_api_key")`. -### OSM Names (`:osmnames`) - -Open source geocoding engine which can be self-hosted. MapTiler.com hosts an installation for use with API key. - -* **API key**: required if not self-hosting (see https://www.maptiler.com/cloud/plans/) -* **Quota**: none if self-hosting; 100,000/mo with MapTiler free plan (more with paid) -* **Region**: world -* **SSL support**: yes -* **Languages**: English -* **Documentation**: https://osmnames.org/ (open source project), https://cloud.maptiler.com/geocoding/ (MapTiler) -* **Terms of Service**: https://www.maptiler.com/terms/ -* **Notes**: To use self-hosted service, set the `:host` option in `Geocoder.configure`. - ### Nationaal Georegister Netherlands (`:nationaal_georegister_nl`) * **API key**: none From 9d32f1f561c136082561ca355ac5af128b66231c Mon Sep 17 00:00:00 2001 From: Stuart Harrison <pezholio@gmail.com> Date: Wed, 17 Apr 2019 14:45:34 +0100 Subject: [PATCH 237/248] Add support for Ordnance Survey Names API --- README_API_GUIDE.md | 26 +- lib/easting_northing.rb | 171 + lib/geocoder/lookup.rb | 1 + .../lookups/uk_ordnance_survey_names.rb | 59 + .../results/uk_ordnance_survey_names.rb | 63 + .../fixtures/uk_ordnance_survey_names_SW1A1AA | 1268 +++++++ test/fixtures/uk_ordnance_survey_names_london | 3044 +++++++++++++++++ .../uk_ordnance_survey_names_no_results | 11 + test/test_helper.rb | 8 + test/unit/lookup_test.rb | 2 +- test/unit/lookups/uk_ordnance_survey_names.rb | 22 + 11 files changed, 4667 insertions(+), 8 deletions(-) create mode 100644 lib/easting_northing.rb create mode 100644 lib/geocoder/lookups/uk_ordnance_survey_names.rb create mode 100644 lib/geocoder/results/uk_ordnance_survey_names.rb create mode 100644 test/fixtures/uk_ordnance_survey_names_SW1A1AA create mode 100644 test/fixtures/uk_ordnance_survey_names_london create mode 100644 test/fixtures/uk_ordnance_survey_names_no_results create mode 100644 test/unit/lookups/uk_ordnance_survey_names.rb diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 1525e17a5..6a33af627 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -297,16 +297,28 @@ Regional Street Address Lookups * **Terms of Service**: http://wiki.geoportail.lu/doku.php?id=en:mcg_1 * **Limitations**: ? -### Postcodes.io (`:postcodes_io`) +### Bing (`:bing`) -* **API key**: none -* **Quota**: ? -* **Region**: UK +* **API key**: required (set `Geocoder.configure(lookup: :bing, api_key: key)`) +* **Key signup**: https://www.microsoft.com/maps/create-a-bing-maps-key.aspx +* **Quota**: 50,0000 requests/day (Windows app), 125,000 requests/year (non-Windows app) +* **Region**: world +* **SSL support**: no +* **Languages**: The preferred language of address elements in the result. Language code must be provided according to RFC 4647 standard. +* **Documentation**: http://msdn.microsoft.com/en-us/library/ff701715.aspx +* **Terms of Service**: http://www.microsoft.com/maps/product/terms.html +* **Limitations**: No country codes or state names. Must be used on "public-facing, non-password protected web sites," "in conjunction with Bing Maps or an application that integrates Bing Maps." + +### Ordnance Survey OpenNames (`:uk_ordnance_survey_names`) + +* **API key**: required (sign up at https://developer.ordnancesurvey.co.uk/os-names-api) +* **Quota**: 250,000 / month +* **Region**: England, Wales and Scotland * **SSL support**: yes * **Languages**: English -* **Documentation**: http://postcodes.io/docs -* **Terms of Service**: ? -* **Limitations**: UK postcodes only +* **Documentation**: https://apidocs.os.uk/docs/os-names-overview +* **Terms of Service**: https://developer.ordnancesurvey.co.uk/os-api-framework-agreement +* **Limitations**: Only searches postcodes and placenames in England, Wales and Scotland ### PostcodeAnywhere UK (`:postcode_anywhere_uk`) diff --git a/lib/easting_northing.rb b/lib/easting_northing.rb new file mode 100644 index 000000000..0b9d2a9b4 --- /dev/null +++ b/lib/easting_northing.rb @@ -0,0 +1,171 @@ +module Geocoder + class EastingNorthing + attr_reader :easting, :northing, :lat_lng + + def initialize(opts) + @easting = opts[:easting] + @northing = opts[:northing] + + @lat_lng = to_WGS84(to_osgb_36) + end + + private + + def to_osgb_36 + osgb_fo = 0.9996012717 + northing0 = -100_000.0 + easting0 = 400_000.0 + phi0 = deg_to_rad(49.0) + lambda0 = deg_to_rad(-2.0) + a = 6_377_563.396 + b = 6_356_256.909 + eSquared = ((a * a) - (b * b)) / (a * a) + phi = 0.0 + lambda = 0.0 + n = (a - b) / (a + b) + m = 0.0 + phiPrime = ((northing - northing0) / (a * osgb_fo)) + phi0 + + while (northing - northing0 - m) >= 0.001 + m = + (b * osgb_fo)\ + * (((1 + n + ((5.0 / 4.0) * n * n) + ((5.0 / 4.0) * n * n * n))\ + * (phiPrime - phi0))\ + - (((3 * n) + (3 * n * n) + ((21.0 / 8.0) * n * n * n))\ + * Math.sin(phiPrime - phi0)\ + * Math.cos(phiPrime + phi0))\ + + ((((15.0 / 8.0) * n * n) + ((15.0 / 8.0) * n * n * n))\ + * Math.sin(2.0 * (phiPrime - phi0))\ + * Math.cos(2.0 * (phiPrime + phi0)))\ + - (((35.0 / 24.0) * n * n * n)\ + * Math.sin(3.0 * (phiPrime - phi0))\ + * Math.cos(3.0 * (phiPrime + phi0)))) + + phiPrime += (northing - northing0 - m) / (a * osgb_fo) + end + + v = a * osgb_fo * ((1.0 - eSquared * sin_pow_2(phiPrime))**-0.5) + rho = + a\ + * osgb_fo\ + * (1.0 - eSquared)\ + * ((1.0 - eSquared * sin_pow_2(phiPrime))**-1.5) + etaSquared = (v / rho) - 1.0 + vii = Math.tan(phiPrime) / (2 * rho * v) + viii = + (Math.tan(phiPrime) / (24.0 * rho * (v**3.0)))\ + * (5.0\ + + (3.0 * tan_pow_2(phiPrime))\ + + etaSquared\ + - (9.0 * tan_pow_2(phiPrime) * etaSquared)) + ix = + (Math.tan(phiPrime) / (720.0 * rho * (v**5.0)))\ + * (61.0\ + + (90.0 * tan_pow_2(phiPrime))\ + + (45.0 * tan_pow_2(phiPrime) * tan_pow_2(phiPrime))) + x = sec(phiPrime) / v + xi = + (sec(phiPrime) / (6.0 * v * v * v))\ + * ((v / rho) + (2 * tan_pow_2(phiPrime))) + xiii = + (sec(phiPrime) / (120.0 * (v**5.0)))\ + * (5.0\ + + (28.0 * tan_pow_2(phiPrime))\ + + (24.0 * tan_pow_2(phiPrime) * tan_pow_2(phiPrime))) + xiia = + (sec(phiPrime) / (5040.0 * (v**7.0)))\ + * (61.0\ + + (662.0 * tan_pow_2(phiPrime))\ + + (1320.0 * tan_pow_2(phiPrime) * tan_pow_2(phiPrime))\ + + (720.0\ + * tan_pow_2(phiPrime)\ + * tan_pow_2(phiPrime)\ + * tan_pow_2(phiPrime))) + phi = + phiPrime\ + - (vii * ((easting - easting0)**2.0))\ + + (viii * ((easting - easting0)**4.0))\ + - (ix * ((easting - easting0)**6.0)) + lambda = + lambda0\ + + (x * (easting - easting0))\ + - (xi * ((easting - easting0)**3.0))\ + + (xiii * ((easting - easting0)**5.0))\ + - (xiia * ((easting - easting0)**7.0)) + + [rad_to_deg(phi), rad_to_deg(lambda)] + end + + def to_WGS84(latlng) + latitude = latlng[0] + longitude = latlng[1] + + a = 6_377_563.396 + b = 6_356_256.909 + eSquared = ((a * a) - (b * b)) / (a * a) + + phi = deg_to_rad(latitude) + lambda = deg_to_rad(longitude) + v = a / Math.sqrt(1 - eSquared * sin_pow_2(phi)) + h = 0 + x = (v + h) * Math.cos(phi) * Math.cos(lambda) + y = (v + h) * Math.cos(phi) * Math.sin(lambda) + z = ((1 - eSquared) * v + h) * Math.sin(phi) + + tx = 446.448 + ty = -124.157 + tz = 542.060 + + s = -0.0000204894 + rx = deg_to_rad(0.00004172222) + ry = deg_to_rad(0.00006861111) + rz = deg_to_rad(0.00023391666) + + xB = tx + (x * (1 + s)) + (-rx * y) + (ry * z) + yB = ty + (rz * x) + (y * (1 + s)) + (-rx * z) + zB = tz + (-ry * x) + (rx * y) + (z * (1 + s)) + + a = 6_378_137.000 + b = 6_356_752.3141 + eSquared = ((a * a) - (b * b)) / (a * a) + + lambdaB = rad_to_deg(Math.atan(yB / xB)) + p = Math.sqrt((xB * xB) + (yB * yB)) + phiN = Math.atan(zB / (p * (1 - eSquared))) + + (1..10).each do |_i| + v = a / Math.sqrt(1 - eSquared * sin_pow_2(phiN)) + phiN1 = Math.atan((zB + (eSquared * v * Math.sin(phiN))) / p) + phiN = phiN1 + end + + phiB = rad_to_deg(phiN) + + [phiB, lambdaB] + end + + def deg_to_rad(degrees) + degrees / 180.0 * Math::PI + end + + def rad_to_deg(r) + (r / Math::PI) * 180 + end + + def sin_pow_2(x) + Math.sin(x) * Math.sin(x) + end + + def cos_pow_2(x) + Math.cos(x) * Math.cos(x) + end + + def tan_pow_2(x) + Math.tan(x) * Math.tan(x) + end + + def sec(x) + 1.0 / Math.cos(x) + end + end +end diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index 40fa94100..51b69cc28 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -37,6 +37,7 @@ def street_services :nominatim, :mapbox, :mapquest, + :uk_ordnance_survey_names, :opencagedata, :pelias, :pickpoint, diff --git a/lib/geocoder/lookups/uk_ordnance_survey_names.rb b/lib/geocoder/lookups/uk_ordnance_survey_names.rb new file mode 100644 index 000000000..b89ecd6d1 --- /dev/null +++ b/lib/geocoder/lookups/uk_ordnance_survey_names.rb @@ -0,0 +1,59 @@ +require 'geocoder/lookups/base' +require 'geocoder/results/uk_ordnance_survey_names' + +module Geocoder::Lookup + class UkOrdnanceSurveyNames < Base + + def name + 'Ordance Survey Names' + end + + def supported_protocols + [:https] + end + + def base_query_url(query) + "#{protocol}://api.ordnancesurvey.co.uk/opennames/v1/find?" + end + + def required_api_key_parts + ["key"] + end + + def query_url(query) + base_query_url(query) + url_query_string(query) + end + + private # ------------------------------------------------------------- + + def results(query) + return [] unless doc = fetch_data(query) + return [] if doc['header']['totalresults'].zero? + return doc['results'].map { |r| r['GAZETTEER_ENTRY'] } + end + + def query_url_params(query) + { + query: query.sanitized_text, + key: configuration.api_key, + fq: filter + }.merge(super) + end + + def local_types + %w[ + City + Hamlet + Other_Settlement + Town + Village + Postcode + ] + end + + def filter + local_types.map { |t| "local_type:#{t}" }.join(' ') + end + + end +end diff --git a/lib/geocoder/results/uk_ordnance_survey_names.rb b/lib/geocoder/results/uk_ordnance_survey_names.rb new file mode 100644 index 000000000..2eae2fb34 --- /dev/null +++ b/lib/geocoder/results/uk_ordnance_survey_names.rb @@ -0,0 +1,63 @@ +require 'geocoder/results/base' +require 'easting_northing' + +module Geocoder::Result + class UkOrdnanceSurveyNames < Base + + def coordinates + [latitude, longitude] + end + + def city + is_postcode? ? data['DISTRICT_BOROUGH'] : data['NAME1'] + end + + def county + data['COUNTY_UNITARY'] + end + alias state county + + def county_code + code_from_uri data['COUNTY_UNITARY_URI'] + end + alias state_code county_code + + def province + data['REGION'] + end + + def province_code + code_from_uri data['REGION_URI'] + end + + def postal_code + is_postcode? ? data['NAME1'] : '' + end + + def country + 'United Kingdom' + end + + def country_code + 'UK' + end + + def coordinates + @coordinates ||= Geocoder::EastingNorthing.new( + easting: data['GEOMETRY_X'], + northing: data['GEOMETRY_Y'], + ).lat_lng + end + + private + + def is_postcode? + data['LOCAL_TYPE'] == 'Postcode' + end + + def code_from_uri(uri) + return '' if uri.nil? + uri.split('/').last + end + end +end diff --git a/test/fixtures/uk_ordnance_survey_names_SW1A1AA b/test/fixtures/uk_ordnance_survey_names_SW1A1AA new file mode 100644 index 000000000..691f09798 --- /dev/null +++ b/test/fixtures/uk_ordnance_survey_names_SW1A1AA @@ -0,0 +1,1268 @@ +{ + "header": { + "uri": "https://api.ordnancesurvey.co.uk/opennames/v1/find?query=SW1a1AA&fq=local_type%3ACity%20local_type%3AHamlet%20local_type%3AOther_Settlement%20local_type%3ATown%20local_type%3AVillage%20local_type%3APostcode", + "query": "SW1a1AA", + "format": "JSON", + "maxresults": 100, + "offset": 0, + "totalresults": 50, + "filter": "fq=local_type:City local_type:Hamlet local_type:Other_Settlement local_type:Town local_type:Village local_type:Postcode" + }, + "results": [ + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1AA", + "NAME1": "SW1A 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529090, + "GEOMETRY_Y": 179645, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW111AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW111AA", + "NAME1": "SW11 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 527614, + "GEOMETRY_Y": 175543, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Battersea", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559558", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW151AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW151AA", + "NAME1": "SW15 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 523544, + "GEOMETRY_Y": 175403, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Putney", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074562835", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW161AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW161AA", + "NAME1": "SW16 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 530019, + "GEOMETRY_Y": 172701, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Streatham", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074575698", + "DISTRICT_BOROUGH": "Lambeth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011144", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW181AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW181AA", + "NAME1": "SW18 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 526140, + "GEOMETRY_Y": 174861, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Wandsworth", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074576254", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW191AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW191AA", + "NAME1": "SW19 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 526211, + "GEOMETRY_Y": 170740, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Wimbledon", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074541243", + "DISTRICT_BOROUGH": "Merton", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010995", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A0AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A0AA", + "NAME1": "SW1A 0AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 530268, + "GEOMETRY_Y": 179545, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1AB", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1AB", + "NAME1": "SW1A 1AB", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 530240, + "GEOMETRY_Y": 180708, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1BA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1BA", + "NAME1": "SW1A 1BA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529292, + "GEOMETRY_Y": 179988, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1DA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1DA", + "NAME1": "SW1A 1DA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529265, + "GEOMETRY_Y": 180092, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1EA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1EA", + "NAME1": "SW1A 1EA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529340, + "GEOMETRY_Y": 180172, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1HA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1HA", + "NAME1": "SW1A 1HA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529266, + "GEOMETRY_Y": 180304, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1LA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1LA", + "NAME1": "SW1A 1LA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529167, + "GEOMETRY_Y": 180313, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1RA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1RA", + "NAME1": "SW1A 1RA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529122, + "GEOMETRY_Y": 180335, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1ZA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1ZA", + "NAME1": "SW1A 1ZA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529548, + "GEOMETRY_Y": 177433, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A2AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A2AA", + "NAME1": "SW1A 2AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 530047, + "GEOMETRY_Y": 179951, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1P1AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1P1AA", + "NAME1": "SW1P 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529391, + "GEOMETRY_Y": 179143, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1V1AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1V1AA", + "NAME1": "SW1V 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529096, + "GEOMETRY_Y": 179021, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "W1A1AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/W1A1AA", + "NAME1": "W1A 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 528887, + "GEOMETRY_Y": 181593, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "CW111AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/CW111AA", + "NAME1": "CW11 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 375892, + "GEOMETRY_Y": 360810, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Sandbach", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074576355", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Cheshire East", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000043553", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "North West", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041431", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "EC1A1AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/EC1A1AA", + "NAME1": "EC1A 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 531131, + "GEOMETRY_Y": 182382, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Islington", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011281", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "KW151AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/KW151AA", + "NAME1": "KW15 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 344877, + "GEOMETRY_Y": 1011082, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Kirkwall", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074557613", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Orkney Islands", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000029961", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "Scotland", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041429", + "COUNTRY": "Scotland", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/scotland" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "NW101AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/NW101AA", + "NAME1": "NW10 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 521839, + "GEOMETRY_Y": 185653, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Brent", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011447", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SA111AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SA111AA", + "NAME1": "SA11 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 275157, + "GEOMETRY_Y": 196858, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Neath / Castell-nedd", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074548341", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Castell-nedd Port Talbot - Neath Port Talbot", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000025498", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "Wales", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041424", + "COUNTRY": "Wales", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/wales" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SA131AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SA131AA", + "NAME1": "SA13 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 276924, + "GEOMETRY_Y": 189650, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Port Talbot", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074549084", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Castell-nedd Port Talbot - Neath Port Talbot", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000025498", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "Wales", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041424", + "COUNTRY": "Wales", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/wales" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SA151AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SA151AA", + "NAME1": "SA15 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 250541, + "GEOMETRY_Y": 200199, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Llanelli", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074571435", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Sir Gaerfyrddin - Carmarthenshire", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000025486", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "Wales", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041424", + "COUNTRY": "Wales", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/wales" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SE151AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SE151AA", + "NAME1": "SE15 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 534257, + "GEOMETRY_Y": 177086, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Southwark", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011013", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SE171AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SE171AA", + "NAME1": "SE17 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 532610, + "GEOMETRY_Y": 178438, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Southwark", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011013", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SE181AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SE181AA", + "NAME1": "SE18 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 544850, + "GEOMETRY_Y": 178228, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Greenwich", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010777", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SE191AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SE191AA", + "NAME1": "SE19 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 533176, + "GEOMETRY_Y": 170843, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Lambeth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011144", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SG111AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SG111AA", + "NAME1": "SG11 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 536285, + "GEOMETRY_Y": 218516, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "High Cross", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074574014", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#village", + "DISTRICT_BOROUGH": "East Hertfordshire", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000003679", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Hertfordshire", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000003909", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "Eastern", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041425", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SG191AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SG191AA", + "NAME1": "SG19 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 517251, + "GEOMETRY_Y": 249189, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Sandy", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074570512", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Central Bedfordshire", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000043870", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "Eastern", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041425", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SK101AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SK101AA", + "NAME1": "SK10 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 391487, + "GEOMETRY_Y": 373814, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Macclesfield", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074577382", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Cheshire East", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000043553", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "North West", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041431", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SK121AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SK121AA", + "NAME1": "SK12 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 391902, + "GEOMETRY_Y": 383726, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Poynton", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074544996", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Cheshire East", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000043553", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "North West", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041431", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SK131AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SK131AA", + "NAME1": "SK13 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 402319, + "GEOMETRY_Y": 396125, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Hadfield", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813565", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#village", + "DISTRICT_BOROUGH": "High Peak", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000013755", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Derbyshire", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000013688", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "East Midlands", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041423", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SK141AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SK141AA", + "NAME1": "SK14 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 394871, + "GEOMETRY_Y": 395016, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Hyde", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074545001", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "DISTRICT_BOROUGH": "Tameside", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000018700", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/MetropolitanDistrict", + "REGION": "North West", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041431", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SK151AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SK151AA", + "NAME1": "SK15 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 396517, + "GEOMETRY_Y": 398691, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Stalybridge", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074565101", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "DISTRICT_BOROUGH": "Tameside", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000018700", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/MetropolitanDistrict", + "REGION": "North West", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041431", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SN151AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SN151AA", + "NAME1": "SN15 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 391958, + "GEOMETRY_Y": 174073, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Chippenham", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074571472", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Wiltshire", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000043925", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "South West", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041427", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SP101AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SP101AA", + "NAME1": "SP10 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 436302, + "GEOMETRY_Y": 145363, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Andover", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074567982", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "DISTRICT_BOROUGH": "Test Valley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000043511", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Hampshire", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000017765", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "South East", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041421", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SS141AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SS141AA", + "NAME1": "SS14 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 570558, + "GEOMETRY_Y": 188641, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Basildon", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074573659", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "DISTRICT_BOROUGH": "Basildon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000019739", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Essex", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000019687", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "Eastern", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041425", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SS171AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SS171AA", + "NAME1": "SS17 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 569923, + "GEOMETRY_Y": 183552, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Stanford-le-Hope", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074573320", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Thurrock", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000038866", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "Eastern", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041425", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "ST101AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/ST101AA", + "NAME1": "ST10 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 400909, + "GEOMETRY_Y": 343400, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Cheadle", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074560862", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "DISTRICT_BOROUGH": "Staffordshire Moorlands", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000015068", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Staffordshire", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000015052", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "West Midlands", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041426", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "ST161AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/ST161AA", + "NAME1": "ST16 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 391804, + "GEOMETRY_Y": 322841, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Stafford", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074560217", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "DISTRICT_BOROUGH": "Stafford", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000014892", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Staffordshire", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000015052", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "West Midlands", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041426", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW100AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW100AA", + "NAME1": "SW10 0AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 526506, + "GEOMETRY_Y": 176966, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Hammersmith and Fulham", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011259", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW101AH", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW101AH", + "NAME1": "SW10 1AH", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 526217, + "GEOMETRY_Y": 177763, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Kensington", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074558539", + "DISTRICT_BOROUGH": "Kensington and Chelsea", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011270", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW101AS", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW101AS", + "NAME1": "SW10 1AS", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 526217, + "GEOMETRY_Y": 177763, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Kensington", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074558539", + "DISTRICT_BOROUGH": "Kensington and Chelsea", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011270", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW101AW", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW101AW", + "NAME1": "SW10 1AW", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 526217, + "GEOMETRY_Y": 177763, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Kensington", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074558539", + "DISTRICT_BOROUGH": "Kensington and Chelsea", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011270", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW109AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW109AA", + "NAME1": "SW10 9AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 526000, + "GEOMETRY_Y": 177635, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Kensington and Chelsea", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011270", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW111AB", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW111AB", + "NAME1": "SW11 1AB", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 527614, + "GEOMETRY_Y": 175543, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Battersea", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559558", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW111AD", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW111AD", + "NAME1": "SW11 1AD", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 526994, + "GEOMETRY_Y": 175265, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + } + ] +} \ No newline at end of file diff --git a/test/fixtures/uk_ordnance_survey_names_london b/test/fixtures/uk_ordnance_survey_names_london new file mode 100644 index 000000000..682a90aeb --- /dev/null +++ b/test/fixtures/uk_ordnance_survey_names_london @@ -0,0 +1,3044 @@ +{ + "header": { + "uri": "https://api.ordnancesurvey.co.uk/opennames/v1/find?query=London&fq=local_type%3ACity%20local_type%3AHamlet%20local_type%3AOther_Settlement%20local_type%3ATown%20local_type%3AVillage%20local_type%3APostcode", + "query": "London", + "format": "JSON", + "maxresults": 100, + "offset": 0, + "totalresults": 211, + "filter": "fq=local_type:City local_type:Hamlet local_type:Other_Settlement local_type:Town local_type:Village local_type:Postcode" + }, + "results": [ + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343985", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343985", + "NAME1": "City of London", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "City", + "GEOMETRY_X": 532473, + "GEOMETRY_Y": 181219, + "MOST_DETAIL_VIEW_RES": 19000, + "LEAST_DETAIL_VIEW_RES": 9000000, + "MBR_XMIN": 530968, + "MBR_YMIN": 180398, + "MBR_XMAX": 533841, + "MBR_YMAX": 182198, + "POSTCODE_DISTRICT": "EC2V", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/EC2V", + "DISTRICT_BOROUGH": "City and County of the City of London", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011105", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2643741", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/City_of_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074813508", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "NAME1": "London", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "City", + "GEOMETRY_X": 530034, + "GEOMETRY_Y": 180381, + "MOST_DETAIL_VIEW_RES": 349000, + "LEAST_DETAIL_VIEW_RES": 9000000, + "MBR_XMIN": 504454, + "MBR_YMIN": 156590, + "MBR_XMAX": 558150, + "MBR_YMAX": 200042, + "POSTCODE_DISTRICT": "WC2N", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/WC2N", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074813722", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813722", + "NAME1": "Chelsfield", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 548252, + "GEOMETRY_Y": 164175, + "MOST_DETAIL_VIEW_RES": 6000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 547768, + "MBR_YMIN": 163894, + "MBR_XMAX": 548712, + "MBR_YMAX": 164415, + "POSTCODE_DISTRICT": "BR6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR6", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074576660", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074576660", + "NAME1": "Coldblow", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 550399, + "GEOMETRY_Y": 173115, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 549931, + "MBR_YMIN": 172851, + "MBR_XMAX": 550764, + "MBR_YMAX": 173640, + "POSTCODE_DISTRICT": "DA5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/DA5", + "DISTRICT_BOROUGH": "Bexley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010759", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074564240", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074564240", + "NAME1": "Cudham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 544691, + "GEOMETRY_Y": 159466, + "MOST_DETAIL_VIEW_RES": 9000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 544368, + "MBR_YMIN": 158661, + "MBR_XMAX": 545149, + "MBR_YMAX": 160099, + "POSTCODE_DISTRICT": "TN14", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/TN14", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2651779", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Cudham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074564565", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074564565", + "NAME1": "Downe", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 543173, + "GEOMETRY_Y": 161647, + "MOST_DETAIL_VIEW_RES": 9000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 542664, + "MBR_YMIN": 160956, + "MBR_XMAX": 543685, + "MBR_YMAX": 162308, + "POSTCODE_DISTRICT": "BR6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR6", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2651033", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Downe" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074339827", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074339827", + "NAME1": "Harefield", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 505235, + "GEOMETRY_Y": 190598, + "MOST_DETAIL_VIEW_RES": 17000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 503985, + "MBR_YMIN": 189776, + "MBR_XMAX": 506559, + "MBR_YMAX": 191754, + "POSTCODE_DISTRICT": "UB9", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/UB9", + "DISTRICT_BOROUGH": "Hillingdon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011539", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074564241", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074564241", + "NAME1": "Hazelwood", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 544729, + "GEOMETRY_Y": 161589, + "MOST_DETAIL_VIEW_RES": 7000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 544293, + "MBR_YMIN": 161137, + "MBR_XMAX": 545223, + "MBR_YMAX": 162253, + "POSTCODE_DISTRICT": "TN14", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/TN14", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074549606", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074549606", + "NAME1": "Keston", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 541242, + "GEOMETRY_Y": 164528, + "MOST_DETAIL_VIEW_RES": 19000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 540811, + "MBR_YMIN": 162042, + "MBR_XMAX": 542564, + "MBR_YMAX": 164993, + "POSTCODE_DISTRICT": "BR2", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR2", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2645758", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Keston" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074558121", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074558121", + "NAME1": "London Apprentice", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 200698, + "GEOMETRY_Y": 49932, + "MOST_DETAIL_VIEW_RES": 3000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 200571, + "MBR_YMIN": 49832, + "MBR_XMAX": 201071, + "MBR_YMAX": 50332, + "POSTCODE_DISTRICT": "PL26", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/PL26", + "COUNTY_UNITARY": "Cornwall", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000043750", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "South West", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041427", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/London_Apprentice" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074564243", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074564243", + "NAME1": "Luxted", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 543324, + "GEOMETRY_Y": 160257, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 542941, + "MBR_YMIN": 160071, + "MBR_XMAX": 543770, + "MBR_YMAX": 160589, + "POSTCODE_DISTRICT": "BR6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR6", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074318884", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074318884", + "NAME1": "Maypole", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 549164, + "GEOMETRY_Y": 163899, + "MOST_DETAIL_VIEW_RES": 4000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 548762, + "MBR_YMIN": 163576, + "MBR_XMAX": 549384, + "MBR_YMAX": 164076, + "POSTCODE_DISTRICT": "BR6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR6", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074550341", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074550341", + "NAME1": "Ruxley", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 547971, + "GEOMETRY_Y": 170542, + "MOST_DETAIL_VIEW_RES": 6000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 547808, + "MBR_YMIN": 170046, + "MBR_XMAX": 548734, + "MBR_YMAX": 170683, + "POSTCODE_DISTRICT": "DA14", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/DA14", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Ruxley" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074569525", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074569525", + "NAME1": "Wennington", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 554128, + "GEOMETRY_Y": 180954, + "MOST_DETAIL_VIEW_RES": 7000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 553691, + "MBR_YMIN": 180709, + "MBR_XMAX": 554762, + "MBR_YMAX": 181209, + "POSTCODE_DISTRICT": "RM13", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/RM13", + "DISTRICT_BOROUGH": "Havering", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010807", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Wennington,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074548838", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074548838", + "NAME1": "Bopeep", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 549085, + "GEOMETRY_Y": 163634, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 548837, + "MBR_YMIN": 163328, + "MBR_XMAX": 549337, + "MBR_YMAX": 163828, + "POSTCODE_DISTRICT": "BR6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR6", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074549966", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074549966", + "NAME1": "Hockenden", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 549654, + "GEOMETRY_Y": 169193, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 549211, + "MBR_YMIN": 168597, + "MBR_XMAX": 549894, + "MBR_YMAX": 169266, + "POSTCODE_DISTRICT": "BR8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR8", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074549232", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074549232", + "NAME1": "Kevingtown", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 548519, + "GEOMETRY_Y": 167454, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 548316, + "MBR_YMIN": 167275, + "MBR_XMAX": 549075, + "MBR_YMAX": 168165, + "POSTCODE_DISTRICT": "BR5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR5", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074541667", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074541667", + "NAME1": "Little London", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 568326, + "GEOMETRY_Y": 235146, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 568103, + "MBR_YMIN": 234793, + "MBR_XMAX": 568603, + "MBR_YMAX": 235293, + "POSTCODE_DISTRICT": "CM7", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/CM7", + "DISTRICT_BOROUGH": "Braintree", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000019795", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Essex", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000019687", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "Eastern", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041425", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074543489", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074543489", + "NAME1": "Little London", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 304475, + "GEOMETRY_Y": 289249, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 304273, + "MBR_YMIN": 289042, + "MBR_XMAX": 304773, + "MBR_YMAX": 289542, + "POSTCODE_DISTRICT": "SY17", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SY17", + "COUNTY_UNITARY": "Powys - Powys", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000025491", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "Wales", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041424", + "COUNTRY": "Wales", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/wales" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074570193", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074570193", + "NAME1": "Little London", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 547673, + "GEOMETRY_Y": 229492, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 547378, + "MBR_YMIN": 229201, + "MBR_XMAX": 547878, + "MBR_YMAX": 229701, + "POSTCODE_DISTRICT": "CM23", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/CM23", + "DISTRICT_BOROUGH": "Uttlesford", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000020033", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Essex", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000019687", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "Eastern", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041425", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074573567", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074573567", + "NAME1": "Little London", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 618547, + "GEOMETRY_Y": 323907, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 618282, + "MBR_YMIN": 323706, + "MBR_XMAX": 618782, + "MBR_YMAX": 324206, + "POSTCODE_DISTRICT": "NR10", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/NR10", + "DISTRICT_BOROUGH": "Broadland", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000006553", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Norfolk", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000007238", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "Eastern", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041425", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074573813", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074573813", + "NAME1": "Little London", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 506577, + "GEOMETRY_Y": 146740, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 506255, + "MBR_YMIN": 146505, + "MBR_XMAX": 506755, + "MBR_YMAX": 147047, + "POSTCODE_DISTRICT": "GU5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/GU5", + "DISTRICT_BOROUGH": "Guildford", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000014002", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Surrey", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000013965", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "South East", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041421", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074543687", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074543687", + "NAME1": "London Beach", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 588416, + "GEOMETRY_Y": 136145, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 588103, + "MBR_YMIN": 136037, + "MBR_XMAX": 588603, + "MBR_YMAX": 136741, + "POSTCODE_DISTRICT": "TN30", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/TN30", + "DISTRICT_BOROUGH": "Ashford", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000018232", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Kent", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000018210", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "South East", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041421", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074549608", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074549608", + "NAME1": "Nash", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 540458, + "GEOMETRY_Y": 163928, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 540112, + "MBR_YMIN": 163546, + "MBR_XMAX": 540612, + "MBR_YMAX": 164046, + "POSTCODE_DISTRICT": "BR2", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR2", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074561498", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074561498", + "NAME1": "Acton", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 520280, + "GEOMETRY_Y": 180066, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 518934, + "MBR_YMIN": 178644, + "MBR_XMAX": 522035, + "MBR_YMAX": 183249, + "POSTCODE_DISTRICT": "W3", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/W3", + "DISTRICT_BOROUGH": "Ealing", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011399", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2657697", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Acton,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343911", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343911", + "NAME1": "Barnet", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 526618, + "GEOMETRY_Y": 196126, + "MOST_DETAIL_VIEW_RES": 39000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 522555, + "MBR_YMIN": 193687, + "MBR_XMAX": 528620, + "MBR_YMAX": 197754, + "POSTCODE_DISTRICT": "EN4", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/EN4", + "DISTRICT_BOROUGH": "Barnet", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011378", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074559558", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559558", + "NAME1": "Battersea", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 527105, + "GEOMETRY_Y": 176161, + "MOST_DETAIL_VIEW_RES": 26000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 526180, + "MBR_YMIN": 173755, + "MBR_XMAX": 528729, + "MBR_YMAX": 177796, + "POSTCODE_DISTRICT": "SW11", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SW11", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/6690602", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Battersea" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074551459", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074551459", + "NAME1": "Beckenham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 537449, + "GEOMETRY_Y": 169604, + "MOST_DETAIL_VIEW_RES": 34000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 534360, + "MBR_YMIN": 166461, + "MBR_XMAX": 539569, + "MBR_YMAX": 171476, + "POSTCODE_DISTRICT": "BR3", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR3", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2656065", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Beckenham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074559226", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559226", + "NAME1": "Bermondsey", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 533627, + "GEOMETRY_Y": 179093, + "MOST_DETAIL_VIEW_RES": 15000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 532687, + "MBR_YMIN": 178167, + "MBR_XMAX": 534952, + "MBR_YMAX": 180499, + "POSTCODE_DISTRICT": "SE1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE1", + "DISTRICT_BOROUGH": "Southwark", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011013", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2655853", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Bermondsey" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074578541", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074578541", + "NAME1": "Bexley", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 549553, + "GEOMETRY_Y": 173602, + "MOST_DETAIL_VIEW_RES": 18000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 547240, + "MBR_YMIN": 172765, + "MBR_XMAX": 549960, + "MBR_YMAX": 174400, + "POSTCODE_DISTRICT": "DA5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/DA5", + "DISTRICT_BOROUGH": "Bexley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010759", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2655775", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Bexley" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074561689", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074561689", + "NAME1": "Brentford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 517697, + "GEOMETRY_Y": 177417, + "MOST_DETAIL_VIEW_RES": 28000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 516017, + "MBR_YMIN": 177011, + "MBR_XMAX": 520292, + "MBR_YMAX": 179637, + "POSTCODE_DISTRICT": "TW8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/TW8", + "DISTRICT_BOROUGH": "Hounslow", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011489", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2654787", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Brentford" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343899", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343899", + "NAME1": "Bromley", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 540261, + "GEOMETRY_Y": 169118, + "MOST_DETAIL_VIEW_RES": 20000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 538629, + "MBR_YMIN": 167477, + "MBR_XMAX": 541185, + "MBR_YMAX": 170564, + "POSTCODE_DISTRICT": "BR1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR1", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074558888", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074558888", + "NAME1": "Camberwell", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 532476, + "GEOMETRY_Y": 176980, + "MOST_DETAIL_VIEW_RES": 21000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 531872, + "MBR_YMIN": 175101, + "MBR_XMAX": 533829, + "MBR_YMAX": 178316, + "POSTCODE_DISTRICT": "SE5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE5", + "DISTRICT_BOROUGH": "Southwark", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011013", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/3345438", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Camberwell" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074575971", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074575971", + "NAME1": "Carshalton", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 528188, + "GEOMETRY_Y": 164544, + "MOST_DETAIL_VIEW_RES": 18000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 526585, + "MBR_YMIN": 163592, + "MBR_XMAX": 528588, + "MBR_YMAX": 166431, + "POSTCODE_DISTRICT": "SM5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SM5", + "DISTRICT_BOROUGH": "Sutton", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010873", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2653646", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Carshalton" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074551841", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074551841", + "NAME1": "Catford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 537693, + "GEOMETRY_Y": 173590, + "MOST_DETAIL_VIEW_RES": 24000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 536510, + "MBR_YMIN": 171977, + "MBR_XMAX": 540189, + "MBR_YMAX": 174275, + "POSTCODE_DISTRICT": "SE6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE6", + "DISTRICT_BOROUGH": "Lewisham", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011039", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2653516", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Catford" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074550344", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074550344", + "NAME1": "Chislehurst", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 543847, + "GEOMETRY_Y": 170855, + "MOST_DETAIL_VIEW_RES": 28000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 542569, + "MBR_YMIN": 167580, + "MBR_XMAX": 545633, + "MBR_YMAX": 171844, + "POSTCODE_DISTRICT": "BR7", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR7", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2653123", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Chislehurst" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074561090", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074561090", + "NAME1": "Chiswick", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 520700, + "GEOMETRY_Y": 178485, + "MOST_DETAIL_VIEW_RES": 18000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 520259, + "MBR_YMIN": 176083, + "MBR_XMAX": 522046, + "MBR_YMAX": 178809, + "POSTCODE_DISTRICT": "W4", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/W4", + "DISTRICT_BOROUGH": "Hounslow", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011489", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2653121", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Chiswick" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074559228", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559228", + "NAME1": "Clapham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 529697, + "GEOMETRY_Y": 175442, + "MOST_DETAIL_VIEW_RES": 12000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 528519, + "MBR_YMIN": 175023, + "MBR_XMAX": 530204, + "MBR_YMAX": 176851, + "POSTCODE_DISTRICT": "SW4", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SW4", + "DISTRICT_BOROUGH": "Lambeth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011144", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2652951", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Clapham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074319395", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074319395", + "NAME1": "Coldharbour", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 552155, + "GEOMETRY_Y": 179050, + "MOST_DETAIL_VIEW_RES": 15000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 551806, + "MBR_YMIN": 178698, + "MBR_XMAX": 552595, + "MBR_YMAX": 179198, + "POSTCODE_DISTRICT": "RM13", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/RM13", + "DISTRICT_BOROUGH": "Havering", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010807", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Coldharbour,_Havering" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074568222", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074568222", + "NAME1": "Coulsdon", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 529832, + "GEOMETRY_Y": 159625, + "MOST_DETAIL_VIEW_RES": 32000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 528039, + "MBR_YMIN": 156590, + "MBR_XMAX": 532962, + "MBR_YMAX": 160883, + "POSTCODE_DISTRICT": "CR5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/CR5", + "DISTRICT_BOROUGH": "Croydon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010896", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2652249", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Coulsdon" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074568828", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074568828", + "NAME1": "Crayford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 551362, + "GEOMETRY_Y": 174898, + "MOST_DETAIL_VIEW_RES": 23000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 549655, + "MBR_YMIN": 173735, + "MBR_XMAX": 553215, + "MBR_YMAX": 176331, + "POSTCODE_DISTRICT": "DA1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/DA1", + "DISTRICT_BOROUGH": "Bexley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010759", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2652046", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Crayford_Manor_House_Astronomical_Society" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074575690", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074575690", + "NAME1": "Croydon", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 532327, + "GEOMETRY_Y": 165555, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 531594, + "MBR_YMIN": 162408, + "MBR_XMAX": 535418, + "MBR_YMAX": 167048, + "POSTCODE_DISTRICT": "CR9", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/CR9", + "DISTRICT_BOROUGH": "Croydon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010896", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2651817", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Croydon" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074544948", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074544948", + "NAME1": "Denham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 523096, + "GEOMETRY_Y": 193921, + "MOST_DETAIL_VIEW_RES": 15000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 522828, + "MBR_YMIN": 193652, + "MBR_XMAX": 523328, + "MBR_YMAX": 194152, + "POSTCODE_DISTRICT": "N20", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/N20", + "DISTRICT_BOROUGH": "Barnet", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011378", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074558536", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074558536", + "NAME1": "Deptford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 537184, + "GEOMETRY_Y": 177255, + "MOST_DETAIL_VIEW_RES": 20000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 535344, + "MBR_YMIN": 175921, + "MBR_XMAX": 537871, + "MBR_YMAX": 179015, + "POSTCODE_DISTRICT": "SE8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE8", + "DISTRICT_BOROUGH": "Lewisham", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011039", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2651349", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Deptford" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343892", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343892", + "NAME1": "Ealing", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 517868, + "GEOMETRY_Y": 180795, + "MOST_DETAIL_VIEW_RES": 33000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 515654, + "MBR_YMIN": 178370, + "MBR_XMAX": 519436, + "MBR_YMAX": 183420, + "POSTCODE_DISTRICT": "W5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/W5", + "DISTRICT_BOROUGH": "Ealing", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011399", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343910", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343910", + "NAME1": "Edgware", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 519576, + "GEOMETRY_Y": 192258, + "MOST_DETAIL_VIEW_RES": 22000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 517960, + "MBR_YMIN": 191431, + "MBR_XMAX": 521413, + "MBR_YMAX": 194020, + "POSTCODE_DISTRICT": "HA8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/HA8", + "DISTRICT_BOROUGH": "Barnet", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011378", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343646", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343646", + "NAME1": "Edmonton", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 534344, + "GEOMETRY_Y": 193523, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 531844, + "MBR_YMIN": 191461, + "MBR_XMAX": 536408, + "MBR_YMAX": 195641, + "POSTCODE_DISTRICT": "N9", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/N9", + "DISTRICT_BOROUGH": "Enfield", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011329", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2650209", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Edmonton,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074551840", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074551840", + "NAME1": "Eltham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 543047, + "GEOMETRY_Y": 174425, + "MOST_DETAIL_VIEW_RES": 32000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 540270, + "MBR_YMIN": 171432, + "MBR_XMAX": 545189, + "MBR_YMAX": 176334, + "POSTCODE_DISTRICT": "SE9", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE9", + "DISTRICT_BOROUGH": "Greenwich", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010777", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2650042", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Eltham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343645", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343645", + "NAME1": "Enfield", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 532620, + "GEOMETRY_Y": 196563, + "MOST_DETAIL_VIEW_RES": 43000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 530532, + "MBR_YMIN": 195470, + "MBR_XMAX": 537168, + "MBR_YMAX": 199940, + "POSTCODE_DISTRICT": "EN2", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/EN2", + "DISTRICT_BOROUGH": "Enfield", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011329", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074569176", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074569176", + "NAME1": "Erith", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 551421, + "GEOMETRY_Y": 178014, + "MOST_DETAIL_VIEW_RES": 24000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 548915, + "MBR_YMIN": 176838, + "MBR_XMAX": 552664, + "MBR_YMAX": 180003, + "POSTCODE_DISTRICT": "DA8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/DA8", + "DISTRICT_BOROUGH": "Bexley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010759", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2649937", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Erith" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074549619", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074549619", + "NAME1": "Feltham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 510632, + "GEOMETRY_Y": 173185, + "MOST_DETAIL_VIEW_RES": 28000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 508526, + "MBR_YMIN": 171139, + "MBR_XMAX": 512005, + "MBR_YMAX": 175516, + "POSTCODE_DISTRICT": "TW13", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/TW13", + "DISTRICT_BOROUGH": "Hounslow", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011489", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2649571", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Feltham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074576629", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074576629", + "NAME1": "Finchley", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 525120, + "GEOMETRY_Y": 190603, + "MOST_DETAIL_VIEW_RES": 39000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 523961, + "MBR_YMIN": 187182, + "MBR_XMAX": 527869, + "MBR_YMAX": 193189, + "POSTCODE_DISTRICT": "N3", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/N3", + "DISTRICT_BOROUGH": "Barnet", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011378", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2649441", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Finchley" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074563040", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074563040", + "NAME1": "Greenford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 514396, + "GEOMETRY_Y": 182238, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 513320, + "MBR_YMIN": 181077, + "MBR_XMAX": 516640, + "MBR_YMAX": 185655, + "POSTCODE_DISTRICT": "UB6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/UB6", + "DISTRICT_BOROUGH": "Ealing", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011399", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2647972", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Greenford" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074578783", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074578783", + "NAME1": "Greenwich", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 538233, + "GEOMETRY_Y": 177402, + "MOST_DETAIL_VIEW_RES": 28000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 537411, + "MBR_YMIN": 176207, + "MBR_XMAX": 540362, + "MBR_YMAX": 180547, + "POSTCODE_DISTRICT": "SE10", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE10", + "DISTRICT_BOROUGH": "Greenwich", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010777", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2647937", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Greenwich" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074559563", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559563", + "NAME1": "Hackney", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 534945, + "GEOMETRY_Y": 184665, + "MOST_DETAIL_VIEW_RES": 22000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 534277, + "MBR_YMIN": 183208, + "MBR_XMAX": 537651, + "MBR_YMAX": 185500, + "POSTCODE_DISTRICT": "E8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/E8", + "DISTRICT_BOROUGH": "Hackney", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011199", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2647694", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Hackney_Central" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074541613", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074541613", + "NAME1": "Hampstead", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 526369, + "GEOMETRY_Y": 185770, + "MOST_DETAIL_VIEW_RES": 42000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 523942, + "MBR_YMIN": 183293, + "MBR_XMAX": 528194, + "MBR_YMAX": 189735, + "POSTCODE_DISTRICT": "NW3", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/NW3", + "DISTRICT_BOROUGH": "Camden", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011244", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2647553", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Hampstead" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074552296", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074552296", + "NAME1": "Harrow", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 515179, + "GEOMETRY_Y": 187073, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 512092, + "MBR_YMIN": 185031, + "MBR_XMAX": 516724, + "MBR_YMAX": 189636, + "POSTCODE_DISTRICT": "HA1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/HA1", + "DISTRICT_BOROUGH": "Harrow", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011391", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2647425", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Harrow,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074564185", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074564185", + "NAME1": "Hayes", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 509843, + "GEOMETRY_Y": 179876, + "MOST_DETAIL_VIEW_RES": 34000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 507650, + "MBR_YMIN": 178316, + "MBR_XMAX": 512301, + "MBR_YMAX": 183498, + "POSTCODE_DISTRICT": "UB3", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/UB3", + "DISTRICT_BOROUGH": "Hillingdon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011539", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2647261", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Hayes,_Hillingdon" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074551186", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074551186", + "NAME1": "Hendon", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 522830, + "GEOMETRY_Y": 188571, + "MOST_DETAIL_VIEW_RES": 29000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 521684, + "MBR_YMIN": 186394, + "MBR_XMAX": 524387, + "MBR_YMAX": 190804, + "POSTCODE_DISTRICT": "NW4", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/NW4", + "DISTRICT_BOROUGH": "Barnet", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011378", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2647116", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Hendon" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343947", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343947", + "NAME1": "Hillingdon", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 507636, + "GEOMETRY_Y": 184701, + "MOST_DETAIL_VIEW_RES": 26000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 506253, + "MBR_YMIN": 180930, + "MBR_XMAX": 508669, + "MBR_YMAX": 184945, + "POSTCODE_DISTRICT": "UB10", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/UB10", + "DISTRICT_BOROUGH": "Hillingdon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011539", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074574005", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074574005", + "NAME1": "Hornchurch", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 554024, + "GEOMETRY_Y": 187115, + "MOST_DETAIL_VIEW_RES": 27000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 551390, + "MBR_YMIN": 184835, + "MBR_XMAX": 555511, + "MBR_YMAX": 188205, + "POSTCODE_DISTRICT": "RM11", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/RM11", + "DISTRICT_BOROUGH": "Havering", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010807", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/6690863", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Hornchurch" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074574948", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074574948", + "NAME1": "Hornsey", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 530455, + "GEOMETRY_Y": 189324, + "MOST_DETAIL_VIEW_RES": 14000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 529382, + "MBR_YMIN": 188499, + "MBR_XMAX": 531480, + "MBR_YMAX": 189864, + "POSTCODE_DISTRICT": "N8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/N8", + "DISTRICT_BOROUGH": "Haringey", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011290", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2646580", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Hornsey" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074561692", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074561692", + "NAME1": "Hounslow", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 513893, + "GEOMETRY_Y": 175576, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 510630, + "MBR_YMIN": 173476, + "MBR_XMAX": 515250, + "MBR_YMAX": 176786, + "POSTCODE_DISTRICT": "TW3", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/TW3", + "DISTRICT_BOROUGH": "Hounslow", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011489", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2646517", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Hounslow" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074579136", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074579136", + "NAME1": "Ilford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 543838, + "GEOMETRY_Y": 186340, + "MOST_DETAIL_VIEW_RES": 28000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 541297, + "MBR_YMIN": 185409, + "MBR_XMAX": 545634, + "MBR_YMAX": 188208, + "POSTCODE_DISTRICT": "IG1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/IG1", + "DISTRICT_BOROUGH": "Redbridge", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010955", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2646277", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Ilford" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074561688", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074561688", + "NAME1": "Isleworth", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 516178, + "GEOMETRY_Y": 175781, + "MOST_DETAIL_VIEW_RES": 20000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 514713, + "MBR_YMIN": 174116, + "MBR_XMAX": 516939, + "MBR_YMAX": 177235, + "POSTCODE_DISTRICT": "TW7", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/TW7", + "DISTRICT_BOROUGH": "Hounslow", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011489", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2646004", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Isleworth" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074559233", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559233", + "NAME1": "Islington", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 531671, + "GEOMETRY_Y": 183777, + "MOST_DETAIL_VIEW_RES": 17000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 530016, + "MBR_YMIN": 182917, + "MBR_XMAX": 532588, + "MBR_YMAX": 185202, + "POSTCODE_DISTRICT": "N1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/N1", + "DISTRICT_BOROUGH": "Islington", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011281", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2646003", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Islington" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074551926", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074551926", + "NAME1": "Kenton", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 516760, + "GEOMETRY_Y": 188419, + "MOST_DETAIL_VIEW_RES": 21000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 515901, + "MBR_YMIN": 187416, + "MBR_XMAX": 519146, + "MBR_YMAX": 190158, + "POSTCODE_DISTRICT": "HA3", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/HA3", + "DISTRICT_BOROUGH": "Brent", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011447", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2645788", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Kenton" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074578779", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074578779", + "NAME1": "Lewisham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 538098, + "GEOMETRY_Y": 174995, + "MOST_DETAIL_VIEW_RES": 14000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 537360, + "MBR_YMIN": 174154, + "MBR_XMAX": 539149, + "MBR_YMAX": 176323, + "POSTCODE_DISTRICT": "SE13", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE13", + "DISTRICT_BOROUGH": "Lewisham", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011039", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2644556", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Lewisham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074575394", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074575394", + "NAME1": "Merton", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 526411, + "GEOMETRY_Y": 169885, + "MOST_DETAIL_VIEW_RES": 11000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 525130, + "MBR_YMIN": 168745, + "MBR_XMAX": 526769, + "MBR_YMAX": 170193, + "POSTCODE_DISTRICT": "SW19", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SW19", + "DISTRICT_BOROUGH": "Merton", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010995", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074575392", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074575392", + "NAME1": "Mitcham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 527355, + "GEOMETRY_Y": 168640, + "MOST_DETAIL_VIEW_RES": 29000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 526118, + "MBR_YMIN": 166836, + "MBR_XMAX": 530598, + "MBR_YMAX": 170915, + "POSTCODE_DISTRICT": "CR4", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/CR4", + "DISTRICT_BOROUGH": "Merton", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010995", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2642414", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Mitcham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343979", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343979", + "NAME1": "Morden", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 525817, + "GEOMETRY_Y": 168499, + "MOST_DETAIL_VIEW_RES": 28000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 523269, + "MBR_YMIN": 165940, + "MBR_XMAX": 527544, + "MBR_YMAX": 169002, + "POSTCODE_DISTRICT": "SM4", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SM4", + "DISTRICT_BOROUGH": "Merton", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010995", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074563041", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074563041", + "NAME1": "Northolt", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 513071, + "GEOMETRY_Y": 184287, + "MOST_DETAIL_VIEW_RES": 24000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 511198, + "MBR_YMIN": 182348, + "MBR_XMAX": 514844, + "MBR_YMAX": 185827, + "POSTCODE_DISTRICT": "UB5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/UB5", + "DISTRICT_BOROUGH": "Ealing", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011399", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2641290", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Northolt" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074541727", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074541727", + "NAME1": "Northwood", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 509249, + "GEOMETRY_Y": 191464, + "MOST_DETAIL_VIEW_RES": 21000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 507333, + "MBR_YMIN": 190307, + "MBR_XMAX": 510504, + "MBR_YMAX": 192389, + "POSTCODE_DISTRICT": "HA6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/HA6", + "DISTRICT_BOROUGH": "Hillingdon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011539", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2641216", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Northwood,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074549229", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074549229", + "NAME1": "Orpington", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 546204, + "GEOMETRY_Y": 166159, + "MOST_DETAIL_VIEW_RES": 42000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 544022, + "MBR_YMIN": 164211, + "MBR_XMAX": 548159, + "MBR_YMAX": 170604, + "POSTCODE_DISTRICT": "BR6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR6", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2640894", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Orpington" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074576542", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074576542", + "NAME1": "Penge", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 535429, + "GEOMETRY_Y": 170332, + "MOST_DETAIL_VIEW_RES": 16000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 533470, + "MBR_YMIN": 169374, + "MBR_XMAX": 535926, + "MBR_YMAX": 171459, + "POSTCODE_DISTRICT": "SE20", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE20", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/6941038", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Penge" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074560966", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074560966", + "NAME1": "Pinner", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 512165, + "GEOMETRY_Y": 189570, + "MOST_DETAIL_VIEW_RES": 27000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 510581, + "MBR_YMIN": 187553, + "MBR_XMAX": 513449, + "MBR_YMAX": 191749, + "POSTCODE_DISTRICT": "HA5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/HA5", + "DISTRICT_BOROUGH": "Harrow", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011391", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2640275", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Pinner" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074567896", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074567896", + "NAME1": "Purley", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 531267, + "GEOMETRY_Y": 161623, + "MOST_DETAIL_VIEW_RES": 22000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 528988, + "MBR_YMIN": 160000, + "MBR_XMAX": 532394, + "MBR_YMAX": 162577, + "POSTCODE_DISTRICT": "CR8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/CR8", + "DISTRICT_BOROUGH": "Croydon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010896", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2639842", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Purley,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074562835", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074562835", + "NAME1": "Putney", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 523957, + "GEOMETRY_Y": 175039, + "MOST_DETAIL_VIEW_RES": 25000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 522538, + "MBR_YMIN": 172558, + "MBR_XMAX": 524467, + "MBR_YMAX": 176357, + "POSTCODE_DISTRICT": "SW15", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SW15", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2639835", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Putney" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074569858", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074569858", + "NAME1": "Rainham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 552037, + "GEOMETRY_Y": 182247, + "MOST_DETAIL_VIEW_RES": 24000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 550509, + "MBR_YMIN": 180570, + "MBR_XMAX": 554151, + "MBR_YMAX": 183556, + "POSTCODE_DISTRICT": "RM13", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/RM13", + "DISTRICT_BOROUGH": "Havering", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010807", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2639690", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Rainham,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074569531", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074569531", + "NAME1": "Romford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 551490, + "GEOMETRY_Y": 189133, + "MOST_DETAIL_VIEW_RES": 33000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 548866, + "MBR_YMIN": 186414, + "MBR_XMAX": 553933, + "MBR_YMAX": 190964, + "POSTCODE_DISTRICT": "RM1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/RM1", + "DISTRICT_BOROUGH": "Havering", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010807", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2639192", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Romford" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074561171", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074561171", + "NAME1": "Ruislip", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 509092, + "GEOMETRY_Y": 187621, + "MOST_DETAIL_VIEW_RES": 48000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 507725, + "MBR_YMIN": 183907, + "MBR_XMAX": 512566, + "MBR_YMAX": 191288, + "POSTCODE_DISTRICT": "HA4", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/HA4", + "DISTRICT_BOROUGH": "Hillingdon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011539", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2638976", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Ruislip" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074550722", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074550722", + "NAME1": "Sidcup", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 546204, + "GEOMETRY_Y": 172826, + "MOST_DETAIL_VIEW_RES": 26000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 544527, + "MBR_YMIN": 170403, + "MBR_XMAX": 548484, + "MBR_YMAX": 174213, + "POSTCODE_DISTRICT": "DA15", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/DA15", + "DISTRICT_BOROUGH": "Bexley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010759", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2637861", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Sidcup" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074562074", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074562074", + "NAME1": "Southall", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 512825, + "GEOMETRY_Y": 180394, + "MOST_DETAIL_VIEW_RES": 33000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 510521, + "MBR_YMIN": 178552, + "MBR_XMAX": 515617, + "MBR_YMAX": 182802, + "POSTCODE_DISTRICT": "UB1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/UB1", + "DISTRICT_BOROUGH": "Ealing", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011399", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2637490", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Southall" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074577371", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074577371", + "NAME1": "Southgate", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 529680, + "GEOMETRY_Y": 193962, + "MOST_DETAIL_VIEW_RES": 26000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 528124, + "MBR_YMIN": 191777, + "MBR_XMAX": 531086, + "MBR_YMAX": 195820, + "POSTCODE_DISTRICT": "N14", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/N14", + "DISTRICT_BOROUGH": "Enfield", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011329", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Southgate,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343954", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343954", + "NAME1": "Southwark", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 532192, + "GEOMETRY_Y": 179919, + "MOST_DETAIL_VIEW_RES": 13000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 531188, + "MBR_YMIN": 178875, + "MBR_XMAX": 533116, + "MBR_YMAX": 180691, + "POSTCODE_DISTRICT": "SE1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE1", + "DISTRICT_BOROUGH": "Southwark", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011013", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074553072", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074553072", + "NAME1": "Stanmore", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 517015, + "GEOMETRY_Y": 192329, + "MOST_DETAIL_VIEW_RES": 35000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 514520, + "MBR_YMIN": 190003, + "MBR_XMAX": 519942, + "MBR_YMAX": 194396, + "POSTCODE_DISTRICT": "HA7", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/HA7", + "DISTRICT_BOROUGH": "Harrow", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011391", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2637063", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Stanmore" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074579133", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074579133", + "NAME1": "Stratford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 538840, + "GEOMETRY_Y": 184272, + "MOST_DETAIL_VIEW_RES": 18000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 537329, + "MBR_YMIN": 182798, + "MBR_XMAX": 539561, + "MBR_YMAX": 185588, + "POSTCODE_DISTRICT": "E15", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/E15", + "DISTRICT_BOROUGH": "Newham", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010929", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2636714", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Stratford,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074575698", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074575698", + "NAME1": "Streatham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 530139, + "GEOMETRY_Y": 171999, + "MOST_DETAIL_VIEW_RES": 28000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 528804, + "MBR_YMIN": 169624, + "MBR_XMAX": 531437, + "MBR_YMAX": 173994, + "POSTCODE_DISTRICT": "SW16", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SW16", + "DISTRICT_BOROUGH": "Lambeth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011144", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2636675", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Streatham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343897", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343897", + "NAME1": "Sutton", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 525864, + "GEOMETRY_Y": 164316, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 524772, + "MBR_YMIN": 162055, + "MBR_XMAX": 526782, + "MBR_YMAX": 166640, + "POSTCODE_DISTRICT": "SM1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SM1", + "DISTRICT_BOROUGH": "Sutton", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010873", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074574409", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074574409", + "NAME1": "Tottenham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 533604, + "GEOMETRY_Y": 189510, + "MOST_DETAIL_VIEW_RES": 26000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 531480, + "MBR_YMIN": 187950, + "MBR_XMAX": 535529, + "MBR_YMAX": 191793, + "POSTCODE_DISTRICT": "N15", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/N15", + "DISTRICT_BOROUGH": "Haringey", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011290", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2635608", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Tottenham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074573321", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074573321", + "NAME1": "Upminster", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 556014, + "GEOMETRY_Y": 186548, + "MOST_DETAIL_VIEW_RES": 22000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 554855, + "MBR_YMIN": 185391, + "MBR_XMAX": 557248, + "MBR_YMAX": 188816, + "POSTCODE_DISTRICT": "RM14", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/RM14", + "DISTRICT_BOROUGH": "Havering", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010807", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2635150", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Upminster" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074565718", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074565718", + "NAME1": "Uxbridge", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 505528, + "GEOMETRY_Y": 184129, + "MOST_DETAIL_VIEW_RES": 21000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 504454, + "MBR_YMIN": 182376, + "MBR_XMAX": 506893, + "MBR_YMAX": 185632, + "POSTCODE_DISTRICT": "UB8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/UB8", + "DISTRICT_BOROUGH": "Hillingdon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011539", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2635042", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Uxbridge" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074575967", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074575967", + "NAME1": "Wallington", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 528955, + "GEOMETRY_Y": 163652, + "MOST_DETAIL_VIEW_RES": 20000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 528184, + "MBR_YMIN": 162582, + "MBR_XMAX": 529792, + "MBR_YMAX": 165683, + "POSTCODE_DISTRICT": "SM6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SM6", + "DISTRICT_BOROUGH": "Sutton", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010873", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2634867", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Wallington,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074576254", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074576254", + "NAME1": "Wandsworth", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 525661, + "GEOMETRY_Y": 174637, + "MOST_DETAIL_VIEW_RES": 20000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 524273, + "MBR_YMIN": 172891, + "MBR_XMAX": 527413, + "MBR_YMAX": 175697, + "POSTCODE_DISTRICT": "SW18", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SW18", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2634812", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Wandsworth" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074552140", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074552140", + "NAME1": "Wanstead", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 540447, + "GEOMETRY_Y": 188594, + "MOST_DETAIL_VIEW_RES": 18000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 539909, + "MBR_YMIN": 187206, + "MBR_XMAX": 541420, + "MBR_YMAX": 189925, + "POSTCODE_DISTRICT": "E11", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/E11", + "DISTRICT_BOROUGH": "Redbridge", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010955", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2634803", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Wanstead" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074563042", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074563042", + "NAME1": "Wembley", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 518419, + "GEOMETRY_Y": 185248, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 516053, + "MBR_YMIN": 184329, + "MBR_XMAX": 520606, + "MBR_YMAX": 187949, + "POSTCODE_DISTRICT": "HA9", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/HA9", + "DISTRICT_BOROUGH": "Brent", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011447", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2634549", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Wembley" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074562838", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074562838", + "NAME1": "Willesden", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 522522, + "GEOMETRY_Y": 184646, + "MOST_DETAIL_VIEW_RES": 20000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 521403, + "MBR_YMIN": 183086, + "MBR_XMAX": 523646, + "MBR_YMAX": 186103, + "POSTCODE_DISTRICT": "NW10", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/NW10", + "DISTRICT_BOROUGH": "Brent", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011447", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2633907", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Willesden" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074541243", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074541243", + "NAME1": "Wimbledon", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 524915, + "GEOMETRY_Y": 170559, + "MOST_DETAIL_VIEW_RES": 35000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 521440, + "MBR_YMIN": 169313, + "MBR_XMAX": 526763, + "MBR_YMAX": 174009, + "POSTCODE_DISTRICT": "SW19", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SW19", + "DISTRICT_BOROUGH": "Merton", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010995", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2633866", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Wimbledon,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343914", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343914", + "NAME1": "Woodford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 540921, + "GEOMETRY_Y": 191835, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 539151, + "MBR_YMIN": 189582, + "MBR_XMAX": 543060, + "MBR_YMAX": 194179, + "POSTCODE_DISTRICT": "IG8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/IG8", + "DISTRICT_BOROUGH": "Redbridge", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010955", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074578663", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074578663", + "NAME1": "Woolwich", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 543354, + "GEOMETRY_Y": 178854, + "MOST_DETAIL_VIEW_RES": 21000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 541660, + "MBR_YMIN": 177231, + "MBR_XMAX": 544364, + "MBR_YMAX": 180531, + "POSTCODE_DISTRICT": "SE18", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE18", + "DISTRICT_BOROUGH": "Greenwich", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010777", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2633583", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Woolwich" + } + } + ] +} \ No newline at end of file diff --git a/test/fixtures/uk_ordnance_survey_names_no_results b/test/fixtures/uk_ordnance_survey_names_no_results new file mode 100644 index 000000000..ed4ad4136 --- /dev/null +++ b/test/fixtures/uk_ordnance_survey_names_no_results @@ -0,0 +1,11 @@ +{ + "header": { + "uri": "https://api.ordnancesurvey.co.uk/opennames/v1/find?query=sxz%60x%60zx%60xz%60xz%60&fq=local_type%3ACity%20local_type%3AHamlet%20local_type%3AOther_Settlement%20local_type%3ATown%20local_type%3AVillage%20local_type%3APostcode", + "query": "sxz`x`zx`xz`xz`", + "format": "JSON", + "maxresults": 100, + "offset": 0, + "totalresults": 0, + "filter": "fq=local_type:City local_type:Hamlet local_type:Other_Settlement local_type:Town local_type:Village local_type:Postcode" + } +} \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 7b9cf3acc..43a91b9ca 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -386,6 +386,14 @@ def default_fixture_filename end end + require 'geocoder/lookups/uk_ordnance_survey_names' + class Geocoder::Lookup::UkOrdnanceSurveyNames + private + def default_fixture_filename + "#{fixture_prefix}_london" + end + end + require 'geocoder/lookups/geoportail_lu' class GeoportailLu private diff --git a/test/unit/lookup_test.rb b/test/unit/lookup_test.rb index 146fff04c..15e2f6a29 100644 --- a/test/unit/lookup_test.rb +++ b/test/unit/lookup_test.rb @@ -25,7 +25,7 @@ def test_search_returns_empty_array_when_no_results def test_query_url_contains_values_in_params_hash Geocoder::Lookup.all_services_except_test.each do |l| - next if [:freegeoip, :maxmind_local, :telize, :pointpin, :geoip2, :maxmind_geoip2, :mapbox, :ipdata_co, :ipinfo_io, :ipapi_com, :ipregistry, :ipstack, :postcodes_io].include? l # does not use query string + next if [:freegeoip, :maxmind_local, :telize, :pointpin, :geoip2, :maxmind_geoip2, :mapbox, :ipdata_co, :ipinfo_io, :ipapi_com, :ipregistry, :ipstack, :postcodes_io, :uk_ordnance_survey_names].include? l # does not use query string set_api_key!(l) url = Geocoder::Lookup.get(l).query_url(Geocoder::Query.new( "test", :params => {:one_in_the_hand => "two in the bush"} diff --git a/test/unit/lookups/uk_ordnance_survey_names.rb b/test/unit/lookups/uk_ordnance_survey_names.rb new file mode 100644 index 000000000..629d8ac4c --- /dev/null +++ b/test/unit/lookups/uk_ordnance_survey_names.rb @@ -0,0 +1,22 @@ +# encoding: utf-8 +require 'test_helper' + +class UkOrdnanceSurveyNamesTest < GeocoderTestCase + + def setup + Geocoder.configure(lookup: :uk_ordnance_survey_names) + set_api_key!(:uk_ordnance_survey_names) + end + + def test_result_on_placename_search + result = Geocoder.search('London').first + assert_in_delta 51.51437, result.coordinates[0] + assert_in_delta -0.09227, result.coordinates[1] + end + + def test_result_on_postcode_search + result = Geocoder.search('SW1A1AA').first + assert_in_delta 51.50100, result.coordinates[0] + assert_in_delta -0.14157, result.coordinates[1] + end +end From 5c41aa888cc21b1f458320932118ce4ffec22333 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 16 Mar 2020 14:11:57 -0700 Subject: [PATCH 238/248] Remove duplicate method declaration. --- lib/geocoder/results/uk_ordnance_survey_names.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/geocoder/results/uk_ordnance_survey_names.rb b/lib/geocoder/results/uk_ordnance_survey_names.rb index 2eae2fb34..c09d357bd 100644 --- a/lib/geocoder/results/uk_ordnance_survey_names.rb +++ b/lib/geocoder/results/uk_ordnance_survey_names.rb @@ -5,7 +5,10 @@ module Geocoder::Result class UkOrdnanceSurveyNames < Base def coordinates - [latitude, longitude] + @coordinates ||= Geocoder::EastingNorthing.new( + easting: data['GEOMETRY_X'], + northing: data['GEOMETRY_Y'], + ).lat_lng end def city @@ -42,13 +45,6 @@ def country_code 'UK' end - def coordinates - @coordinates ||= Geocoder::EastingNorthing.new( - easting: data['GEOMETRY_X'], - northing: data['GEOMETRY_Y'], - ).lat_lng - end - private def is_postcode? From 8956162731444f09cb76dd11db292bd99c78e44d Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 16 Mar 2020 17:29:55 -0700 Subject: [PATCH 239/248] Prepare for release of gem version 1.6.2. --- CHANGELOG.md | 6 ++++++ lib/geocoder/version.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15104f65a..2b5854dad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ Changelog Major changes to Geocoder for each release. Please see the Git log for complete list of changes. +1.6.2 (2020 Mar 16) +------------------- +* Add support for :nationaal_georegister_nl lookup (thanks github.com/opensourceame). +* Add support for :uk_ordnance_survey_names lookup (thanks github.com/pezholio). +* Refactor and fix bugs in Yandex lookup (thanks github.com/iarie and stereodenis). + 1.6.1 (2020 Jan 23) ------------------- * Sanitize lat/lon values passed to within_bounding_box to prevent SQL injection. diff --git a/lib/geocoder/version.rb b/lib/geocoder/version.rb index 092dec535..7f12e3831 100644 --- a/lib/geocoder/version.rb +++ b/lib/geocoder/version.rb @@ -1,3 +1,3 @@ module Geocoder - VERSION = "1.6.1" + VERSION = "1.6.2" end From 5a4bee21278647fefe9e67fc557d587df1defac2 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 16 Mar 2020 19:19:38 -0700 Subject: [PATCH 240/248] Make SmartyStreets recognize errors. Fixes #1426. --- lib/geocoder/lookups/smarty_streets.rb | 7 ++++++- test/fixtures/smarty_streets_10300 | 1 + test/unit/lookups/smarty_streets_test.rb | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/smarty_streets_10300 diff --git a/lib/geocoder/lookups/smarty_streets.rb b/lib/geocoder/lookups/smarty_streets.rb index e4f56ec6e..7745a94a5 100644 --- a/lib/geocoder/lookups/smarty_streets.rb +++ b/lib/geocoder/lookups/smarty_streets.rb @@ -57,7 +57,12 @@ def query_url_params(query) end def results(query) - fetch_data(query) || [] + doc = fetch_data(query) || [] + if doc.is_a?(Hash) and doc.key?('status') # implies there's an error + return [] + else + return doc + end end end end diff --git a/test/fixtures/smarty_streets_10300 b/test/fixtures/smarty_streets_10300 new file mode 100644 index 000000000..2b5ed627d --- /dev/null +++ b/test/fixtures/smarty_streets_10300 @@ -0,0 +1 @@ +{"input_index":0, "status":"invalid_zipcode", "reason":"Invalid ZIP Code."} diff --git a/test/unit/lookups/smarty_streets_test.rb b/test/unit/lookups/smarty_streets_test.rb index 1baf99c25..d25048488 100644 --- a/test/unit/lookups/smarty_streets_test.rb +++ b/test/unit/lookups/smarty_streets_test.rb @@ -73,6 +73,12 @@ def test_no_results assert_equal 0, results.length end + def test_invalid_zipcode_returns_no_results + assert_nothing_raised do + assert_nil Geocoder.search("10300").first + end + end + def test_raises_exception_on_error_http_status error_statuses = { '400' => Geocoder::InvalidRequest, From 6e0c6c8375e9786f30912119a64e83274018aff9 Mon Sep 17 00:00:00 2001 From: Damien White <damien.white@visoftinc.com> Date: Mon, 23 Mar 2020 16:49:40 -0400 Subject: [PATCH 241/248] Added preferredLabelValues param for ESRI See https://developers.arcgis.com/rest/geocode/api-reference/geocoding-find-address-candidates.htm for more information --- lib/geocoder/lookups/esri.rb | 2 ++ test/unit/lookups/esri_test.rb | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/geocoder/lookups/esri.rb b/lib/geocoder/lookups/esri.rb index 6f6cf0eb8..e80ba5437 100644 --- a/lib/geocoder/lookups/esri.rb +++ b/lib/geocoder/lookups/esri.rb @@ -47,6 +47,8 @@ def query_url_params(query) params[:forStorage] = for_storage_value end params[:sourceCountry] = configuration[:source_country] if configuration[:source_country] + params[:preferredLabelValues] = configuration[:preferred_label_values] if configuration[:preferred_label_values] + params.merge(super) end diff --git a/test/unit/lookups/esri_test.rb b/test/unit/lookups/esri_test.rb index 4329276d4..7d76457d2 100644 --- a/test/unit/lookups/esri_test.rb +++ b/test/unit/lookups/esri_test.rb @@ -24,6 +24,14 @@ def test_query_for_geocode_with_source_country assert_match %r{sourceCountry=USA}, url end + def test_query_for_geocode_with_preferred_label_values + Geocoder.configure(esri: {preferred_label_values: 'localCity'}) + query = Geocoder::Query.new("Bluffton, SC") + lookup = Geocoder::Lookup.get(:esri) + url = lookup.query_url(query) + assert_match %r{preferredLabelValues=localCity}, url + end + def test_query_for_geocode_with_token_and_for_storage token = Geocoder::EsriToken.new('xxxxx', Time.now + 60*60*24) Geocoder.configure(esri: {token: token, for_storage: true}) From 2e1c9464b814d636e0cc793784d33e23fe12814d Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Thu, 9 Apr 2020 09:57:00 -0700 Subject: [PATCH 242/248] Update limitations for :google service. Fixes #1445. --- README_API_GUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index 6a33af627..bd9dddd0f 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -38,7 +38,7 @@ Global Street Address Lookups * `:google_place_id` - pass `true` if search query is a Google Place ID * **Documentation**: https://developers.google.com/maps/documentation/geocoding/intro * **Terms of Service**: http://code.google.com/apis/maps/terms.html#section_10_12 -* **Limitations**: "You must not use or display the Content without a corresponding Google map, unless you are explicitly permitted to do so in the Maps APIs Documentation, or through written permission from Google." "You must not pre-fetch, cache, or store any Content, except that you may store: (i) limited amounts of Content for the purpose of improving the performance of your Maps API Implementation..." +* **Limitations**: "You can display Geocoding API results on a Google Map, or without a map. If you want to display Geocoding API results on a map, then these results must be displayed on a Google Map. ... If your application displays data from the Geocoding API on a page or view that does not also display a Google Map, you must show a Powered by Google logo with that data. ... ...you must not pre-fetch, index, store, or cache any Content except under the limited conditions stated in the terms." (see: https://developers.google.com/maps/documentation/geocoding/policies) ### Google Maps API for Work (`:google_premier`) From 95124477fc4c7a676ce1059418ad8b41d3c179b1 Mon Sep 17 00:00:00 2001 From: Viktor <skcc321@gmail.com> Date: Fri, 10 Apr 2020 00:23:45 +0300 Subject: [PATCH 243/248] [fix] ruby 2.7.1 warning --- lib/geocoder/lookups/latlon.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/geocoder/lookups/latlon.rb b/lib/geocoder/lookups/latlon.rb index e6a77f299..cdc47ae38 100644 --- a/lib/geocoder/lookups/latlon.rb +++ b/lib/geocoder/lookups/latlon.rb @@ -25,8 +25,7 @@ def results(query) # The API returned a 404 response, which indicates no results found elsif doc['error']['type'] == 'api_error' [] - elsif - doc['error']['type'] == 'authentication_error' + elsif doc['error']['type'] == 'authentication_error' raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "LatLon.io service error: invalid API key.") else From dac0ae2a5cc13c80e7c5e23f9fa60015523d67df Mon Sep 17 00:00:00 2001 From: Gabe D <gpad88@gmail.com> Date: Mon, 13 Apr 2020 17:08:24 -0700 Subject: [PATCH 244/248] Support IP search with port [3ffe:0b00:000:0000:0001:0000:0000:000a]:80 should be valid --- lib/geocoder/ip_address.rb | 3 ++- test/unit/ip_address_test.rb | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/geocoder/ip_address.rb b/lib/geocoder/ip_address.rb index c6858cc74..466636a3b 100644 --- a/lib/geocoder/ip_address.rb +++ b/lib/geocoder/ip_address.rb @@ -20,7 +20,8 @@ def private? end def valid? - !!((self =~ Resolv::IPv4::Regex) || (self =~ Resolv::IPv6::Regex)) + ip = self[/(?<=\[)(.*?)(?=\])/] || self + !!((ip =~ Resolv::IPv4::Regex) || (ip =~ Resolv::IPv6::Regex)) end end end diff --git a/test/unit/ip_address_test.rb b/test/unit/ip_address_test.rb index e2dedf79e..1be4c8d16 100644 --- a/test/unit/ip_address_test.rb +++ b/test/unit/ip_address_test.rb @@ -13,6 +13,7 @@ def test_valid assert !Geocoder::IpAddress.new("232.65.123").valid? assert !Geocoder::IpAddress.new("::ffff:123.456.789").valid? assert !Geocoder::IpAddress.new("Test\n232.65.123.94").valid? + assert Geocoder::IpAddress.new("[3ffe:0b00:000:0000:0001:0000:0000:000a]:80").valid? end def test_internal From ef1afc556ce8cddbb93d34ec27881505a8cc493e Mon Sep 17 00:00:00 2001 From: Alexander Khatlamadzhiev <hatlam@hatlam.com> Date: Thu, 23 Apr 2020 21:38:14 +0300 Subject: [PATCH 245/248] Yandex fix. No more "found" param in meta section (#1448) Yandex fix. No more "found" param in meta section --- lib/geocoder/lookups/yandex.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/geocoder/lookups/yandex.rb b/lib/geocoder/lookups/yandex.rb index b39a9050a..3d3d8e26e 100644 --- a/lib/geocoder/lookups/yandex.rb +++ b/lib/geocoder/lookups/yandex.rb @@ -33,8 +33,7 @@ def results(query) return [] end if doc = doc['response']['GeoObjectCollection'] - meta = doc['metaDataProperty']['GeocoderResponseMetaData'] - return meta['found'].to_i > 0 ? doc['featureMember'] : [] + return doc['featureMember'].to_a else Geocoder.log(:warn, "Yandex Geocoding API error: unexpected response format.") return [] From b723d0fdf238bc717ebf6a351a18602652a622a5 Mon Sep 17 00:00:00 2001 From: Alex Walling <alex.walling19@gmail.com> Date: Thu, 30 Apr 2020 12:28:33 -0700 Subject: [PATCH 246/248] Update from Mashape to RapidAPI (#1450) Switch from Mashape URL to RapidAPI The Mashape API proxy URL has been deprecated and replaced with the RapidAPI proxy URL. --- README_API_GUIDE.md | 2 +- lib/geocoder/lookups/telize.rb | 2 +- test/unit/lookup_test.rb | 2 +- test/unit/lookups/telize_test.rb | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index bd9dddd0f..f78f46a6b 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -421,7 +421,7 @@ IP Address Lookups * **Region**: world * **SSL support**: yes * **Languages**: English -* **Documentation**: https://market.mashape.com/fcambus/telize +* **Documentation**: https://rapidapi.com/fcambus/api/telize * **Terms of Service**: ? * **Limitations**: ? * **Notes**: To use Telize set `Geocoder.configure(ip_lookup: :telize, api_key: "your_api_key")`. Or configure your self-hosted telize with the `host` option: `Geocoder.configure(ip_lookup: :telize, telize: {host: "localhost"})`. diff --git a/lib/geocoder/lookups/telize.rb b/lib/geocoder/lookups/telize.rb index 2dd84523a..839d42e9b 100644 --- a/lib/geocoder/lookups/telize.rb +++ b/lib/geocoder/lookups/telize.rb @@ -16,7 +16,7 @@ def query_url(query) if configuration[:host] "#{protocol}://#{configuration[:host]}/location/#{query.sanitized_text}" else - "#{protocol}://telize-v1.p.mashape.com/location/#{query.sanitized_text}?mashape-key=#{api_key}" + "#{protocol}://telize-v1.p.rapidapi.com/location/#{query.sanitized_text}?rapidapi-key=#{api_key}" end end diff --git a/test/unit/lookup_test.rb b/test/unit/lookup_test.rb index 15e2f6a29..baaa76a9a 100644 --- a/test/unit/lookup_test.rb +++ b/test/unit/lookup_test.rb @@ -147,7 +147,7 @@ def test_geocoder_ca_showpostal def test_telize_api_key Geocoder.configure(:api_key => "MY_KEY") g = Geocoder::Lookup::Telize.new - assert_match "mashape-key=MY_KEY", g.query_url(Geocoder::Query.new("232.65.123.94")) + assert_match "rapidapi-key=MY_KEY", g.query_url(Geocoder::Query.new("232.65.123.94")) end def test_ipinfo_io_api_key diff --git a/test/unit/lookups/telize_test.rb b/test/unit/lookups/telize_test.rb index 4280fe241..744a9069b 100644 --- a/test/unit/lookups/telize_test.rb +++ b/test/unit/lookups/telize_test.rb @@ -10,14 +10,14 @@ def setup def test_query_url lookup = Geocoder::Lookup::Telize.new query = Geocoder::Query.new("74.200.247.59") - assert_match %r{^https://telize-v1\.p\.mashape\.com/location/74\.200\.247\.59}, lookup.query_url(query) + assert_match %r{^https://telize-v1\.p\.rapidapi\.com/location/74\.200\.247\.59}, lookup.query_url(query) end def test_includes_api_key_when_set Geocoder.configure(api_key: "api_key") lookup = Geocoder::Lookup::Telize.new query = Geocoder::Query.new("74.200.247.59") - assert_match %r{/location/74\.200\.247\.59\?mashape-key=api_key}, lookup.query_url(query) + assert_match %r{/location/74\.200\.247\.59\?rapidapi-key=api_key}, lookup.query_url(query) end def test_uses_custom_host_when_set @@ -38,7 +38,7 @@ def test_requires_https_when_not_custom_host Geocoder.configure(use_https: false) lookup = Geocoder::Lookup::Telize.new query = Geocoder::Query.new("74.200.247.59") - assert_match %r{^https://telize-v1\.p\.mashape\.com}, lookup.query_url(query) + assert_match %r{^https://telize-v1\.p\.rapidapi\.com}, lookup.query_url(query) end def test_result_on_ip_address_search @@ -83,7 +83,7 @@ def test_cache_key_strips_off_query_string query = Geocoder::Query.new("8.8.8.8") qurl = lookup.send(:query_url, query) key = lookup.send(:cache_key, query) - assert qurl.include?("mashape-key") - assert !key.include?("mashape-key") + assert qurl.include?("rapidapi-key") + assert !key.include?("rapidapi-key") end end From 9b8984df6b0eee07df07eff31aa218eae72c734c Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Thu, 30 Apr 2020 12:28:53 -0700 Subject: [PATCH 247/248] Parse config stored in api_keys.yml. --- bin/console | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bin/console b/bin/console index c5867d3dc..8a177d5b0 100755 --- a/bin/console +++ b/bin/console @@ -3,5 +3,11 @@ require 'bundler/setup' require 'geocoder' +if File.exist?("api_keys.yml") + require 'yaml' + @api_keys = YAML.load(File.read("api_keys.yml"), symbolize_names: true) + Geocoder.configure(@api_keys) +end + require 'irb' IRB.start From 4a575d05e4878abadb32cf0c0c362a896adad6ed Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Thu, 30 Apr 2020 12:37:02 -0700 Subject: [PATCH 248/248] Prepare for release of gem version 1.6.3. --- CHANGELOG.md | 5 +++++ geocoder.gemspec | 2 +- lib/geocoder/version.rb | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b5854dad..faa88bfd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ Changelog Major changes to Geocoder for each release. Please see the Git log for complete list of changes. +1.6.3 (2020 Apr 30) +------------------- +* Update URL for :telize lookup (thanks github.com/alexwalling). +* Fix bug parsing IPv6 with port (thanks github.com/gdomingu). + 1.6.2 (2020 Mar 16) ------------------- * Add support for :nationaal_georegister_nl lookup (thanks github.com/opensourceame). diff --git a/geocoder.gemspec b/geocoder.gemspec index c2c8aba26..ed6955a26 100644 --- a/geocoder.gemspec +++ b/geocoder.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |s| s.homepage = "http://www.rubygeocoder.com" s.date = Date.today.to_s s.summary = "Complete geocoding solution for Ruby." - s.description = "Provides object geocoding (by street or IP address), reverse geocoding (coordinates to street address), distance queries for ActiveRecord and Mongoid, result caching, and more. Designed for Rails but works with Sinatra and other Rack frameworks too." + s.description = "Object geocoding (by street or IP address), reverse geocoding (coordinates to street address), distance queries for ActiveRecord and Mongoid, result caching, and more. Designed for Rails but works with Sinatra and other Rack frameworks too." s.files = Dir['CHANGELOG.md', 'LICENSE', 'README.md', 'examples/**/*', 'lib/**/*', 'bin/*'] s.require_paths = ["lib"] s.executables = ["geocode"] diff --git a/lib/geocoder/version.rb b/lib/geocoder/version.rb index 7f12e3831..6f3e16be6 100644 --- a/lib/geocoder/version.rb +++ b/lib/geocoder/version.rb @@ -1,3 +1,3 @@ module Geocoder - VERSION = "1.6.2" + VERSION = "1.6.3" end