Added the module classyfire_api
This commit is contained in:
parent
7837013d14
commit
e4d467db5c
|
@ -0,0 +1,50 @@
|
|||
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
|
Loading…
Reference in New Issue