summaryrefslogtreecommitdiff
path: root/app/models/pager_group.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-06-20 19:06:19 +0200
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-06-20 19:06:19 +0200
commiteb0e1cc5c26275ff3e5c341404e8bc558f8312b8 (patch)
tree71f449ccd6f15422717de3ac24f87d5e888ddd79 /app/models/pager_group.rb
parentdf6e17e48995f25e72509986f30700d778b179b6 (diff)
parent3b27a5d45b12f6bac65da2a8e17387bfda42a2f1 (diff)
Merge branch 'develop'
Diffstat (limited to 'app/models/pager_group.rb')
-rw-r--r--app/models/pager_group.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/app/models/pager_group.rb b/app/models/pager_group.rb
new file mode 100644
index 0000000..5c91ed8
--- /dev/null
+++ b/app/models/pager_group.rb
@@ -0,0 +1,36 @@
+class PagerGroup < ActiveRecord::Base
+ attr_accessible :sip_account_id, :callback_url
+ attr_writer :pager_group_destination_ids
+
+ has_many :pager_group_destinations, :dependent => :destroy
+ belongs_to :sip_account
+
+ validates_presence_of :sip_account_id
+
+ after_create :call
+ before_destroy :hangup_all
+
+ before_save :save_pager_group_destination_ids
+
+ def save_pager_group_destination_ids
+ if @pager_group_destination_ids
+ self.pager_group_destination_ids = @pager_group_destination_ids.split(/,/).map { |sip_account_id| self.pager_group_destinations.build(:sip_account_id => sip_account_id) }
+ end
+ end
+
+ def identifier
+ "pager#{self.id}"
+ end
+
+ def call
+ self.sip_account.call("f-pager-#{self.id}")
+ end
+
+ def hangup_all
+ require 'freeswitch_event'
+ return FreeswitchAPI.execute(
+ 'conference', "#{self.identifier} hup all",
+ true
+ );
+ end
+end