updated the classyfire api. you can get query or entity in the sdf format now.

This commit is contained in:
Yannick 2015-02-05 13:14:53 -07:00
parent 68c662759a
commit f6165c61c3
1 changed files with 30 additions and 8 deletions

View File

@ -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