From acf5094b1eb8ee5cc105128dd16a1e330bd74864 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 21 May 2010 15:58:31 +0200 Subject: READMEs updated --- README | 14 +++++++------- application.rb | 28 ++++++++++++++++------------ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/README b/README index 30b3e36..f2721fc 100644 --- a/README +++ b/README @@ -20,24 +20,24 @@ Supported MIME formats (http://chemical-mime.sourceforge.net/): Examples: Create a compound_uri from smiles: - curl -X POST -H "Content-Type:chemical/x-daylight-smiles" --data-binary "c1ccccc1" http://webservices.in-silico.ch/test/compound + curl -X POST -H "Content-Type:chemical/x-daylight-smiles" --data-binary "c1ccccc1" http://webservices.in-silico.ch/compound Create a compound_uri from a SD file: - curl -X POST -H "Content-Type:chemical/x-mdl-sdfile" --data-binary @my.sdf http://webservices.in-silico.ch/test/compound + curl -X POST -H "Content-Type:chemical/x-mdl-sdfile" --data-binary @my.sdf http://webservices.in-silico.ch/compound Create a compound_uri from name (or any other identifier that can be resolved with the Cactus service): - curl -X POST -H "Content-Type:text/plain" --data-binary "Benzene" http://webservices.in-silico.ch/test/compound + curl -X POST -H "Content-Type:text/plain" --data-binary "Benzene" http://webservices.in-silico.ch/compound Create a compound_uri from CAS: - curl -X POST -H "Content-Type:text/plain" --data-binary "71-43-2" http://webservices.in-silico.ch/test/compound + curl -X POST -H "Content-Type:text/plain" --data-binary "71-43-2" http://webservices.in-silico.ch/compound Get SMILES for a compound_uri: - curl http://webservices.in-silico.ch/test/compound/InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H + curl http://webservices.in-silico.ch/compound/InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H Get a SD file for a compound_uri: - curl -H "Accept:chemical/x-mdl-sdfile" http://webservices.in-silico.ch/test/compound/InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H + curl -H "Accept:chemical/x-mdl-sdfile" http://webservices.in-silico.ch/compound/InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H Get all names for a compound_uri: - curl -H "Accept:text/plain" http://webservices.in-silico.ch/test/compound/InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H + curl -H "Accept:text/plain" http://webservices.in-silico.ch/compound/InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H Installation: http://wiki.github.com/helma/opentox-documentation/installation-of-opentox-webservices diff --git a/application.rb b/application.rb index 73d1702..e19f680 100644 --- a/application.rb +++ b/application.rb @@ -23,7 +23,6 @@ get %r{/(.+)} do |inchi| # catches all remaining get requests when "image/gif" response['Content-Type'] = "image/gif" OpenTox::Compound.new(:inchi => inchi).image - #"#{CACTUS_URI}#{inchi}/image" when "text/plain" response['Content-Type'] = "text/plain" uri = File.join CACTUS_URI,inchi,"names" @@ -37,17 +36,22 @@ post '/?' do input = request.env["rack.input"].read response['Content-Type'] = 'text/uri-list' - case request.content_type - when /chemical\/x-daylight-smiles/ - OpenTox::Compound.new(:smiles => input).uri + "\n" - when /chemical\/x-inchi/ - OpenTox::Compound.new(:inchi => input).uri + "\n" - when /chemical\/x-mdl-sdfile|chemical\/x-mdl-molfile/ - OpenTox::Compound.new(:sdf => input).uri + "\n" - when /text\/plain/ - OpenTox::Compound.new(:name => input).uri + "\n" - else + begin + case request.content_type + when /chemical\/x-daylight-smiles/ + OpenTox::Compound.new(:smiles => input).uri + "\n" + when /chemical\/x-inchi/ + OpenTox::Compound.new(:inchi => input).uri + "\n" + when /chemical\/x-mdl-sdfile|chemical\/x-mdl-molfile/ + OpenTox::Compound.new(:sdf => input).uri + "\n" + when /text\/plain/ + OpenTox::Compound.new(:name => input).uri + "\n" + else + status 400 + "Unsupported MIME type '#{request.content_type}'" + end + rescue status 400 - "Unsupported MIME type '#{request.content_type}'" + "Cannot process request '#{input}' for content type '#{request.content_type}'" end end -- cgit v1.2.3