more initial metadata implementation
authorTom Clegg <tom@clinicalfuture.com>
Sat, 5 Jan 2013 23:36:02 +0000 (15:36 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Sat, 5 Jan 2013 23:36:02 +0000 (15:36 -0800)
app/controllers/orvos/v1/metadata_controller.rb
config/routes.rb
public/discovery/v1/apis/orvos/v1/rest

index b7916d84d2623b63dea9814645de87353a49ab4d..51abe5f5768c19fbea69d1227bded61ed244622e 100644 (file)
@@ -1,2 +1,41 @@
-class MetadataController < ApplicationController
+class Orvos::V1::MetadataController < ApplicationController
+  def index
+    @metadata = Collection.all
+    @metadatumlist = {
+      :kind  => "orvos#metadatumList",
+      :etag => "",
+      :self_link => "",
+      :next_page_token => "",
+      :next_link => "",
+      :items => @metadata.map { |x| x }
+    }
+    respond_to do |format|
+      format.json { render json: @metadatumlist }
+    end
+  end
+
+  def show
+    @m = Metadatum.find(params[:id])
+
+    respond_to do |format|
+      format.json { render json: @m }
+    end
+  end
+
+  def create
+    if params[:metadatum].class == String
+      @m = Metadatum.new(JSON.parse(params[:metadatum]))
+    else
+      @m = Metadatum.new(params[:metadatum])
+    end
+    respond_to do |format|
+      if @m.save
+        format.html { redirect_to @m, notice: 'Metadatum was successfully created.' }
+        format.json { render json: @m, status: :created, location: @m }
+      else
+        format.html { render action: "new" }
+        format.json { render json: @m.errors, status: :unprocessable_entity }
+      end
+    end
+  end
 end
index b292fd38bdab77e05ef8e40e25602ec4b27bceca..59c1e6e4584fe16279eeb97d4223008315c381e4 100644 (file)
@@ -1,7 +1,6 @@
 Server::Application.routes.draw do
-  resources :metadata
-
   resources :collections
+  resources :metadata
 
   # The priority is based upon order of creation:
   # first created -> highest priority.
@@ -63,6 +62,7 @@ Server::Application.routes.draw do
   namespace :orvos do
     namespace :v1 do
       resources :collections
+      resources :metadata
     end
   end
 
index a914f0e90a1158f2ec7a0074613233c1374bb32e..a08bb37bcfa0927f39518b641d20db0fa7df6c30 100644 (file)
     }
    }
   },
+  "metadata": {
+   "methods": {
+    "create": {
+     "id": "orvos.metadata.create",
+     "path": "metadata",
+     "httpMethod": "POST",
+     "description": "Create a new metadata object.",
+     "parameters": {
+      "metadatum": {
+       "required": true,
+       "location": "query",
+       "properties": {
+        "metadata_class": {
+         "type": "string",
+         "description": "Metadata class.",
+         "required": true
+        },
+        "key": {
+         "type": "string",
+         "description": "Metadata key.",
+         "required": true
+        },
+        "value": {
+         "type": "string",
+         "description": "Metadata value.",
+         "required": true
+        }
+       }
+      }
+     },
+     "request": {
+      "$ref": "Metadatum"
+     },
+     "response": {
+      "$ref": "Metadatum"
+     },
+     "scopes": [
+      "https://api.clinicalfuture.com/auth/orvos",
+      "https://api.clinicalfuture.com/auth/orvos.metadatum"
+     ]
+    },
+    "list": {
+     "id": "orvos.metadata.list",
+     "path": "metadata",
+     "httpMethod": "GET",
+     "description": "Lists metadata objects.",
+     "parameters": {
+      "maxResults": {
+       "type": "integer",
+       "description": "Maximum number of metadata objects to return.",
+       "default": "100",
+       "format": "int32",
+       "minimum": "0",
+       "location": "query"
+      },
+      "pageToken": {
+       "type": "string",
+       "description": "Page token for metadata objects.",
+       "location": "query"
+      },
+      "q": {
+       "type": "string",
+       "description": "Query string for searching metadata.",
+       "location": "query"
+      }
+     },
+     "response": {
+      "$ref": "MetadatumList"
+     },
+     "scopes": [
+      "https://api.clinicalfuture.com/auth/orvos",
+      "https://api.clinicalfuture.com/auth/orvos.metadatum",
+      "https://api.clinicalfuture.com/auth/orvos.metadatum.readonly",
+      "https://api.clinicalfuture.com/auth/orvos.readonly"
+     ]
+    }
+   }
+  },
   "collections": {
    "methods": {
     "copy": {