我试图在我的应用程序中获得github repo以下
https://github.com/mtodd/geoip
我试过像
那样添加它gem "geoip", :git => "git://github.com/mtodd/geoip.git"
错误=
Could not find gem 'geoip (>= 0) ruby' in git://github.com/mtodd/geoip.git (at master).
Source does not contain any versions of 'geoip (>= 0) ruby'
GeoIP是否有与最新GEOIP兼容的红宝石宝石包装? 我已经搜索了很长的一个,上面的一个似乎与1.4.7及更高版本兼容,但我无法安装它,任何其他建议?谢谢!
答案 0 :(得分:2)
我在我的Gemfile中有这个:
gem "geoip-c", '~> 0.7.1', :git => "git://github.com/mtodd/geoip.git"
据我所知,它完全兼容。
答案 1 :(得分:1)
我知道这是几年前发布的,但我最近很难找到一个好的最新宝石。我发现的是Geoip2 by YotpoLtd。
在我的Gemfile中
gem 'geoip2'
<强>设置/配置强>
Geoip2.configure do |conf|
# Mandatory
conf.license_key = 'Your MaxMind License Key'
conf.user_id = 'Your MaxMind User Id'
# Optional
conf.host = 'geoip.maxmind.com' # Or any host that you would like to work with
conf.base_path = '/geoip/v2.0' # Or any other version of this API
conf.parallel_requests = 5 # Or any other amount of parallel requests that you would like to use
end
是强>
data = Geoip2.omni('0.0.0.0') #this call is synchronous
*注意:我相信你可以取代&#39; omni&#39;与产品层的名称:城市,国家等
<强>错误强> 如果存在错误,则返回的散列将具有错误对象,因此只需检查其是否存在
if data.error
# error handling
else #still might want to check for data's existence ( if data )
#access object as you will
data.city.names.en
data.postal.code
end
有关返回的哈希的详细信息,请参阅MaxMind Web Services Documentation