Class: Ubea::CurrencyConverter::RateExchange
- Inherits:
-
Object
- Object
- Ubea::CurrencyConverter::RateExchange
- Defined in:
- lib/ubea/currency_converter.rb
Constant Summary collapse
- URL =
"http://rate-exchange.appspot.com/currency?from=%s&to=%s".freeze
Class Method Summary collapse
Class Method Details
.get_json(url) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/ubea/currency_converter.rb', line 50 def self.get_json(url) Retryable.retryable(tries: 3, sleep: 1) do json = open(url).read JSON.parse(json) end end |
.get_rate(from, to) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/ubea/currency_converter.rb', line 43 def self.get_rate(from, to) url = URL % [from, to] json = get_json(url) rate = json["rate"].to_s BigDecimal.new(rate) end |