mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-25 04:22:28 +01:00
Work around holidays
This commit is contained in:
parent
a52fadf715
commit
4a8993cdfb
14
lib/app.rb
14
lib/app.rb
@ -7,25 +7,23 @@ set :root, File.expand_path('..', File.dirname(__FILE__))
|
||||
|
||||
helpers do
|
||||
def redirect_to_api
|
||||
if request.host =~ /^f/
|
||||
redirect request.url.sub %r(://f), '://api.f'
|
||||
if request.url.include? 'https://f'
|
||||
redirect request.url.sub %r{//}, '//api.'
|
||||
end
|
||||
end
|
||||
|
||||
# Ugly as fuck.
|
||||
def snapshot
|
||||
symbols = params.delete('symbols') || params.delete('currencies')
|
||||
|
||||
quote = Snapshot
|
||||
quotes = Snapshot
|
||||
.new(params)
|
||||
.quote
|
||||
|
||||
if symbols
|
||||
if symbols = params.delete('symbols') || params.delete('currencies')
|
||||
symbols = symbols.split ','
|
||||
quote[:rates].keep_if { |k, v| symbols.include? k }
|
||||
quotes[:rates].keep_if { |k, _| symbols.include? k }
|
||||
end
|
||||
|
||||
quote
|
||||
quotes
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -5,9 +5,20 @@ class Snapshot
|
||||
include Virtus
|
||||
|
||||
attribute :base, String, default: 'EUR'
|
||||
attribute :date, Date, default: proc { Currency.last_date }
|
||||
attribute :date, Date
|
||||
|
||||
def quote
|
||||
self.date =
|
||||
if date
|
||||
Currency
|
||||
.where("date <= '#{date}'")
|
||||
.order(:date)
|
||||
.last
|
||||
.date
|
||||
else
|
||||
Currency.last_date
|
||||
end
|
||||
|
||||
attributes.merge rates: rebase(rates)
|
||||
end
|
||||
|
||||
|
@ -30,7 +30,6 @@ describe 'the application' do
|
||||
end
|
||||
|
||||
it 'works around holidays' do
|
||||
skip 'an "oh, wow" feature'
|
||||
get '/2010-01-01'
|
||||
json['rates'].wont_be :empty?
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user