Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
pkg/
mkmf.log
Makefile
.bundle
/data
/doc
/pkg
conftest.dSYM/
Gemfile.lock
geoip.bundle
geoip.so
geoip.o
geoip.so
Makefile
mkmf.log
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gemspec
58 changes: 26 additions & 32 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,55 +1,49 @@
require 'rake'
require 'rake/clean'
require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/gempackagetask'
require 'rdoc/task'
require 'rubygems/package_task'
require "rake/extensiontask"

task :default => [:compile, :test]
task :default => [:test]

CLEAN.add "geoip.{o,bundle,so,obj,pdb,lib,def,exp}"
CLOBBER.add ['Makefile', 'mkmf.log','doc']
CLOBBER.add 'doc', 'data'

Rake::RDocTask.new do |rdoc|
rdoc.rdoc_files.add ['README', 'geoip.c']
rdoc.main = "README" # page to start on
RDoc::Task.new do |rdoc|
rdoc.main = "README.md" # page to start on
rdoc.rdoc_files.include("README.md", "ext/geoip/geoip.c")
rdoc.rdoc_dir = 'doc/' # rdoc output folder
end

Rake::TestTask.new do |t|
t.test_files = ['test.rb']
t.verbose = true
end

spec = Gem::Specification.new do |s|
s.name = 'geoip-c'
s.version = "0.8.1"
spec = Gem::Specification.load "geoip-c.gemspec"

s.authors = ['Ryah Dahl', 'Matt Todd', 'Andy Lindeman']
s.email = ['alindeman@gmail.com', 'mtodd@highgroove.com']

s.summary = "A Binding to the GeoIP C library"
s.description = 'Generic GeoIP lookup tool. Based on the geoip_city RubyGem by Ryah Dahl'
s.homepage = "http://github.com/mtodd/geoip"
Gem::PackageTask.new(spec) do |pkg|
pkg.need_tar = true
end

s.files = ["Rakefile", "extconf.rb", "test.rb", "geoip.c", "README.md"]
s.test_files = ['test.rb']
s.extensions = ['extconf.rb']
s.require_path = '.'
Rake::ExtensionTask.new("geoip", spec) do |ext|
end

Rake::GemPackageTask.new(spec) do |p|
p.need_tar = true
p.gem_spec = spec
task(:webpage) do
sh 'scp -r doc/* rydahl@rubyforge.org:/var/www/gforge-projects/geoip-city/'
end

desc 'compile the extension'
task(:compile => 'Makefile') { sh 'make' }
file('Makefile' => "geoip.c") { ruby 'extconf.rb' }
directory "data"

task :install => [:gem] do
`env ARCHFLAGS="-arch i386" gem install pkg/geoip-c-0.5.0.gem -- --with-geoip-dir=/usr/local/GeoIP`
file "data/GeoLiteCity.dat" => ["data"] do |f|
url = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz"

sh "curl #{url} -o data/GeoLiteCity.dat.gz"
sh "gunzip data/GeoLiteCity.dat.gz"
touch f.name
end

task(:webpage) do
sh 'scp -r doc/* rydahl@rubyforge.org:/var/www/gforge-projects/geoip-city/'
task :database => ["data/GeoLiteCity.dat"] do
ENV['CITY'] = File.expand_path("data/GeoLiteCity.dat")
end

task :test => [:compile, :database]
File renamed without changes.
5 changes: 4 additions & 1 deletion geoip.c → ext/geoip/geoip.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ static VALUE generic_single_value_lookup_response(char *key, char *value)
VALUE rb_city_record_to_hash(GeoIPRecord *record)
{
VALUE hash = rb_hash_new();
char *region_name;

if(record->country_code)
rb_hash_sset(hash, "country_code", encode_to_utf8_and_return_rb_str(record->country_code));
Expand All @@ -126,7 +127,9 @@ VALUE rb_city_record_to_hash(GeoIPRecord *record)
rb_hash_sset(hash, "country_name", encode_to_utf8_and_return_rb_str(record->country_name));
if(record->region) {
rb_hash_sset(hash, "region", encode_to_utf8_and_return_rb_str(record->region));
rb_hash_sset(hash, "region_name", encode_to_utf8_and_return_rb_str(GeoIP_region_name_by_code(record->country_code, record->region)));
region_name = GeoIP_region_name_by_code(record->country_code, record->region);
if (region_name)
rb_hash_sset(hash, "region_name", encode_to_utf8_and_return_rb_str(region_name));
}
if(record->city)
rb_hash_sset(hash, "city", encode_to_utf8_and_return_rb_str(record->city));
Expand Down
19 changes: 12 additions & 7 deletions geoip-c.gemspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = 'geoip-c'
s.version = "0.8.1"

s.authors = ['Ryan Dahl', 'Matt Todd', 'Charles Brian Quinn', 'Michael Sheakoski', 'Silvio Quadri', 'Andy Lindeman']
s.email = ['alindeman@gmail.com', 'mtodd@highgroove.com']

s.summary = "A Binding to the GeoIP C library"
s.description = 'Generic GeoIP lookup tool. Based on the geoip_city RubyGem by Ryan Dahl'
s.homepage = "http://github.com/mtodd/geoip"

s.files = ["Rakefile", "extconf.rb", "test.rb", "geoip.c", "README.md"]
s.test_files = ['test.rb']
s.extensions = ['extconf.rb']
s.require_path = '.'

s.files = ["Rakefile", "ext/geoip/extconf.rb", "ext/geoip/geoip.c", "test/test_geoip.rb", "README.md"]
s.test_files = ['test/test_geoip.rb']
s.extensions = ["ext/geoip/extconf.rb"]

s.add_development_dependency "rake", "~> 0.9.6"
s.add_development_dependency "rdoc", "~> 3.12"
s.add_development_dependency "rake-compiler", "~> 0.8.2"
end
170 changes: 0 additions & 170 deletions test.rb

This file was deleted.

Binary file added test/fixtures/asnum.dat
Binary file not shown.
6 changes: 6 additions & 0 deletions test/fixtures/asnum.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0, 167772159, AS12345
184549376, 2130706431, AS12345
2147483648, 2851995647, AS12345
2852061184, 2886729727, AS12345
2887778304, 3232235519, AS12345
3232301056, 4294967294, AS12345
Binary file added test/fixtures/city.dat
Binary file not shown.
6 changes: 6 additions & 0 deletions test/fixtures/city.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"0","167772159","US","NY","New York","5.4321","-25.2015","1005","212","123"
"184549376","2130706431","US","NY","New York","5.4321","-25.2015","1005","212","123"
"2147483648","2851995647","US","NY","New York","5.4321","-25.2015","1005","212","123"
"2852061184","2886729727","US","NY","New York","5.4321","-25.2015","1005","212","123"
"2887778304","3232235519","US","NY","New York","5.4321","-25.2015","1005","212","123"
"3232301056","4294967294","US","NY","New York","5.4321","-25.2015","1005","212","123"
Binary file added test/fixtures/country.dat
Binary file not shown.
6 changes: 6 additions & 0 deletions test/fixtures/country.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0.0.0.0, 9.255.255.255, 0, 167772159, US
11.0.0.0, 126.255.255.255, 184549376, 2130706431, US
128.0.0.0, 169.253.255.255, 2147483648, 2851995647, US
169.255.0.0, 172.15.255.255, 2852061184, 2886729727, US
172.32.0.0, 192.167.255.255, 2887778304, 3232235519, US
192.169.0.0, 255.255.255.254, 3232301056, 4294967294, US
Binary file added test/fixtures/isp.dat
Binary file not shown.
6 changes: 6 additions & 0 deletions test/fixtures/isp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0,167772159,0.0.0.0,9.255.255.255,"A Company"
184549376,2130706431,11.0.0.0,126.255.255.255,"A Company"
2147483648,2851995647,128.0.0.0,169.253.255.255,"A Company"
2852061184,2886729727,169.255.0.0,172.15.255.255,"A Company"
2887778304,3232235519,172.32.0.0,192.167.255.255,"A Company"
3232301056,4294967294,192.169.0.0,255.255.255.254,"A Company"
Binary file added test/fixtures/netspeed.dat
Binary file not shown.
6 changes: 6 additions & 0 deletions test/fixtures/netspeed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0,167772159,0.0.0.0,9.255.255.255,2
184549376,2130706431,11.0.0.0,126.255.255.255,2
2147483648,2851995647,128.0.0.0,169.253.255.255,2
2852061184,2886729727,169.255.0.0,172.15.255.255,2
2887778304,3232235519,172.32.0.0,192.167.255.255,2
3232301056,4294967294,192.169.0.0,255.255.255.254,2
Binary file added test/fixtures/org.dat
Binary file not shown.
6 changes: 6 additions & 0 deletions test/fixtures/org.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0,167772159,"org test 123 org"
184549376,2130706431,"org test 123 org"
2147483648,2851995647,"org test 123 org"
2852061184,2886729727,"org test 123 org"
2887778304,3232235519,"org test 123 org"
3232301056,4294967294,"org test 123 org"
Binary file added test/fixtures/region.dat
Binary file not shown.
6 changes: 6 additions & 0 deletions test/fixtures/region.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0,167772159,0.0.0.0,9.255.255.255,US,NY
184549376,2130706431,11.0.0.0,126.255.255.255,US,NY
2147483648,2851995647,128.0.0.0,169.253.255.255,US,NY
2852061184,2886729727,169.255.0.0,172.15.255.255,US,NY
2887778304,3232235519,172.32.0.0,192.167.255.255,US,NY
3232301056,4294967294,192.169.0.0,255.255.255.254,US,NY
Loading