summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-03-14 03:47:54 -0400
committerPeter Kozak <spag@golwen.net>2013-03-14 03:47:54 -0400
commit0840ee7eb193d838724de7227b19824abd5b2bf3 (patch)
tree33113fe8e6b9c3d255e7569cb96655d78965f653
parenta14a948cce2380ecf5d15d92dad2324ea8d24c65 (diff)
gateway status methods
-rw-r--r--app/models/gateway.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/models/gateway.rb b/app/models/gateway.rb
index 2f17b57..bf391fb 100644
--- a/app/models/gateway.rb
+++ b/app/models/gateway.rb
@@ -27,7 +27,34 @@ class Gateway < ActiveRecord::Base
"#{GATEWAY_PREFIX}#{self.id}"
end
+ def status
+ if self.technology == 'sip' then
+ return status_sip
+ end
+ end
+
+ def inbound_register
+ username = self.gateway_settings.where(:name => 'inbound_username').first.try(:value)
+ if username.blank?
+ return
+ end
+
+ return SipRegistration.where(:sip_user => username).first
+ end
+
private
+ def status_sip
+ require 'freeswitch_event'
+ result = FreeswitchAPI.api_result(FreeswitchAPI.api('sofia', 'xmlstatus', 'gateway', "gateway#{self.id}"))
+ if result =~ /^\<\?xml/
+ data = Hash.from_xml(result)
+ if data
+ return data.fetch('gateway', nil)
+ end
+ end
+ return nil
+ end
+
def downcase_technology
self.technology = self.technology.downcase if !self.technology.blank?
end