Class: ExchangerYahoo1
- Inherits:
-
ExchangerBase
- Object
- ExchangerBase
- ExchangerYahoo1
- Defined in:
- lib/mrpin/core/currency_exchanger/yahoo/exchanger_yahoo1.rb
Instance Method Summary collapse
- #get_rate(from_currency, to_currency) ⇒ Object
-
#initialize ⇒ ExchangerYahoo1
constructor
A new instance of ExchangerYahoo1.
Constructor Details
#initialize ⇒ ExchangerYahoo1
Returns a new instance of ExchangerYahoo1.
6 7 8 9 10 |
# File 'lib/mrpin/core/currency_exchanger/yahoo/exchanger_yahoo1.rb', line 6 def initialize super @exchanger_api = ManagerRemoteHttp.new(url: 'http://query.yahooapis.com') end |
Instance Method Details
#get_rate(from_currency, to_currency) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mrpin/core/currency_exchanger/yahoo/exchanger_yahoo1.rb', line 14 def get_rate(from_currency, to_currency) params = { q: "select * from yahoo.finance.xchange where pair in ('#{from_currency}#{to_currency}')", format: 'json', env: 'store://datatables.org/alltableswithkeys', callback: nil } response = @exchanger_api.get('v1/public/yql', params) assert(response[:status] == EResponseType::ERT_OK, response) response_exchanger = JSON.parse response[:response], {symbolize_names: true} rate_string = response_exchanger.assert_property!(:query).assert_property!(:results).assert_property!(:rate).assert_property!(:Rate) rate_string.to_f end |