summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.de>2009-11-30 16:27:28 +0100
committerChristoph Helma <helma@in-silico.de>2009-11-30 16:27:28 +0100
commitf21aabdc79c631b07b06092e137ffc95ba67eb8d (patch)
tree3a140ec2b3b117bbc690cf326f39bb90c831641e
parentf5a9d52b26f0890157ec7ff6d2e461b1509bdf34 (diff)
Accept header parsing fixed, sinatra/respond_to removed
-rw-r--r--README17
-rw-r--r--application.rb46
2 files changed, 34 insertions, 29 deletions
diff --git a/README b/README
index 5b09122..7134d6a 100644
--- a/README
+++ b/README
@@ -2,8 +2,19 @@ OpenTox Compounds
=================
* An OpenTox REST Webservice (http://www.opentox.org)
-* Implements the OpenTox compounds API
+* Implements the OpenTox compound API 1.1 (http://opentox.org/dev/apis/api-1.1/structure)
-Documentation: Source code (application.rb)
+REST operations:
-Copyright (c) 2009 Christoph Helma. See LICENSE for details.
+Get the representation of a compound GET /compound/{id} - Compound representation 200,404,503
+Create a new compound POST /compound Compound representation URIs for new compounds 200,400,503
+
+Supported MIME formats (http://chemical-mime.sourceforge.net/):
+
+ * chemical/x-daylight-smiles (default)
+ * chemical/x-inchi
+ * chemical/x-mdl-sdfile
+ * text/plain (chemical names)
+ * link to image/gif (output only)
+
+Installation: http://wiki.github.com/helma/opentox-documentation/installation-of-opentox-webservices
diff --git a/application.rb b/application.rb
index 3fbc9fb..7829fff 100644
--- a/application.rb
+++ b/application.rb
@@ -1,23 +1,24 @@
require 'rubygems'
require 'opentox-ruby-api-wrapper'
-require 'sinatra/respond_to'
-
-mime :smiles, "chemical/x-daylight-smiles"
-mime :inchi, "chemical/x-inchi"
-mime :sdf, "chemical/x-mdl-sdfile"
-mime :image, "image/gif"
-mime :names, "text/plain"
-
-set :default_content, :smiles
get %r{/(.+)} do |inchi| # catches all remaining get requests
- inchi = URI.unescape request.env['REQUEST_URI'].sub(/^\//,'') # hack to avoid sinatra's URI/CGI unescaping, splitting, ...
- respond_to do |format|
- format.smiles { OpenTox::Compound.new(:inchi => inchi).smiles }
- format.names { RestClient.get "#{CACTUS_URI}#{inchi}/names" }
- format.inchi { inchi }
- format.sdf { RestClient.get "#{CACTUS_URI}#{inchi}/sdf" }
- format.image { "#{CACTUS_URI}#{inchi}/image" }
+ inchi = URI.unescape request.env['REQUEST_URI'].sub(/^\//,'') # hack to avoid sinatra's URI/CGI unescaping, splitting, ..."
+ case request.env['HTTP_ACCEPT']
+ when "*/*"
+ OpenTox::Compound.new(:inchi => inchi).smiles
+ when "chemical/x-daylight-smiles"
+ OpenTox::Compound.new(:inchi => inchi).smiles
+ when "chemical/x-inchi"
+ inchi
+ when "chemical/x-mdl-sdfile"
+ OpenTox::Compound.new(:inchi => inchi).sdf
+ when "image/gif"
+ "#{CACTUS_URI}#{inchi}/image"
+ when "text/plain"
+ RestClient.get "#{CACTUS_URI}#{inchi}/names"
+ else
+ status 400
+ "Unsupported MIME type '#{request.content_type}'"
end
end
@@ -29,19 +30,12 @@ post '/?' do
OpenTox::Compound.new(:smiles => input).uri
when /chemical\/x-inchi/
OpenTox::Compound.new(:inchi => input).uri
+ when /chemical\/x-mdl-sdfile|chemical\/x-mdl-molfile/
+ OpenTox::Compound.new(:sdf => input).uri
when /text\/plain/
OpenTox::Compound.new(:name => input).uri
else
status 400
- "Unsupported MIME type #{request.content_type}"
- end
-=begin
- if params[:smiles]
- OpenTox::Compound.new(:smiles => params[:smiles]).uri
- elsif params[:inchi]
- OpenTox::Compound.new(:inchi => params[:inchi]).uri
- elsif params[:name]
- OpenTox::Compound.new(:name => params[:name]).uri
+ "Unsupported MIME type '#{request.content_type}'"
end
-=end
end