diff options
author | Christoph Helma <helma@in-silico.de> | 2009-12-17 13:58:26 +0100 |
---|---|---|
committer | Christoph Helma <helma@in-silico.de> | 2009-12-17 13:58:26 +0100 |
commit | 89a053cb15ca5b7c50f39fe29fe052bf7e5fe436 (patch) | |
tree | cc3ca3899c8d19930db40f6f0e996c6eb7bed122 /application.rb | |
parent | 8954c222603a700136e0ab07a545ed8e326a866d (diff) |
YAML output for datasets added
Diffstat (limited to 'application.rb')
-rw-r--r-- | application.rb | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/application.rb b/application.rb index 2bd3125..e89a39f 100644 --- a/application.rb +++ b/application.rb @@ -2,8 +2,8 @@ require 'rubygems' gem 'opentox-ruby-api-wrapper', '~>1.2' require 'opentox-ruby-api-wrapper' -mime :rdf, "application/rdf+xml" -set :default_content, :rdf +#mime :rdf, "application/rdf+xml" +#set :default_content, :rdf ## REST API @@ -12,7 +12,20 @@ get '/?' do end get '/:id/?' do - send_file File.join("datasets",params[:id] + ".rdf") + uri = url_for("/#{params[:id]}", :full) + path = File.join("datasets",params[:id] + ".rdf") + halt 404, "Dataset #{uri} not found." unless File.exists? path + accept = request.env['HTTP_ACCEPT'] + puts accept + accept = 'application/rdf+xml' if accept == '*/*' or accept == '' or accept.nil? + case accept + when /rdf/ + send_file path + when /yaml/ + OpenTox::Dataset.find(uri).to_yaml + else + halt 400, "Unsupported MIME type '#{accept}'" + end end get '/:id/features/:feature_id/?' do |