From 09678bd48e41af7e6f980bf05ccfc5263a8f1b44 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Mon, 28 Jul 2014 11:35:55 +0200 Subject: [PATCH] utf-8 response --- app.rb | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/app.rb b/app.rb index 6783cabe..fe82b9ca 100644 --- a/app.rb +++ b/app.rb @@ -10,25 +10,26 @@ require_relative './lib/ledger' class LedgerRbApp < Sinatra::Base helpers Sinatra::Param + before do + content_type :json, 'charset' => 'utf-8' + end + get '/' do + content_type :html send_file './public/app/index.html' end get '/api/ledger/accounts/?' do - content_type :json - Ledger.accounts.to_json end get '/api/ledger/accounts/depth/:depth/?' do - content_type :json param :depth, Integer, required: true Ledger.accounts( params[ :depth ] ).to_json end get '/api/ledger/register/:period/?' do - content_type :json param :period, String, required: true # TODO: restrict possible values to [ 'yearly', 'monthly' ] param :categories, Array, default: Ledger.accounts( 1 ) @@ -41,29 +42,23 @@ class LedgerRbApp < Sinatra::Base end get '/api/ledger/balance/?' do - content_type :json - - Ledger.balance#.to_json + Ledger.balance # .to_json end get '/api/ledger/balance/depth/:depth/?' do - content_type :json param :depth, Integer, required: true - Ledger.balance( false, params[ :depth ] )#.to_json + Ledger.balance( false, params[ :depth ] ) # .to_json end get '/api/ledger/cleared/?' do - content_type :json - - Ledger.balance( true )#.to_json + Ledger.balance( true ) # .to_json end get '/api/ledger/cleared/depth/:depth/?' do - content_type :json param :depth, Integer, required: true - Ledger.balance( true, params[ :depth ] )#.to_json + Ledger.balance( true, params[ :depth ] ) # .to_json end get '/api/ledger/version/?' do