Project

General

Profile

Download (2.21 KB) Statistics
| Branch: | Tag: | Revision:
e1a1fa81 Joseph Mitchell Magen
module Api
module V2
dc38aad3 Joseph Magen
class SmartProxiesController < V2::BaseController
e1a1fa81 Joseph Mitchell Magen
include Api::Version2
include Api::TaxonomyScope
dc38aad3 Joseph Magen
include Api::ImportPuppetclassesCommonController
before_filter :find_resource, :only => %w{show update destroy refresh}

api :GET, "/smart_proxies/", "List all smart_proxies."
d4dff460 Joseph Magen
param :search, String, :desc => "Filter results"
param :order, String, :desc => "Sort results"
dc38aad3 Joseph Magen
param :page, String, :desc => "paginate results"
param :per_page, String, :desc => "number of entries per request"
e1a1fa81 Joseph Mitchell Magen
def index
d4dff460 Joseph Magen
@smart_proxies = SmartProxy.authorized(:view_smart_proxies).includes(:features).
search_for(*search_options).paginate(paginate_options)
@total = SmartProxy.authorized(:view_smart_proxies).includes(:features).count
e1a1fa81 Joseph Mitchell Magen
end

dc38aad3 Joseph Magen
api :GET, "/smart_proxies/:id/", "Show a smart proxy."
param :id, :identifier, :required => true

e1a1fa81 Joseph Mitchell Magen
def show
dc38aad3 Joseph Magen
end

2be84f3d Joseph Magen
def_param_group :smart_proxy do
param :smart_proxy, Hash, :action_aware => true do
param :name, String, :required => true
param :url, String, :required => true
end
dc38aad3 Joseph Magen
end

2be84f3d Joseph Magen
api :POST, "/smart_proxies/", "Create a smart proxy."
param_group :smart_proxy, :as => :create

dc38aad3 Joseph Magen
def create
@smart_proxy = SmartProxy.new(params[:smart_proxy])
process_response @smart_proxy.save
end

api :PUT, "/smart_proxies/:id/", "Update a smart proxy."
param :id, String, :required => true
2be84f3d Joseph Magen
param_group :smart_proxy
dc38aad3 Joseph Magen
def update
process_response @smart_proxy.update_attributes(params[:smart_proxy])
end

api :DELETE, "/smart_proxies/:id/", "Delete a smart_proxy."
param :id, String, :required => true

def destroy
process_response @smart_proxy.destroy
end

api :PUT, "/smart_proxies/:id/refresh", "Refresh smart proxy features"
param :id, String, :required => true

def refresh
process_response @smart_proxy.refresh.blank? && @smart_proxy.save
end

private
acfbc458 Marek Hulan
def action_permission
case params[:action]
when 'refresh'
:edit
else
super
end
dc38aad3 Joseph Magen
end

e1a1fa81 Joseph Mitchell Magen
end
end
end