Class: CcyConvertor::YahooFinance

Inherits:
RateProvider show all
Defined in:
lib/ccy_convertor/rate_providers/yahoo_finance.rb

Instance Attribute Summary

Attributes included from RateCache

#cache_duration

Class Method Summary collapse

Methods inherited from RateProvider

api_key_nil?, convert, rate_from_rate_matrix, rate_matrix_response, rate_provider_name, rate_response, response_hash

Methods included from RateCache

#cache, #cache_duration_nil?, #cache_key

Methods included from ProcessAndValidateOption

#validate_amount!, #validate_currency_codes!, #validate_currency_support!, #validate_options!, #validate_presence_of_hash_keys!

Class Method Details

.rate(from_ccy, to_ccy) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/ccy_convertor/rate_providers/yahoo_finance.rb', line 10

def rate(from_ccy, to_ccy)
  rate = rate_response(from_ccy, to_ccy)['query']['results']['rate']['Rate']
  if rate.nil? || rate == 'N/A'
    raise CcyConvertor::CurrencyNotSupported, "No rates available for #{from_ccy}/#{to_ccy}"
  end
  rate.to_f
end

.rest_url_for_rate(from_ccy, to_ccy) ⇒ Object



4
5
6
7
8
# File 'lib/ccy_convertor/rate_providers/yahoo_finance.rb', line 4

def rest_url_for_rate(from_ccy, to_ccy)
  'https://query.yahooapis.com/v1/public/yql?q='\
  "select%20%20Rate%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22#{to_ccy}#{from_ccy}%22)"\
  '&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys'
end