frankfurter/lib/app.rb
2012-11-23 14:28:55 +00:00

41 lines
651 B
Ruby

require_relative 'snapshot'
require 'sinatra'
require 'sinatra/jsonp'
require 'yajl'
set :root, File.expand_path('..', File.dirname(__FILE__))
helpers do
# Ugly as fuck.
def snapshot
symbols = params.delete('symbols') || params.delete('currencies')
quote = Snapshot
.new(params)
.quote
if symbols
symbols = symbols.split ','
quote[:rates].keep_if { |k, v| symbols.include? k }
end
quote
end
end
get '/' do
File.read File.join 'public', 'index.html'
end
get '/latest' do
jsonp snapshot
end
get '/:date' do
jsonp snapshot
end
error do
"Something is rotten in the state of Denmark."
end