cjheath/geoip

Doesn't work with ruby 1.9

adamsalter opened this issue · 5 comments

I was able to get this working by just changing every instance of 'getc' with 'getc.ord', but then of course it won't work with 1.8 any more (needs a detection).

I also had to make another small change but can't find it any more :/

Fixed (I think) in the latest commit. Yet to be confirmed as working with 1.9 however.

Yeah sorry can't confirm as I had a couple too many problems with 1.9 and moved back.

sorry it's taken a while to get back to you...

OK... so I had several issues which may or may not be ruby 1.9 related...

First on my local machine, all the lines:

ip = IPSocket.getaddress(hostname)

were returning a IPv6 address "::1", so I had to add the following:

ip = '0.0.0.0' if ip == '::1'

and second it crashed on line 582 with 'can't convert string to integer, CountryCode[code]', because it needed the following on line 544:

code = record[0].ord

I still haven't done a comprehensive testing, but it seems to work... hopefully you can see better what else might be outstanding... the main issues are reading chars as char codes. You can call #ord on an integer so the above fix should work for ruby 1.9 and 1.8.

I got the following when I ran the tests (which passed):

(in /Users/adam/dev/web/answer-my-office/vendor/gems/geoip-0.8.1)
Hoe.new {...} deprecated. Switch to Hoe.spec.
/opt/local/bin/ruby1.9 -w -Ilib:ext:bin:test -e 'require "rubygems"; require "test/unit"; require "test/test_geoip.rb"; require "test/test_helper.rb"'
/opt/local/lib/ruby1.9/1.9.1/test/unit/assertions.rb:31: warning: shadowing outer local variable - line
Loaded suite -e
Started
.
Finished in 0.000546 seconds.

1 tests, 1 assertions, 0 failures, 0 errors, 0 skips

Is this still an issue?

I haven't had a problem using this in 1.9.2 so far. I'm using .country and .city just fine. Disclaimer: I haven't used any other methods and don't plan on it so far.