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 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/endpoint.rb (limited to 'lib/endpoint.rb') 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 -- cgit v1.2.3 From 741701df8ff0861b3607a30e9aaf8b8a0c303cdf Mon Sep 17 00:00:00 2001 From: gebele Date: Thu, 13 Jun 2019 15:28:59 +0000 Subject: update with API --- lib/endpoint.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/endpoint.rb') diff --git a/lib/endpoint.rb b/lib/endpoint.rb index ef39787..66b7ab2 100644 --- a/lib/endpoint.rb +++ b/lib/endpoint.rb @@ -1,7 +1,7 @@ # 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 +get "/api/endpoint/?" do models = Model::Validation.all endpoints = models.collect{|m| m.endpoint}.uniq case @accept @@ -10,14 +10,14 @@ get "/endpoint/?" do when "application/json" return endpoints.to_json else - bad_request_error "Mime type #{@accept} is not supported." + halt 400, "Mime type #{@accept} is not supported." end end -get "/endpoint/:endpoint/?" do +get "/api/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? + models.each{|m| list << {m.species => uri("/api/model/#{m.id}")} } + halt 404, "Endpoint: #{params[:endpoint]} not found." if models.blank? return list.to_json end -- cgit v1.2.3