]> git.openstreetmap.org Git - rails.git/commitdiff
Drop geocoder.us from search engines
authorTom Hughes <tom@compton.nu>
Mon, 25 Sep 2017 21:52:03 +0000 (22:52 +0100)
committerTom Hughes <tom@compton.nu>
Mon, 25 Sep 2017 21:52:03 +0000 (22:52 +0100)
Fixes #1633

app/controllers/geocoder_controller.rb
config/locales/en.yml
config/routes.rb
test/controllers/geocoder_controller_test.rb
test/http/geocoder_us.yml [deleted file]

index 6ec2d46f8ac2db2e752909ff92fe8db49d710b42..82c290aa794927d0d8b33cd43a3580ff80ed5ea5 100644 (file)
@@ -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]
index a05083a1e59956cff11cba0621d71fa8c7c35b91..6b7fb470c3eb362072b6d601c485c2a35a822225 100644 (file)
@@ -367,7 +367,6 @@ en:
     search:
       title:
         latlon: 'Results from <a href="http://openstreetmap.org/">Internal</a>'
-        us_postcode: 'Results from <a href="http://geocoder.us/">Geocoder.us</a>'
         uk_postcode: 'Results from <a href="http://www.npemap.org.uk/">NPEMap / FreeThe Postcode</a>'
         ca_postcode: 'Results from <a href="http://geocoder.ca/">Geocoder.CA</a>'
         osm_nominatim: 'Results from <a href="http://nominatim.openstreetmap.org/">OpenStreetMap Nominatim</a>'
index 47bedac08ed80e809970f2fffd3883177198358e..98bb332f23cb01bba04f2a149695b16e82bbeb67 100644 (file)
@@ -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
index ecddf96aaaa08fe399dcf385b18e5db86e0a265e..d29d77e8b0873acfed4c234ec20237ab429b434e 100644 (file)
@@ -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 (file)
index de54aa3..0000000
+++ /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"