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