Sha256: 2e3be001f31b20ea8f6bd73cc650e746bdd4a91fb1d007eacfd397f059bc8643
Contents?: true
Size: 1.67 KB
Versions: 5
Compression:
Stored size: 1.67 KB
Contents
module Api module V2 class HostgroupClassesController < V2::BaseController include Api::Version2 include Api::TaxonomyScope before_filter :find_hostgroup_id, :only => [:index, :create, :destroy] api :GET, "/hostgroups/:hostgroup_id/puppetclass_ids/", "List all puppetclass id's for hostgroup" def index render :json => HostgroupClass.where(:hostgroup_id => hostgroup_id).pluck('puppetclass_id') end api :POST, "/hostgroups/:hostgroup_id/puppetclass_ids", "Add a puppetclass to hostgroup" param :hostgroup_id, String, :required => true, :desc => "id of hostgroup" param :puppetclass_id, String, :required => true, :desc => "id of puppetclass" def create @hostgroup_class = HostgroupClass.create!(:hostgroup_id => hostgroup_id, :puppetclass_id => params[:puppetclass_id].to_i) render :json => {:hostgroup_id => @hostgroup_class.hostgroup_id, :puppetclass_id => @hostgroup_class.puppetclass_id} end api :DELETE, "/hostgroups/:hostgroup_id/puppetclass_ids/:id/", "Remove a puppetclass from hostgroup" param :hostgroup_id, String, :required => true, :desc => "id of hostgroup" param :puppetclass_id, String, :required => true, :desc => "id of puppetclass" def destroy @hostgroup_class = HostgroupClass.where(:hostgroup_id => @hostgroup_id, :puppetclass_id => params[:id]) process_response @hostgroup_class.destroy_all end private attr_reader :hostgroup_id # params[:hostgroup_id] is "id-to_label.parameterize" and .to_i returns the id def find_hostgroup_id @hostgroup_id = params[:hostgroup_id].to_i end end end end
Version data entries
5 entries across 5 versions & 1 rubygems