From 878f014ec6cc808af99af5045bcc1a1143cab8d9 Mon Sep 17 00:00:00 2001 From: gebele Date: Thu, 5 Jul 2018 10:38:55 +0000 Subject: updated with endpoint list; refined error handling; refined prediction input --- lib/endpoint.rb | 23 +++++++++++++++++++++++ lib/model.rb | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 lib/endpoint.rb (limited to 'lib') diff --git a/lib/endpoint.rb b/lib/endpoint.rb new file mode 100644 index 0000000..ef39787 --- /dev/null +++ b/lib/endpoint.rb @@ -0,0 +1,23 @@ +# Get a list of all endpoints +# @param [Header] Accept one of text/uri-list, +# @return [text/uri-list] list of all prediction models +get "/endpoint/?" do + models = Model::Validation.all + endpoints = models.collect{|m| m.endpoint}.uniq + case @accept + when "text/uri-list" + return endpoints.join("\n") + "\n" + when "application/json" + return endpoints.to_json + else + bad_request_error "Mime type #{@accept} is not supported." + end +end + +get "/endpoint/:endpoint/?" do + models = Model::Validation.where(endpoint: params[:endpoint]) + list = [] + models.each{|m| list << {m.species => uri("/model/#{m.id}")} } + not_found_error "Endpoint: #{params[:endpoint]} not found." if models.blank? + return list.to_json +end diff --git a/lib/model.rb b/lib/model.rb index 9fbd90f..3764ee2 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -27,7 +27,7 @@ end post "/model/:id/?" do identifier = params[:identifier].split(",") - compounds = identifier.collect{ |i| Compound.from_smiles i.strip } + compounds = identifier.collect{ |i| Compound.from_smiles i.strip.gsub(/\A"|"\Z/,'') } model = Model::Validation.find params[:id] batch = {} compounds.each do |compound| -- cgit v1.2.3