mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-22 11:02:30 +01:00
e5815737c1
- bumped gems - rm bots - rm pry byebug - added rubocop-shopify and corrected generated warnings
52 lines
1.1 KiB
Ruby
52 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "net/http"
|
|
require "ox"
|
|
|
|
module Bank
|
|
class Feed
|
|
include Enumerable
|
|
|
|
class << self
|
|
def current
|
|
url = URI("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml")
|
|
xml = Net::HTTP.get(url)
|
|
|
|
new(xml)
|
|
end
|
|
|
|
def ninety_days
|
|
url = URI("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml")
|
|
xml = Net::HTTP.get(url)
|
|
|
|
new(xml)
|
|
end
|
|
|
|
def historical
|
|
url = URI("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml")
|
|
xml = Net::HTTP.get(url)
|
|
|
|
new(xml)
|
|
end
|
|
|
|
def saved_data
|
|
xml = File.read(File.join(__dir__, "eurofxref-hist.xml"))
|
|
new(xml)
|
|
end
|
|
end
|
|
|
|
def initialize(xml)
|
|
@document = Ox.load(xml)
|
|
end
|
|
|
|
def each
|
|
@document.locate("gesmes:Envelope/Cube/Cube").each do |day|
|
|
yield(date: Date.parse(day["time"]),
|
|
rates: day.nodes.each_with_object({}) do |currency, rates|
|
|
rates[currency[:currency]] = Float(currency[:rate])
|
|
end)
|
|
end
|
|
end
|
|
end
|
|
end
|