geoipdb 0.5.5-java

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/geoipdb.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "geoipdb"
5
+ gem.version = "0.5.5"
6
+ gem.licenses = ["MIT"]
7
+
8
+ gem.authors = ["Eugen Martin", "Martin Karlsch", "Thomas Hirsch", "Benedikt Böhm"]
9
+ gem.email = ["eugeniusmartinus@googlemail.com", "martin.karlsch@madvertise.com", "thomas.hirsch@madvertise.com", "benedikt.boehm@madvertise.com"]
10
+
11
+ gem.description = "Returns a GeoLocation and additional information for given IP. Reads Data from CSV-Files and uses internal binary caching."
12
+ gem.summary = "Fast (>3 Mio queries/sec!!!) GeoIpDb implementation for Ruby using C-Extensions."
13
+ gem.homepage = "http://github.com/madvertise/geoipdb"
14
+
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.files = `git ls-files`.split("\n")
17
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ gem.require_paths = ["lib", "ext"]
19
+
20
+ if RUBY_PLATFORM =~ /java/
21
+ gem.platform = "java"
22
+ gem.files << "lib/geoipdb.jar"
23
+ else
24
+ gem.extensions = ["ext/geoipdb/extconf.rb"]
25
+ end
26
+
27
+ gem.add_development_dependency "rake-compiler"
28
+ end
data/lib/geoipdb.jar ADDED
Binary file
data/lib/geoipdb.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'ip_information'
2
+
3
+ if defined?(JRUBY_VERSION)
4
+ require 'jgeoipdb'
5
+ require 'rbconfig'
6
+ else
7
+ require 'geoipdb/geoipdb'
8
+ end
@@ -0,0 +1,27 @@
1
+ class IpInformation
2
+
3
+ ATTRIBS = [
4
+ :country_iso_code,
5
+ :city_code,
6
+ :city_name,
7
+ :lat,
8
+ :lng,
9
+ :is_mobile,
10
+ :isp_name,
11
+ ]
12
+
13
+ ATTRIBS.each do |attrib|
14
+ attr_accessor attrib
15
+ end
16
+
17
+ def mobile?
18
+ @is_mobile
19
+ end
20
+
21
+ def to_h
22
+ Hash[ATTRIBS.map do |attrib|
23
+ [attrib, send(attrib)]
24
+ end]
25
+ end
26
+
27
+ end
data/lib/jgeoipdb.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'java'
2
+ require File.expand_path('../geoipdb.jar', __FILE__)
3
+
4
+ class GeoIpDb
5
+
6
+ def self.init(cities_file, ranges_file, cache_file)
7
+ self.new(cities_file, ranges_file, cache_file)
8
+ rescue java.io.FileNotFoundException => e
9
+ return nil
10
+ end
11
+
12
+ def initialize(cities_file, ranges_file, cache_file)
13
+ # the Java implementation does not support cache files,
14
+ # since the java serialisation is slower than the actual csv parsing
15
+ @jdb = Java::GeoIpDb.new(cities_file, ranges_file)
16
+ end
17
+
18
+ def information_for_ip(ip)
19
+ range = @jdb.find_range_for_ip(ip)
20
+ return nil unless range
21
+
22
+ city = @jdb.find_city_for_ip_range(range)
23
+ return nil unless city
24
+
25
+ isp = range.isp_name
26
+ build_ip_information_object(range, city, isp)
27
+ end
28
+
29
+ def build_ip_information_object(range, city, isp)
30
+ info = IpInformation.new
31
+
32
+ info.country_iso_code = city.country_iso2
33
+ info.city_name = city.name
34
+ info.city_code = city.city_code
35
+ info.lng = city.lng
36
+ info.lat = city.lat
37
+ info.is_mobile = range.is_mobile
38
+ info.isp_name = isp && isp.to_sym
39
+
40
+ info
41
+ end
42
+
43
+ end
@@ -0,0 +1,7 @@
1
+ COUNTRY,REGION,CITY-NAME,METRO-CODE,CITY-CODE,LATITUDE,LONGITUDE
2
+ ***,***,?,0,7,0,0
3
+ afg,?,?,0,1,33,1
4
+ afg,no region,herat,-1,2,34.3452,62.12
5
+ afg,no region,kabul,-1,3,34.5167,69.1833
6
+ afg,no region,kandahar,-1,4,31.6111,65.702
7
+ afg,no region,mazar-e sharif,-1,5,36.7041,67.1096
@@ -0,0 +1,8 @@
1
+ COUNTRY,REGION,CITY-NAME,METRO-CODE,CITY-CODE,LATITUDE,LONGITUDE
2
+ ***,***,?,0,7,0,0
3
+ afg,?,?,0,1,33,1
4
+ afg,no region,herat,-1,2,34.3452,62.
5
+
6
+ afg,no , , , , region,kabul,-1,3,34.5167,69.1833
7
+ afg,no region,, , kandahar,-1,4,31.6111,65.702
8
+ afg,no region,maza , ,r-e sharif,-1,5,36.7041,67.1096
@@ -0,0 +1,11 @@
1
+ start_ip,end_ip,connection_type,city_code,isp_name
2
+ 0.0.0.0,0.0.0.255,mobile,0,?
3
+ 0.0.1.0,0.255.255.255,mobile,1,asdf,
4
+ 1.0.0.0,1.0.0.255,xdsl,2,vodafone
5
+ 1.0.1.0,1.1.0.255,wireless,3,?
6
+ 1.1.1.0,1.1.1.255,mobile,4,1vodafone2vodafone3vodafone4vodafone5vodafone1vodafone2vodafone3vodafone4vodafone5vodafone1vodafone2vodafone3vodafone4vodafone5vodafone1vodafone2vodafone3vodafone4vodafone5vodafone
7
+ 1.1.2.0,1.2.2.255,mobile,5,?
8
+ 1.2.3.0,1.2.3.255,mobile,5,?
9
+ 1.2.4.0,1.3.255.255,mobile,2,?
10
+ 1.4.0.0,1.4.0.255,mobile,5,?
11
+ 1.4.1.0,1.8.255.255,mobile,3,?
@@ -0,0 +1,20 @@
1
+ asdf,as,dsa,g,asdf,g,as,d,ga,sd,f,as,dg,
2
+
3
+
4
+ start_ip,end_ip,field 13,
5
+ 0.0.0.0,0.0.0.255,0,
6
+
7
+ 0.0.1.0,0.255.255.255,1,
8
+
9
+ 1.0.0.0,1.0.0.255,2,
10
+
11
+ 1.0.1.0,1.1.0.255,3,
12
+
13
+ asfdasdf asdf asfasdfasdf§$%&/
14
+
15
+ 1, , , 7 ,.1.1.0,1.1.1.255,4,,asdf,f,as,df,ag,as,df,asd,
16
+ 1.1.2.0,1.2.2.255,5,
17
+ 1.2.3.0,1.2.3.255,5,
18
+ 1.2.4.0,1.3.255.255,2,
19
+ 1.4.0.0,1.4.0.255,5,
20
+ 1.4.1.0,1.8.255.255,3,
@@ -0,0 +1,63 @@
1
+ require File.expand_path(File.dirname(__FILE__)+'/spec_helper')
2
+
3
+
4
+ describe GeoIpDb do
5
+
6
+ CACHE_FILE = 'sample_data/ipdb.cache'
7
+
8
+ def init_db
9
+ @db = GeoIpDb.init './sample_data/cities.csv', './sample_data/ip_ranges.csv', CACHE_FILE
10
+ end
11
+
12
+ it "should not throw an exception fault if data is corrupt" do
13
+ @db = GeoIpDb.init './sample_data/cities_corrupt.csv', './sample_data/ip_ranges_corrupt.csv', CACHE_FILE
14
+ end
15
+
16
+ it "should not init a db object if data files are missing" do
17
+ GeoIpDb.init( './sample_data/bla.csv', './sample_data/blubb.csv', CACHE_FILE ).should be_nil
18
+ end
19
+
20
+ it "should init correctly with sample data" do
21
+ init_db
22
+ @db.should_not be_nil
23
+ end
24
+
25
+ unless defined? JRUBY_VERSION
26
+ it "initializes cache_file correctly with sample data" do
27
+ init_db
28
+ File.exist?(CACHE_FILE).should be_true
29
+ end
30
+ end
31
+
32
+ it "sould find the sample cities correcty" do
33
+ init_db
34
+ #afg,no region,kabul,-1,3,34.5167,69.1833
35
+ info = @db.information_for_ip "1.1.0.254"
36
+ info.city_code.should == 3
37
+ info.city_name.should == 'kabul'
38
+ info.country_iso_code.should == 'af'
39
+ info.lat.should == 34.5167
40
+ info.lng.should == 69.1833
41
+ info.should_not be_mobile
42
+ end
43
+
44
+ it 'should return correct is_mobile information' do
45
+ init_db
46
+ @db.information_for_ip("1.0.0.1").should_not be_mobile
47
+ @db.information_for_ip("1.1.1.1").should be_mobile
48
+ end
49
+
50
+ it 'should return correct isp_name in ip_information' do
51
+ init_db
52
+ @db.information_for_ip("1.0.0.1").isp_name.should == :vodafone
53
+ @db.information_for_ip("1.1.1.1").isp_name.should == "1vodafone2vodafone3vodafone4vodafone5vodafone1vodafone2vodafone3vodafone4vodafone5vodafone1vodafone2vodafone3vodafone4vodafone5vodafone1vodafone2vodafone3vodafone4vodafone5vodafone"[0..99].to_sym
54
+ @db.information_for_ip("1.2.1.1").isp_name.should == nil
55
+ end
56
+
57
+ it "should write and read the cachefile correctly"
58
+
59
+ after :each do
60
+ File.unlink CACHE_FILE if File.exist? CACHE_FILE
61
+ end
62
+
63
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+
4
+ require 'simplecov'
5
+ SimpleCov.start
6
+
7
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
8
+ $:.unshift(File.dirname(__FILE__) + '/../ext')
9
+ require 'geoipdb'
10
+
11
+ RSpec.configure do |config|
12
+ end
@@ -0,0 +1,8 @@
1
+ case RUBY_PLATFORM
2
+ when 'java'
3
+ require 'rake/javaextensiontask'
4
+ Rake::JavaExtensionTask.new('geoipdb')
5
+ else
6
+ require 'rake/extensiontask'
7
+ Rake::ExtensionTask.new('geoipdb')
8
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run the specs"
5
+ RSpec::Core::RakeTask.new do |t|
6
+ t.verbose = false
7
+ end
data/tasks/yard.rake ADDED
@@ -0,0 +1,5 @@
1
+ require 'yard'
2
+
3
+ YARD::Rake::YardocTask.new do |t|
4
+ t.files = ['lib/**/*.rb', 'README.rdoc']
5
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geoipdb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.5
5
+ prerelease:
6
+ platform: java
7
+ authors:
8
+ - Eugen Martin
9
+ - Martin Karlsch
10
+ - Thomas Hirsch
11
+ - Benedikt Böhm
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+ date: 2013-01-17 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: rake-compiler
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: !binary |-
24
+ MA==
25
+ none: false
26
+ requirement: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: !binary |-
31
+ MA==
32
+ none: false
33
+ prerelease: false
34
+ type: :development
35
+ description: Returns a GeoLocation and additional information for given IP. Reads Data from CSV-Files and uses internal binary caching.
36
+ email:
37
+ - eugeniusmartinus@googlemail.com
38
+ - martin.karlsch@madvertise.com
39
+ - thomas.hirsch@madvertise.com
40
+ - benedikt.boehm@madvertise.com
41
+ executables: []
42
+ extensions: []
43
+ extra_rdoc_files: []
44
+ files:
45
+ - ".document"
46
+ - ".gitignore"
47
+ - ".jrubyrc"
48
+ - ".rspec"
49
+ - ".rvmrc"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.markdown
53
+ - Rakefile
54
+ - ext/geoipdb/extconf.rb
55
+ - ext/geoipdb/geoipdb.c
56
+ - ext/geoipdb/ipdb.c
57
+ - ext/geoipdb/ipdb.h
58
+ - ext/geoipdb/src/City.java
59
+ - ext/geoipdb/src/CsvReader.java
60
+ - ext/geoipdb/src/GeoIpDb.java
61
+ - ext/geoipdb/src/IpRange.java
62
+ - geoipdb.gemspec
63
+ - lib/geoipdb.jar
64
+ - lib/geoipdb.rb
65
+ - lib/ip_information.rb
66
+ - lib/jgeoipdb.rb
67
+ - sample_data/cities.csv
68
+ - sample_data/citiess_corrupt.csv
69
+ - sample_data/ip_ranges.csv
70
+ - sample_data/ip_ranges_corrupt.csv
71
+ - spec/geoipdb_spec.rb
72
+ - spec/spec_helper.rb
73
+ - tasks/compile.rake
74
+ - tasks/rspec.rake
75
+ - tasks/yard.rake
76
+ homepage: http://github.com/madvertise/geoipdb
77
+ licenses:
78
+ - MIT
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ - ext
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ version: !binary |-
91
+ MA==
92
+ hash: 2
93
+ none: false
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: !binary |-
99
+ MA==
100
+ none: false
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.24
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Fast (>3 Mio queries/sec!!!) GeoIpDb implementation for Ruby using C-Extensions.
107
+ test_files:
108
+ - spec/geoipdb_spec.rb
109
+ - spec/spec_helper.rb
110
+ has_rdoc: