Class: ExchangerFixer
- Inherits:
-
ExchangerBase
- Object
- ExchangerBase
- ExchangerFixer
- Defined in:
- lib/mrpin/core/currency_exchanger/fixer/exchanger_fixer.rb
Instance Method Summary collapse
- #get_rate(from_currency, to_currency) ⇒ Object
-
#initialize ⇒ ExchangerFixer
constructor
A new instance of ExchangerFixer.
Constructor Details
#initialize ⇒ ExchangerFixer
Returns a new instance of ExchangerFixer.
13 14 15 16 17 |
# File 'lib/mrpin/core/currency_exchanger/fixer/exchanger_fixer.rb', line 13 def initialize super @exchanger_api = ManagerRemoteHttp.new(url: 'http://api.fixer.io') end |
Instance Method Details
#get_rate(from_currency, to_currency) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mrpin/core/currency_exchanger/fixer/exchanger_fixer.rb', line 21 def get_rate(from_currency, to_currency) result = nil params = { base: from_currency, symbols: to_currency } response = @exchanger_api.get('latest', params) assert(response[:status] == EResponseType::ERT_OK, response) response_exchanger = JSON.parse response[:response], {symbolize_names: true} rates = response_exchanger.assert_property!(:rates) #not all currencies supported by fixer.io. So we need check them. if rates.has_key?(to_currency.to_sym) rate_string = rates[to_currency.to_sym] result = rate_string.to_f end result end |