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'
require 'sinatra/jsonp' require 'sinatra/jsonp'
helpers do
def base
params[:base] || 'EUR'
end
end
get '/' do get '/' do
File.read File.join 'public', 'index.html' File.read File.join 'public', 'index.html'
end end
get '/latest' do get '/latest' do
jsonp Snapshot.last jsonp Snapshot
.last
.to_base base
end end
get '/:date' do get '/:date' do |date|
jsonp Snapshot.new params[:date] jsonp Snapshot
.new(date)
.to_base base
end end

View File

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

View File

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