]> git.openstreetmap.org Git - rails.git/commitdiff
Remove npemap as a source for UK postcodes
authorTom Hughes <tom@compton.nu>
Mon, 29 Jan 2018 18:53:57 +0000 (18:53 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 4 Feb 2018 15:14:41 +0000 (15:14 +0000)
app/controllers/geocoder_controller.rb
config/locales/en.yml
config/routes.rb
test/controllers/geocoder_controller_test.rb
test/http/npemap.yml [deleted file]

index e9fa7f26af847ca7e61b27710ff4e787f83ea359..384f2c24c36a86272c47c6f713426edb971316a4 100644 (file)
@@ -19,7 +19,6 @@ class GeocoderController < ApplicationController
       if @params[:query] =~ /^\d{5}(-\d{4})?$/
         @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"
         @sources.push "osm_nominatim"
       elsif @params[:query] =~ /^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i
         @sources.push "ca_postcode"
@@ -55,32 +54,6 @@ class GeocoderController < ApplicationController
     end
   end
 
-  def search_uk_postcode
-    # get query parameters
-    query = params[:query]
-
-    # create result array
-    @results = []
-
-    # ask npemap.org.uk to do a combined npemap + freethepostcode search
-    response = fetch_text("http://www.npemap.org.uk/cgi/geocoder.fcgi?format=text&postcode=#{escape_query(query)}")
-
-    # parse the response
-    unless response =~ /Error/
-      dataline = response.split(/\n/)[1]
-      data = dataline.split(/,/) # easting,northing,postcode,lat,long
-      postcode = data[2].delete("'")
-      zoom = POSTCODE_ZOOM - postcode.count("#")
-      @results.push(:lat => data[3], :lon => data[4], :zoom => zoom,
-                    :name => postcode)
-    end
-
-    render :action => "results"
-  rescue StandardError => ex
-    @error = "Error contacting www.npemap.org.uk: #{ex}"
-    render :action => "error"
-  end
-
   def search_ca_postcode
     # get query parameters
     query = params[:query]
index 036f8de35d6aab5c1aa5d292496a8558aeba4028..43e007eee61bf616a0ebf2d8d2037c5170e52b50 100644 (file)
@@ -368,7 +368,6 @@ en:
     search:
       title:
         latlon: 'Results from <a href="https://openstreetmap.org/">Internal</a>'
-        uk_postcode: 'Results from <a href="http://www.npemap.org.uk/">NPEMap / FreeThe Postcode</a>'
         ca_postcode: 'Results from <a href="https://geocoder.ca/">Geocoder.CA</a>'
         osm_nominatim: 'Results from <a href="https://nominatim.openstreetmap.org/">OpenStreetMap Nominatim</a>'
         geonames: 'Results from <a href="http://www.geonames.org/">GeoNames</a>'
index 98bb332f23cb01bba04f2a149695b16e82bbeb67..66eda1916504026e4c3d76e64ac57b6bee0563a9 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_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
   match "/geocoder/search_geonames" => "geocoder#search_geonames", :via => :get
index 0d062cf4237abea2da71bb1f75502044cd746eff..e05c8d06a2744147751589696b9f7cdd9048ca14 100644 (file)
@@ -13,10 +13,6 @@ class GeocoderControllerTest < ActionController::TestCase
       { :path => "/geocoder/search_latlon", :method => :get },
       { :controller => "geocoder", :action => "search_latlon" }
     )
-    assert_routing(
-      { :path => "/geocoder/search_uk_postcode", :method => :get },
-      { :controller => "geocoder", :action => "search_uk_postcode" }
-    )
     assert_routing(
       { :path => "/geocoder/search_ca_postcode", :method => :get },
       { :controller => "geocoder", :action => "search_ca_postcode" }
@@ -263,7 +259,7 @@ class GeocoderControllerTest < ActionController::TestCase
       "CR2 6XH",
       "DN55 1PT"
     ].each do |code|
-      search_check code, %w[uk_postcode osm_nominatim]
+      search_check code, %w[osm_nominatim]
     end
   end
 
@@ -298,24 +294,6 @@ class GeocoderControllerTest < ActionController::TestCase
     results_check_error "Longitude 180.23 out of range"
   end
 
-  ##
-  # Test the UK postcode search
-  def test_search_uk_postcode
-    with_http_stubs "npemap" do
-      get :search_uk_postcode, :xhr => true,
-                               :params => { :query => "CV4 7AL", :zoom => 10,
-                                            :minlon => -0.559, :minlat => 51.217,
-                                            :maxlon => 0.836, :maxlat => 51.766 }
-      results_check :name => "CV4 7AL", :lat => 52.381748701968, :lon => -1.56176420939232
-
-      get :search_uk_postcode, :xhr => true,
-                               :params => { :query => "XX9 9XX", :zoom => 10,
-                                            :minlon => -0.559, :minlat => 51.217,
-                                            :maxlon => 0.836, :maxlat => 51.766 }
-      results_check
-    end
-  end
-
   ##
   # Test the Canadian postcode search
   def test_search_ca_postcode
diff --git a/test/http/npemap.yml b/test/http/npemap.yml
deleted file mode 100644 (file)
index 28074d0..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-/cgi/geocoder.fcgi?format=text&postcode=CV4%207AL:
-  code: 200
-  body: |
-    # Easting,Northing,Matched Postcode,Latitude,Longitude
-    429926,276058,'CV4 7AL',52.381748701968,-1.56176420939232
-
-/cgi/geocoder.fcgi?format=text&postcode=XX9%209XX:
-  code: 200
-  body: |
-    Error: Postcode area 'XX' not found, postcode probably invalid