geoip-extensions 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ *.orig
2
+ .*.swp
3
+ .*.swo
4
+ *.tmp
5
+ *.patch
6
+ *.kpf
7
+ *~
8
+ .DS_Store
9
+ Thumbs.db
10
+ Gemfile.lock
11
+ doc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2012 2167961 Ontario Inc., Zoocasa <code@zoocasa.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
data/README.rdoc ADDED
@@ -0,0 +1,14 @@
1
+
2
+ = GeoIP Extensions
3
+
4
+ A handful of GeoIP extensions. By "handful" we mean "one", at the moment:
5
+ integration with ffi-geos.
6
+
7
+ DB = GeoIP::City.new('/path/to/db.dat')
8
+ DB.look_up('24.24.24.24')
9
+ DB[:geom] # => contains a Geos::Point.
10
+
11
+ == License
12
+
13
+ See the MIT-LICENSE file for details.
14
+
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+
2
+ # -*- ruby -*-
3
+
4
+ require 'rubygems'
5
+
6
+ gem 'rdoc', '~> 3.12'
7
+
8
+ require 'rubygems/package_task'
9
+ require 'rake/testtask'
10
+ require 'rdoc/task'
11
+ require 'bundler/gem_tasks'
12
+
13
+ if RUBY_VERSION >= '1.9'
14
+ begin
15
+ gem 'psych'
16
+ rescue Exception => e
17
+ # it's okay, fall back on the bundled psych
18
+ end
19
+ end
20
+
21
+ $:.push 'lib'
22
+
23
+ version = GeoIP::Extensions::VERSION
24
+
25
+ desc 'Test GeoIP Extensions'
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.test_files = FileList['test/**/*_tests.rb']
28
+ t.verbose = !!ENV['VERBOSE_TESTS']
29
+ t.warning = !!ENV['WARNINGS']
30
+ end
31
+
32
+ desc 'Build docs'
33
+ Rake::RDocTask.new do |t|
34
+ t.main = 'README.rdoc'
35
+ t.title = "GeoIP Extensions #{version}"
36
+ t.rdoc_dir = 'doc'
37
+ t.rdoc_files.include('README.rdoc', 'MIT-LICENSE', 'lib/**/*.rb')
38
+ end
39
+
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/geoip/extensions/version', __FILE__)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "geoip-extensions"
7
+ s.version = GeoIP::Extensions::VERSION
8
+
9
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.authors = ["J Smith"]
11
+ s.description = "Extensions to the GeoIP library."
12
+ s.summary = s.description
13
+ s.email = "code@zoocasa.com"
14
+ s.extra_rdoc_files = [
15
+ "README.rdoc"
16
+ ]
17
+ s.files = `git ls-files`.split($\)
18
+ s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
19
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
+ s.homepage = "https://git.i.internal/ruby/geoip-extensions"
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_dependency("geoip-c")
24
+ s.add_dependency("ffi-geos")
25
+ s.add_dependency("rdoc")
26
+ s.add_dependency("rake", ["~> 0.9"])
27
+ s.add_dependency("minitest")
28
+ s.add_dependency("turn")
29
+ end
@@ -0,0 +1,6 @@
1
+
2
+ require 'geoip'
3
+ require 'geoip/extensions'
4
+
5
+ module GeoIP
6
+ end
@@ -0,0 +1,7 @@
1
+
2
+ require 'geoip/extensions/geos'
3
+
4
+ module GeoIP
5
+ module Extensions
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+
2
+ require 'ffi-geos'
3
+
4
+ module GeoIP
5
+ module Extensions
6
+ module Geos
7
+ def self.included(base)
8
+ base.class_eval do
9
+ alias :look_up_without_geos :look_up
10
+ alias :look_up :look_up_with_geos
11
+ end
12
+ end
13
+
14
+ def look_up_with_geos(*args)
15
+ look_up_without_geos(*args).tap do |ret|
16
+ if ret && ret[:latitude] && ret[:longitude]
17
+ ret[:geom] = ::Geos.create_point(::Geos::CoordinateSequence.new([ ret[:longitude], ret[:latitude] ]))
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ class GeoIP::City
26
+ include GeoIP::Extensions::Geos
27
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module GeoIP
3
+ module Extensions
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: UTF-8
2
+
3
+ $: << File.dirname(__FILE__)
4
+ require 'test_helper'
5
+
6
+ class GeosTests < MiniTest::Unit::TestCase
7
+ include TestHelper
8
+
9
+ def test_geos
10
+ city = CITY_DB.look_up('24.24.24.24')
11
+
12
+ if city && city[:latitude] && city[:longitude]
13
+ assert(city[:geom])
14
+ else
15
+ skip("Couldn't find a location in this GeoIP database for 24.24.24.24.")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rubygems'
4
+ require 'minitest/autorun'
5
+ require 'turn/autorun'
6
+ require File.join(File.dirname(__FILE__), %w{ .. lib geoip-extensions })
7
+
8
+ module TestHelper
9
+ CITY_DB = begin
10
+ GeoIP::City.new(ENV['GEOIP_DB'])
11
+ rescue
12
+ raise "You must supply a path to a GeoIP database using the GEOIP_DB environment variable."
13
+ end
14
+ end
15
+
16
+ if ENV['autotest']
17
+ module Turn::Colorize
18
+ def self.color_supported?
19
+ true
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geoip-extensions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - J Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: geoip-c
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: ffi-geos
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '0.9'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.9'
78
+ - !ruby/object:Gem::Dependency
79
+ name: minitest
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: turn
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Extensions to the GeoIP library.
111
+ email: code@zoocasa.com
112
+ executables: []
113
+ extensions: []
114
+ extra_rdoc_files:
115
+ - README.rdoc
116
+ files:
117
+ - .gitignore
118
+ - Gemfile
119
+ - MIT-LICENSE
120
+ - README.rdoc
121
+ - Rakefile
122
+ - geoip-extensions.gemspec
123
+ - lib/geoip-extensions.rb
124
+ - lib/geoip/extensions.rb
125
+ - lib/geoip/extensions/geos.rb
126
+ - lib/geoip/extensions/version.rb
127
+ - test/geos_tests.rb
128
+ - test/test_helper.rb
129
+ homepage: https://git.i.internal/ruby/geoip-extensions
130
+ licenses: []
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 1.8.23
150
+ signing_key:
151
+ specification_version: 3
152
+ summary: Extensions to the GeoIP library.
153
+ test_files:
154
+ - test/geos_tests.rb
155
+ - test/test_helper.rb