Skip to content
Snippets Groups Projects
Commit 35115b4f authored by Alex Reisner's avatar Alex Reisner Committed by GitHub
Browse files

Merge pull request #1092 from teohm/patch/ipinfo_io_loopback_address

Fix result of ipinfo.io for loopback address (127.0.0.1)
parents 07aeeab9 f735a8bc
No related branches found
No related tags found
No related merge requests found
......@@ -42,7 +42,14 @@ module Geocoder::Lookup
end
def reserved_result(ip)
{"message" => "Input string is not a valid IP address", "code" => 401}
{
"ip" => ip,
"city" => "",
"region" => "",
"country" => "",
"loc" => "0,0",
"postal" => ""
}
end
def query_url_params(query)
......
......@@ -8,7 +8,7 @@ module Geocoder::Result
end
def coordinates
@data['loc'].split(",").map(&:to_f)
@data['loc'].to_s.split(",").map(&:to_f)
end
def city
......@@ -36,7 +36,7 @@ module Geocoder::Result
end
def self.response_attributes
%w['ip', 'region', 'postal']
%w(ip region postal)
end
response_attributes.each do |a|
......
......@@ -14,4 +14,20 @@ class IpinfoIoTest < GeocoderTestCase
query = Geocoder::Query.new("8.8.8.8")
assert_match(/^https:/, query.url)
end
def test_ipinfo_io_lookup_loopback_address
Geocoder.configure(:ip_lookup => :ipinfo_io, :use_https => true)
result = Geocoder.search("127.0.0.1").first
assert_equal 0.0, result.longitude
assert_equal 0.0, result.latitude
assert_equal "127.0.0.1", result.ip
end
def test_ipinfo_io_extra_attributes
Geocoder.configure(:ip_lookup => :ipinfo_io, :use_https => true)
result = Geocoder.search("8.8.8.8").first
assert_equal "8.8.8.8", result.ip
assert_equal "California", result.region
assert_equal "94040", result.postal
end
end
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