diff options
author | rautenberg <rautenberg@in-silico.ch> | 2016-08-30 18:30:36 +0200 |
---|---|---|
committer | rautenberg <rautenberg@in-silico.ch> | 2016-08-30 18:30:36 +0200 |
commit | f96a6cdfed2b41a3262239a125fc8302ec548914 (patch) | |
tree | 8b394d46b427876c0daee9e340365a51563c2c99 | |
parent | c328cc73ff6236cd3f901d003e3d87f22def0c7b (diff) |
add dataset routes to api
-rw-r--r-- | api/api.json | 145 | ||||
-rw-r--r-- | lib/dataset.rb | 17 |
2 files changed, 149 insertions, 13 deletions
diff --git a/api/api.json b/api/api.json index d811f21..f64959c 100644 --- a/api/api.json +++ b/api/api.json @@ -143,6 +143,147 @@ } } }, + "/dataset": { + "get": { + "tags": [ + "dataset" + ], + "description": "Get a list of all datasets", + "parameters": [ + { + "name": "accept", + "in": "header", + "description": "requested Content-Type", + "required": true, + "type": "string", + "enum": [ + "text/uri-list", + "application/json" + ] + } + ], + "produces": [ + "text/uri-list", + "application/json" + ], + "responses": { + "200": { + "$ref": "#/responses/200" + }, + "400": { + "$ref": "#/responses/400" + }, + "401": { + "$ref": "#/responses/401" + }, + "404": { + "$ref": "#/responses/404" + }, + "500": { + "$ref": "#/responses/500" + } + } + } + }, + "/dataset/{id}": { + "get": { + "tags": [ + "dataset" + ], + "description": "Get dataset representation", + "parameters": [ + { + "name": "Content-Type", + "in": "header", + "description": "body Content-Type", + "required": true, + "type": "string", + "enum": [ + "application/json" + ] + }, + { + "$ref": "#/parameters/id" + } + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "$ref": "#/responses/200" + }, + "400": { + "$ref": "#/responses/400" + }, + "401": { + "$ref": "#/responses/401" + }, + "403": { + "$ref": "#/responses/403" + }, + "404": { + "$ref": "#/responses/404" + } + } + } + }, + "/dataset/{id}/{attribute}": { + "get": { + "tags": [ + "dataset" + ], + "description": "Get dataset representation", + "parameters": [ + { + "name": "Content-Type", + "in": "header", + "description": "body Content-Type", + "required": true, + "type": "string", + "enum": [ + "application/json" + ] + }, + { + "name": "attribute", + "in": "path", + "description": "requested attribute", + "required": true, + "type": "string", + "enum": [ + "compounds", + "nanoparticles", + "substances", + "features" + ] + }, + { + "$ref": "#/parameters/id" + } + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "$ref": "#/responses/200" + }, + "400": { + "$ref": "#/responses/400" + }, + "401": { + "$ref": "#/responses/401" + }, + "403": { + "$ref": "#/responses/403" + }, + "404": { + "$ref": "#/responses/404" + } + } + } + }, "/validation": { "get": { "tags": [ @@ -571,6 +712,10 @@ "description": "Compound" }, { + "name": "dataset", + "description": "Dataset" + }, + { "name": "validation", "description": "Validation" } diff --git a/lib/dataset.rb b/lib/dataset.rb index 6ab1c39..75ad238 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -1,6 +1,4 @@ -include OpenTox - -# route to swagger API file +# Get all datasets get "/dataset/?" do datasets = OpenTox::Dataset.all case @accept @@ -18,7 +16,7 @@ get "/dataset/?" do end end - +# Get a dataset get "/dataset/:id/?" do dataset = Dataset.find :id => params[:id] resource_not_found_error "Dataset with id: #{params[:id]} not found." unless dataset @@ -28,19 +26,12 @@ get "/dataset/:id/?" do return dataset.to_json end - +# Get a dataset attribute. One of compounds, nanoparticles, substances, features get "/dataset/:id/:attribute/?" do dataset = Dataset.find :id => params[:id] resource_not_found_error "Dataset with id: #{params[:id]} not found." unless dataset attribs = ["compounds", "nanoparticles", "substances", "features"] - bad_request_error "Attribute #{params[:attribute]} is not availabe. Choose one of #{attribs.join(', ')}" unless attribs.include? params[:attribute] + return "Attribute '#{params[:attribute]}' is not available. Choose one of #{attribs.join(', ')}." unless attribs.include? params[:attribute] out = dataset.send(params[:attribute]) return out.to_json end - - -# d = OpenTox::Dataset.find :id => "57c446d13c58a77ec9baaecf" -# d.data_entries -# d.name d.source -# OpenTox::Substance.find :id => "57c446d23c58a77ec9baaed8" -# OpenTox::Feature.find :id => "57c446d53c58a77ec9bab236"
\ No newline at end of file |