Sha256: 5a1a58f1677b38de97895a4241f4c04ab8421bb2d4bbcbc6fe4ea46700492a52

Contents?: true

Size: 671 Bytes

Versions: 2

Compression:

Stored size: 671 Bytes

Contents

require "action_controller"

module ActsAsGeocodable
  module RemoteLocation
    # Get the remote location of the request IP using http://hostip.info
    def remote_location
      if request.remote_ip == "127.0.0.1"
        # otherwise people would complain that it doesn't work
        Graticule::Location.new(locality: "localhost")
      else
        Graticule.service(:host_ip).new.locate(request.remote_ip)
      end
    rescue Graticule::Error => error
      logger.warn "An error occurred while looking up the location of '#{request.remote_ip}': #{error.message}"
      nil
    end
  end
end

ActionController::Base.send(:include, ActsAsGeocodable::RemoteLocation)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acts_as_geocodable-2.1.1 lib/acts_as_geocodable/remote_location.rb
acts_as_geocodable-2.1.0 lib/acts_as_geocodable/remote_location.rb