summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/call.rb39
-rw-r--r--app/models/sip_account.rb2
2 files changed, 38 insertions, 3 deletions
diff --git a/app/models/call.rb b/app/models/call.rb
index c0f0f08..db6d9d6 100644
--- a/app/models/call.rb
+++ b/app/models/call.rb
@@ -1,9 +1,31 @@
class Call < ActiveRecord::Base
self.table_name = 'detailed_calls'
self.primary_key = 'uuid'
+
+ attr_writer :sip_account_id
+
+ validates :dest,
+ :presence => true
- def readonly?
- return true
+ def create(attributes=nil)
+ if ! attributes
+ return
+ end
+
+ self.sip_account = SipAccount.where(:id => attributes[:sip_account_id]).first
+ self.dest = attributes[:dest]
+ return self
+ end
+
+ def save(attributes=nil)
+
+ end
+
+ def call(number=nil)
+ if @sip_account && self.dest
+ return @sip_account.call(self.dest)
+ end
+ return false
end
def destroy
@@ -15,15 +37,25 @@ class Call < ActiveRecord::Base
return FreeswitchAPI.execute('uuid_kill', self.uuid, true);
end
+ def sip_account=(sip_a)
+ @sip_account = sip_a
+ end
+
def sip_account
+ if @sip_account
+ return @sip_account
+ end
+
result = self.presence_id.match('^(.+)@(.+)$')
if result && ! result[1].blank? and ! result[2].blank?
domain = SipDomain.where(:host => result[2]).first
if domain
- return SipAccount.where(:auth_name => result[1], :sip_domain_id => domain.id).first
+ @sip_account = SipAccount.where(:auth_name => result[1], :sip_domain_id => domain.id).first
end
end
+
+ return @sip_account
end
def sip_account_bleg
@@ -69,4 +101,5 @@ class Call < ActiveRecord::Base
true
end
end
+
end
diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb
index 034af7c..2040b41 100644
--- a/app/models/sip_account.rb
+++ b/app/models/sip_account.rb
@@ -38,6 +38,8 @@ class SipAccount < ActiveRecord::Base
has_many :ringtones, :as => :ringtoneable, :dependent => :destroy
+ has_many :calls, :finder_sql => lambda { |s| "SELECT DISTINCT detailed_calls.* FROM detailed_calls WHERE presence_id LIKE '#{self.auth_name}@%'" }
+
# Delegations:
#
delegate :host, :to => :sip_domain, :allow_nil => true