sgeoip 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +5 -0
- data/README.md +9 -1
- data/lib/sgeoip.rb +12 -8
- data/lib/sgeoip/version.rb +1 -1
- data/sgeoip-0.0.9.gem +0 -0
- data/spec/sgeoip_spec.rb +21 -0
- data/spec/spec_helper.rb +7 -0
- metadata +9 -4
- data/sgeoip-0.0.8.gem +0 -0
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Sgeoip
|
2
|
+
[](http://travis-ci.org/ninetwentyfour/scrape-geoip)
|
2
3
|
|
3
4
|
Scrape http://www.geoiptool.com/ for ip information
|
4
5
|
|
@@ -18,7 +19,14 @@ Or install it yourself as:
|
|
18
19
|
|
19
20
|
## Usage
|
20
21
|
|
21
|
-
|
22
|
+
require 'sgeoip'
|
23
|
+
|
24
|
+
ip_info = Sgeoip::scrape('8.8.8.8')
|
25
|
+
puts ip_info
|
26
|
+
|
27
|
+
## Expected output
|
28
|
+
|
29
|
+
{"host"=>"google-public-dns-a.google.com", "country"=>" United States ", "country_code"=>"US (USA)", "region"=>"California", "city"=>"Mountain View", "zip"=>"94043"}
|
22
30
|
|
23
31
|
## Contributing
|
24
32
|
|
data/lib/sgeoip.rb
CHANGED
@@ -5,14 +5,18 @@ require 'open-uri'
|
|
5
5
|
module Sgeoip
|
6
6
|
def self.scrape(ip)
|
7
7
|
url = "http://www.geoiptool.com/en/?IP=#{ip}"
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
begin
|
9
|
+
doc = Nokogiri::HTML(open(url))
|
10
|
+
geoip = { "host" => doc.at_css(".tbl_style tr:nth-child(1) td.arial_bold").text,
|
11
|
+
"country" => doc.at_css(".tbl_style tr:nth-child(3) td.arial_bold").text,
|
12
|
+
"country_code" => doc.at_css(".tbl_style tr:nth-child(4) td.arial_bold").text,
|
13
|
+
"region" => doc.at_css(".tbl_style tr:nth-child(5) td.arial_bold").text,
|
14
|
+
"city" => doc.at_css(".tbl_style tr:nth-child(6) td.arial_bold").text,
|
15
|
+
"zip" => doc.at_css(".tbl_style tr:nth-child(7) td.arial_bold").text
|
16
|
+
}
|
17
|
+
rescue Exception => e
|
18
|
+
geoip = { "host" => ""}
|
19
|
+
end
|
16
20
|
if geoip["host"].empty?
|
17
21
|
geoip["error"] = "Results Not Found"
|
18
22
|
end
|
data/lib/sgeoip/version.rb
CHANGED
data/sgeoip-0.0.9.gem
ADDED
Binary file
|
data/spec/sgeoip_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sgeoip do
|
4
|
+
it 'should return correct info for ip' do
|
5
|
+
ip_info = Sgeoip::scrape('8.8.8.8')
|
6
|
+
|
7
|
+
ip_info["host"].should == "google-public-dns-a.google.com"
|
8
|
+
ip_info["country"].should == " United States "
|
9
|
+
ip_info["country_code"].should == "US (USA)"
|
10
|
+
ip_info["region"].should == "California"
|
11
|
+
ip_info["city"].should == "Mountain View"
|
12
|
+
ip_info["zip"].should == "94043"
|
13
|
+
ip_info["error"].should be_nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should return an error for a bad ip' do
|
17
|
+
ip_info = Sgeoip::scrape('1.c.aa.p/')
|
18
|
+
|
19
|
+
ip_info["error"].should == "Results Not Found"
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sgeoip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -51,14 +51,17 @@ extensions: []
|
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
53
53
|
- .gitignore
|
54
|
+
- .travis.yml
|
54
55
|
- Gemfile
|
55
56
|
- LICENSE.txt
|
56
57
|
- README.md
|
57
58
|
- Rakefile
|
58
59
|
- lib/sgeoip.rb
|
59
60
|
- lib/sgeoip/version.rb
|
60
|
-
- sgeoip-0.0.
|
61
|
+
- sgeoip-0.0.9.gem
|
61
62
|
- sgeoip.gemspec
|
63
|
+
- spec/sgeoip_spec.rb
|
64
|
+
- spec/spec_helper.rb
|
62
65
|
homepage: https://github.com/ninetwentyfour/scrape-geoip
|
63
66
|
licenses: []
|
64
67
|
post_install_message:
|
@@ -83,4 +86,6 @@ rubygems_version: 1.8.23
|
|
83
86
|
signing_key:
|
84
87
|
specification_version: 3
|
85
88
|
summary: Scrape http://www.geoiptool.com/
|
86
|
-
test_files:
|
89
|
+
test_files:
|
90
|
+
- spec/sgeoip_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
data/sgeoip-0.0.8.gem
DELETED
Binary file
|