-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipinfoapi.rb
54 lines (52 loc) · 866 Bytes
/
ipinfoapi.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'net/http'
require "json"
class IPinfo
def initialize(id)
@id = id
url = URI.parse("http://ip-api.com/json/#{@id}")
req = Net::HTTP::Get.new(url.to_s)
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
@@re1 = JSON.parse(res.body)
end
def country
return @@re1['country']
end
def countryCode
return @@re1['countryCode']
end
def region
return @@re1['region']
end
def regionName
return @@re1['regionName']
end
def city
return @@re1['city']
end
def zip
return @@re1['zip']
end
def lat
return @@re1['lat']
end
def lon
return @@re1['lon']
end
def timezone
return @@re1['timezone']
end
def isp
return @@re1['isp']
end
def org
return @@re1['org']
end
def as
return @@re1['as']
end
def query
return @@re1['query']
end
end