From acedca207179925286810dd9c2ad7934ce5bfe69 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Mon, 4 Nov 2013 14:17:01 -0800 Subject: [PATCH] include "href" key for each object in API response --- services/api/app/controllers/application_controller.rb | 5 ++++- services/api/app/models/arvados_model.rb | 4 ++++ services/api/lib/common_api_template.rb | 1 + services/api/lib/current_api_client.rb | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb index 0c7578a015..9878547f30 100644 --- a/services/api/app/controllers/application_controller.rb +++ b/services/api/app/controllers/application_controller.rb @@ -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 diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb index ec99c9efb9..136684d009 100644 --- a/services/api/app/models/arvados_model.rb +++ b/services/api/app/models/arvados_model.rb @@ -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$/ diff --git a/services/api/lib/common_api_template.rb b/services/api/lib/common_api_template.rb index 7b7478e25b..5426d13c23 100644 --- a/services/api/lib/common_api_template.rb +++ b/services/api/lib/common_api_template.rb @@ -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 diff --git a/services/api/lib/current_api_client.rb b/services/api/lib/current_api_client.rb index 3f595af8b5..d2421d2d6d 100644 --- a/services/api/lib/current_api_client.rb +++ b/services/api/lib/current_api_client.rb @@ -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 && -- 2.30.2