From 9f0425e75ee9b29b2567b6717b5ddd5c02e285f1 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Sun, 13 Jan 2013 12:17:44 -0800 Subject: [PATCH] use acts_as_api --- Gemfile | 2 ++ Gemfile.lock | 5 +++++ app/controllers/application_controller.rb | 4 ++-- app/controllers/orvos/v1/nodes_controller.rb | 4 ---- app/models/node.rb | 18 ++++++++++++++++++ 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 6a2cd9c646..67b74a9f8a 100644 --- a/Gemfile +++ b/Gemfile @@ -37,3 +37,5 @@ gem 'jquery-rails' # gem 'ruby-debug' gem 'rvm-capistrano', :group => :test + +gem 'acts_as_api' diff --git a/Gemfile.lock b/Gemfile.lock index 9b6c5690c5..b081b16792 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,6 +29,10 @@ GEM activesupport (= 3.1.5) activesupport (3.1.5) multi_json (>= 1.0, < 1.3) + acts_as_api (0.4.1) + activemodel (>= 3.0.0) + activesupport (>= 3.0.0) + rack (>= 1.1.0) arel (2.2.3) builder (3.0.4) capistrano (2.14.1) @@ -127,6 +131,7 @@ PLATFORMS ruby DEPENDENCIES + acts_as_api coffee-rails (~> 3.1.1) jquery-rails json diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 493db3cc1b..e9d715b653 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -38,7 +38,7 @@ class ApplicationController < ActionController::Base end def show - render json: @object + render_for_api :superuser, json: @object end def create @@ -123,7 +123,7 @@ class ApplicationController < ActionController::Base :self_link => "", :next_page_token => "", :next_link => "", - :items => @objects.map { |x| x } + :items => @objects.as_api_response(:superuser) } render json: @object_list end diff --git a/app/controllers/orvos/v1/nodes_controller.rb b/app/controllers/orvos/v1/nodes_controller.rb index 90a236af45..4629d969a8 100644 --- a/app/controllers/orvos/v1/nodes_controller.rb +++ b/app/controllers/orvos/v1/nodes_controller.rb @@ -6,10 +6,6 @@ class Orvos::V1::NodesController < ApplicationController show end - def show - render json: @object.to_json - end - def ping @object.ping({ ip: params[:local_ipv4] || request.env['REMOTE_ADDR'], ping_secret: params[:ping_secret], diff --git a/app/models/node.rb b/app/models/node.rb index 044035294d..67a14384c6 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -15,6 +15,24 @@ class Node < ActiveRecord::Base end @@domain = Rails.configuration.compute_node_domain rescue `hostname --domain`.strip + acts_as_api + api_accessible :superuser do |t| + t.add :uuid + t.add :created_by_client + t.add :created_by_user + t.add :created_at + t.add :modified_by_client + t.add :modified_by_user + t.add :modified_at + t.add :hostname + t.add :domain + t.add :ip_address + t.add :first_ping_at + t.add :last_ping_at + t.add :info + t.add :updated_at + end + def info @info ||= Hash.new super -- 2.39.5