diff options
author | Martin Gütlein <martin.guetlein@gmail.com> | 2009-11-13 11:51:21 +0100 |
---|---|---|
committer | Martin Gütlein <martin.guetlein@gmail.com> | 2009-11-13 11:51:21 +0100 |
commit | 41e5d1e6160115356c54d2907552b9a943126ae1 (patch) | |
tree | 8b011c251ecfbd69d2435d07b91e275f56fc1682 /report/report_application.rb | |
parent | 14904ee55e85000b97fa7b735c22a82529fbdf10 (diff) |
merged reports into this rep
Diffstat (limited to 'report/report_application.rb')
-rw-r--r-- | report/report_application.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/report/report_application.rb b/report/report_application.rb new file mode 100644 index 0000000..4cba0ae --- /dev/null +++ b/report/report_application.rb @@ -0,0 +1,44 @@ +load "report/environment.rb" + +def perform + begin + $rep = Reports::ReportService.new(url_for("", :full)) unless $rep + yield( $rep ) + rescue Reports::NotFound => ex + halt 404, ex.message + rescue Reports::BadRequest => ex + halt 400, ex.message + rescue Exception => ex + LOGGER.error(ex.message) + #raise ex # sinatra returns 501 + halt 500, ex.message + end +end + +get '/report/?' do + perform{ |rs| rs.get_report_types } +end + +get '/report/:type' do + perform{ |rs| rs.get_all_reports(params[:type]) } +end + +get '/report/:type/:id' do + perform do |rs| + #request.env['HTTP_ACCEPT'] = "application/pdf" + result = body(File.new( rs.get_report(params[:type],params[:id],request.env['HTTP_ACCEPT']) )) + end +end + +get '/report/:type/:id/:resource' do + #hack: using request.env['REQUEST_URI'].split("/")[-1] instead of params[:resource] because the file extension is lost + perform{ |rs| result = body(File.new(rs.get_report_resource(params[:type],params[:id],request.env['REQUEST_URI'].split("/")[-1]))) } +end + +delete '/report/:type/:id' do + perform{ |rs| rs.delete_report(params[:type],params[:id]) } +end + +post '/report/:type' do + perform{ |rs| rs.create_report(params[:type],params[:uri_list]?params[:uri_list].split("\n"):nil) } +end |