3

私のアプリでgithubリポジトリを下回ろうとしています

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'

LATEST GEOIPと互換性のあるGeoIP用のrubygemラッパーはありますか? 私は非常に長い間検索しました。上記のものは1.4.7以降と互換性がないようですが、インストールできません。他の提案はありますか?どうも !

4

2 に答える 2

2

私はこれを私のGemfileに持っています:

gem "geoip-c", '~> 0.7.1', :git => "git://github.com/mtodd/geoip.git"

私の知る限り、それは完全に互換性があります。

于 2012-03-07T16:16:39.397 に答える
1

これが数年前に投稿されたことは知っていますが、最近、これに適した最新の宝石を見つけるのに苦労しました。私が見つけたのはYotpoLtdのGeoip2でした

私の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

*注:「omni」を製品階層の名前(都市、国など)に置き換えることができると思います

エラーエラー が発生した場合、返されるハッシュにはエラーオブジェクトが含まれるため、その存在を確認するだけです。

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

返されるハッシュの詳細については、MaxMindWebサービスのドキュメントを参照してください。

于 2014-05-09T20:27:29.190 に答える