classyfire_api/lib/classyfire_api.rb

50 lines
1.3 KiB
Ruby

require 'JSON'
require 'RestClient'
module ClassyFireAPI
URL = 'http://classyfire.wishartlab.com'
# URL = 'http://localhost:3000'
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
end
end
def ClassyFireAPI.get_query(query_id)
begin
puts "#{URL}/queries/#{query_id}.json"
RestClient.get "#{URL}/queries/#{query_id}.json", :accept => :json
rescue RestClient::ResourceNotFound => e
e.response
rescue RestClient::InternalServerError => e
e.response
end
end
def ClassyFireAPI.get_entity_classification(inchikey)
inchikey_id = inchikey.to_s.gsub('InChIKey=','')
begin
RestClient.get "#{URL}/entities/#{inchikey_id}.json", :accept => :json
rescue RestClient::ResourceNotFound => e
e.response
rescue RestClient::InternalServerError => e
e.response
end
end
def ClassyFireAPI.query_status(query_id)
s = JSON.parse(get_query(query_id))
if s['error']
s
elsif s['state']
s['state']
end
end
end