10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/atech/foreign_currency/cacher.rb', line 10
def get
url = "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"
uri = URI.parse(url)
data = Net::HTTP.start(uri.host, uri.port) {|http| http.get(uri.path) }.body
gbp = get_rate_from_string(data, 'GBP')
eur = 1 / gbp
usd = get_rate_from_string(data, 'USD')
usd = usd / gbp
cache_file = File.expand_path(ForeignCurrency.cache_file)
File.open(cache_file, 'w') { |f| f.write({:eur => eur, :usd => usd}.to_yaml)}
end
|