diff options
author | Christoph Helma <helma@in-silico.de> | 2010-01-09 18:24:39 +0100 |
---|---|---|
committer | Christoph Helma <helma@in-silico.de> | 2010-01-09 18:24:39 +0100 |
commit | 693d58aa0050a283d20f441ed238bdbc5915a191 (patch) | |
tree | 3625be10ea52ddbf1bbcd164086cb28593fc299b /application.rb | |
parent | 4b1387fc59d1d0a38d396c097059061739636d58 (diff) |
tasks added
Diffstat (limited to 'application.rb')
-rw-r--r-- | application.rb | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/application.rb b/application.rb index a190d34..0214b69 100644 --- a/application.rb +++ b/application.rb @@ -1,6 +1,58 @@ require 'rubygems' gem 'opentox-ruby-api-wrapper', '~>1.2' require 'opentox-ruby-api-wrapper' +require 'dm-core' +require 'dm-serializer' +require 'dm-timestamps' +require 'dm-types' + + +#set :default_content, :yaml +DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/model.sqlite3") + +class Model + include DataMapper::Resource + property :id, Serial + property :uri, String, :length => 100 + property :owl, Text + property :yaml, Text + property :created_at, DateTime +end + +DataMapper.auto_upgrade! + require 'lazar.rb' -set :default_content, :yaml +get '/?' do # get index of models + Model.all.collect{|m| m.uri}.join("\n") +end + +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? + case accept + when "application/rdf+xml" + model.owl + when /yaml/ + model.yaml + else + halt 400, "Unsupported MIME type '#{request.content_type}'" + end +end + +delete '/:id/?' do + begin + Model.get(params[:id]).destroy! + "Model #{params[:id]} deleted." + rescue + halt 404, "Model #{params[:id]} does not exist." + end +end + + +delete '/?' do + Model.all.each { |d| d.destroy! } + "All datasets deleted." +end |