ledgerrb/app.rb

70 lines
1.4 KiB
Ruby
Raw Normal View History

2014-07-14 12:30:48 +02:00
# encoding: utf-8
2014-07-14 16:19:05 +02:00
require 'json'
require 'bundler'
2014-07-14 16:19:05 +02:00
2014-07-28 11:35:28 +02:00
Bundler.require( :default, ENV[ 'RACK_ENV' ].to_sym )
2014-07-14 16:19:05 +02:00
require_relative './options'
2014-07-14 16:19:05 +02:00
require_relative './lib/ledger'
# Sinatra app serving API
class LedgerRbApp < Sinatra::Base
2014-07-28 11:35:55 +02:00
before do
content_type :json, 'charset' => 'utf-8'
end
2014-07-14 16:19:05 +02:00
get '/' do
2014-07-28 11:35:55 +02:00
content_type :html
2014-07-14 19:59:46 +02:00
send_file './public/app/index.html'
2014-07-14 16:19:05 +02:00
end
get '/budget' do
content_type :html
erb :budget
end
2014-07-14 16:19:05 +02:00
get '/api/ledger/accounts/?' do
Ledger.accounts.to_json
end
2014-07-27 22:02:59 +02:00
get '/api/ledger/accounts/depth/:depth/?' do
2014-07-14 16:19:05 +02:00
Ledger.accounts( params[ :depth ] ).to_json
end
2014-09-30 12:15:37 +02:00
get '/api/ledger/dates_salaries/?' do
Ledger.dates_salaries.to_json
end
2014-08-01 22:25:36 +02:00
get '/api/ledger/register/?' do
2014-10-12 08:23:36 +02:00
{ key: params[ :categories ],
values: Ledger.register( params[ :period ], params[ :categories ] ) }
2014-08-01 22:25:36 +02:00
.to_json
2014-07-14 16:19:05 +02:00
end
2014-07-27 22:04:26 +02:00
get '/api/ledger/balance/?' do
Ledger.balance( params[ :cleared ],
params[ :depth ],
params[ :period ],
params[ :categories ] )
.to_json
2014-07-27 22:04:26 +02:00
end
2014-10-20 12:52:49 +02:00
get '/api/ledger/cleared/?' do
Ledger.cleared.to_json
end
2014-07-27 22:04:26 +02:00
2014-11-06 17:15:25 +01:00
get '/api/ledger/budget/?' do
2014-11-08 17:40:48 +01:00
Ledger.budget( params[ :period ],
params[ :categories ] ).to_json
2014-11-06 17:15:25 +01:00
end
2015-08-30 19:54:06 +02:00
get '/api/ledger/graph_values/?' do
2015-08-30 19:54:06 +02:00
Ledger.graph_values( params[:period], params[:categories].split(' ') ).to_json
end
2014-11-06 17:15:25 +01:00
2014-07-14 16:19:05 +02:00
get '/api/ledger/version/?' do
Ledger.version
end
2014-07-14 12:30:48 +02:00
end