autometal-geoip 0.2.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,7 +34,13 @@ You can also pass it a domain instead of an IP address
34
34
  @geo = Autometal::Geoip.new("www.google.com")
35
35
  @geo.country
36
36
  => US
37
-
37
+
38
+ If you have purchased the Organization edition of the GeoIP database, you can also do this:
39
+ @geo.organization
40
+ => Google
41
+ Currently, the gem does not support installing the file itself, you will need to make sure that GeoIPOrg.dat is located in /usr/local/shared/
42
+
43
+
38
44
  You can make any object Geo-location aware, as long as it has an IP or a domain attribute:
39
45
  require "rubygems"
40
46
  require "geoip"
@@ -44,6 +50,7 @@ You can make any object Geo-location aware, as long as it has an IP or a domain
44
50
  Site.new(:domain => "google.com")
45
51
  site.country
46
52
  => "US"
53
+ site.organization # if GeoIPOrg.dat is not installed, this will return nil
47
54
 
48
55
  The above will work if your class has a +domain+ attribute.
49
56
  You can override the attribute used to geolocate by overriding +geo_attr+
@@ -61,14 +68,22 @@ You can override the attribute used to geolocate by overriding +geo_attr+
61
68
  == REQUIREMENTS:
62
69
 
63
70
  * GeoIP C bindings (installed along with the Gem)
64
- * Active Support
65
- This isn't really needed, I just like using the 1.day.ago stuff too much...
66
71
 
67
72
  == INSTALL:
68
73
 
69
74
  sudo gem install autometal-geoip
70
75
  sudo install_geoip (unless already installed)
71
76
 
77
+ == CHANGELOG
78
+ * 0.3.3
79
+ Removed active_support dependency
80
+ * 0.2.2
81
+ Reworked class hierarchy, added support for GeoIP's Organization database
82
+ * 0.1.3
83
+ Installer bugfix, fixes datafile install crash
84
+ * 0.1.1
85
+ Initial release
86
+
72
87
  == LICENSE:
73
88
 
74
89
  Copyright (c) 2010 Achillefs Charmpilas, Humbucker Ltd
data/Rakefile CHANGED
@@ -9,7 +9,6 @@ $hoe = Hoe.spec 'autometal-geoip' do
9
9
  self.developer 'Achillefs Charmpilas', 'ac@humbuckercode.co.uk'
10
10
  self.post_install_message = File.read('PostInstall.txt')
11
11
  self.rubyforge_name = self.name
12
- self.extra_deps = [['activesupport','>= 0']]
13
12
  end
14
13
 
15
14
  require 'newgem/tasks'
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{autometal-geoip}
5
- s.version = "0.2.2"
5
+ s.version = "0.3.1"
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{2010-12-07}
9
+ s.date = %q{2010-12-08}
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.
@@ -37,16 +37,13 @@ For more information on autometal-geoip, see http://humbuckercode.co.uk/licks/ge
37
37
  s.specification_version = 3
38
38
 
39
39
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
41
40
  s.add_development_dependency(%q<rubyforge>, [">= 2.0.4"])
42
41
  s.add_development_dependency(%q<hoe>, [">= 2.6.2"])
43
42
  else
44
- s.add_dependency(%q<activesupport>, [">= 0"])
45
43
  s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
46
44
  s.add_dependency(%q<hoe>, [">= 2.6.2"])
47
45
  end
48
46
  else
49
- s.add_dependency(%q<activesupport>, [">= 0"])
50
47
  s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
51
48
  s.add_dependency(%q<hoe>, [">= 2.6.2"])
52
49
  end
@@ -3,14 +3,28 @@ $:.unshift(File.dirname(__FILE__)) unless
3
3
 
4
4
  module Autometal
5
5
  class Geoip
6
- VERSION = '0.2.2'
6
+ VERSION = '0.3.3'
7
7
  DATA_FILE_PATH = "/usr/local/share/GeoIP/"
8
8
  BIN = "geoiplookup"
9
+ def initialize ip_or_domain
10
+ @org = Organization.new(ip_or_domain) if Organization.installed?
11
+ @geo = City.new(ip_or_domain) if City.installed?
12
+ end
13
+
14
+ def method_missing(m, *args, &block)
15
+ return @org.send(m, *args, &block) if @org and @org.respond_to?(m)
16
+ return @geo.send(m, *args, &block) if @geo and @geo.respond_to?(m)
17
+ end
9
18
 
10
19
  def self.bin_installed?
11
20
  %x{ #{self::BIN} --version } == "" ? false : true
12
21
  end
13
-
22
+ =begin rdoc
23
+ Extensible class that uses the Geoip binaries and data files to geolocate IPs and Hostnames.
24
+ To extend it to use a database, you will need to subclass Geoip::Package, define process_response, and self.data_file
25
+
26
+ See geoip/city.rb and geoip/organization.rb for extension examples
27
+ =end
14
28
  class Package
15
29
  attr_accessor :version
16
30
  def initialize ip_or_domain
@@ -19,6 +33,14 @@ module Autometal
19
33
  process_response
20
34
  end
21
35
 
36
+ def process_response
37
+ # deine this in the extension models
38
+ end
39
+
40
+ def self.data_file
41
+
42
+ end
43
+
22
44
  def self.installed?
23
45
  return false unless Geoip.bin_installed?
24
46
  return false unless File.exists? data_file
@@ -26,7 +48,6 @@ module Autometal
26
48
  end
27
49
 
28
50
  def lookup ip_or_domain
29
- puts "#{Geoip::BIN} -f #{self.class.data_file} #{ip_or_domain}"
30
51
  %x{ #{Geoip::BIN} -f #{self.class.data_file} #{ip_or_domain} }
31
52
  end
32
53
  end
@@ -1,8 +1,9 @@
1
- require "active_support"
2
1
  require "fileutils"
3
-
4
2
  module Autometal
5
3
  class Geoip
4
+ =begin rdoc
5
+ Installer class that handles downloading and installing databases and binaries
6
+ =end
6
7
  class Installer
7
8
  BASE_DB_URL = "http://geolite.maxmind.com/download/geoip/database/*.dat.gz"
8
9
  PACKAGE_URL = "http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz"
@@ -25,7 +26,7 @@ module Autometal
25
26
 
26
27
  def install_database
27
28
  target = File.join(Autometal::Geoip::DATA_FILE_PATH,"#{@package_name}.dat")
28
- if File.exists?(target) and File::ctime(target) > 1.month.ago
29
+ if File.exists?(target) and File::ctime(target) > Time.now - (30*24*60*60)
29
30
  puts "Datafile is up to date, skipping"
30
31
  else
31
32
  `cd #{File.dirname(__FILE__)}/../../shellscripts/ && ./install_db #{@db_url}`
@@ -15,6 +15,13 @@ class TestGeoip < Test::Unit::TestCase
15
15
  assert_not_nil @dummy.organization if Autometal::Geoip::Organization.installed?
16
16
  end
17
17
 
18
+ def test_geopi_proxy_class_works
19
+ assert_not_nil Autometal::Geoip.new(@dummy.ip).city, "City Package Delegation should work"
20
+ if Autometal::Geoip::Organization.installed?
21
+ assert_not_nil Autometal::Geoip.new(@dummy.ip).organization, "Organization Package Delegation should work"
22
+ end
23
+ end
24
+
18
25
  def test_gem_can_install_binaries
19
26
  assert_nothing_raised do
20
27
  Autometal::Geoip::Installer.new("GeoLiteCity")
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: 19
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 2
10
- version: 0.2.2
8
+ - 3
9
+ - 3
10
+ version: 0.3.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Achillefs Charmpilas
@@ -15,27 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-07 00:00:00 +01:00
18
+ date: 2010-12-08 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: activesupport
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
33
- type: :runtime
34
- version_requirements: *id001
35
21
  - !ruby/object:Gem::Dependency
36
22
  name: rubyforge
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
39
25
  none: false
40
26
  requirements:
41
27
  - - ">="
@@ -47,11 +33,11 @@ dependencies:
47
33
  - 4
48
34
  version: 2.0.4
49
35
  type: :development
50
- version_requirements: *id002
36
+ version_requirements: *id001
51
37
  - !ruby/object:Gem::Dependency
52
38
  name: hoe
53
39
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ requirement: &id002 !ruby/object:Gem::Requirement
55
41
  none: false
56
42
  requirements:
57
43
  - - ">="
@@ -63,7 +49,7 @@ dependencies:
63
49
  - 2
64
50
  version: 2.6.2
65
51
  type: :development
66
- version_requirements: *id003
52
+ version_requirements: *id002
67
53
  description: |-
68
54
  A wrapper to MaxMind's GeoIP services, that can work with both free and paid versions.
69
55
  Also provides geo-location methods to Active Record and Sequel Models.