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-28 03:16:33 +01:00
|
|
|
quotes = Snapshot
|
2012-11-23 15:13:49 +01:00
|
|
|
.new(params)
|
|
|
|
.quote
|
2012-11-23 15:27:09 +01:00
|
|
|
|
2012-11-28 03:16:33 +01:00
|
|
|
if symbols = params.delete('symbols') || params.delete('currencies')
|
2012-11-23 15:27:09 +01:00
|
|
|
symbols = symbols.split ','
|
2012-11-28 03:16:33 +01:00
|
|
|
quotes[:rates].keep_if { |k, _| symbols.include? k }
|
2012-11-23 15:27:09 +01:00
|
|
|
end
|
|
|
|
|
2012-11-28 03:16:33 +01:00
|
|
|
quotes
|
2012-11-21 12:31:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-20 17:36:12 +01:00
|
|
|
get '/' do
|
2013-04-30 00:55:33 +02:00
|
|
|
redirect 'http://fixer.io'
|
2012-11-20 17:36:12 +01:00
|
|
|
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
|