2017-12-31 17:44:08 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-03 15:48:30 +02:00
|
|
|
require 'day'
|
2018-03-08 02:05:19 +01:00
|
|
|
require 'bank/feed'
|
2017-12-31 17:44:08 +01:00
|
|
|
|
|
|
|
module Bank
|
2018-10-03 15:48:30 +02:00
|
|
|
class << self
|
|
|
|
def fetch_all!
|
|
|
|
data = Feed.historical.to_a
|
|
|
|
jsonify!(data)
|
|
|
|
Day.dataset.insert_conflict.multi_insert(data)
|
|
|
|
end
|
2017-12-31 17:44:08 +01:00
|
|
|
|
2018-10-03 15:48:30 +02:00
|
|
|
def fetch_ninety_days!
|
|
|
|
data = Feed.ninety_days.to_a
|
|
|
|
jsonify!(data)
|
|
|
|
Day.dataset.insert_conflict.multi_insert(data)
|
|
|
|
end
|
2018-06-06 17:30:18 +02:00
|
|
|
|
2018-10-03 15:48:30 +02:00
|
|
|
def fetch_current!
|
|
|
|
data = Feed.current.to_a
|
|
|
|
jsonify!(data)
|
|
|
|
Day.find_or_create(data.first)
|
2017-12-31 17:44:08 +01:00
|
|
|
end
|
2018-03-22 09:49:32 +01:00
|
|
|
|
2018-10-03 15:48:30 +02:00
|
|
|
def replace_all!
|
|
|
|
data = Feed.historical.to_a
|
|
|
|
jsonify!(data)
|
|
|
|
Day.dataset.delete
|
|
|
|
Day.multi_insert(data)
|
|
|
|
end
|
|
|
|
|
2020-04-02 15:38:07 +02:00
|
|
|
def seed_with_saved_data!
|
|
|
|
data = Feed.saved_data.to_a
|
|
|
|
jsonify!(data)
|
|
|
|
Day.dataset.delete
|
|
|
|
Day.multi_insert(data)
|
|
|
|
end
|
|
|
|
|
2018-10-03 15:48:30 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def jsonify!(data)
|
|
|
|
data.each do |day|
|
|
|
|
day[:rates] = Sequel.pg_jsonb(day[:rates])
|
|
|
|
end
|
|
|
|
end
|
2018-03-22 09:49:32 +01:00
|
|
|
end
|
2017-12-31 17:44:08 +01:00
|
|
|
end
|