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