From 87cf6e55f76901c340ec99cf216637a2b9672cc2 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 4 Jun 2013 15:06:50 +0200 Subject: JSON API for PagerGroup (new) --- app/controllers/api/v1/pager_groups_controller.rb | 47 +++++++++++++++++++++++ app/controllers/pager_groups_controller.rb | 4 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 app/controllers/api/v1/pager_groups_controller.rb (limited to 'app/controllers') diff --git a/app/controllers/api/v1/pager_groups_controller.rb b/app/controllers/api/v1/pager_groups_controller.rb new file mode 100644 index 0000000..6db9b90 --- /dev/null +++ b/app/controllers/api/v1/pager_groups_controller.rb @@ -0,0 +1,47 @@ +module Api + module V1 + class PagerGroupsController < ApplicationController + respond_to :json + + def index + # if params[:ids] + # @sip_accounts = SipAccount.where(:id => params[:ids]) + # else + # @sip_accounts = SipAccount.all + # end + @pager_groups = PagerGroup.all + + respond_with @pager_groups + end + + def show + @pager_group = PagerGroup.find(params[:id]) + + respond_with @pager_group + end + + + def new + if params[:sip_account_id] && SipAccount.find(params[:sip_account_id]) + @pager_group = SipAccount.find(params[:sip_account_id]).pager_groups.new + @pager_group.callback_url = params[:callback_url] + @pager_group.pager_group_destination_ids = params[:pager_group_destination_ids] + if @pager_group.save + respond_with @pager_group + end + end + + end + + def create + @pager_group = PagerGroup.new(params[:pager_group]) + if @pager_group.save + redirect_to @pager_group, :notice => t('pager_groups.controller.successfuly_created') + else + render :new + end + end + + end + end +end diff --git a/app/controllers/pager_groups_controller.rb b/app/controllers/pager_groups_controller.rb index 4fa21c2..3b145b1 100644 --- a/app/controllers/pager_groups_controller.rb +++ b/app/controllers/pager_groups_controller.rb @@ -1,6 +1,8 @@ class PagerGroupsController < ApplicationController + load_resource :sip_account + load_resource :pager_group, :through => :sip_account + def index - @pager_groups = PagerGroup.all end def show -- cgit v1.2.3