class Geolocater

Constants

REQUEST_URI
VERSION

Attributes

ip_address[RW]

Public Class Methods

geolocate_ip(ip_address) click to toggle source
# File lib/geolocater.rb, line 29
def geolocate_ip(ip_address)
  geolocator = Geolocater.new(ip_address)
  geolocator.geolocate_ip
end
new(ip_address) click to toggle source
# File lib/geolocater.rb, line 11
def initialize(ip_address)
  @ip_address = IPAddr.new ip_address
  raise "IPv6 NOT SUPPORTED" if @ip_address.ipv6?
end

Public Instance Methods

geolocate_ip() click to toggle source
# File lib/geolocater.rb, line 16
def geolocate_ip
  http_response = Faraday.get REQUEST_URI + ip_address.to_s
  if http_response.success? == true && http_response.status == 200;
    geolocated_info = JSON.parse(http_response.body)
    if geolocated_info["city"].empty?
      raise "Incomplete record. Please try another IP address"
    else
      return geolocated_info
    end
  end
end