mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-10-30 07:42:43 +01:00
32 lines
523 B
Ruby
32 lines
523 B
Ruby
require 'sinatra'
|
|
require 'sinatra/jsonp'
|
|
require 'yajl'
|
|
require 'snapshot'
|
|
|
|
set :root, File.expand_path('..', File.dirname(__FILE__))
|
|
|
|
helpers do
|
|
def snapshot
|
|
quotes = Snapshot.new(params).quote
|
|
|
|
if symbols = params.delete('symbols') || params.delete('currencies')
|
|
symbols = symbols.split(',')
|
|
quotes[:rates].keep_if { |k, _| symbols.include?(k) }
|
|
end
|
|
|
|
quotes
|
|
end
|
|
end
|
|
|
|
get '/' do
|
|
redirect 'http://fixer.io'
|
|
end
|
|
|
|
get '/latest' do
|
|
jsonp snapshot
|
|
end
|
|
|
|
get '/:date' do
|
|
jsonp snapshot
|
|
end
|