From f6165c61c3d4e4b07efe01cd1ac836330b577766 Mon Sep 17 00:00:00 2001 From: Yannick Date: Thu, 5 Feb 2015 13:14:53 -0700 Subject: [PATCH] updated the classyfire api. you can get query or entity in the sdf format now. --- lib/classyfire_api.rb | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/classyfire_api.rb b/lib/classyfire_api.rb index b3ed247..9297b78 100644 --- a/lib/classyfire_api.rb +++ b/lib/classyfire_api.rb @@ -11,28 +11,51 @@ module ClassyFireAPI 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) + def ClassyFireAPI.get_query(query_id,format="json") + # format can be either 'json' or 'sdf' begin - puts "#{URL}/queries/#{query_id}.json" - RestClient.get "#{URL}/queries/#{query_id}.json", :accept => :json + 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) + def ClassyFireAPI.get_entity_classification(inchikey,format="json") + # format can be either 'json' or 'sdf' inchikey_id = inchikey.to_s.gsub('InChIKey=','') begin - RestClient.get "#{URL}/entities/#{inchikey_id}.json", :accept => :json + 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 @@ -40,9 +63,8 @@ module ClassyFireAPI s = JSON.parse(get_query(query_id)) if s['error'] s - elsif s['state'] - - s['state'] + elsif s['classification_status:'] + s['classification_status'] end end end \ No newline at end of file