include "href" key for each object in API response
authorTom Clegg <tom@clinicalfuture.com>
Mon, 4 Nov 2013 22:17:01 +0000 (14:17 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Mon, 4 Nov 2013 22:17:01 +0000 (14:17 -0800)
services/api/app/controllers/application_controller.rb
services/api/app/models/arvados_model.rb
services/api/lib/common_api_template.rb
services/api/lib/current_api_client.rb

index 0c7578a01577f961bce9b8f46f4fc4841acd3f3d..9878547f30002fd7d319e3e40fb787b5228918bf 100644 (file)
@@ -37,7 +37,9 @@ class ApplicationController < ActionController::Base
   end
 
   def update
-    attrs_to_update = resource_attrs.reject { |k,v| [:kind,:etag].index k }
+    attrs_to_update = resource_attrs.reject { |k,v|
+      [:kind, :etag, :href].index k
+    }
     if @object.update_attributes attrs_to_update
       show
     else
@@ -238,6 +240,7 @@ class ApplicationController < ActionController::Base
   end
 
   def thread_with_auth_info
+    Thread.current[:api_url_base] = root_url.sub(/\/$/,'') + '/arvados/v1'
     begin
       user = nil
       api_client = nil
index ec99c9efb90a920b24652b044e1815981703232a..136684d009d533791172f6969ea9e326836e0633 100644 (file)
@@ -22,6 +22,10 @@ class ArvadosModel < ActiveRecord::Base
     kind.match(/^arvados\#(.+?)(_list|List)?$/)[1].pluralize.classify.constantize rescue nil
   end
 
+  def href
+    "#{current_api_base}/#{self.class.to_s.pluralize.underscore}/#{self.uuid}"
+  end
+
   def eager_load_associations
     self.class.columns.each do |col|
       re = col.name.match /^(.*)_kind$/
index 7b7478e25ba04609fad19055ef4349e46277646e..5426d13c2375fc9560e9ecadb275029068dd85fb 100644 (file)
@@ -3,6 +3,7 @@ module CommonApiTemplate
     base.extend(ClassMethods)
     base.acts_as_api
     base.api_accessible :common do |t|
+      t.add :href
       t.add :kind
       t.add :etag
       t.add :uuid
index 3f595af8b5fb6047c43da6e0ee64497ccd4c5948..d2421d2d6d181ee396193d3eb73bb1b20d7c5494 100644 (file)
@@ -11,6 +11,10 @@ module CurrentApiClient
     Thread.current[:api_client_authorization]
   end
 
+  def current_api_base
+    Thread.current[:api_url_base]
+  end
+
   def current_default_owner
     # owner_uuid for newly created objects
     ((current_api_client_authorization &&