From cea2cc3c1cc1e48fc4600c698d52dfda2bde4505 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Wed, 3 Apr 2013 22:08:19 +0200 Subject: Massive changes to the switchboard. --- app/controllers/api/v1/phone_numbers_controller.rb | 23 ++++++++++++++++++++++ app/controllers/api/v1/sip_accounts_controller.rb | 23 ++++++++++++++++++++++ .../api/v1/switchboard_entries_controller.rb | 23 ++++++++++++++++++++++ app/controllers/api/v1/switchboards_controller.rb | 21 ++++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 app/controllers/api/v1/phone_numbers_controller.rb create mode 100644 app/controllers/api/v1/sip_accounts_controller.rb create mode 100644 app/controllers/api/v1/switchboard_entries_controller.rb create mode 100644 app/controllers/api/v1/switchboards_controller.rb (limited to 'app/controllers/api/v1') diff --git a/app/controllers/api/v1/phone_numbers_controller.rb b/app/controllers/api/v1/phone_numbers_controller.rb new file mode 100644 index 0000000..ff58fd3 --- /dev/null +++ b/app/controllers/api/v1/phone_numbers_controller.rb @@ -0,0 +1,23 @@ +module Api + module V1 + class PhoneNumbersController < ApplicationController + respond_to :json + + def index + if params[:ids] + @phone_numbers = PhoneNumber.where(:id => params[:ids]) + else + @phone_numbers = PhoneNumber.all + end + + respond_with @phone_numbers + end + + def show + @phone_number = PhoneNumber.find(params[:id]) + + respond_with @phone_number + end + end + end +end diff --git a/app/controllers/api/v1/sip_accounts_controller.rb b/app/controllers/api/v1/sip_accounts_controller.rb new file mode 100644 index 0000000..6f305a4 --- /dev/null +++ b/app/controllers/api/v1/sip_accounts_controller.rb @@ -0,0 +1,23 @@ +module Api + module V1 + class SipAccountsController < ApplicationController + respond_to :json + + def index + if params[:ids] + @sip_accounts = SipAccount.where(:id => params[:ids]) + else + @sip_accounts = SipAccount.all + end + + respond_with @sip_accounts + end + + def show + @sip_account = SipAccount.find(params[:id]) + + respond_with @sip_account + end + end + end +end diff --git a/app/controllers/api/v1/switchboard_entries_controller.rb b/app/controllers/api/v1/switchboard_entries_controller.rb new file mode 100644 index 0000000..688f108 --- /dev/null +++ b/app/controllers/api/v1/switchboard_entries_controller.rb @@ -0,0 +1,23 @@ +module Api + module V1 + class SwitchboardEntriesController < ApplicationController + respond_to :json + + def index + if params[:ids] + @switchboard_entries = SwitchboardEntry.where(:id => params[:ids]) + else + @switchboard_entries = SwitchboardEntry.all + end + + respond_with @switchboard_entries + end + + def show + @switchboard_entry = SwitchboardEntry.find(params[:id]) + + respond_with @switchboard_entry + end + end + end +end \ No newline at end of file diff --git a/app/controllers/api/v1/switchboards_controller.rb b/app/controllers/api/v1/switchboards_controller.rb new file mode 100644 index 0000000..e6996ca --- /dev/null +++ b/app/controllers/api/v1/switchboards_controller.rb @@ -0,0 +1,21 @@ +module Api + module V1 + class SwitchboardsController < ApplicationController + respond_to :json + + def index + @user = current_user + @switchboards = @user.switchboards + + respond_with @switchboards + end + + def show + @user = current_user + @switchboard = @user.switchboards.find(params[:id]) + + respond_with @switchboard + end + end + end +end -- cgit v1.2.3 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 +++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 app/controllers/api/v1/pager_groups_controller.rb (limited to 'app/controllers/api/v1') 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 -- cgit v1.2.3 From 7a5a635a93e0803569d1107d2a64cfaa081d6743 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 4 Jun 2013 15:25:25 +0200 Subject: skip_before_filter :verify_authenticity_token --- app/controllers/api/v1/pager_groups_controller.rb | 25 +++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'app/controllers/api/v1') diff --git a/app/controllers/api/v1/pager_groups_controller.rb b/app/controllers/api/v1/pager_groups_controller.rb index 6db9b90..468a6aa 100644 --- a/app/controllers/api/v1/pager_groups_controller.rb +++ b/app/controllers/api/v1/pager_groups_controller.rb @@ -3,6 +3,8 @@ module Api class PagerGroupsController < ApplicationController respond_to :json + skip_before_filter :verify_authenticity_token + def index # if params[:ids] # @sip_accounts = SipAccount.where(:id => params[:ids]) @@ -20,7 +22,6 @@ module Api 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 @@ -33,14 +34,20 @@ module Api 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 + # 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 + + def destroy + @pager_group = PagerGroup.find(params[:id]) + @pager_group.destroy + respond_with nil + end end end -- cgit v1.2.3 From 98e9aa73e258391bd2eaf935cf00d91d91546801 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 4 Jun 2013 15:53:09 +0200 Subject: Added destroy to the API --- app/controllers/api/v1/pager_groups_controller.rb | 25 +++++------------------ 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'app/controllers/api/v1') diff --git a/app/controllers/api/v1/pager_groups_controller.rb b/app/controllers/api/v1/pager_groups_controller.rb index 468a6aa..753e938 100644 --- a/app/controllers/api/v1/pager_groups_controller.rb +++ b/app/controllers/api/v1/pager_groups_controller.rb @@ -1,24 +1,16 @@ module Api module V1 class PagerGroupsController < ApplicationController - respond_to :json - skip_before_filter :verify_authenticity_token + 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 @@ -34,19 +26,12 @@ module Api 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 - def destroy @pager_group = PagerGroup.find(params[:id]) - @pager_group.destroy - respond_with nil + if @pager_group + @pager_group.destroy + respond_with @pager_group + end end end -- cgit v1.2.3