Set base currency

This commit is contained in:
Hakan Ensari 2012-11-21 11:31:50 +00:00
parent 9c4da44db4
commit 6fb6ab7feb
3 changed files with 19 additions and 8 deletions

View File

@ -2,14 +2,24 @@ require_relative 'snapshot'
require 'sinatra'
require 'sinatra/jsonp'
helpers do
def base
params[:base] || 'EUR'
end
end
get '/' do
File.read File.join 'public', 'index.html'
end
get '/latest' do
jsonp Snapshot.last
jsonp Snapshot
.last
.to_base base
end
get '/:date' do
jsonp Snapshot.new params[:date]
get '/:date' do |date|
jsonp Snapshot
.new(date)
.to_base base
end

View File

@ -10,10 +10,12 @@ class Snapshot
@date = date
end
def to_json
Yajl::Encoder.new.encode base: 'EUR',
def to_base(base)
{
base: base,
date: @date,
rates: rates
}
end
private

View File

@ -14,7 +14,6 @@ describe 'the application' do
end
it 'sets base currency' do
skip 'pending'
get '/latest?base=USD'
json['base'].must_equal 'USD'
end