autometal-geoip 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.
@@ -0,0 +1,4 @@
1
+ === 0.1.1 2010-10-11
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,17 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ autometal-geoip.gemspec
7
+ bin/install_geoip
8
+ lib/geoip.rb
9
+ lib/geoip/geolocatable.rb
10
+ lib/geoip/installer.rb
11
+ script/console
12
+ script/destroy
13
+ script/generate
14
+ shellscripts/install_binary
15
+ shellscripts/install_db
16
+ test/test_geoip.rb
17
+ test/test_helper.rb
@@ -0,0 +1,7 @@
1
+
2
+ Thank you for installing autometal-geoip
3
+
4
+ Please run +sudo install_geoip+ to install the MaxMind binaries
5
+
6
+ For more information on autometal-geoip, see http://humbuckercode.co.uk/licks/gems/geoip/
7
+
@@ -0,0 +1,88 @@
1
+ = autometal-geoip
2
+
3
+ * http://github.com/Achillefs/geoip
4
+
5
+ == DESCRIPTION:
6
+ A wrapper to MaxMind's GeoIP services, that can work with both free and paid versions.
7
+ Also provides geo-location methods to Active Record and Sequel Models.
8
+
9
+ This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com/."
10
+
11
+ == FEATURES/PROBLEMS:
12
+
13
+ * While you are installing the MaxMind binaries on Linux systems, you mayget an error similar to this:
14
+ libGeoIP.so.1: cannot open shared object file: No such file or directory
15
+ If you do, do the following:
16
+ $ vim /etc/ld.so.conf (and add the directory the libraries were installed in usually /var/lib or /var/shared/lib)
17
+ $ ldconfig
18
+ And rerun the installer
19
+
20
+ == SYNOPSIS:
21
+
22
+ Autometal::Geoip provides a standalone GeoIP service:
23
+ require "rubygems"
24
+ require "geoip"
25
+ @geo = Autometal::Geoip.new("66.102.13.106")
26
+ @geo.country
27
+ => US
28
+
29
+ You can also pass it a domain instead of an IP address
30
+ @geo = Autometal::Geoip.new("www.google.com")
31
+ @geo.country
32
+ => US
33
+
34
+ You can make any object Geo-location aware, as long as it has an IP or a domain attribute:
35
+ require "rubygems"
36
+ require "geoip"
37
+ class Site
38
+ include Geolocatable
39
+ end
40
+ Site.new(:domain => "google.com")
41
+ site.country
42
+ => "US"
43
+
44
+ The above will work if your class has a +domain+ attribute.
45
+ You can override the attribute used to geolocate by overriding +geo_attr+
46
+
47
+ require "rubygems"
48
+ require "geoip"
49
+ class Site
50
+ include Geolocatable
51
+ def geo_attr; self.weird_ip_field_name; end
52
+ end
53
+ Site.new(:weird_ip_field_name => "66.102.13.106")
54
+ site.country
55
+ => "US"
56
+
57
+ == REQUIREMENTS:
58
+
59
+ * GeoIP C bindings (installed along with the Gem)
60
+ * Active Support (sudo gem install active-support --no-ri --no-rdoc)
61
+ This isn't really needed, I just like using the 1.day.ago stuff too much...
62
+
63
+ == INSTALL:
64
+
65
+ sudo gem install autometal-geoip
66
+
67
+ == LICENSE:
68
+
69
+ Copyright (c) 2010 Achillefs Charmpilas, Humbucker Ltd
70
+
71
+ Permission is hereby granted, free of charge, to any person obtaining
72
+ a copy of this software and associated documentation files (the
73
+ 'Software'), to deal in the Software without restriction, including
74
+ without limitation the rights to use, copy, modify, merge, publish,
75
+ distribute, sublicense, and/or sell copies of the Software, and to
76
+ permit persons to whom the Software is furnished to do so, subject to
77
+ the following conditions:
78
+
79
+ The above copyright notice and this permission notice shall be
80
+ included in all copies or substantial portions of the Software.
81
+
82
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
83
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
84
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
85
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
86
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
87
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
88
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/geoip'
6
+
7
+ Hoe.plugin :newgem
8
+ $hoe = Hoe.spec 'autometal-geoip' do
9
+ self.developer 'Achillefs Charmpilas', 'ac@humbuckercode.co.uk'
10
+ self.post_install_message = File.read('PostInstall.txt')
11
+ self.rubyforge_name = self.name
12
+ self.extra_deps = [['activesupport','>= 0']]
13
+ end
14
+
15
+ require 'newgem/tasks'
16
+ Dir['tasks/**/*.rake'].each { |t| load t }
@@ -0,0 +1,42 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{autometal-geoip}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Achillefs Charmpilas"]
9
+ s.date = %q{2010-10-11}
10
+ 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
+ s.email = ["ac@humbuckercode.co.uk"]
13
+ 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"]
15
+ 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.
18
+
19
+ For more information on autometal-geoip, see http://humbuckercode.co.uk/licks/gems/geoip/}
20
+ s.rdoc_options = ["--main", "README.rdoc"]
21
+ s.require_paths = ["lib"]
22
+ s.rubyforge_project = %q{autometal-geoip}
23
+ s.rubygems_version = %q{1.3.7}
24
+ s.summary = %q{A wrapper to MaxMind's GeoIP services, that can work with both free and paid versions}
25
+ s.test_files = ["test/test_geoip.rb", "test/test_helper.rb"]
26
+
27
+ if s.respond_to? :specification_version then
28
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
29
+ s.specification_version = 3
30
+
31
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
32
+ s.add_development_dependency(%q<rubyforge>, [">= 2.0.4"])
33
+ s.add_development_dependency(%q<hoe>, [">= 2.6.2"])
34
+ else
35
+ s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
36
+ s.add_dependency(%q<hoe>, [">= 2.6.2"])
37
+ end
38
+ else
39
+ s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
40
+ s.add_dependency(%q<hoe>, [">= 2.6.2"])
41
+ end
42
+ end
@@ -0,0 +1,7 @@
1
+ #! /usr/bin/env ruby
2
+ require "rubygems"
3
+ require "geoip"
4
+
5
+ puts "Attempting to install MaxMind GeoIP binaries..."
6
+ Autometal::Geoip::Installer.new("GeoLiteCity")
7
+ puts "Done."
@@ -0,0 +1,40 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ %W[installer geolocatable].each { |r| require "#{File.dirname(__FILE__)}/geoip/#{r}" }
5
+
6
+ module Autometal
7
+ class Geoip
8
+ VERSION = '0.1.2'
9
+ DEFAULT_PACKAGE = "GeoLiteCity"
10
+ DATA_FILE_PATH = "/usr/local/share/GeoIP/"
11
+ BIN = "geoiplookup"
12
+
13
+ def self.bin_installed?
14
+ %x{ #{BIN} --version } == "" ? false : true
15
+ end
16
+
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} }
33
+ end
34
+
35
+ def latlng
36
+ [self.lat,self.lng]
37
+ end
38
+ alias :latlon :latlng
39
+ end
40
+ end
@@ -0,0 +1,27 @@
1
+ module Autometal
2
+ module Geolocatable
3
+ def geoip
4
+ @geoip = Autometal::Geoip.new(geo_attr) unless @geoip
5
+ @geoip
6
+ end
7
+ def geo_attr
8
+ begin
9
+ send(:ip)
10
+ rescue NoMethodError => e
11
+ send(:domain)
12
+ end
13
+ end
14
+ def country; geoip.country; end
15
+
16
+ def county; geoip.county; end
17
+
18
+ def city; geoip.city; end
19
+
20
+ def lat; geoip.lat; end
21
+
22
+ def lng; geoip.lng; end
23
+
24
+ def latlng; geoip.latlng; end
25
+ alias :latlon :latlng
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ require "active_support"
2
+
3
+ module Autometal
4
+ class Geoip
5
+ class Installer
6
+ BASE_DB_URL = "http://geolite.maxmind.com/download/geoip/database/*.dat.gz"
7
+ PACKAGE_URL = "http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz"
8
+
9
+ def initialize package_name = "GeoLiteCity"
10
+ @package_name = package_name
11
+ @db_url = BASE_DB_URL.gsub("*",@package_name)
12
+ install_binary
13
+ install_database
14
+ end
15
+
16
+ private
17
+ def install_binary
18
+ if Autometal::Geoip.bin_installed?
19
+ puts "Binary already installed, skipping"
20
+ else
21
+ `cd #{File.dirname(__FILE__)}/../../shellscripts/ && ./install_binary #{PACKAGE_URL}`
22
+ end
23
+ end
24
+
25
+ def install_database
26
+ if File::ctime(File.join(Autometal::Geoip::DATA_FILE_PATH,"#{@package_name}.dat")) > 1.month.ago
27
+ puts "Datafile is up to date, skipping"
28
+ else
29
+ `cd #{File.dirname(__FILE__)}/../../shellscripts/ && ./install_db #{@db_url}`
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/geoip.rb'}"
9
+ puts "Loading geoip gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,7 @@
1
+ #! /bin/bash
2
+ mkdir ./tmp && cd ./tmp
3
+ wget $1
4
+ tar -xzvf *.gz && cd GeoIP*
5
+ ./configure && make && make check && sudo make install
6
+ cd ../..
7
+ rm -rf ./tmp
@@ -0,0 +1,9 @@
1
+ #! /bin/bash
2
+ mkdir ./tmp
3
+ cd ./tmp
4
+ wget $1
5
+ gunzip *.gz
6
+ sudo mkdir -p /usr/local/share/GeoIP/
7
+ sudo mv *.dat /usr/local/share/GeoIP/
8
+ cd ..
9
+ rm -rf ./tmp
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestGeoip < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @dummy = Dummy.new
7
+ @dummy2 = AnotherDummy.new
8
+ end
9
+
10
+ def test_objects_are_geolocatable
11
+ assert_not_nil @dummy.country
12
+ end
13
+
14
+ def test_gem_can_install_binaries
15
+ assert_nothing_raised do
16
+ Autometal::Geoip::Installer.new("GeoLiteCity")
17
+ end
18
+ assert_equal true, Autometal::Geoip.bin_installed?
19
+ assert_not_nil @dummy.country, "Country should not be nil"
20
+ assert_not_nil @dummy.city, "City should not be nil"
21
+ assert_not_nil @dummy.lat, "Latitude should not be nil"
22
+ assert_not_nil @dummy.lng, "Longitude should not be nil"
23
+ end
24
+
25
+ def test_can_override_geo_attribute
26
+ assert_equal @dummy.country, @dummy2.country
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ %W[ stringio test/unit open-uri #{File.dirname(__FILE__)}/../lib/geoip ].each { |r| require r }
2
+
3
+ class Dummy
4
+ include Autometal::Geolocatable
5
+ attr_accessor :ip
6
+
7
+ def initialize
8
+ @ip = open("http://check-rankings.co.uk").read rescue "66.102.13.105"
9
+ end
10
+ end
11
+
12
+ class AnotherDummy
13
+ include Autometal::Geolocatable
14
+ attr_accessor :pantera
15
+
16
+ def initialize
17
+ @pantera = open("http://check-rankings.co.uk").read rescue "66.102.13.105"
18
+ end
19
+ def geo_attr; pantera; end
20
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: autometal-geoip
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 2
10
+ version: 0.1.2
11
+ platform: ruby
12
+ authors:
13
+ - Achillefs Charmpilas
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-11 00:00:00 +02:00
19
+ default_executable:
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
+ - !ruby/object:Gem::Dependency
36
+ name: rubyforge
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 7
44
+ segments:
45
+ - 2
46
+ - 0
47
+ - 4
48
+ version: 2.0.4
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: hoe
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 19
60
+ segments:
61
+ - 2
62
+ - 6
63
+ - 2
64
+ version: 2.6.2
65
+ type: :development
66
+ version_requirements: *id003
67
+ description: |-
68
+ A wrapper to MaxMind's GeoIP services, that can work with both free and paid versions.
69
+ Also provides geo-location methods to Active Record and Sequel Models.
70
+
71
+ This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com/."
72
+ email:
73
+ - ac@humbuckercode.co.uk
74
+ executables:
75
+ - install_geoip
76
+ extensions: []
77
+
78
+ extra_rdoc_files:
79
+ - History.txt
80
+ - Manifest.txt
81
+ - PostInstall.txt
82
+ files:
83
+ - History.txt
84
+ - Manifest.txt
85
+ - PostInstall.txt
86
+ - README.rdoc
87
+ - Rakefile
88
+ - autometal-geoip.gemspec
89
+ - bin/install_geoip
90
+ - lib/geoip.rb
91
+ - lib/geoip/geolocatable.rb
92
+ - lib/geoip/installer.rb
93
+ - script/console
94
+ - script/destroy
95
+ - script/generate
96
+ - shellscripts/install_binary
97
+ - shellscripts/install_db
98
+ - test/test_geoip.rb
99
+ - test/test_helper.rb
100
+ has_rdoc: true
101
+ homepage: http://github.com/Achillefs/geoip
102
+ licenses: []
103
+
104
+ post_install_message: |+
105
+
106
+ Thank you for installing autometal-geoip
107
+
108
+ Please run +sudo install_geoip+ to install the MaxMind binaries
109
+
110
+ For more information on autometal-geoip, see http://humbuckercode.co.uk/licks/gems/geoip/
111
+
112
+ rdoc_options:
113
+ - --main
114
+ - README.rdoc
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ hash: 3
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ requirements: []
136
+
137
+ rubyforge_project: autometal-geoip
138
+ rubygems_version: 1.3.7
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: A wrapper to MaxMind's GeoIP services, that can work with both free and paid versions
142
+ test_files:
143
+ - test/test_geoip.rb
144
+ - test/test_helper.rb