Sha256: a025a3141f1e40f8df79ec0a0d97e8a7c245a8b40bd1496ab6e816971e7266a3
Contents?: true
Size: 1 KB
Versions: 2
Compression:
Stored size: 1 KB
Contents
require 'geocoder/lookups/base' require 'geocoder/results/freegeoip' module Geocoder::Lookup class Freegeoip < Base private # --------------------------------------------------------------- def results(query, reverse = false) # don't look up a loopback address, just return the stored result return [reserved_result(query)] if loopback_address?(query) begin return (doc = fetch_data(query, reverse)) ? [doc] : [] rescue StandardError # Freegeoip.net returns HTML on bad request return [] end end def reserved_result(ip) { "ip" => ip, "city" => "", "region_code" => "", "region_name" => "", "metrocode" => "", "zipcode" => "", "latitude" => "0", "longitude" => "0", "country_name" => "Reserved", "country_code" => "RD" } end def query_url(query, reverse = false) "http://freegeoip.net/json/#{query}" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
geocoder-1.0.2 | lib/geocoder/lookups/freegeoip.rb |
geocoder-1.0.1 | lib/geocoder/lookups/freegeoip.rb |