basic API in front of ledgerrb lib

This commit is contained in:
Gwenhael Le Moine 2014-07-14 16:19:05 +02:00
parent 75624779eb
commit 6d0a5d11f7
3 changed files with 46 additions and 17 deletions

View file

@ -3,4 +3,4 @@
source 'https://rubygems.org'
gem 'sinatra'
gem 'sinatra-contrib'
gem 'sinatra-param'

View file

@ -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
View file

@ -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