trifle 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+
3
+ branches:
4
+ only:
5
+ - master
6
+
7
+ rvm:
8
+ - 1.9.2
9
+ - 1.9.3
10
+
11
+ notifications:
12
+ email:
13
+ - cristiano@emberads.com
14
+
data/Gemfile CHANGED
@@ -3,4 +3,8 @@ source :rubygems
3
3
  # Specify your gem's dependencies in messages.gemspec
4
4
  gemspec
5
5
 
6
- gem "fakeredis", github: "caius/fakeredis", branch: "redis-rb-3"
6
+ gem "fakeredis", github: "caius/fakeredis", branch: "redis-rb-3"
7
+
8
+ group :test do
9
+ gem "rake"
10
+ end
data/Gemfile.lock CHANGED
@@ -9,7 +9,7 @@ GIT
9
9
  PATH
10
10
  remote: .
11
11
  specs:
12
- trifle (0.0.7)
12
+ trifle (0.0.8)
13
13
  redis
14
14
 
15
15
  GEM
@@ -19,6 +19,7 @@ GEM
19
19
  activesupport (= 3.0.0)
20
20
  activesupport (3.0.0)
21
21
  diff-lcs (1.1.3)
22
+ rake (0.9.2.2)
22
23
  redis (3.0.1)
23
24
  rspec (2.10.0)
24
25
  rspec-core (~> 2.10.0)
@@ -35,5 +36,6 @@ PLATFORMS
35
36
  DEPENDENCIES
36
37
  active_support
37
38
  fakeredis!
39
+ rake
38
40
  rspec
39
41
  trifle!
data/README.md CHANGED
@@ -1,11 +1,17 @@
1
1
  # Trifle
2
2
 
3
+ ![Build status](https://secure.travis-ci.org/EmberAds/trifle.png?branch=master)
4
+
3
5
  Stores the GeoIP databases in Redis and gives it a simple way to lookup IPs and map them to countries/country codes.
4
6
 
5
7
  Get your GeoIP country CSVs from http://www.maxmind.com/app/geolite.
6
8
 
7
9
  Trifle supports both the IPV4 and IPV6 databases.
8
10
 
11
+ ## Why?
12
+
13
+ Loading the GeoIP databases from disk is slow, and doing that for every request is a pain. Trifle keeps your GeoIP database in memory and makes it easy to query.
14
+
9
15
  ## Installation
10
16
 
11
17
  Install the gem
@@ -62,9 +68,9 @@ trifle.find "192.168.1.1"
62
68
  # => nil
63
69
  ```
64
70
 
65
-
66
71
  ## Release notes
67
72
 
73
+ * **0.0.8** Fixed a search bug that created conflicts between IPv4 and IPv6 data
68
74
  * **0.0.7** Loading now happens into separate key, making loading possible without downtime
69
75
  * **0.0.6** Added a fix for invalid IPs
70
76
  * **0.0.5** Fixed bug when finding IPs at the edge of the data set
@@ -73,6 +79,11 @@ trifle.find "192.168.1.1"
73
79
  * **0.0.2** Added support for custom Redis key
74
80
  * **0.0.1** First draft
75
81
 
82
+ ## Future releases
83
+
84
+ * Allow for loading of more data than just country data
85
+ * Split country data into separate Redis records
86
+
76
87
  ## License
77
88
 
78
89
  See LICENSE
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Set up and run tests"
4
+ task :default => [:test]
5
+
6
+ desc "Run tests"
7
+ task :test do
8
+ sh "bundle exec rspec spec"
9
+ end
data/lib/trifle/finder.rb CHANGED
@@ -15,14 +15,13 @@ class Trifle
15
15
  protected
16
16
 
17
17
  def find ip_i, lower, upper
18
- return nil if lower >= upper
19
-
20
18
  index = (lower+upper)/2
21
-
22
19
  current = entry_for(index)
23
20
 
24
21
  if in_range(current, ip_i)
25
22
  current.last(2)
23
+ elsif lower >= upper
24
+ nil
26
25
  elsif ip_i < current[0]
27
26
  find ip_i, lower, index-1
28
27
  else
@@ -31,7 +30,7 @@ class Trifle
31
30
  end
32
31
 
33
32
  def max
34
- redis.llen(key)
33
+ redis.llen(key)-1
35
34
  end
36
35
 
37
36
  def entry_for index
@@ -1,3 +1,3 @@
1
1
  class Trifle
2
- VERSION = "0.0.7" unless defined? Trifle::VERSION
2
+ VERSION = "0.0.8" unless defined? Trifle::VERSION
3
3
  end
@@ -14,7 +14,16 @@ describe Trifle::Finder do
14
14
  ["223.255.248.0","223.255.251.255","3758094336","3758095359","AU","Australia"],
15
15
  ["223.255.252.0","223.255.253.255","3758095360","3758095871","CN","China"],
16
16
  ["223.255.254.0","223.255.254.255","3758095872","3758096127","SG","Singapore"],
17
- ["223.255.255.0","223.255.255.255","3758096128","3758096383","AU","Australia"]
17
+ ["223.255.255.0","223.255.255.255","3758096128","3758096383","AU","Australia"],
18
+ ["2407:7800::", "2407:7800:ffff:ffff:ffff:ffff:ffff:ffff", "47890987815419153418387641314551267328", "47890987894647315932651978908095217663", "AU", "Australia"],
19
+ ["2407:8400::", "2407:8400:ffff:ffff:ffff:ffff:ffff:ffff", "47891231204334397238432728681566699520", "47891231283562559752697066275110649855", "AU", "Australia"],
20
+ ["2407:8600::", "2407:8600:ffff:ffff:ffff:ffff:ffff:ffff", "47891271769153604541773576576069271552", "47891271848381767056037914169613221887", "AU", "Australia"],
21
+ ["2407:8800::", "2407:8800:ffff:ffff:ffff:ffff:ffff:ffff", "47891312333972811845114424470571843584", "47891312413200974359378762064115793919", "IN", "India"],
22
+ ["2407:8e00::", "2407:8e00:ffff:ffff:ffff:ffff:ffff:ffff", "47891434028430433755136968154079559680", "47891434107658596269401305747623510015", "AU", "Australia"],
23
+ ["2407:9000::", "2407:9000:ffff:ffff:ffff:ffff:ffff:ffff", "47891474593249641058477816048582131712", "47891474672477803572742153642126082047", "AU", "Australia"],
24
+ ["2407:a200::", "2407:a200:ffff:ffff:ffff:ffff:ffff:ffff", "47891839676622506788545447099105280000", "47891839755850669302809784692649230335", "AU", "Australia"],
25
+ ["2407:aa00::", "2407:aa00:ffff:ffff:ffff:ffff:ffff:ffff", "47892001935899336001908838677115568128", "47892002015127498516173176270659518463", "AU", "Australia"],
26
+ ["2407:ae00::", "2407:ae00:ffff:ffff:ffff:ffff:ffff:ffff", "47892083065537750608590534466120712192", "47892083144765913122854872059664662527", "AU", "Australia"],
18
27
  ]
19
28
  @redis = Redis.new
20
29
  @trifle = Trifle.new(@redis)
@@ -27,6 +36,8 @@ describe Trifle::Finder do
27
36
  @finder.handle("223.255.128.0").should be == ["HK", "Hong Kong"]
28
37
  @finder.handle("223.255.244.10").should be == ["IN", "India"]
29
38
  @finder.handle("223.255.255.255").should be == ["AU","Australia"]
39
+ @finder.handle("2407:8800:ffff:ffff:ffff:ffff:ffff:ffff").should be == ["IN","India"]
40
+ @finder.handle("2407:ae00:ffff:ffff:ffff:ffff:ffff:ffff").should be == ["AU","Australia"]
30
41
  end
31
42
 
32
43
  it "should return nil if the entry wasn't found" do
data/trifle.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Trifle::VERSION
8
8
  s.authors = ["Cristiano Betta"]
9
9
  s.email = ["cristiano@emberads.com"]
10
- s.homepage = "http://emberads.com"
10
+ s.homepage = "http://github.com/EmberAds/trifle"
11
11
  s.summary = "A GeoIP lookup in Redis"
12
12
  s.description = "Stores the GeoIP databases in Redis and gives it a simple way to lookup IPs and map them to countries"
13
13
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trifle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-22 00:00:00.000000000 Z
12
+ date: 2012-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70133403697660 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70133403697660
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: active_support
27
- requirement: &70133403697060 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70133403697060
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: fakeredis
38
- requirement: &70133403696340 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 0.3.0
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70133403696340
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.3.0
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: redis
49
- requirement: &70133403695580 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,7 +69,12 @@ dependencies:
54
69
  version: '0'
55
70
  type: :runtime
56
71
  prerelease: false
57
- version_requirements: *70133403695580
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  description: Stores the GeoIP databases in Redis and gives it a simple way to lookup
59
79
  IPs and map them to countries
60
80
  email:
@@ -66,6 +86,7 @@ extra_rdoc_files: []
66
86
  files:
67
87
  - .gitignore
68
88
  - .rspec
89
+ - .travis.yml
69
90
  - Gemfile
70
91
  - Gemfile.lock
71
92
  - LICENSE
@@ -83,7 +104,7 @@ files:
83
104
  - spec/trifle/loader_spec.rb
84
105
  - spec/trifle_spec.rb
85
106
  - trifle.gemspec
86
- homepage: http://emberads.com
107
+ homepage: http://github.com/EmberAds/trifle
87
108
  licenses: []
88
109
  post_install_message:
89
110
  rdoc_options: []
@@ -95,15 +116,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
116
  - - ! '>='
96
117
  - !ruby/object:Gem::Version
97
118
  version: '0'
119
+ segments:
120
+ - 0
121
+ hash: -2107613967180143252
98
122
  required_rubygems_version: !ruby/object:Gem::Requirement
99
123
  none: false
100
124
  requirements:
101
125
  - - ! '>='
102
126
  - !ruby/object:Gem::Version
103
127
  version: '0'
128
+ segments:
129
+ - 0
130
+ hash: -2107613967180143252
104
131
  requirements: []
105
132
  rubyforge_project: trifle
106
- rubygems_version: 1.8.10
133
+ rubygems_version: 1.8.24
107
134
  signing_key:
108
135
  specification_version: 3
109
136
  summary: A GeoIP lookup in Redis