blob: 332493d7941110c4ebdeca32d05c62794f835110 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# Get all Nanoparticles
get "/nanoparticle/?" do
nanoparticles = Nanoparticle.all
case @accept
when "text/uri-list"
uri_list = nanoparticles.collect{|nanoparticle| uri("/nanoparticle/#{nanoparticle.id}")}
return uri_list.join("\n") + "\n"
when "application/json"
nanoparticles = JSON.parse nanoparticles.to_json
nanoparticles.each_index do |idx|
nanoparticles[idx][:URI] = uri("/nanoparticle/#{nanoparticles[idx]["_id"]["$oid"]}")
end
return nanoparticles.to_json
else
bad_request_error "Mime type #{@accept} is not supported."
end
end
# Get a nanoparticle
get "/nanoparticle/:id/?" do
case @accept
when "application/json"
nanoparticle = Nanoparticle.find :id => params[:id]
not_found_error "Nanoparticle with id: #{params[:id]} not found." unless nanoparticle
nanoparticle[:URI] = uri("/nanoparticle/#{nanoparticle.id}")
return nanoparticle.to_json
else
bad_request_error "Mime type #{@accept} is not supported."
end
end
|