Class: AsteriskManager::Client
- Inherits:
-
Object
- Object
- AsteriskManager::Client
- Defined in:
- lib/asterisk_manager/client.rb
Overview
Usage:
AsteriskManager::Client.start(‘host’, ‘user’, ‘secret’) do |asterisk|
asterisk.originate('SIP/123testphone', '7275551212')
end
Class Method Summary collapse
-
.start(host, username, secret, port = 5038, &block) ⇒ Object
Convience method for new().start().
Instance Method Summary collapse
-
#dbput(family, key, value) ⇒ Object
Stores the given value for the key in the Asterisk database.
-
#initialize(host, port = 5038) ⇒ Client
constructor
host
-
Asterisk host/IP.
-
#originate(channel, extension, options = {}) ⇒ Object
Dials the extension from the channel.
-
#ping ⇒ Object
Sends the ping command.
-
#start(username, secret, &block) ⇒ Object
TODO: Check authentication response, flag logged in or raise error.
Constructor Details
#initialize(host, port = 5038) ⇒ Client
host
-
Asterisk host/IP.
port
-
Defaults to 5038
18 19 20 21 22 |
# File 'lib/asterisk_manager/client.rb', line 18 def initialize(host, port=5038) @host = host @port = port @socket = TCPSocket.new(@host, @port) end |
Class Method Details
.start(host, username, secret, port = 5038, &block) ⇒ Object
Convience method for new().start()
host
-
Asterisk host/IP.
username
-
Asterisk username.
secret
-
Asterisk secret.
port
-
Defaults to 5038
33 34 35 |
# File 'lib/asterisk_manager/client.rb', line 33 def start(host, username, secret, port=5038, &block) new(host, port).start(username, secret, &block) end |
Instance Method Details
#dbput(family, key, value) ⇒ Object
Stores the given value for the key in the Asterisk database
family
-
Your Asterisk device.
key
-
Your Asterisk device.
value
-
The number to dial.
87 88 89 90 91 92 93 |
# File 'lib/asterisk_manager/client.rb', line 87 def dbput(family, key, value) send_action "DBPut", { :family => family, :key => key, :val => value } end |
#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
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/asterisk_manager/client.rb', line 70 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
Sends the ping command
57 58 59 |
# File 'lib/asterisk_manager/client.rb', line 57 def ping send_action "Ping" end |
#start(username, secret, &block) ⇒ Object
TODO: Check authentication response, flag logged in or raise error
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/asterisk_manager/client.rb', line 44 def start(username, secret, &block) return unless block_given? begin login(username, secret) return yield(self) ensure logout @socket.close end end |