Sha256: b5a4405fa66ea59582e9b11099cf7038100552adb7b74f574afce2d32550ee9a

Contents?: true

Size: 649 Bytes

Versions: 2

Compression:

Stored size: 649 Bytes

Contents

# -*- encoding : utf-8 -*-
# Code adapted from geocoder(https://github.com/alexreisner/geocoder)

module IpToCountry
  module Request

    def geoip
      unless defined?(@geoip)
        if env.has_key?('HTTP_X_REAL_IP')
          @geoip = IpToCountry::Geoip.by_ip(env['HTTP_X_REAL_IP'])
        elsif env.has_key?('HTTP_X_FORWARDED_FOR')
          @geoip = IpToCountry::Geoip.by_ip(env['HTTP_X_FORWARDED_FOR'].split(/\s*,\s*/)[0])
        else
          @geoip = IpToCountry::Geoip.by_ip(ip)
        end
      end
      @geoip
    end

  end
end

if defined?(Rack) && defined?(Rack::Request)
  Rack::Request.send :include, IpToCountry::Request
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ip_to_country-0.1.0 lib/ip_to_country/request.rb
ip_to_country-0.0.3 lib/ip_to_country/request.rb