summaryrefslogtreecommitdiff
path: root/application.rb
blob: 3fbc9fb8e8737fe02deade087a263e595f161d09 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 

	input =	request.env["rack.input"].read
	case request.content_type
	when /chemical\/x-daylight-smiles/
		OpenTox::Compound.new(:smiles => input).uri
	when /chemical\/x-inchi/
		OpenTox::Compound.new(:inchi => 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
	end
=end
end