summaryrefslogtreecommitdiff
path: root/lib/feature.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/feature.rb')
-rw-r--r--lib/feature.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/feature.rb b/lib/feature.rb
new file mode 100644
index 0000000..3123997
--- /dev/null
+++ b/lib/feature.rb
@@ -0,0 +1,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