geoip2
geoip2 copied to clipboard
Does not work with hashie 2.1.0+
Running rake when hashie 2.1.1 is installed there are many failures which all look like this:
Failure/Error: @response = Geoip2.country('62.219.147.28') TypeError: superclass mismatch for class Rash # ./lib/geoip2/client.rb:79:in `block in connection' # ./lib/geoip2/client.rb:74:in `connection' # ./lib/geoip2/client.rb:39:in `block in get' # ./lib/geoip2/client.rb:67:in `call' # ./lib/geoip2/client.rb:67:in `block in preform' # ./lib/geoip2/client.rb:66:in `preform' # ./lib/geoip2/client.rb:38:in `get' # ./lib/geoip2/api/country.rb:5:in `country' # ./lib/geoip2.rb:65:in `method_missing' # ./spec/api/country_spec.rb:7:in `block (4 levels) in' # ./spec/api/country_spec.rb:6:in `block (3 levels) in '
Hashie 2.1.1 defines Rash which is different from rash's Rash.
@p-originate Thanks I'll check it... didn't see it until now.
Looks like it's working please tell me if you still have an issue?
ruby-2.1.1/bin/ruby -S rspec ./spec/api/country_spec.rb ./spec/geoip2_spec.rb
[Coveralls] Set up the SimpleCov formatter.
[Coveralls] Using SimpleCov's default settings.
You are using WebMock 1.15.0. VCR is known to work with WebMock >= 1.8.0, < 1.14. It may not work with this version.
..........
Finished in 0.0358 seconds
10 examples, 0 failures
Randomized with seed 20449
Using hashie (3.3.1) + rash (0.2.0) + rails (4.1.4) + ruby (2.1.2p95)
Geoip2.country('70.112.225.219')
TypeError: superclass mismatch for class Rash
from /home/funkdified/.rvm/gems/[email protected]/gems/rash-0.2.0/lib/rash.rb:5:in `<module:Hashie>'
Any update on this issue?
In the meantime I have a workaround for others
https://gist.github.com/funkdified/4a9ea5aada528489e60e
module GeoHelper
def maxmind_locate
uri = URI("https://geoip.maxmind.com/geoip/v2.1/city/#{request.remote_ip}?pretty")
Net::HTTP.start(uri.host, uri.port,
:use_ssl => uri.scheme == 'https',
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
request = Net::HTTP::Get.new uri.request_uri
#Key from https://www.maxmind.com/en/my_license_key
request.basic_auth 'USER_ID', 'USER_KEY'
response = http.request request # Net::HTTPResponse object
if response.kind_of? Net::HTTPSuccess
location_hash = JSON.parse(response.body)
end
end
end
end
@p-originate, @abrambailey Sorry for the long response (didn't notice that there are updates here) We don't use Rash in our gem... The Rash gem seems to be deprecated and have moved into the Hashie project. So if you will update hashie to a greater version you will not have this issue.