Module: IPLocation

Defined in:
lib/ip-location.rb

Defined Under Namespace

Classes: Info

Class Method Summary collapse

Class Method Details

.query(ip) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ip-location.rb', line 14

def query(ip)
  res = open("http://ip.taobao.com/service/getIpInfo.php?ip=#{ip}").read
  json = JSON.parse(res)
  if json["code"] == 0
    info = IPLocation::Info.new
    %W(country area region city isp).each do |key|
      info.send("#{key}=", json["data"][key])
    end
    
    return info
  end
  return nil
end