sgeoip 0.1.1 → 0.1.2
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/lib/sgeoip.rb +13 -10
- data/lib/sgeoip/version.rb +1 -1
- data/sgeoip-0.1.1.gem +0 -0
- data/spec/sgeoip_spec.rb +11 -0
- metadata +3 -3
- data/sgeoip-0.1.0.gem +0 -0
data/lib/sgeoip.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require "sgeoip/version"
|
2
4
|
require 'nokogiri'
|
3
5
|
require 'open-uri'
|
4
6
|
require 'active_support'
|
5
7
|
require 'geo_location'
|
6
8
|
|
7
|
-
module Sgeoip
|
9
|
+
module Sgeoip
|
8
10
|
def self.scrape(ip)
|
9
11
|
geoip = geoiptool(ip)
|
10
12
|
if geoip["error"]
|
@@ -17,13 +19,14 @@ module Sgeoip
|
|
17
19
|
url = "http://www.geoiptool.com/en/?IP=#{ip}"
|
18
20
|
begin
|
19
21
|
doc = Nokogiri::HTML(open(url))
|
20
|
-
geoip = { "host" => doc.at_css(".tbl_style tr:nth-child(1) td.arial_bold").text,
|
21
|
-
"country" => doc.at_css(".tbl_style tr:nth-child(3) td.arial_bold").text.to_s[1..-2], #strip extra spaces
|
22
|
-
"country_code" => doc.at_css(".tbl_style tr:nth-child(4) td.arial_bold").text,
|
23
|
-
"region" => doc.at_css(".tbl_style tr:nth-child(5) td.arial_bold").text,
|
24
|
-
"city" => doc.at_css(".tbl_style tr:nth-child(6) td.arial_bold").text,
|
25
|
-
"zip" => doc.at_css(".tbl_style tr:nth-child(7) td.arial_bold").text
|
22
|
+
geoip = { "host" => doc.at_css(".tbl_style tr:nth-child(1) td.arial_bold").text.chars.select{|i| i.valid_encoding?}.join,
|
23
|
+
"country" => doc.at_css(".tbl_style tr:nth-child(3) td.arial_bold").text.to_s[1..-2].chars.select{|i| i.valid_encoding?}.join, #strip extra spaces
|
24
|
+
"country_code" => doc.at_css(".tbl_style tr:nth-child(4) td.arial_bold").text.chars.select{|i| i.valid_encoding?}.join,
|
25
|
+
"region" => doc.at_css(".tbl_style tr:nth-child(5) td.arial_bold").text.chars.select{|i| i.valid_encoding?}.join,
|
26
|
+
"city" => doc.at_css(".tbl_style tr:nth-child(6) td.arial_bold").text.chars.select{|i| i.valid_encoding?}.join,
|
27
|
+
"zip" => doc.at_css(".tbl_style tr:nth-child(7) td.arial_bold").text.chars.select{|i| i.valid_encoding?}.join
|
26
28
|
}
|
29
|
+
|
27
30
|
rescue Exception => e
|
28
31
|
geoip = { "host" => ""}
|
29
32
|
end
|
@@ -38,10 +41,10 @@ module Sgeoip
|
|
38
41
|
GeoLocation::use = :hostip
|
39
42
|
location = GeoLocation.find(ip)
|
40
43
|
geoip = { "host" => "N/A",
|
41
|
-
"country" => location[:country],
|
42
|
-
"country_code" => location[:country_code],
|
44
|
+
"country" => location[:country].chars.select{|i| i.valid_encoding?}.join,
|
45
|
+
"country_code" => location[:country_code].chars.select{|i| i.valid_encoding?}.join,
|
43
46
|
"region" => "N/A",
|
44
|
-
"city" => location[:city],
|
47
|
+
"city" => location[:city].chars.select{|i| i.valid_encoding?}.join,
|
45
48
|
"zip" => "N/A"
|
46
49
|
}
|
47
50
|
rescue Exception => e
|
data/lib/sgeoip/version.rb
CHANGED
data/sgeoip-0.1.1.gem
ADDED
Binary file
|
data/spec/sgeoip_spec.rb
CHANGED
@@ -43,4 +43,15 @@ describe Sgeoip do
|
|
43
43
|
ip_info["error"].should == "Results Not Found"
|
44
44
|
end
|
45
45
|
|
46
|
+
it 'should strip and special non utf-8 characters' do
|
47
|
+
ip_info = Sgeoip::scrape('189.62.243.113')
|
48
|
+
|
49
|
+
ip_info["host"].should == "bd3ef371.virtua.com.br"
|
50
|
+
ip_info["country"].should == "Brazil"
|
51
|
+
ip_info["country_code"].should == "BR (BRA)"
|
52
|
+
ip_info["region"].should == "Sao Paulo"
|
53
|
+
ip_info["city"].should == "So Paulo"
|
54
|
+
ip_info["error"].should be_nil
|
55
|
+
end
|
56
|
+
|
46
57
|
end
|
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.1.
|
4
|
+
version: 0.1.2
|
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-10-
|
12
|
+
date: 2012-10-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -90,7 +90,7 @@ files:
|
|
90
90
|
- Rakefile
|
91
91
|
- lib/sgeoip.rb
|
92
92
|
- lib/sgeoip/version.rb
|
93
|
-
- sgeoip-0.1.
|
93
|
+
- sgeoip-0.1.1.gem
|
94
94
|
- sgeoip.gemspec
|
95
95
|
- spec/sgeoip_spec.rb
|
96
96
|
- spec/spec_helper.rb
|
data/sgeoip-0.1.0.gem
DELETED
Binary file
|