mtodd-geoip 0.5.4 → 0.5.5

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.
Files changed (4) hide show
  1. data/Rakefile +1 -1
  2. data/geoip.c +11 -0
  3. data/test.rb +33 -8
  4. metadata +1 -1
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ end
22
22
 
23
23
  spec = Gem::Specification.new do |s|
24
24
  s.name = 'geoip'
25
- s.version = "0.5.4"
25
+ s.version = "0.5.5"
26
26
 
27
27
  s.authors = ['Ryah Dahl', 'Matt Todd', 'Charles Brian Quinn']
28
28
  s.email = 'mtodd@highgroove.com'
data/geoip.c CHANGED
@@ -181,6 +181,16 @@ VALUE rb_geoip_addr_to_num(VALUE self, VALUE addr) {
181
181
  return UINT2NUM((unsigned long)_GeoIP_addr_to_num(STR2CSTR(addr)));
182
182
  }
183
183
 
184
+ VALUE rb_geoip_num_to_addr(VALUE self, VALUE num) {
185
+ VALUE num_type = TYPE(num);
186
+ switch(num_type) {
187
+ case T_FIXNUM: break;
188
+ case T_BIGNUM: break;
189
+ default: rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or Bignum)", rb_obj_classname(num));
190
+ }
191
+ return rb_str_new2((char*)_GeoIP_num_to_addr(NULL, (unsigned long)NUM2UINT(num)));
192
+ }
193
+
184
194
  void Init_geoip()
185
195
  {
186
196
  mGeoIP = rb_define_module("GeoIP");
@@ -198,4 +208,5 @@ void Init_geoip()
198
208
  rb_define_method( mGeoIP_Organization, "look_up", rb_geoip_org_look_up, 1);
199
209
 
200
210
  rb_define_singleton_method(mGeoIP, "addr_to_num", rb_geoip_addr_to_num, 1);
211
+ rb_define_singleton_method(mGeoIP, "num_to_addr", rb_geoip_num_to_addr, 1);
201
212
  }
data/test.rb CHANGED
@@ -16,16 +16,22 @@ end
16
16
 
17
17
  class GeoIPTest < Test::Unit::TestCase
18
18
 
19
+ def setup
20
+ @ip = "24.24.24.24"
21
+ @ipnum = 16777216*24 + 65536*24 + 256*24 + 24
22
+
23
+ @large_ip = "245.245.245.245"
24
+ @large_ipnum = 16777216*245 + 65536*245 + 256*245 + 245
25
+ end
26
+
27
+ # addr_to_num
28
+
19
29
  def test_addr_to_num_converts_an_ip_to_an_ipnum
20
- ip = "24.24.24.24"
21
- ipnum = 16777216*24 + 65536*24 + 256*24 + 24
22
- assert_equal ipnum, GeoIP.addr_to_num(ip)
30
+ assert_equal @ipnum, GeoIP.addr_to_num(@ip)
23
31
  end
24
32
 
25
33
  def test_addr_to_num_converts_large_ips_to_an_ipnum_correctly
26
- ip = "245.245.245.245"
27
- ipnum = 16777216*245 + 65536*245 + 256*245 + 245
28
- assert_equal ipnum, GeoIP.addr_to_num(ip)
34
+ assert_equal @large_ipnum, GeoIP.addr_to_num(@large_ip)
29
35
  end
30
36
 
31
37
  def test_addr_to_num_expects_an_ip_string
@@ -38,13 +44,32 @@ class GeoIPTest < Test::Unit::TestCase
38
44
  assert_equal 0, GeoIP.addr_to_num("foo.bar")
39
45
  end
40
46
 
47
+ # num_to_addr
48
+
49
+ def test_num_to_addr_converts_an_ipnum_to_an_ip
50
+ assert_equal @ip, GeoIP.num_to_addr(@ipnum)
51
+ end
52
+
53
+ def test_num_to_addr_converts_large_ipnums_to_an_ip_correctly
54
+ assert_equal @large_ip, GeoIP.num_to_addr(@large_ipnum)
55
+ end
56
+
57
+ def test_num_to_addr_expects_a_numeric_ip
58
+ assert_raises TypeError do
59
+ GeoIP.num_to_addr(nil)
60
+ end
61
+ assert_raises TypeError do
62
+ GeoIP.num_to_addr("foo.bar")
63
+ end
64
+ end
65
+
41
66
  end
42
67
 
43
68
  class GeoIPCityTest < Test::Unit::TestCase
44
69
 
45
70
  def setup
46
71
  ## Change me!
47
- @dbfile = '/opt/GeoIP/share/GeoIP/GeoLiteCity.dat'
72
+ @dbfile = '/usr/local/GeoIP/share/GeoIP/GeoLiteCity.dat'
48
73
  end
49
74
 
50
75
  def test_construction_default
@@ -93,7 +118,7 @@ class GeoIPOrgTest < Test::Unit::TestCase
93
118
 
94
119
  def setup
95
120
  ## Change me!
96
- @dbfile = '/opt/GeoIP/share/GeoIP/GeoIPOrg.dat'
121
+ @dbfile = '/usr/local/GeoIP/share/GeoIP/GeoIPOrg.dat'
97
122
  end
98
123
 
99
124
  def test_construction_default
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtodd-geoip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Dahl