module GeolocationIp

Constants

VERSION

Public Class Methods

find(remote, callback = nil) click to toggle source
# File lib/geolocation_ip.rb, line 10
def self.find(remote, callback = nil)
      request(remote, callback)
end
now(callback = nil) click to toggle source
# File lib/geolocation_ip.rb, line 6
def self.now(callback = nil)
              request(nil, callback)
end

Private Class Methods

request(remote = nil, callback = nil) click to toggle source

source : ip-api.com/docs/api:json

# File lib/geolocation_ip.rb, line 17
def self.request(remote = nil, callback = nil)
      url           = 'http://ip-api.com/json/'
      uri      = URI("#{url}#{remote}#{callback.nil? ? '' : '?callback=' + callback }")
              response = Net::HTTP.get_response(uri)
              data     = response.body
              callback.nil? ? JSON.parse(data) : data
end