From 38d3590c33e6e29553f5bc91b29a1a91b3174a44 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 19 Feb 2010 14:31:40 +0100 Subject: mime types added to response header --- application.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index db5b41e..74929dc 100644 --- a/application.rb +++ b/application.rb @@ -5,8 +5,7 @@ require 'opentox-ruby-api-wrapper' class Model include DataMapper::Resource property :id, Serial - property :uri, String, :length => 100 - #property :task_uri, String, :length => 100 + property :uri, String, :length => 255 property :owl, Text, :length => 2**32-1 property :yaml, Text, :length => 2**32-1 property :created_at, DateTime @@ -17,6 +16,7 @@ DataMapper.auto_upgrade! require 'lazar.rb' get '/?' do # get index of models + response['Content-Type'] = 'text/uri-list' Model.all.collect{|m| m.uri}.join("\n") end @@ -24,14 +24,16 @@ get '/:id/?' do model = Model.get(params[:id]) halt 404, "Model #{uri} not found." unless model accept = request.env['HTTP_ACCEPT'] - accept = "application/rdf+xml" if accept == '*/*' or accept == '' or accept.nil? + accept = "application/rdf+xml" if accept == '*/*' or accept =~ /html/ or accept == '' or accept.nil? case accept when "application/rdf+xml" + response['Content-Type'] = 'application/rdf+xml' model.owl when /yaml/ + response['Content-Type'] = 'application/x-yaml' model.yaml else - halt 400, "Unsupported MIME type '#{request.content_type}'" + halt 400, "Unsupported MIME type '#{accept}'" end end @@ -46,7 +48,8 @@ end delete '/?' do - #Model.all.each { |d| d.destroy! } + # TODO delete datasets Model.auto_migrate! + response['Content-Type'] = 'text/plain' "All Models deleted." end -- cgit v1.2.3