Sha256: fd661d8165ac1638752430cf6240a5225cf7a462411b0e6724427ceb57ed238f

Contents?: true

Size: 713 Bytes

Versions: 1

Compression:

Stored size: 713 Bytes

Contents

module WorldFlags
  class GeoIPError < StandardError; end

  module Helper
  	module Geo
  		def self.country_code_from_ip ip = nil
        ip ||= request.remote_ip
        raise WorldFlags::GeoIPError, "IP address #{ip} is a localhost address" if local_ip?(ip)
        
        @geoip ||= ::GeoIP.new WorldFlags.geo_ip_db_path
        country = @geoip.country(ip)
        return country[2] unless country.nil?
        raise WorldFlags::GeoIPError, "No country code could be found for IP: #{ip}"
      end

      def self.local_ip? ip
        WorldFlags.localhost_list.include?(ip)
      end

  		def country_code_from_ip ip = nil
      	WorldFlags::Helper::Geo.country_code_from_ip ip
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
world-flags-0.4.8.2 lib/world_flags/helper/geo.rb