summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorgebele <gebele@in-silico.ch>2018-07-05 10:38:55 +0000
committergebele <gebele@in-silico.ch>2018-07-05 10:38:55 +0000
commit878f014ec6cc808af99af5045bcc1a1143cab8d9 (patch)
tree38458f73295d58c2ab487c81056d0abf0e4c4c19 /lib
parent395506ca3fe4daa5689fd197e57f7ab944beb1d7 (diff)
updated with endpoint list; refined error handling; refined prediction input
Diffstat (limited to 'lib')
-rw-r--r--lib/endpoint.rb23
-rw-r--r--lib/model.rb2
2 files changed, 24 insertions, 1 deletions
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|