blob: eb927e059a97a15929738196fdde0f96bf0f2251 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
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" }
end
end
post '/?' do
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
end
end
|