diff options
author | Christoph Helma <helma@in-silico.ch> | 2012-03-12 14:27:55 +0100 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2012-03-12 14:27:55 +0100 |
commit | a3f677eca58b9a2876e1fcdd05ca5859194f80a2 (patch) | |
tree | 0359d18da5acf6846364a8e3ca8f9d66db845304 | |
parent | 2aed7a3550d51223ca6b9301e6562c61fc1a66cb (diff) |
uri helper and before filter added?
-rw-r--r-- | lib/opentox.rb | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/lib/opentox.rb b/lib/opentox.rb index e603336..fbdca32 100644 --- a/lib/opentox.rb +++ b/lib/opentox.rb @@ -2,9 +2,8 @@ require 'sinatra/base' require "sinatra/reloader" module OpenTox + # Base class for OpenTox services - # Errors are formated according to acccept-header - # Non OpenTox::Errors (defined in error.rb) are handled as internal error (500), stacktrace is logged class Service < Sinatra::Base helpers Sinatra::UrlForHelper @@ -17,25 +16,30 @@ module OpenTox register Sinatra::Reloader end + helpers do + def uri + params[:id] ? url_for("/#{params[:id]}", :full) : "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}" + end + end + + before do + @accept = request.env['HTTP_ACCEPT'] + response['Content-Type'] = @accept + # TODO: A+A + end + error do error = request.env['sinatra.error'] - error.uri = "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}#{request.env['REQUEST_URI']}" - case request.env['HTTP_ACCEPT'] - when 'application/rdf+xml' - content_type 'application/rdf+xml' - when /html/ - content_type 'text/html' - when "text/n3" - content_type "text/n3" - else - content_type "text/turtle" - end + error.uri = uri if error.respond_to? :report - case request.env['HTTP_ACCEPT'] + # Errors are formated according to acccept-header + case @accept when 'application/rdf+xml' body = error.report.to_rdfxml when /html/ - body = error.report.to_yaml + # TODO + # body = error.report.to_html + body = error.report.to_turtle when "text/n3" body = error.report.to_ntriples else |