frankfurter/lib/app.rb

41 lines
651 B
Ruby
Raw Normal View History

2012-11-20 17:36:12 +01:00
require_relative 'snapshot'
require 'sinatra'
require 'sinatra/jsonp'
2012-11-21 13:44:33 +01:00
require 'yajl'
2012-11-20 17:36:12 +01:00
2012-11-21 14:18:16 +01:00
set :root, File.expand_path('..', File.dirname(__FILE__))
2012-11-21 12:31:50 +01:00
helpers do
2012-11-23 15:27:09 +01:00
# Ugly as fuck.
2012-11-23 15:13:49 +01:00
def snapshot
2012-11-23 15:27:09 +01:00
symbols = params.delete('symbols') || params.delete('currencies')
quote = Snapshot
2012-11-23 15:13:49 +01:00
.new(params)
.quote
2012-11-23 15:27:09 +01:00
if symbols
symbols = symbols.split ','
quote[:rates].keep_if { |k, v| symbols.include? k }
end
quote
2012-11-21 12:31:50 +01:00
end
end
2012-11-20 17:36:12 +01:00
get '/' do
File.read File.join 'public', 'index.html'
end
get '/latest' do
2012-11-23 15:13:49 +01:00
jsonp snapshot
2012-11-20 17:36:12 +01:00
end
2012-11-20 20:32:26 +01:00
2012-11-21 14:18:24 +01:00
get '/:date' do
2012-11-23 15:13:49 +01:00
jsonp snapshot
end
error do
"Something is rotten in the state of Denmark."
2012-11-20 20:32:26 +01:00
end