Module: Sylfy::Service::CIR::REST

Defined in:
lib/sylfy/service/cactusncirest.rb

Constant Summary collapse

@@baseuri =
"http://cactus.nci.nih.gov/chemical/structure"
@@representation_type =
[:stdinchi, :stdinchikey, :smiles, :ficts, :ficus, :uuuuu, :sdf, :names, :hashisy, :image, :iupac_name]

Class Method Summary collapse

Class Method Details

.perform(identifier, representation, xml = false) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sylfy/service/cactusncirest.rb', line 24

def perform(identifier, representation, xml = false)
	if @@representation_type.include?(representation.to_sym)
		uri = "#{@@baseuri}/#{URI.escape(identifier, "[] ")}/#{representation.to_s}"
		
		begin
			return URI.parse(uri).read().strip().chomp.split(/\n/)
		rescue OpenURI::HTTPError
			return []
		end
		
	else
		raise Sylfy::Service::ParameterError, "Wrong representation type. Should be #{@@representation_type.join(', ')}"
	end
end