diff options
author | Christoph Helma <helma@in-silico.ch> | 2013-03-26 10:57:31 +0100 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2013-03-26 10:57:31 +0100 |
commit | ade93108bb8a226dc77c07377db3ead54a550a44 (patch) | |
tree | 153863c5222fa82c7c64ac57839249d8cdd9532e /lib/opentox.rb | |
parent | 5b529f42d5fcc68b350b7bf10f6b4f7e71b7f9e2 (diff) |
code cleanup and refactoring. 4store moved from opentox-client.
Diffstat (limited to 'lib/opentox.rb')
-rw-r--r-- | lib/opentox.rb | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/opentox.rb b/lib/opentox.rb index 894033d..eb35b38 100644 --- a/lib/opentox.rb +++ b/lib/opentox.rb @@ -22,11 +22,17 @@ module OpenTox configure :development do register Sinatra::Reloader also_reload "./*.rb" + also_reload "./**/*.rb" also_reload "../opentox-client/lib/*.rb" also_reload File.join(ENV["HOME"],".opentox","config","#{SERVICE}.rb") end before do + @uri = uri(request.env['REQUEST_URI']) + # fix IE + request.env['HTTP_ACCEPT'] += ";text/html" if request.env["HTTP_USER_AGENT"]=~/MSIE/ + request.env['HTTP_ACCEPT'] = request.params["media"] if request.params["media"] + request.content_type ? response['Content-Type'] = request.content_type : response['Content-Type'] = request.env['HTTP_ACCEPT'] parse_input if request.request_method =~ /POST|PUT/ @accept = request.env['HTTP_ACCEPT'] @@ -35,10 +41,6 @@ module OpenTox response['Content-Type'] = @accept end - before "/#{SERVICE}/:id" do - @uri = uri("/#{SERVICE}/#{params[:id]}") - end - helpers do def parse_input case request.content_type @@ -56,7 +58,7 @@ module OpenTox end end - # Attention: Error within tasks are catched by Task.create + # Attention: Error within tasks are catched by Task.run error do error = request.env['sinatra.error'] if error.respond_to? :report @@ -97,10 +99,18 @@ module OpenTox # Default methods, may be overwritten by derived services # see http://jcalcote.wordpress.com/2008/10/16/put-or-post-the-rest-of-the-story/ - # Get a list of objects at the server + # Get a list of objects at the server or perform a SPARQL query get "/#{SERVICE}/?" do - $logger.debug "listing all #{SERVICE} objects" - FourStore.list @accept + if params[:query] + case @accept + when "text/uri-list" # result URIs are protected by A+A + FourStore.query(params[:query], "text/uri-list") + else # prevent searches for protected resources + bad_request_error "Accept header '#{@accept}' is disabled for SPARQL queries at service URIs in order to protect private data. Use 'text/uri-list' and repeat the query at the result URIs.", uri("/#{SERVICE}") + end + else + FourStore.list(@accept) + end end # Create a new resource @@ -111,9 +121,9 @@ module OpenTox @uri end - # Get resource representation + # Get resource representation or perform a SPARQL query get "/#{SERVICE}/:id/?" do - FourStore.get(@uri, @accept) + params[:query] ? FourStore.query(params[:query], @accept) : FourStore.get(@uri, @accept) end # Modify (i.e. add rdf statments to) a resource |