]> git.openstreetmap.org Git - rails.git/commitdiff
Merge pull request #1732 from tomhughes/npemap
authorAndy Allan <github@gravitystorm.co.uk>
Fri, 23 Feb 2018 02:23:22 +0000 (10:23 +0800)
committerGitHub <noreply@github.com>
Fri, 23 Feb 2018 02:23:22 +0000 (10:23 +0800)
Remove npemap as a source for UK postcodes

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 2412a2b9c27e1baddccffddaab032a452b4d0143..2550b5b962900f586f8383dc05489ebb75a912cf 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