blob: f32d834f0ec76dea82198ca4f853ccf978c41639 (
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
|
# 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
nanoparticle = Nanoparticle.find :id => params[:id]
resource_not_found_error "Nanoparticle with id: #{params[:id]} not found." unless nanoparticle
nanoparticle[:URI] = uri("/nanoparticle/#{nanoparticle.id}")
return nanoparticle.to_json
end
|