summaryrefslogtreecommitdiff
path: root/app/models/call.rb
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-03-07 03:11:28 -0500
committerPeter Kozak <spag@golwen.net>2013-03-07 03:11:28 -0500
commit2964ebf277568536ac215f3a651e1841a73d68f8 (patch)
tree0f372f8edadc75cebac9b9aca41920f46237ee83 /app/models/call.rb
parentc98072557273ff4383013f73621061ece34fc6d2 (diff)
call origination fixed
Diffstat (limited to 'app/models/call.rb')
-rw-r--r--app/models/call.rb76
1 files changed, 18 insertions, 58 deletions
diff --git a/app/models/call.rb b/app/models/call.rb
index b0cd9b2..8f657fa 100644
--- a/app/models/call.rb
+++ b/app/models/call.rb
@@ -2,29 +2,31 @@ class Call < ActiveRecord::Base
self.table_name = 'calls_active'
self.primary_key = 'uuid'
- attr_writer :sip_account_id
+ belongs_to :sip_account
+ belongs_to :b_sip_account, :class_name => SipAccount
- validates :dest,
+ validates :sip_account_id,
:presence => 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
+ validates :destination,
+ :presence => true
+
+ def save(attributes=nil)
end
- def save(attributes=nil)
-
- end
+ def call
+ if self.sip_account && self.destination
+ return self.sip_account.call(self.destination)
+ end
- def call(number=nil)
- if @sip_account && self.dest
- return @sip_account.call(self.dest)
+ if !self.sip_account
+ errors.add(:sip_account_id, 'no sip_account')
end
+
+ if self.destination.blank?
+ errors.add(:destination, 'no destination')
+ end
+
return false
end
@@ -37,38 +39,6 @@ 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
- @sip_account = SipAccount.where(:auth_name => result[1], :sip_domain_id => domain.id).first
- end
- end
-
- return @sip_account
- end
-
- def sip_account_bleg
- result = self.b_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
- end
- end
- end
-
def get_variable_from_uuid(channel_uuid, variable_name)
if channel_uuid.blank?
return nil
@@ -92,14 +62,4 @@ class Call < ActiveRecord::Base
return get_variable_from_uuid(self.b_uuid, variable_name);
end
- def is_sip
- return self.name.match('^sofia') != nil
- end
-
- def is_caller
- if (self.uuid == self.call_uuid) || self.call_uuid.blank?
- true
- end
- end
-
end