From e4d467db5c20b2c0104d68e90bc7c1a2c8b9b20f Mon Sep 17 00:00:00 2001 From: Yannick Date: Sun, 13 Jul 2014 23:08:02 -0600 Subject: [PATCH] Added the module classyfire_api --- lib/classyfire_api.rb | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 lib/classyfire_api.rb diff --git a/lib/classyfire_api.rb b/lib/classyfire_api.rb new file mode 100644 index 0000000..65fcef0 --- /dev/null +++ b/lib/classyfire_api.rb @@ -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 \ No newline at end of file