autometal-geoip 0.3.7 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -75,6 +75,8 @@ You can override the attribute used to geolocate by overriding +geo_attr+
75
75
  sudo install_geoip (unless already installed)
76
76
 
77
77
  == CHANGELOG
78
+ * 0.4
79
+ Ruby 1.9.* support. Previous version of this gem would product encoding errors in some instances due to the different way Ruby 1.9+ deals with source and text encodings.
78
80
  * 0.3.7
79
81
  Installation now checks for sudo command, and runs accordingly. Bear in mind that if you are not root and sudo does not exist, the installation will fail as it will not have enough permissions to install binaries.
80
82
  * 0.3.5
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{autometal-geoip}
5
- s.version = "0.3.7"
5
+ s.version = "0.4.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Achillefs Charmpilas"]
9
- s.date = %q{2011-01-12}
9
+ s.date = %q{2011-01-16}
10
10
  s.default_executable = %q{install_geoip}
11
11
  s.description = %q{A wrapper to MaxMind's GeoIP services, that can work with both free and paid versions.
12
12
  Also provides geo-location methods to Active Record and Sequel Models.
@@ -28,12 +28,11 @@ For more information on autometal-geoip, see http://humbuckercode.co.uk/licks/ge
28
28
  s.rdoc_options = ["--main", "README.rdoc"]
29
29
  s.require_paths = ["lib"]
30
30
  s.rubyforge_project = %q{autometal-geoip}
31
- s.rubygems_version = %q{1.3.7}
31
+ s.rubygems_version = %q{1.4.2}
32
32
  s.summary = %q{A wrapper to MaxMind's GeoIP services, that can work with both free and paid versions}
33
33
  s.test_files = ["test/test_geoip.rb", "test/test_helper.rb"]
34
34
 
35
35
  if s.respond_to? :specification_version then
36
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
37
36
  s.specification_version = 3
38
37
 
39
38
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
data/lib/geoip.rb CHANGED
@@ -3,7 +3,7 @@ $:.unshift(File.dirname(__FILE__)) unless
3
3
 
4
4
  module Autometal
5
5
  class Geoip
6
- VERSION = '0.3.7'
6
+ VERSION = '0.4.0'
7
7
  DATA_FILE_PATH = "/usr/local/share/GeoIP/"
8
8
  BIN = "geoiplookup"
9
9
  def initialize ip_or_domain
@@ -48,7 +48,11 @@ module Autometal
48
48
  end
49
49
 
50
50
  def lookup ip_or_domain
51
- %x{ #{Geoip::BIN} -f #{self.class.data_file} #{ip_or_domain} }
51
+ str = %x{ #{Geoip::BIN} -f #{self.class.data_file} #{ip_or_domain} }
52
+ if RUBY_VERSION.to_f > 1.8
53
+ str.force_encoding("iso-8859-1") unless str.valid_encoding?
54
+ end
55
+ str
52
56
  end
53
57
  end
54
58
  end
data/lib/geoip/city.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  module Autometal
2
2
  class Geoip
3
+ =begin rdoc
4
+ GeoLiteCity database extension
5
+ provides Country, City, Latitude and Longitude information.
6
+ =end
3
7
  class City < Geoip::Package
4
8
  attr_accessor :country, :county, :city, :lat, :lng
5
9
  def latlng
@@ -2,7 +2,8 @@ require "fileutils"
2
2
  module Autometal
3
3
  class Geoip
4
4
  =begin rdoc
5
- Installer class that handles downloading and installing databases and binaries
5
+ Installer class that handles downloading and installing GeoIP databases and binaries
6
+ It will call the two shellscripts included in <gem_root>/shellscripts/
6
7
  =end
7
8
  class Installer
8
9
  BASE_DB_URL = "http://geolite.maxmind.com/download/geoip/database/*.dat.gz"
@@ -20,16 +21,20 @@ module Autometal
20
21
  if Autometal::Geoip.bin_installed?
21
22
  puts "Binary already installed, skipping"
22
23
  else
23
- `cd #{File.dirname(__FILE__)}/../../shellscripts/ && ./install_binary #{PACKAGE_URL}`
24
+ `cd #{shellscripts_path} && ./install_binary #{PACKAGE_URL}`
24
25
  end
25
26
  end
26
-
27
+
28
+ def shellscripts_path
29
+ File.join(File.dirname(__FILE__),"..","..","shellscripts")
30
+ end
31
+
27
32
  def install_database
28
33
  target = File.join(Autometal::Geoip::DATA_FILE_PATH,"#{@package_name}.dat")
29
34
  if File.exists?(target) and File::ctime(target) > Time.now - (30*24*60*60)
30
35
  puts "Datafile is up to date, skipping"
31
36
  else
32
- `cd #{File.dirname(__FILE__)}/../../shellscripts/ && ./install_db #{@db_url}`
37
+ `cd #{shellscripts_path} && ./install_db #{@db_url}`
33
38
  end
34
39
  end
35
40
  end
@@ -1,5 +1,9 @@
1
1
  module Autometal
2
2
  class Geoip
3
+ =begin rdoc
4
+ GeoIPOrg database extension
5
+ provides Country and Organization (ISP) information
6
+ =end
3
7
  class Organization < Package
4
8
  attr_accessor :organization
5
9
 
data/test/test_geoip.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
1
+ require File.join(File.dirname(__FILE__),"test_helper")
2
2
 
3
3
  class TestGeoip < Test::Unit::TestCase
4
4
 
@@ -22,11 +22,21 @@ class TestGeoip < Test::Unit::TestCase
22
22
  end
23
23
  end
24
24
 
25
+ # Test suite should be run on Ruby 1.8+ and Ruby 1.9+
26
+ def test_gem_handles_weird_chars_without_exceptions
27
+ assert_nothing_raised do
28
+ assert_equal "DE", Autometal::Geoip.new('78.46.60.181').country
29
+ assert_equal "SE", Autometal::Geoip.new('81.237.231.174').country
30
+ end
31
+ end
32
+
25
33
  def test_gem_can_install_binaries
26
34
  assert_nothing_raised do
27
35
  Autometal::Geoip::Installer.new("GeoLiteCity")
28
36
  end
29
37
  assert_equal true, Autometal::Geoip.bin_installed?
38
+ assert_equal false, Autometal::StubbedGeoip.bin_installed?
39
+
30
40
  assert_not_nil @dummy.country, "Country should not be nil"
31
41
  assert_not_nil @dummy.city, "City should not be nil"
32
42
  assert_not_nil @dummy.lat, "Latitude should not be nil"
data/test/test_helper.rb CHANGED
@@ -17,4 +17,10 @@ class AnotherDummy
17
17
  @pantera = open("http://check-rankings.co.uk").read rescue "66.102.13.105"
18
18
  end
19
19
  def geo_attr; pantera; end
20
+ end
21
+
22
+ module Autometal
23
+ class StubbedGeoip < Geoip
24
+ BIN = "zoot-allures.666"
25
+ end
20
26
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autometal-geoip
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
4
+ hash: 15
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 7
10
- version: 0.3.7
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Achillefs Charmpilas
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-12 00:00:00 +01:00
18
+ date: 2011-01-16 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  requirements: []
124
124
 
125
125
  rubyforge_project: autometal-geoip
126
- rubygems_version: 1.3.7
126
+ rubygems_version: 1.4.2
127
127
  signing_key:
128
128
  specification_version: 3
129
129
  summary: A wrapper to MaxMind's GeoIP services, that can work with both free and paid versions