Class: Devilicious::CurrencyConverter::RateExchange

Inherits:
Object
  • Object
show all
Defined in:
lib/devilicious/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



46
47
48
49
50
51
# File 'lib/devilicious/currency_converter.rb', line 46

def self.get_json(url)
  retryable(tries: 3, sleep: 1) do
    json = open(url).read
    JSON.parse(json)
  end
end

.get_rate(from, to) ⇒ Object



39
40
41
42
43
44
# File 'lib/devilicious/currency_converter.rb', line 39

def self.get_rate(from, to)
  url = URL % [from, to]
  json = get_json(url)
  rate = json["rate"].to_s
  BigDecimal.new(rate)
end