summaryrefslogtreecommitdiff
path: root/lib/feature.rb
blob: 312399789c90de64924d6c3e0e5c22a82e1620af (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
# Get all Features
get "/api/feature/?" do
  features = Feature.all
  case @accept
  when "text/uri-list"
    uri_list = features.collect{|feature| uri("/feature/#{feature.id}")}
    return uri_list.join("\n") + "\n"
  when "application/json"
    features = JSON.parse features.to_json
    list = []
    features.each{|f| list << uri("/feature/#{f["_id"]["$oid"]}")}
    return list.to_json
  else
    bad_request_error "Mime type #{@accept} is not supported."
  end
end

# Get a feature
get "/api/feature/:id/?" do
  case @accept
  when "application/json"
    feature = Feature.find :id => params[:id]
    not_found_error "Feature with id: #{params[:id]} not found." unless feature
    feature[:URI] = uri("/feature/#{feature.id}")
    return feature.to_json
  else
    bad_request_error "Mime type #{@accept} is not supported."
  end
end