Class: AsteriskManager
- Inherits:
-
Object
- Object
- AsteriskManager
- Defined in:
- lib/asterisk_manager.rb
Overview
AsteriskManager.start(‘host’, ‘user’, ‘secret’) do |asterisk|
asterisk.dial('SIP/123testphone', '7275551212')
end
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(host, port = 5038) ⇒ AsteriskManager
constructor
:host
-
Asterisk host/IP.
-
#originate(channel, extension, options = {}) ⇒ Object
Dials the extension from the channel.
- #ping ⇒ Object
-
#start(host, username, secret, port = 5038) ⇒ Object
TODO: Check authentication response, flag logged in or raise error.
Constructor Details
#initialize(host, port = 5038) ⇒ AsteriskManager
:host
-
Asterisk host/IP.
:port
-
Defaults to 5038
18 19 20 21 |
# File 'lib/asterisk_manager.rb', line 18 def initialize(host, port=5038) @host = host @port = port end |
Class Method Details
.start(host, username, secret, &block) ⇒ Object
25 26 27 |
# File 'lib/asterisk_manager.rb', line 25 def start(host, username, secret, &block) new(host).start(host, username, secret, &block) end |
Instance Method Details
#originate(channel, extension, options = {}) ⇒ Object
Dials the extension from the channel. Required fields are:
:channel
-
Your Asterisk device.
:extension
-
The number to dial.
Options
:context
-
Context
:priority
-
Priority
:caller_id
-
Caller ID
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/asterisk_manager.rb', line 61 def originate(channel, extension, ={}) = {:context => "phones", :priority => 1, :callerid => "Asterisk Automatic Wardial"}.merge() send_action "Originate", { :channel => channel, :context => [:context], :exten => extension, :priority => [:priority], :callerid => [:callerid], } end |
#ping ⇒ Object
48 49 50 |
# File 'lib/asterisk_manager.rb', line 48 def ping send_action "Ping" end |
#start(host, username, secret, port = 5038) ⇒ Object
TODO: Check authentication response, flag logged in or raise error
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/asterisk_manager.rb', line 37 def start(host, username, secret, port=5038) begin @socket = TCPSocket.new(host, port) login(username, secret) return yield(self) ensure logout @socket.close end end |