frankfurter/lib/api.rb

32 lines
523 B
Ruby
Raw Normal View History

2012-11-20 17:36:12 +01:00
require 'sinatra'
require 'sinatra/jsonp'
2012-11-21 13:44:33 +01:00
require 'yajl'
2013-04-30 00:56:40 +02:00
require 'snapshot'
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:13:49 +01:00
def snapshot
2013-04-30 00:56:40 +02:00
quotes = Snapshot.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')
2013-04-30 00:56:40 +02:00
symbols = symbols.split(',')
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