ffi-geoip 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.travis.yml +14 -0
- data/Gemfile +25 -0
- data/Guardfile +17 -0
- data/MIT-LICENSE +22 -0
- data/README.rdoc +22 -0
- data/Rakefile +29 -0
- data/ffi-geoip.gemspec +26 -0
- data/lib/ffi-geoip.rb +470 -0
- data/lib/ffi-geoip/base.rb +68 -0
- data/lib/ffi-geoip/city.rb +26 -0
- data/lib/ffi-geoip/country.rb +24 -0
- data/lib/ffi-geoip/isp.rb +20 -0
- data/lib/ffi-geoip/organization.rb +20 -0
- data/lib/ffi-geoip/record.rb +53 -0
- data/lib/ffi-geoip/tools.rb +26 -0
- data/lib/ffi-geoip/version.rb +6 -0
- data/test/city_tests.rb +77 -0
- data/test/country_tests.rb +51 -0
- data/test/geoip_tests.rb +50 -0
- data/test/isp_tests.rb +54 -0
- data/test/organization_tests.rb +61 -0
- data/test/test_helper.rb +53 -0
- metadata +107 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
$: << File.dirname(__FILE__)
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class GeoIPOrganizationTest < MiniTest::Test
|
7
|
+
ORGANIZATION = {
|
8
|
+
:name => "AT&T Worldnet Services"
|
9
|
+
}
|
10
|
+
|
11
|
+
ORGANIZATION_IP = '12.87.118.0'
|
12
|
+
|
13
|
+
def assert_look_up(db, expected = ORGANIZATION, lookup = ORGANIZATION_IP)
|
14
|
+
hash = db.look_up(lookup)
|
15
|
+
assert_kind_of(Hash, hash)
|
16
|
+
assert_equal(expected, hash)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_construction_default
|
20
|
+
db = GeoIP::ISP.new(ISP_DB)
|
21
|
+
assert_raises_type_error(db)
|
22
|
+
assert_look_up(db)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_construction_default
|
26
|
+
db = GeoIP::Organization.new(ORG_DB)
|
27
|
+
assert_raises_type_error(db)
|
28
|
+
assert_look_up(db)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_construction_index
|
32
|
+
db = GeoIP::Organization.new(ORG_DB, :index)
|
33
|
+
assert_raises_type_error(db)
|
34
|
+
assert_look_up(db)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_construction_filesystem
|
38
|
+
db = GeoIP::Organization.new(ORG_DB, :filesystem)
|
39
|
+
assert_raises_type_error(db)
|
40
|
+
assert_look_up(db)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_construction_memory
|
44
|
+
db = GeoIP::Organization.new(ORG_DB, :memory)
|
45
|
+
assert_raises_type_error(db)
|
46
|
+
assert_look_up(db)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_construction_filesystem_check
|
50
|
+
db = GeoIP::Organization.new(ORG_DB, :filesystem, true)
|
51
|
+
assert_raises_type_error(db)
|
52
|
+
assert_look_up(db)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_bad_db_file
|
56
|
+
assert_raises(Errno::ENOENT) do
|
57
|
+
GeoIP::Organization.new('/supposed-to-fail')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
if RUBY_VERSION >= '1.9'
|
4
|
+
require 'simplecov'
|
5
|
+
|
6
|
+
SimpleCov.command_name('Unit Tests')
|
7
|
+
SimpleCov.merge_timeout(3600)
|
8
|
+
SimpleCov.start do
|
9
|
+
add_filter '/test/'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'minitest/autorun'
|
15
|
+
require 'minitest/reporters' if RUBY_VERSION >= '1.9'
|
16
|
+
|
17
|
+
if ENV['USE_BINARY']
|
18
|
+
Object.send(:remove_const, :GeoIP)
|
19
|
+
require 'geoip'
|
20
|
+
else
|
21
|
+
require File.join(File.dirname(__FILE__), %w{ .. lib ffi-geoip })
|
22
|
+
end
|
23
|
+
|
24
|
+
puts "Ruby version #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} - #{RbConfig::CONFIG['RUBY_INSTALL_NAME']}"
|
25
|
+
puts "ffi version #{Gem.loaded_specs['ffi'].version}" if Gem.loaded_specs['ffi']
|
26
|
+
puts "ffi-geoip version #{GeoIP::VERSION}" if defined?(GeoIP::VERSION)
|
27
|
+
puts "GeoIP version #{GeoIP.version}" if GeoIP.respond_to?(:version)
|
28
|
+
|
29
|
+
TEST_DIR = File.dirname(__FILE__)
|
30
|
+
DATA_DIR = File.join(TEST_DIR, 'data')
|
31
|
+
|
32
|
+
COUNTRY_DB = ENV.fetch('COUNTRY', File.join(DATA_DIR, 'GeoIP.dat'))
|
33
|
+
CITY_DB = ENV.fetch('CITY', File.join(DATA_DIR, 'GeoIPCity.dat'))
|
34
|
+
ISP_DB = ENV.fetch('ISP', File.join(DATA_DIR, 'GeoIPISP.dat'))
|
35
|
+
ORG_DB = ENV.fetch('ORG', File.join(DATA_DIR, 'GeoIPOrg.dat'))
|
36
|
+
|
37
|
+
if RUBY_VERSION >= '1.9'
|
38
|
+
MiniTest::Reporters.use!(MiniTest::Reporters::SpecReporter.new)
|
39
|
+
end
|
40
|
+
|
41
|
+
class Minitest::Test
|
42
|
+
def assert_look_up(db, addr, field, value)
|
43
|
+
h = db.look_up(addr)
|
44
|
+
assert_equal value, h[field]
|
45
|
+
h
|
46
|
+
end
|
47
|
+
|
48
|
+
def assert_raises_type_error(db)
|
49
|
+
assert_raises(TypeError) do
|
50
|
+
db.look_up(nil)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ffi-geoip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- J Smith
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
27
|
+
description: An ffi wrapper for GeoIP
|
28
|
+
email: dark.panda@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".travis.yml"
|
36
|
+
- Gemfile
|
37
|
+
- Guardfile
|
38
|
+
- MIT-LICENSE
|
39
|
+
- README.rdoc
|
40
|
+
- Rakefile
|
41
|
+
- ffi-geoip.gemspec
|
42
|
+
- lib/ffi-geoip.rb
|
43
|
+
- lib/ffi-geoip/base.rb
|
44
|
+
- lib/ffi-geoip/city.rb
|
45
|
+
- lib/ffi-geoip/country.rb
|
46
|
+
- lib/ffi-geoip/isp.rb
|
47
|
+
- lib/ffi-geoip/organization.rb
|
48
|
+
- lib/ffi-geoip/record.rb
|
49
|
+
- lib/ffi-geoip/tools.rb
|
50
|
+
- lib/ffi-geoip/version.rb
|
51
|
+
- test/city_tests.rb
|
52
|
+
- test/country_tests.rb
|
53
|
+
- test/data/GeoIP.dat
|
54
|
+
- test/data/GeoIPASNum.dat
|
55
|
+
- test/data/GeoIPCity.dat
|
56
|
+
- test/data/GeoIPDistance.dat
|
57
|
+
- test/data/GeoIPDomain.dat
|
58
|
+
- test/data/GeoIPISP.dat
|
59
|
+
- test/data/GeoIPNetSpeedCell.dat
|
60
|
+
- test/data/GeoIPOrg.dat
|
61
|
+
- test/data/GeoIPUserType.dat
|
62
|
+
- test/data/GeoLiteCityv6.dat
|
63
|
+
- test/geoip_tests.rb
|
64
|
+
- test/isp_tests.rb
|
65
|
+
- test/organization_tests.rb
|
66
|
+
- test/test_helper.rb
|
67
|
+
homepage: http://github.com/dark-panda/ffi-geoip
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.2.5
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: An ffi wrapper for GeoIP
|
91
|
+
test_files:
|
92
|
+
- test/city_tests.rb
|
93
|
+
- test/country_tests.rb
|
94
|
+
- test/data/GeoIP.dat
|
95
|
+
- test/data/GeoIPASNum.dat
|
96
|
+
- test/data/GeoIPCity.dat
|
97
|
+
- test/data/GeoIPDistance.dat
|
98
|
+
- test/data/GeoIPDomain.dat
|
99
|
+
- test/data/GeoIPISP.dat
|
100
|
+
- test/data/GeoIPNetSpeedCell.dat
|
101
|
+
- test/data/GeoIPOrg.dat
|
102
|
+
- test/data/GeoIPUserType.dat
|
103
|
+
- test/data/GeoLiteCityv6.dat
|
104
|
+
- test/geoip_tests.rb
|
105
|
+
- test/isp_tests.rb
|
106
|
+
- test/organization_tests.rb
|
107
|
+
- test/test_helper.rb
|