summaryrefslogtreecommitdiff
path: root/lib/endpoint.rb
blob: ef397876ec1480aacba3b44ea1c9d8e6d2d64109 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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