Class: RubyAsterisk::AMI

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-asterisk.rb

Overview

Ruby-asterisk main classes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ AMI

Returns a new instance of AMI.



14
15
16
17
18
19
20
21
# 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

Instance Attribute Details

#connectedObject

Returns the value of attribute connected.



12
13
14
# File 'lib/ruby-asterisk.rb', line 12

def connected
  @connected
end

#hostObject

Returns the value of attribute host.



12
13
14
# File 'lib/ruby-asterisk.rb', line 12

def host
  @host
end

#portObject

Returns the value of attribute port.



12
13
14
# File 'lib/ruby-asterisk.rb', line 12

def port
  @port
end

#timeoutObject

Returns the value of attribute timeout.



12
13
14
# File 'lib/ruby-asterisk.rb', line 12

def timeout
  @timeout
end

#wait_timeObject

Returns the value of attribute wait_time.



12
13
14
# File 'lib/ruby-asterisk.rb', line 12

def wait_time
  @wait_time
end

Instance Method Details

#atxfer(channel, exten, context, priority = '1') ⇒ Object



182
183
184
# 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) ⇒ Object



207
208
209
# File 'lib/ruby-asterisk.rb', line 207

def change_monitor(channel,file)
  execute 'ChangeMonitor', {'Channel' => channel, 'File' => file}
end

#channelsObject



117
118
119
# File 'lib/ruby-asterisk.rb', line 117

def channels
  execute 'Command', { 'Command' => 'show channels' }
end

#command(command) ⇒ Object



52
53
54
# File 'lib/ruby-asterisk.rb', line 52

def command(command)
  execute 'Command', {'Command' => command}
end

#confbridge(conference) ⇒ Object



68
69
70
# File 'lib/ruby-asterisk.rb', line 68

def confbridge(conference)
  execute 'ConfbridgeList', {'Conference' => conference}
end

#confbridge_kick(conference, channel) ⇒ Object



80
81
82
# File 'lib/ruby-asterisk.rb', line 80

def confbridge_kick(conference, channel)
  execute 'ConfbridgeKick', {'Conference' => conference, 'Channel' => channel}
end

#confbridge_mute(conference, channel) ⇒ Object



72
73
74
# File 'lib/ruby-asterisk.rb', line 72

def confbridge_mute(conference, channel)
  execute 'ConfbridgeMute', {'Conference' => conference, 'Channel' => channel}
end

#confbridge_unmute(conference, channel) ⇒ Object



76
77
78
# File 'lib/ruby-asterisk.rb', line 76

def confbridge_unmute(conference, channel)
  execute 'ConfbridgeUnmute', {'Conference' => conference, 'Channel' => channel}
end

#confbridgesObject



64
65
66
# File 'lib/ruby-asterisk.rb', line 64

def confbridges
  execute 'ConfbridgeListRooms'
end

#connectObject



23
24
25
26
27
28
29
30
# 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_channelsObject



56
57
58
# File 'lib/ruby-asterisk.rb', line 56

def core_show_channels
  execute 'CoreShowChannels'
end

#device_state_listObject



92
93
94
# File 'lib/ruby-asterisk.rb', line 92

def device_state_list
  execute 'DeviceStateList'
end

#disconnectObject



32
33
34
35
36
37
38
39
40
41
# 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') ⇒ Object



166
167
168
# 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) ⇒ Object



88
89
90
# 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) ⇒ Object



178
179
180
# File 'lib/ruby-asterisk.rb', line 178

def hangup(channel)
  execute 'Hangup', {'Channel' => channel}
end

#login(username, password) ⇒ Object



43
44
45
46
# File 'lib/ruby-asterisk.rb', line 43

def (username, password)
  self.connect unless self.connected
  execute 'Login', {'Username' => username, 'Secret' => password, 'Event' => 'On'}
end

#logoffObject



48
49
50
# File 'lib/ruby-asterisk.rb', line 48

def logoff
  execute 'Logoff'
end

#mailbox_count(exten, context = 'default') ⇒ Object



154
155
156
# File 'lib/ruby-asterisk.rb', line 154

def mailbox_count(exten, context='default')
  execute 'MailboxCount', {'Mailbox' => "#{exten}@#{context}"}
end

#mailbox_status(exten, context = 'default') ⇒ Object



150
151
152
# File 'lib/ruby-asterisk.rb', line 150

def mailbox_status(exten, context='default')
  execute 'MailboxStatus', {'Mailbox' => "#{exten}@#{context}"}
end

#meet_me_listObject



60
61
62
# File 'lib/ruby-asterisk.rb', line 60

def meet_me_list
  execute 'MeetMeList'
end

#monitor(channel, mix = false, file = nil, format = 'wav') ⇒ Object



191
192
193
# 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) ⇒ Object



108
109
110
111
# 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) ⇒ Object



113
114
115
# 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_callsObject



84
85
86
# File 'lib/ruby-asterisk.rb', line 84

def parked_calls
  execute 'ParkedCalls'
end

#pause_monitor(channel) ⇒ Object



199
200
201
# File 'lib/ruby-asterisk.rb', line 199

def pause_monitor(channel)
  execute 'PauseMonitor', {'Channel' => channel}
end

#pingObject



162
163
164
# File 'lib/ruby-asterisk.rb', line 162

def ping
  execute 'Ping'
end

#queue_add(queue, exten, penalty = 2, paused = false, member_name = '') ⇒ Object



130
131
132
# 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(interface, paused, queue, reason = 'none') ⇒ Object



134
135
136
# File 'lib/ruby-asterisk.rb', line 134

def queue_pause(exten, paused)
  execute 'QueuePause', {'Interface' => exten, 'Paused' => paused}
end

#queue_remove(queue, exten) ⇒ Object



138
139
140
# File 'lib/ruby-asterisk.rb', line 138

def queue_remove(queue, exten)
  execute 'QueueRemove', {'Queue' => queue, 'Interface' => exten}
end

#queue_statusObject



142
143
144
# File 'lib/ruby-asterisk.rb', line 142

def queue_status
  execute 'QueueStatus'
end

#queue_summary(queue) ⇒ Object



146
147
148
# File 'lib/ruby-asterisk.rb', line 146

def queue_summary(queue)
  execute 'QueueSummary', {'Queue' => queue}
end

#queuesObject



126
127
128
# File 'lib/ruby-asterisk.rb', line 126

def queues
  execute 'Queues', {}
end

#redirect(channel, context, callee, priority, variable = nil, caller_id = nil, timeout = 30000) ⇒ Object



121
122
123
124
# 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_peersObject



170
171
172
# File 'lib/ruby-asterisk.rb', line 170

def sip_peers
  execute 'SIPpeers'
end

#sip_show_peer(peer) ⇒ Object



174
175
176
# File 'lib/ruby-asterisk.rb', line 174

def sip_show_peer(peer)
  execute 'SIPshowpeer', {'Peer' => peer}
end

#skinny_devicesObject



96
97
98
# File 'lib/ruby-asterisk.rb', line 96

def skinny_devices
  execute 'SKINNYdevices'
end

#skinny_linesObject



100
101
102
# File 'lib/ruby-asterisk.rb', line 100

def skinny_lines
  execute 'SKINNYlines'
end

#status(channel = nil, action_id = nil) ⇒ Object



104
105
106
# 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) ⇒ Object



195
196
197
# File 'lib/ruby-asterisk.rb', line 195

def stop_monitor(channel)
  execute 'StopMonitor', {'Channel' => channel}
end

#unpause_monitor(channel) ⇒ Object



203
204
205
# File 'lib/ruby-asterisk.rb', line 203

def unpause_monitor(channel)
  execute 'UnpauseMonitor', {'Channel' => channel}
end

#wait_event(timeout = -1)) ⇒ Object



186
187
188
189
# File 'lib/ruby-asterisk.rb', line 186

def wait_event(timeout=-1)
  @timeout = [@timeout, timeout].max
  execute 'WaitEvent', {'Timeout' => timeout}
end