ip-location 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +25 -0
- data/lib/ip-location.rb +28 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6163f0a6266e4d6b456ed3626fe780b97d9d864f
|
4
|
+
data.tar.gz: e6157700cc357e2912fcfbaeef5073546207f245
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 332c80bd4651c2e4fe5d5f7cbae8601597827d398ffa31d5c2ca4070790deec906c41ea97ba3fe1b00f72bf920f8e48f2e17575f22b073ce13723a1ff13a51d3
|
7
|
+
data.tar.gz: b556d85c550dd5f26b70928c84118799fa403ca9866c4ec2576cc1dba8ac6d46c00924c7b71cdd774756193deaa061669b7122c0dd00739c7f5408072ae46b86
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Jason Lee
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
ip-location
|
2
|
+
===========
|
3
|
+
|
4
|
+
通过淘宝 IP 库查询 IP 所在地域位置 http://ip.taobao.com
|
5
|
+
|
6
|
+
## Limit
|
7
|
+
|
8
|
+
* 官方限制每个服务器请求过去屏率无能超过 10 Qps。
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
irb> require "ip-location"
|
14
|
+
true
|
15
|
+
irb> info = IPLocation.query("222.212.254.17")
|
16
|
+
irb> info.country
|
17
|
+
"中国"
|
18
|
+
ifb> info.region
|
19
|
+
"四川省"
|
20
|
+
irb> info.city
|
21
|
+
"成都市"
|
22
|
+
irb> info.isp
|
23
|
+
"电信"
|
24
|
+
irb> info.fullname
|
25
|
+
"中国四川省成都市"
|
data/lib/ip-location.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module IPLocation
|
5
|
+
class Info
|
6
|
+
attr_accessor :country, :area, :region, :city, :isp
|
7
|
+
|
8
|
+
def fullname
|
9
|
+
[self.country, self.region, self.city].join("")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def query(ip)
|
15
|
+
res = open("http://ip.taobao.com/service/getIpInfo.php?ip=#{ip}").read
|
16
|
+
json = JSON.parse(res)
|
17
|
+
if json["code"] == 0
|
18
|
+
info = IPLocation::Info.new
|
19
|
+
%W(country area region city isp).each do |key|
|
20
|
+
info.send("#{key}=", json["data"][key])
|
21
|
+
end
|
22
|
+
|
23
|
+
return info
|
24
|
+
end
|
25
|
+
return nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ip-location
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Lee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Query location with IP address by Taobao Service!
|
14
|
+
email: huacnlee@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- LICENSE
|
20
|
+
- README.md
|
21
|
+
- lib/ip-location.rb
|
22
|
+
homepage: https://github.com/huacnlee/ip-location
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.2.2
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Query location with IP address!
|
46
|
+
test_files: []
|
47
|
+
has_rdoc:
|