autometal-geoip 0.1.3 → 0.2.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/Manifest.txt CHANGED
@@ -6,8 +6,10 @@ Rakefile
6
6
  autometal-geoip.gemspec
7
7
  bin/install_geoip
8
8
  lib/geoip.rb
9
+ lib/geoip/city.rb
9
10
  lib/geoip/geolocatable.rb
10
11
  lib/geoip/installer.rb
12
+ lib/geoip/organization.rb
11
13
  script/console
12
14
  script/destroy
13
15
  script/generate
@@ -2,21 +2,29 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{autometal-geoip}
5
- s.version = "0.1.1"
5
+ s.version = "0.2.2"
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-10-11}
9
+ s.date = %q{2010-12-07}
10
+ s.default_executable = %q{install_geoip}
10
11
  s.description = %q{A wrapper to MaxMind's GeoIP services, that can work with both free and paid versions.
11
- Also provides geo-location methods to Active Record and Sequel Models.}
12
+ Also provides geo-location methods to Active Record and Sequel Models.
13
+
14
+ This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com/.}
12
15
  s.email = ["ac@humbuckercode.co.uk"]
16
+ s.executables = ["install_geoip"]
13
17
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt"]
14
- s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "geoip.gemspec", "lib/geoip.rb", "lib/geoip/geolocatable.rb", "lib/geoip/installer.rb", "script/console", "script/destroy", "script/generate", "shellscripts/install_binary", "shellscripts/install_db", "test/test_geoip.rb", "test/test_helper.rb"]
18
+ s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "autometal-geoip.gemspec", "bin/install_geoip", "lib/geoip.rb", "lib/geoip/city.rb", "lib/geoip/geolocatable.rb", "lib/geoip/installer.rb", "lib/geoip/organization.rb", "script/console", "script/destroy", "script/generate", "shellscripts/install_binary", "shellscripts/install_db", "test/test_geoip.rb", "test/test_helper.rb"]
15
19
  s.homepage = %q{http://github.com/Achillefs/geoip}
16
- s.post_install_message = %q{Thank you for installing autometal-geoip
17
- This gem will install and use MaxMind's GeoLiteCity database by default.
20
+ s.post_install_message = %q{
21
+ Thank you for installing autometal-geoip
22
+
23
+ Please run +sudo install_geoip+ to install the MaxMind binaries
24
+
25
+ For more information on autometal-geoip, see http://humbuckercode.co.uk/licks/gems/geoip/
18
26
 
19
- For more information on autometal-geoip, see http://humbuckercode.co.uk/licks/gems/geoip/}
27
+ }
20
28
  s.rdoc_options = ["--main", "README.rdoc"]
21
29
  s.require_paths = ["lib"]
22
30
  s.rubyforge_project = %q{autometal-geoip}
@@ -29,13 +37,16 @@ For more information on autometal-geoip, see http://humbuckercode.co.uk/licks/ge
29
37
  s.specification_version = 3
30
38
 
31
39
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
32
41
  s.add_development_dependency(%q<rubyforge>, [">= 2.0.4"])
33
42
  s.add_development_dependency(%q<hoe>, [">= 2.6.2"])
34
43
  else
44
+ s.add_dependency(%q<activesupport>, [">= 0"])
35
45
  s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
36
46
  s.add_dependency(%q<hoe>, [">= 2.6.2"])
37
47
  end
38
48
  else
49
+ s.add_dependency(%q<activesupport>, [">= 0"])
39
50
  s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
40
51
  s.add_dependency(%q<hoe>, [">= 2.6.2"])
41
52
  end
data/lib/geoip.rb CHANGED
@@ -1,40 +1,36 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
- %W[installer geolocatable].each { |r| require "#{File.dirname(__FILE__)}/geoip/#{r}" }
5
-
6
4
  module Autometal
7
5
  class Geoip
8
- VERSION = '0.1.3'
9
- DEFAULT_PACKAGE = "GeoLiteCity"
6
+ VERSION = '0.2.2'
10
7
  DATA_FILE_PATH = "/usr/local/share/GeoIP/"
11
8
  BIN = "geoiplookup"
12
9
 
13
10
  def self.bin_installed?
14
- %x{ #{BIN} --version } == "" ? false : true
11
+ %x{ #{self::BIN} --version } == "" ? false : true
15
12
  end
16
13
 
17
- def initialize ip_or_domain, opts = {}
18
- raise LoadError.new("No GeoIP binary is installed on your system.") unless self.class.bin_installed?
19
- package = opts.delete(:package) || DEFAULT_PACKAGE
20
- @data_file = File.join(DATA_FILE_PATH,"#{package}.dat")
21
- @response = self.lookup ip_or_domain
22
- ar = @response.split(", ")
23
- @version = ar[0]
24
- @country = ar[1].gsub("Rev 1: ","")
25
- @county = ar[2]
26
- @city = ar[3]
27
- @lat = ar[5].to_f
28
- @lng = ar[6].to_f
29
- end
30
- attr_accessor :country, :county, :city, :lat, :lng
31
- def lookup ip_or_domain
32
- %x{ #{BIN} -f #{@data_file} #{ip_or_domain} }
14
+ class Package
15
+ attr_accessor :version
16
+ def initialize ip_or_domain
17
+ return false unless self.class.installed?
18
+ @response = self.lookup ip_or_domain
19
+ process_response
20
+ end
21
+
22
+ def self.installed?
23
+ return false unless Geoip.bin_installed?
24
+ return false unless File.exists? data_file
25
+ true
26
+ end
27
+
28
+ def lookup ip_or_domain
29
+ puts "#{Geoip::BIN} -f #{self.class.data_file} #{ip_or_domain}"
30
+ %x{ #{Geoip::BIN} -f #{self.class.data_file} #{ip_or_domain} }
31
+ end
33
32
  end
34
-
35
- def latlng
36
- [self.lat,self.lng]
37
- end
38
- alias :latlon :latlng
39
33
  end
40
- end
34
+ end
35
+
36
+ %W[installer geolocatable city organization].each { |r| require "#{File.dirname(__FILE__)}/geoip/#{r}" }
data/lib/geoip/city.rb ADDED
@@ -0,0 +1,25 @@
1
+ module Autometal
2
+ class Geoip
3
+ class City < Geoip::Package
4
+ attr_accessor :country, :county, :city, :lat, :lng
5
+ def latlng
6
+ [self.lat,self.lng]
7
+ end
8
+ alias :latlon :latlng
9
+
10
+ def self.data_file
11
+ File.join(Geoip::DATA_FILE_PATH,"GeoLiteCity.dat")
12
+ end
13
+
14
+ def process_response
15
+ ar = @response.split(", ")
16
+ @version = ar[0]
17
+ @country = ar[1].gsub("Rev 1: ","")
18
+ @county = ar[2]
19
+ @city = ar[3]
20
+ @lat = ar[5].to_f
21
+ @lng = ar[6].to_f
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,27 +1,40 @@
1
1
  module Autometal
2
2
  module Geolocatable
3
- def geoip
4
- @geoip = Autometal::Geoip.new(geo_attr) unless @geoip
5
- @geoip
3
+ def geoip_city
4
+ @geoip_city = false unless @geoip_city
5
+ if Autometal::Geoip::City.installed?
6
+ @geoip_city = Autometal::Geoip::City.new(geo_attr) unless @geoip_city
7
+ end
8
+ @geoip_city
9
+ end
10
+ def geoip_org
11
+ @geoip_org = false unless @geoip_org
12
+ if Autometal::Geoip::Organization.installed?
13
+ @geoip_org = Autometal::Geoip::Organization.new(geo_attr) unless @geoip_org
14
+ end
15
+ @geoip_org
6
16
  end
17
+
7
18
  def geo_attr
8
19
  begin
9
20
  send(:ip)
10
- rescue NoMethodError => e
21
+ rescue NoMethodError
11
22
  send(:domain)
12
23
  end
13
24
  end
14
- def country; geoip.country; end
15
-
16
- def county; geoip.county; end
17
-
18
- def city; geoip.city; end
25
+ def country; geoip_city.country if geoip_city; end
26
+
27
+ def county; geoip_city.county if geoip_city; end
19
28
 
20
- def lat; geoip.lat; end
29
+ def city; geoip_city.city if geoip_city; end
21
30
 
22
- def lng; geoip.lng; end
31
+ def lat; geoip_city.lat if geoip_city; end
23
32
 
24
- def latlng; geoip.latlng; end
33
+ def lng; geoip_city.lng if geoip_city; end
34
+
35
+ def organization; geoip_org.organization if geoip_org; end
36
+
37
+ def latlng; geoip_city.latlng if geoip_city; end
25
38
  alias :latlon :latlng
26
39
  end
27
40
  end
@@ -0,0 +1,17 @@
1
+ module Autometal
2
+ class Geoip
3
+ class Organization < Package
4
+ attr_accessor :organization
5
+
6
+ def self.data_file
7
+ File.join(Geoip::DATA_FILE_PATH,"GeoIPOrg.dat")
8
+ end
9
+
10
+ def process_response
11
+ ar = @response.split(": ")
12
+ @version = ar[0].strip
13
+ @organization = ar[1].strip
14
+ end
15
+ end
16
+ end
17
+ end
data/test/test_geoip.rb CHANGED
@@ -8,7 +8,11 @@ class TestGeoip < Test::Unit::TestCase
8
8
  end
9
9
 
10
10
  def test_objects_are_geolocatable
11
- assert_not_nil @dummy.country
11
+ assert_not_nil @dummy.country if Autometal::Geoip::City.installed?
12
+ end
13
+
14
+ def test_object_responds_to_organization_if_installed
15
+ assert_not_nil @dummy.organization if Autometal::Geoip::Organization.installed?
12
16
  end
13
17
 
14
18
  def test_gem_can_install_binaries
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
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
8
+ - 2
9
+ - 2
10
+ version: 0.2.2
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: 2010-12-06 00:00:00 +01:00
18
+ date: 2010-12-07 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -88,8 +88,10 @@ files:
88
88
  - autometal-geoip.gemspec
89
89
  - bin/install_geoip
90
90
  - lib/geoip.rb
91
+ - lib/geoip/city.rb
91
92
  - lib/geoip/geolocatable.rb
92
93
  - lib/geoip/installer.rb
94
+ - lib/geoip/organization.rb
93
95
  - script/console
94
96
  - script/destroy
95
97
  - script/generate