diff options
author | Peter Kozak <spag@golwen.net> | 2013-03-13 06:49:01 -0400 |
---|---|---|
committer | Peter Kozak <spag@golwen.net> | 2013-03-13 06:49:01 -0400 |
commit | 56bf23a88b1397d8648a18a32770b32c084aa017 (patch) | |
tree | d4fd980444a66d22602c6083d99a60aa95be65bf | |
parent | a489e08d92e4266de08719b61c0dd4458b3334c8 (diff) |
api methods added
-rw-r--r-- | lib/freeswitch_event.rb | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/lib/freeswitch_event.rb b/lib/freeswitch_event.rb index 68d9df2..6745bef 100644 --- a/lib/freeswitch_event.rb +++ b/lib/freeswitch_event.rb @@ -103,8 +103,41 @@ class FreeswitchEvent end class FreeswitchAPI - def self.execute(command, arguments, bgapi = false) + def self.api_result(result) + if not result + return nil + end + + if result['Content-Type'] == 'api/response' + if result['_BODY'].blank? + return nil + elsif result['_BODY'] =~ /^\+OK/ + return true + elsif result['_BODY'] =~ /^\-ERR/ + return false + else + return result['_BODY'] + end + end + + return nil + end + def self.api(command, *arguments) + event = FreeswitchEventSocket.new() + if event && event.connect() + event.command("api #{command} #{arguments.join(' ')}") + result = event.result() + content_length = result['Content-Length'].to_i + if content_length > 0 && result['_BODY'].blank? + result['_BODY'] = event.read(content_length); + end + event.close() + return result + end + end + + def self.execute(command, arguments, bgapi = false) event = FreeswitchEventSocket.new() if event && event.connect() api = bgapi ? 'bgapi' : 'api' |