From: Tom Hughes Date: Mon, 25 Sep 2017 21:52:03 +0000 (+0100) Subject: Drop geocoder.us from search engines X-Git-Tag: live~3890 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/6209a9be78bd0a99f32e8351975beb67f2393bc7 Drop geocoder.us from search engines Fixes #1633 --- diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 6ec2d46f8..82c290aa7 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -19,7 +19,6 @@ class GeocoderController < ApplicationController @sources.push "geonames_reverse" if defined?(GEONAMES_USERNAME) elsif @params[:query] if @params[:query] =~ /^\d{5}(-\d{4})?$/ - @sources.push "us_postcode" @sources.push "osm_nominatim" elsif @params[:query] =~ /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i @sources.push "uk_postcode" @@ -58,31 +57,6 @@ class GeocoderController < ApplicationController end end - def search_us_postcode - # get query parameters - query = params[:query] - - # create result array - @results = [] - - # ask geocoder.us (they have a non-commercial use api) - response = fetch_text("http://rpc.geocoder.us/service/csv?zip=#{escape_query(query)}") - - # parse the response - unless response =~ /couldn't find this zip/ - data = response.split(/\s*,\s+/) # lat,long,town,state,zip - @results.push(:lat => data[0], :lon => data[1], - :zoom => POSTCODE_ZOOM, - :prefix => "#{data[2]}, #{data[3]},", - :name => data[4]) - end - - render :action => "results" - rescue StandardError => ex - @error = "Error contacting rpc.geocoder.us: #{ex}" - render :action => "error" - end - def search_uk_postcode # get query parameters query = params[:query] diff --git a/config/locales/en.yml b/config/locales/en.yml index a05083a1e..6b7fb470c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -367,7 +367,6 @@ en: search: title: latlon: 'Results from Internal' - us_postcode: 'Results from Geocoder.us' uk_postcode: 'Results from NPEMap / FreeThe Postcode' ca_postcode: 'Results from Geocoder.CA' osm_nominatim: 'Results from OpenStreetMap Nominatim' diff --git a/config/routes.rb b/config/routes.rb index 47bedac08..98bb332f2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -246,7 +246,6 @@ OpenStreetMap::Application.routes.draw do # geocoder match "/search" => "geocoder#search", :via => :get, :as => :search match "/geocoder/search_latlon" => "geocoder#search_latlon", :via => :get - match "/geocoder/search_us_postcode" => "geocoder#search_us_postcode", :via => :get match "/geocoder/search_uk_postcode" => "geocoder#search_uk_postcode", :via => :get match "/geocoder/search_ca_postcode" => "geocoder#search_ca_postcode", :via => :get match "/geocoder/search_osm_nominatim" => "geocoder#search_osm_nominatim", :via => :get diff --git a/test/controllers/geocoder_controller_test.rb b/test/controllers/geocoder_controller_test.rb index ecddf96aa..d29d77e8b 100644 --- a/test/controllers/geocoder_controller_test.rb +++ b/test/controllers/geocoder_controller_test.rb @@ -15,10 +15,6 @@ class GeocoderControllerTest < ActionController::TestCase { :path => "/geocoder/search_latlon", :method => :get }, { :controller => "geocoder", :action => "search_latlon" } ) - assert_routing( - { :path => "/geocoder/search_us_postcode", :method => :get }, - { :controller => "geocoder", :action => "search_us_postcode" } - ) assert_routing( { :path => "/geocoder/search_uk_postcode", :method => :get }, { :controller => "geocoder", :action => "search_uk_postcode" } @@ -253,7 +249,7 @@ class GeocoderControllerTest < ActionController::TestCase ].each do |code| post :search, :params => { :query => code } assert_response :success - assert_equal %w[us_postcode osm_nominatim], assigns(:sources) + assert_equal %w[osm_nominatim], assigns(:sources) end end @@ -304,25 +300,6 @@ class GeocoderControllerTest < ActionController::TestCase results_check_error "Longitude 180.23 out of range" end - ## - # Test the US postcode search - def test_search_us_postcode - with_http_stubs "geocoder_us" do - get :search_us_postcode, :xhr => true, - :params => { :query => "90210", :zoom => 10, - :minlon => -0.559, :minlat => 51.217, - :maxlon => 0.836, :maxlat => 51.766 } - results_check :prefix => "Beverly Hills, CA,", :name => "90210", - :lat => 34.088808, :lon => -118.40612 - - get :search_us_postcode, :xhr => true, - :params => { :query => "00000", :zoom => 10, - :minlon => -0.559, :minlat => 51.217, - :maxlon => 0.836, :maxlat => 51.766 } - results_check - end - end - ## # Test the UK postcode search def test_search_uk_postcode diff --git a/test/http/geocoder_us.yml b/test/http/geocoder_us.yml deleted file mode 100644 index de54aa306..000000000 --- a/test/http/geocoder_us.yml +++ /dev/null @@ -1,6 +0,0 @@ -/service/csv?zip=90210: - code: 200 - body: "34.088808, -118.40612, Beverly Hills, CA, 90210" -/service/csv?zip=00000: - code: 200 - body: "1: couldn't find this zip code: 00000! sorry"