diff --git a/lib/geocoder/results/maxmind.rb b/lib/geocoder/results/maxmind.rb index aa6c7aa92b2cafaa63c83aff6f6f6abec7f7d421..6682bfc64eed45e571ab45b9fb59e09c19a28494 100644 --- a/lib/geocoder/results/maxmind.rb +++ b/lib/geocoder/results/maxmind.rb @@ -67,13 +67,12 @@ module Geocoder::Result ## # Name of the MaxMind service being used. - # Inferred from format of @data. # def service_name - self.class.field_names.to_a.each do |n,f| - return n if (@data.size..@data.size+1).include?(f.size) - end - nil + # it would be much better to infer this from the length of the @data + # array, but MaxMind seems to send inconsistent and wide-ranging response + # lengths (see https://github.com/alexreisner/geocoder/issues/396) + Geocoder.config.maxmind[:service] end def field_names diff --git a/test/services_test.rb b/test/services_test.rb index e2df65fa91a6440489f0f4b23f08e71a9e0d7443..fd0ac30041a6f0051a7b7d3a92081f6a802068cd 100644 --- a/test/services_test.rb +++ b/test/services_test.rb @@ -171,27 +171,27 @@ class ServicesTest < Test::Unit::TestCase end def test_maxmind_result_knows_country_service_name - Geocoder.configure(:ip_lookup => :maxmind) + Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :country}) assert_equal :country, Geocoder.search("24.24.24.21").first.service_name end def test_maxmind_result_knows_city_service_name - Geocoder.configure(:ip_lookup => :maxmind) + Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :city}) assert_equal :city, Geocoder.search("24.24.24.22").first.service_name end def test_maxmind_result_knows_city_isp_org_service_name - Geocoder.configure(:ip_lookup => :maxmind) + Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :city_isp_org}) assert_equal :city_isp_org, Geocoder.search("24.24.24.23").first.service_name end def test_maxmind_result_knows_omni_service_name - Geocoder.configure(:ip_lookup => :maxmind) + Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :omni}) assert_equal :omni, Geocoder.search("24.24.24.24").first.service_name end def test_maxmind_special_result_components - Geocoder.configure(:ip_lookup => :maxmind) + Geocoder.configure(:ip_lookup => :maxmind, :maxmind => {:service => :omni}) result = Geocoder.search("24.24.24.24").first assert_equal "Road Runner", result.isp_name assert_equal "Cable/DSL", result.netspeed