Class: AsteriskManager

Inherits:
Object
  • Object
show all
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

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, options={})
  options = {:context => "phones", :priority => 1, :callerid => "Asterisk Automatic Wardial"}.merge(options)
  send_action "Originate", {
    :channel  => channel,
    :context  => options[:context],
    :exten    => extension,
    :priority => options[:priority],
    :callerid => options[:callerid],
  }
end

#pingObject



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)
    (username, secret)
    return yield(self)
  ensure
    logout
    @socket.close
  end
end