70 lines
2.0 KiB
Ruby
70 lines
2.0 KiB
Ruby
require 'JSON'
|
|
require 'RestClient'
|
|
|
|
module ClassyFireAPI
|
|
URL = 'http://classyfire.wishartlab.com'
|
|
|
|
def ClassyFireAPI.submit_query(label,input)
|
|
begin
|
|
RestClient.post URL+'/queries', {:label => label, :query_input => input}.to_json, :accept => :json, :content_type => :json
|
|
rescue RestClient::BadRequest => e
|
|
e.response
|
|
rescue RestClient::InternalServerError => e
|
|
e.response
|
|
rescue RestClient::GatewayTimeout => e
|
|
e.response
|
|
rescue RestClient::RequestTimeout => e
|
|
e.response
|
|
end
|
|
end
|
|
|
|
def ClassyFireAPI.get_query(query_id,format="json")
|
|
# format can be either 'json' or 'sdf'
|
|
begin
|
|
if format == "json"
|
|
puts "#{URL}/queries/#{query_id}.json"
|
|
RestClient.get "#{URL}/queries/#{query_id}.json", :accept => :json
|
|
elsif format == "sdf"
|
|
puts "#{URL}/queries/#{query_id}.sdf"
|
|
RestClient.get "#{URL}/queries/#{query_id}.sdf", :accept => :sdf
|
|
end
|
|
rescue RestClient::ResourceNotFound => e
|
|
e.response
|
|
rescue RestClient::InternalServerError => e
|
|
e.response
|
|
rescue RestClient::GatewayTimeout => e
|
|
e.response
|
|
rescue RestClient::RequestTimeout => e
|
|
e.response
|
|
end
|
|
end
|
|
|
|
def ClassyFireAPI.get_entity_classification(inchikey,format="json")
|
|
# format can be either 'json' or 'sdf'
|
|
inchikey_id = inchikey.to_s.gsub('InChIKey=','')
|
|
begin
|
|
if format == "json"
|
|
RestClient.get "#{URL}/entities/#{inchikey_id}.#{format}", :accept => :json
|
|
elsif format == "sdf"
|
|
RestClient.get "#{URL}/entities/#{inchikey_id}.#{format}", :accept => :sdf
|
|
end
|
|
rescue RestClient::ResourceNotFound => e
|
|
e.response
|
|
rescue RestClient::InternalServerError => e
|
|
e.response
|
|
rescue RestClient::GatewayTimeout => e
|
|
e.response
|
|
rescue RestClient::RequestTimeout => e
|
|
e.response
|
|
end
|
|
end
|
|
|
|
def ClassyFireAPI.query_status(query_id)
|
|
s = JSON.parse(get_query(query_id))
|
|
if s['error']
|
|
s
|
|
elsif s['classification_status:']
|
|
s['classification_status']
|
|
end
|
|
end
|
|
end |