From b24c662df429b65f49c6e72782290c9e977f671a Mon Sep 17 00:00:00 2001 From: rautenberg Date: Wed, 7 Sep 2016 10:30:44 +0200 Subject: add text/csv to get a dataset --- api/api.json | 6 ++++-- lib/dataset.rb | 20 +++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/api/api.json b/api/api.json index 4cd07c7..69369b0 100644 --- a/api/api.json +++ b/api/api.json @@ -199,7 +199,8 @@ "required": true, "type": "string", "enum": [ - "application/json" + "application/json", + "text/csv" ] }, { @@ -207,7 +208,8 @@ } ], "produces": [ - "application/json" + "application/json", + "text/csv" ], "responses": { "200": { diff --git a/lib/dataset.rb b/lib/dataset.rb index ff16640..1468c8d 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -20,14 +20,20 @@ end get "/dataset/:id/?" do dataset = Dataset.find :id => params[:id] resource_not_found_error "Dataset with id: #{params[:id]} not found." unless dataset - dataset.data_entries.each do |k, v| - dataset.data_entries[k][:URI] = uri("/substance/#{k}") + case @accept + when "application/json" + dataset.data_entries.each do |k, v| + dataset.data_entries[k][:URI] = uri("/substance/#{k}") + end + dataset[:URI] = uri("/dataset/#{dataset.id}") + dataset[:substances] = uri("/dataset/#{dataset.id}/substances") + dataset[:features] = uri("/dataset/#{dataset.id}/features") + return dataset.to_json + when "text/csv" + return dataset.to_csv + else + bad_request_error "Mime type #{@accept} is not supported." end - - dataset[:URI] = uri("/dataset/#{dataset.id}") - dataset[:substances] = uri("/dataset/#{dataset.id}/substances") - dataset[:features] = uri("/dataset/#{dataset.id}/features") - return dataset.to_json end # Get a dataset attribute. One of compounds, nanoparticles, substances, features -- cgit v1.2.3