Sha256: 0b4922237d3d785fa8598a0544d1c0a157802b2bbd0aa7f9ef757f098be462bb

Contents?: true

Size: 867 Bytes

Versions: 9

Compression:

Stored size: 867 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)
        
        # puts "find country code for ip: #{ip}" if debug?

        @geoip ||= ::GeoIP.new WorldFlags.geo_ip_db_path
        country = @geoip.country(ip)
        return country[2] unless country.nil?
      rescue Exception => e
        raise WorldFlags::GeoIPError, "No country code could be found for IP: #{ip} - #{e}"
      end

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

      def self.debug?
        WorldFlags.debug?
      end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
world-flags-0.6.6 lib/world_flags/helper/geo.rb
world-flags-0.6.5 lib/world_flags/helper/geo.rb
world-flags-0.6.4 lib/world_flags/helper/geo.rb
world-flags-0.6.3.1 lib/world_flags/helper/geo.rb
world-flags-0.6.3 lib/world_flags/helper/geo.rb
world-flags-0.6.2.1 lib/world_flags/helper/geo.rb
world-flags-0.6.2 lib/world_flags/helper/geo.rb
world-flags-0.6.1.1 lib/world_flags/helper/geo.rb
world-flags-0.6.1 lib/world_flags/helper/geo.rb