diff options
author | Christoph Helma <helma@in-silico.ch> | 2019-09-03 13:45:36 +0200 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2019-09-03 13:45:36 +0200 |
commit | d1032e4f40d9fbb212e85e0db4f0ecd2e8ac9a88 (patch) | |
tree | 48922d60d750839dacd5d0a4a6e50ea3fe68da63 /lib/feature.rb | |
parent | 5bb4c24c6cfc1ddfae14eb9543b283baae2d75be (diff) | |
parent | a84d9eabf1b921086a688f81df28b0f21ba4df19 (diff) |
development merged, git links in FAQ.md fixed1.4.0
Diffstat (limited to 'lib/feature.rb')
-rw-r--r-- | lib/feature.rb | 29 |
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 |