class RubyAsterisk::AMI
Ruby-asterisk main classes
Attributes
connected[RW]
host[RW]
port[RW]
timeout[RW]
wait_time[RW]
Public Class Methods
new(host, port)
click to toggle source
# File lib/ruby-asterisk.rb, line 14 def initialize(host, port) self.host = host.to_s self.port = port.to_i self.connected = false @timeout = 5 @wait_time = 0.1 @session = nil end
Public Instance Methods
atxfer(channel, exten, context, priority = '1')
click to toggle source
# File lib/ruby-asterisk.rb, line 182 def atxfer(channel, exten, context, priority = '1') execute 'Atxfer', {'Channel' => channel, 'Exten' => exten.to_s, 'Context' => context, 'Priority' => priority} end
change_monitor(channel,file)
click to toggle source
# File lib/ruby-asterisk.rb, line 207 def change_monitor(channel,file) execute 'ChangeMonitor', {'Channel' => channel, 'File' => file} end
channels()
click to toggle source
# File lib/ruby-asterisk.rb, line 117 def channels execute 'Command', { 'Command' => 'show channels' } end
command(command)
click to toggle source
# File lib/ruby-asterisk.rb, line 52 def command(command) execute 'Command', {'Command' => command} end
confbridge(conference)
click to toggle source
# File lib/ruby-asterisk.rb, line 68 def confbridge(conference) execute 'ConfbridgeList', {'Conference' => conference} end
confbridge_kick(conference, channel)
click to toggle source
# File lib/ruby-asterisk.rb, line 80 def confbridge_kick(conference, channel) execute 'ConfbridgeKick', {'Conference' => conference, 'Channel' => channel} end
confbridge_mute(conference, channel)
click to toggle source
# File lib/ruby-asterisk.rb, line 72 def confbridge_mute(conference, channel) execute 'ConfbridgeMute', {'Conference' => conference, 'Channel' => channel} end
confbridge_unmute(conference, channel)
click to toggle source
# File lib/ruby-asterisk.rb, line 76 def confbridge_unmute(conference, channel) execute 'ConfbridgeUnmute', {'Conference' => conference, 'Channel' => channel} end
confbridges()
click to toggle source
# File lib/ruby-asterisk.rb, line 64 def confbridges execute 'ConfbridgeListRooms' end
connect()
click to toggle source
# File lib/ruby-asterisk.rb, line 23 def connect begin @session = Net::Telnet::new('Host' => self.host, 'Port' => self.port, 'Timeout' => 10) self.connected = true rescue Exception => ex false end end
core_show_channels()
click to toggle source
# File lib/ruby-asterisk.rb, line 56 def core_show_channels execute 'CoreShowChannels' end
device_state_list()
click to toggle source
# File lib/ruby-asterisk.rb, line 92 def device_state_list execute 'DeviceStateList' end
disconnect()
click to toggle source
# File lib/ruby-asterisk.rb, line 32 def disconnect begin @session.close if self.connected self.connected = false true rescue Exception => ex puts ex false end end
event_mask(event_mask='off')
click to toggle source
# File lib/ruby-asterisk.rb, line 166 def event_mask(event_mask='off') execute 'Events', {'EventMask' => event_mask} end
extension_state(exten, context, action_id = nil)
click to toggle source
# File lib/ruby-asterisk.rb, line 88 def extension_state(exten, context, action_id = nil) execute 'ExtensionState', {'Exten' => exten, 'Context' => context, 'ActionID' => action_id} end
hangup(channel)
click to toggle source
# File lib/ruby-asterisk.rb, line 178 def hangup(channel) execute 'Hangup', {'Channel' => channel} end
login(username, password)
click to toggle source
# File lib/ruby-asterisk.rb, line 43 def login(username, password) self.connect unless self.connected execute 'Login', {'Username' => username, 'Secret' => password, 'Event' => 'On'} end
logoff()
click to toggle source
# File lib/ruby-asterisk.rb, line 48 def logoff execute 'Logoff' end
mailbox_count(exten, context='default')
click to toggle source
# File lib/ruby-asterisk.rb, line 154 def mailbox_count(exten, context='default') execute 'MailboxCount', {'Mailbox' => "#{exten}@#{context}"} end
mailbox_status(exten, context='default')
click to toggle source
# File lib/ruby-asterisk.rb, line 150 def mailbox_status(exten, context='default') execute 'MailboxStatus', {'Mailbox' => "#{exten}@#{context}"} end
meet_me_list()
click to toggle source
# File lib/ruby-asterisk.rb, line 60 def meet_me_list execute 'MeetMeList' end
monitor(channel,mix=false,file=nil,format='wav')
click to toggle source
# File lib/ruby-asterisk.rb, line 191 def monitor(channel,mix=false,file=nil,format='wav') execute 'Monitor', {'Channel' => channel, 'File' => file, 'Mix' => mix} end
originate(channel, context, callee, priority, variable = nil, caller_id = nil, timeout = 30000)
click to toggle source
# File lib/ruby-asterisk.rb, line 108 def originate(channel, context, callee, priority, variable = nil, caller_id = nil, timeout = 30000) @timeout = [@timeout, timeout/1000].max execute 'Originate', {'Channel' => channel, 'Context' => context, 'Exten' => callee, 'Priority' => priority, 'CallerID' => caller_id || channel, 'Timeout' => timeout.to_s, 'Variable' => variable } end
originate_app(caller, app, data, async)
click to toggle source
# File lib/ruby-asterisk.rb, line 113 def originate_app(caller, app, data, async) execute 'Originate', {'Channel' => caller, 'Application' => app, 'Data' => data, 'Timeout' => '30000', 'Async' => async } end
parked_calls()
click to toggle source
# File lib/ruby-asterisk.rb, line 84 def parked_calls execute 'ParkedCalls' end
pause_monitor(channel)
click to toggle source
# File lib/ruby-asterisk.rb, line 199 def pause_monitor(channel) execute 'PauseMonitor', {'Channel' => channel} end
ping()
click to toggle source
# File lib/ruby-asterisk.rb, line 162 def ping execute 'Ping' end
queue_add(queue, exten, penalty = 2, paused = false, member_name = '')
click to toggle source
# File lib/ruby-asterisk.rb, line 130 def queue_add(queue, exten, penalty = 2, paused = false, member_name = '') execute 'QueueAdd', {'Queue' => queue, 'Interface' => exten, 'Penalty' => penalty, 'Paused' => paused, 'MemberName' => member_name} end
queue_pause(exten, paused)
click to toggle source
# File lib/ruby-asterisk.rb, line 134 def queue_pause(exten, paused) execute 'QueuePause', {'Interface' => exten, 'Paused' => paused} end
queue_remove(queue, exten)
click to toggle source
# File lib/ruby-asterisk.rb, line 138 def queue_remove(queue, exten) execute 'QueueRemove', {'Queue' => queue, 'Interface' => exten} end
queue_status()
click to toggle source
# File lib/ruby-asterisk.rb, line 142 def queue_status execute 'QueueStatus' end
queue_summary(queue)
click to toggle source
# File lib/ruby-asterisk.rb, line 146 def queue_summary(queue) execute 'QueueSummary', {'Queue' => queue} end
queues()
click to toggle source
# File lib/ruby-asterisk.rb, line 126 def queues execute 'Queues', {} end
redirect(channel, context, callee, priority, variable=nil, caller_id = nil, timeout = 30000)
click to toggle source
# File lib/ruby-asterisk.rb, line 121 def redirect(channel, context, callee, priority, variable=nil, caller_id = nil, timeout = 30000) @timeout = [@timeout, timeout/1000].max execute 'Redirect', {'Channel' => channel, 'Context' => context, 'Exten' => callee, 'Priority' => priority, 'CallerID' => caller_id || channel, 'Timeout' => timeout.to_s, 'Variable' => variable} end
sip_peers()
click to toggle source
# File lib/ruby-asterisk.rb, line 170 def sip_peers execute 'SIPpeers' end
sip_show_peer(peer)
click to toggle source
# File lib/ruby-asterisk.rb, line 174 def sip_show_peer(peer) execute 'SIPshowpeer', {'Peer' => peer} end
skinny_devices()
click to toggle source
# File lib/ruby-asterisk.rb, line 96 def skinny_devices execute 'SKINNYdevices' end
skinny_lines()
click to toggle source
# File lib/ruby-asterisk.rb, line 100 def skinny_lines execute 'SKINNYlines' end
status(channel = nil, action_id = nil)
click to toggle source
# File lib/ruby-asterisk.rb, line 104 def status(channel = nil, action_id = nil) execute 'Status', {'Channel' => channel, 'ActionID' => action_id} end
stop_monitor(channel)
click to toggle source
# File lib/ruby-asterisk.rb, line 195 def stop_monitor(channel) execute 'StopMonitor', {'Channel' => channel} end
unpause_monitor(channel)
click to toggle source
# File lib/ruby-asterisk.rb, line 203 def unpause_monitor(channel) execute 'UnpauseMonitor', {'Channel' => channel} end
wait_event(timeout=-1)
click to toggle source
# File lib/ruby-asterisk.rb, line 186 def wait_event(timeout=-1) @timeout = [@timeout, timeout].max execute 'WaitEvent', {'Timeout' => timeout} end
Private Instance Methods
execute(command, options = {})
click to toggle source
# File lib/ruby-asterisk.rb, line 212 def execute(command, options = {}) request = Request.new(command, options) request.commands.each do |command| @session.write(command) end @session.waitfor('Match' => /ActionID: #{request.action_id}.*?\n\n/m, "Timeout" => @timeout, "Waittime" => @wait_time) do |data| request.response_data << data.to_s end Response.new(command, request.response_data) end