Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix MultiGeocoder with geocoders that only have one argument (e.g. Bing)

  • Loading branch information...
commit 9446d23f42cd5102fe7dd6c5a6c3e641d2624947 1 parent 1111283
@mnoack mnoack authored
View
4 CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.8.3
+
+* Fix MultiGeocoder with geocoders that only have one argument
+
## 1.8.2
* Fix due to name clash with dependency definitions in geokit 1.8.1
View
4 lib/geokit/multi_geocoder.rb
@@ -22,14 +22,14 @@ class MultiGeocoder < Geocoder
#
# The failover approach is crucial for production-grade apps, but is rarely used.
# 98% of your geocoding calls will be successful with the first call
- def self.do_geocode(address, options = {})
+ def self.do_geocode(address, *args)
geocode_ip = /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/.match(address)
provider_order = geocode_ip ? Geokit::Geocoders::ip_provider_order : Geokit::Geocoders::provider_order
provider_order.each do |provider|
klass = geocoder(provider)
begin
- res = klass.send :geocode, address, options
+ res = klass.send :geocode, address, *args
return res if res.success?
rescue => e
logger.error("An error has occurred during geocoding: #{e}\nAddress: #{address}. Provider: #{provider}")
View
2  lib/geokit/version.rb
@@ -1,3 +1,3 @@
module Geokit
- VERSION = '1.8.2'
+ VERSION = '1.8.3'
end
View
28 test/test_multi_geocoder.rb
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), 'helper')
-Geokit::Geocoders::provider_order=[:google,:yahoo,:us]
+Geokit::Geocoders::provider_order=[:google, :bing, :us]
class MultiGeocoderTest < BaseGeocoderTest #:nodoc: all
@@ -10,27 +10,27 @@ def setup
end
def test_successful_first
- Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address, {}).returns(@success)
+ Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address).returns(@success)
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@address)
end
def test_failover
- Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
- Geokit::Geocoders::YahooGeocoder.expects(:geocode).with(@address, {}).returns(@success)
+ Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address).returns(@failure)
+ Geokit::Geocoders::BingGeocoder.expects(:geocode).with(@address).returns(@success)
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@address)
end
def test_double_failover
- Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
- Geokit::Geocoders::YahooGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
- Geokit::Geocoders::UsGeocoder.expects(:geocode).with(@address, {}).returns(@success)
+ Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address).returns(@failure)
+ Geokit::Geocoders::BingGeocoder.expects(:geocode).with(@address).returns(@failure)
+ Geokit::Geocoders::UsGeocoder.expects(:geocode).with(@address).returns(@success)
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@address)
end
def test_failure
- Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
- Geokit::Geocoders::YahooGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
- Geokit::Geocoders::UsGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
+ Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address).returns(@failure)
+ Geokit::Geocoders::BingGeocoder.expects(:geocode).with(@address).returns(@failure)
+ Geokit::Geocoders::UsGeocoder.expects(:geocode).with(@address).returns(@failure)
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode(@address)
end
@@ -45,7 +45,7 @@ def test_blank_address
t1, t2 = Geokit::Geocoders.provider_order, Geokit::Geocoders.ip_provider_order # will need to reset after
Geokit::Geocoders.provider_order = [:google]
Geokit::Geocoders.ip_provider_order = [:geo_plugin]
- Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with("", {}).returns(@failure)
+ Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with("").returns(@failure)
Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).never
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode("")
Geokit::Geocoders.provider_order, Geokit::Geocoders.ip_provider_order = t1, t2 # reset to orig values
@@ -58,20 +58,20 @@ def test_reverse_geocode_successful_first
def test_reverse_geocode_failover
Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
- Geokit::Geocoders::YahooGeocoder.expects(:reverse_geocode).with(@latlng).returns(@success)
+ Geokit::Geocoders::BingGeocoder.expects(:reverse_geocode).with(@latlng).returns(@success)
assert_equal @success, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
end
def test_reverse_geocode_double_failover
Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
- Geokit::Geocoders::YahooGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
+ Geokit::Geocoders::BingGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
Geokit::Geocoders::UsGeocoder.expects(:reverse_geocode).with(@latlng).returns(@success)
assert_equal @success, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
end
def test_reverse_geocode_failure
Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
- Geokit::Geocoders::YahooGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
+ Geokit::Geocoders::BingGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
Geokit::Geocoders::UsGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
end
View
10 test/test_multi_ip_geocoder.rb
@@ -12,19 +12,19 @@ def setup
end
def test_successful_first
- Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address, {}).returns(@success)
+ Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address).returns(@success)
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
end
def test_failover
- Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address, {}).returns(@failure)
- Geokit::Geocoders::IpGeocoder.expects(:geocode).with(@ip_address, {}).returns(@success)
+ Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address).returns(@failure)
+ Geokit::Geocoders::IpGeocoder.expects(:geocode).with(@ip_address).returns(@success)
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
end
def test_failure
- Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address, {}).returns(@failure)
- Geokit::Geocoders::IpGeocoder.expects(:geocode).with(@ip_address, {}).returns(@failure)
+ Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address).returns(@failure)
+ Geokit::Geocoders::IpGeocoder.expects(:geocode).with(@ip_address).returns(@failure)
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
end
Please sign in to comment.
Something went wrong with that request. Please try again.