只是想知道是否有人使用货币兑换红宝石宝石从外部api获得汇率并且实际上有效。我尝试了以下宝石,但未能使它们中的任何一个按照描述运行:
goog_currency,yahoo_currency,google_currency,yahoo_finance_currency
其中一个使用已弃用的代码,因此无法正常工作。
我只是想在铁路视图中显示货币汇率,这是从外部API中获取的。
我还考虑过试图从yahoo / google财务网址解析json,但这似乎比应该更难做。
答案 0 :(得分:6)
我从您的列表中选择google_currency
作为最受欢迎的,并且最近一直在维护。它对我来说很好,我从概要中运行代码没有问题。
如果您看到了消息:
You are using an old or stdlib version of json gem
Please upgrade to the recent version by adding this to your Gemfile:
gem 'json', '~> 1.7.7'
然后,您可能需要更新multi_json
的副本以避免json弃用警告:
gem install json
gem install multi_json
应该(在编写本文时)安装json 1.8.0和multi_json 1.7.8。或者当然,如果这是针对项目的,那么您应该能够在Gemfile
中选择这些版本,前提是项目中的其他库没有冲突。该消息可能会引起您的关注,但google_currency
不是问题。
我没有注意到google_currency
gem的任何冲突或问题,使用了已弃用的JSON模块或最新的模块。做一些类似于你想要的事情:
require 'money'
require 'money/bank/google_currency'
bank = Money::Bank::GoogleCurrency.new
bank.get_rate(:GBP, :USD).to_f
=> 1.5513