2014-07-14 12:30:48 +02:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2014-07-14 16:19:05 +02:00
|
|
|
require 'json'
|
|
|
|
|
|
|
|
Bundler.require( :default, :development ) # require tout les gems définis dans Gemfile
|
|
|
|
|
|
|
|
require_relative './lib/ledger'
|
|
|
|
|
|
|
|
# Sinatra app serving API
|
|
|
|
class LedgerRbApp < Sinatra::Base
|
|
|
|
helpers Sinatra::Param
|
|
|
|
|
|
|
|
get '/' do
|
2014-07-14 19:59:46 +02:00
|
|
|
send_file './public/app/index.html'
|
2014-07-14 16:19:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
get '/api/ledger/accounts/?' do
|
|
|
|
content_type :json
|
|
|
|
|
|
|
|
Ledger.accounts.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/api/ledger/accounts/depth/:depth' do
|
|
|
|
content_type :json
|
2014-07-27 10:10:02 +02:00
|
|
|
param :depth, Integer, required: true
|
2014-07-14 16:19:05 +02:00
|
|
|
|
|
|
|
Ledger.accounts( params[ :depth ] ).to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/api/ledger/monthly/?' do
|
|
|
|
content_type :json
|
2014-07-27 10:10:02 +02:00
|
|
|
param :categories, Array, default: Ledger.accounts( 1 )
|
2014-07-27 10:10:40 +02:00
|
|
|
|
|
|
|
params[ :categories ].map do
|
|
|
|
|category|
|
|
|
|
cat = category.first
|
|
|
|
{ category: cat,
|
|
|
|
data: Ledger.monthly_register( cat ) }
|
2014-07-27 10:10:54 +02:00
|
|
|
end.to_json
|
2014-07-14 16:19:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
get '/api/ledger/version/?' do
|
|
|
|
content_type :json
|
|
|
|
|
|
|
|
Ledger.version
|
|
|
|
end
|
2014-07-14 12:30:48 +02:00
|
|
|
end
|