Skip to content
Snippets Groups Projects
Commit 0b8f4d5d authored by Alex Reisner's avatar Alex Reisner
Browse files

Read MaxMind service name from config

instead of inferring from response length. This is less than ideal but
it fixes issue #396 and, given what appears to be MaxMind's inconsistent
response lengths, it may not be possible to do much better.
parent a1ba3757
No related branches found
No related tags found
No related merge requests found
...@@ -67,13 +67,12 @@ module Geocoder::Result ...@@ -67,13 +67,12 @@ module Geocoder::Result
## ##
# Name of the MaxMind service being used. # Name of the MaxMind service being used.
# Inferred from format of @data.
# #
def service_name def service_name
self.class.field_names.to_a.each do |n,f| # it would be much better to infer this from the length of the @data
return n if (@data.size..@data.size+1).include?(f.size) # array, but MaxMind seems to send inconsistent and wide-ranging response
end # lengths (see https://github.com/alexreisner/geocoder/issues/396)
nil Geocoder.config.maxmind[:service]
end end
def field_names def field_names
......
...@@ -171,27 +171,27 @@ class ServicesTest < Test::Unit::TestCase ...@@ -171,27 +171,27 @@ class ServicesTest < Test::Unit::TestCase
end end
def test_maxmind_result_knows_country_service_name 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 assert_equal :country, Geocoder.search("24.24.24.21").first.service_name
end end
def test_maxmind_result_knows_city_service_name 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 assert_equal :city, Geocoder.search("24.24.24.22").first.service_name
end end
def test_maxmind_result_knows_city_isp_org_service_name 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 assert_equal :city_isp_org, Geocoder.search("24.24.24.23").first.service_name
end end
def test_maxmind_result_knows_omni_service_name 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 assert_equal :omni, Geocoder.search("24.24.24.24").first.service_name
end end
def test_maxmind_special_result_components 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 result = Geocoder.search("24.24.24.24").first
assert_equal "Road Runner", result.isp_name assert_equal "Road Runner", result.isp_name
assert_equal "Cable/DSL", result.netspeed assert_equal "Cable/DSL", result.netspeed
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment