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
|
|
|
|
def base
|
2012-11-21 14:18:24 +01:00
|
|
|
params[:base] || Snapshot::DEFAULT_BASE
|
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-21 12:31:50 +01:00
|
|
|
jsonp Snapshot
|
|
|
|
.last
|
2012-11-21 13:44:33 +01:00
|
|
|
.with_base(base)
|
|
|
|
.to_hash
|
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-21 12:31:50 +01:00
|
|
|
jsonp Snapshot
|
2012-11-21 14:18:24 +01:00
|
|
|
.new(params[:date])
|
2012-11-21 13:44:33 +01:00
|
|
|
.with_base(base)
|
|
|
|
.to_hash
|
2012-11-20 20:32:26 +01:00
|
|
|
end
|