mirror of
https://github.com/gwenhael-le-moine/ledgerrb.git
synced 2024-12-26 09:59:18 +01:00
basic API in front of ledgerrb lib
This commit is contained in:
parent
75624779eb
commit
6d0a5d11f7
3 changed files with 46 additions and 17 deletions
2
Gemfile
2
Gemfile
|
@ -3,4 +3,4 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
gem 'sinatra'
|
||||
gem 'sinatra-contrib'
|
||||
gem 'sinatra-param'
|
||||
|
|
15
Gemfile.lock
15
Gemfile.lock
|
@ -1,24 +1,15 @@
|
|||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
backports (3.6.0)
|
||||
multi_json (1.10.1)
|
||||
rack (1.5.2)
|
||||
rack-protection (1.5.3)
|
||||
rack
|
||||
rack-test (0.6.2)
|
||||
rack (>= 1.0)
|
||||
sinatra (1.4.5)
|
||||
rack (~> 1.4)
|
||||
rack-protection (~> 1.4)
|
||||
tilt (~> 1.3, >= 1.3.4)
|
||||
sinatra-contrib (1.4.2)
|
||||
backports (>= 2.0)
|
||||
multi_json
|
||||
rack-protection
|
||||
rack-test
|
||||
sinatra (~> 1.4.0)
|
||||
tilt (~> 1.3)
|
||||
sinatra-param (1.2.2)
|
||||
sinatra (~> 1.3)
|
||||
tilt (1.4.1)
|
||||
|
||||
PLATFORMS
|
||||
|
@ -26,4 +17,4 @@ PLATFORMS
|
|||
|
||||
DEPENDENCIES
|
||||
sinatra
|
||||
sinatra-contrib
|
||||
sinatra-param
|
||||
|
|
46
app.rb
46
app.rb
|
@ -1,8 +1,46 @@
|
|||
# encoding: utf-8
|
||||
|
||||
require 'sinatra'
|
||||
require 'sinatra/reloader'
|
||||
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
|
||||
'OH HAI!'
|
||||
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
|
||||
|
||||
Ledger.accounts( params[ :depth ] ).to_json
|
||||
end
|
||||
|
||||
get '/api/ledger/monthly/?' do
|
||||
content_type :json
|
||||
param :categories, Array
|
||||
|
||||
params[ :categories ].map do |category|
|
||||
{ category: category,
|
||||
data: Ledger.monthly_register( category ).to_json }
|
||||
end
|
||||
end
|
||||
|
||||
get '/api/ledger/version/?' do
|
||||
content_type :json
|
||||
|
||||
Ledger.version
|
||||
end
|
||||
|
||||
get '/' do
|
||||
'OH HAI!'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue