ruby-agi 1.1.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +0 -9
- data/DOWNLOAD +1 -1
- data/INSTALL +1 -6
- data/README +10 -7
- data/Release-Notes +18 -9
- data/lib/ruby-agi/asterisk_variable.rb +2 -2
- data/lib/ruby-agi/command.rb +40 -37
- data/lib/ruby-agi/error.rb +3 -0
- data/lib/ruby-agi/return_status.rb +31 -92
- data/lib/ruby-agi/rs/answer.rb +68 -0
- data/lib/ruby-agi/rs/channel_status.rb +127 -0
- data/lib/ruby-agi/rs/exec.rb +69 -0
- data/lib/ruby-agi/rs/get_variable.rb +76 -0
- data/lib/ruby-agi/rs/hangup.rb +76 -0
- data/lib/ruby-agi/rs/noop.rb +68 -0
- data/lib/ruby-agi/rs/receive_char.rb +112 -0
- data/lib/ruby-agi/rs/receive_text.rb +73 -0
- data/lib/ruby-agi/rs/record_file.rb +184 -0
- data/lib/ruby-agi/rs/result.rb +47 -0
- data/lib/ruby-agi/rs/return_status.rb +98 -0
- data/lib/ruby-agi/rs/say_digits.rb +85 -0
- data/lib/ruby-agi/rs/say_number.rb +88 -0
- data/lib/ruby-agi/rs/say_phonetic.rb +88 -0
- data/lib/ruby-agi/rs/say_time.rb +90 -0
- data/lib/ruby-agi/rs/send_image.rb +83 -0
- data/lib/ruby-agi/rs/send_text.rb +83 -0
- data/lib/ruby-agi/rs/set_auto_hangup.rb +69 -0
- data/lib/ruby-agi/rs/set_caller_id.rb +72 -0
- data/lib/ruby-agi/rs/set_context.rb +71 -0
- data/lib/ruby-agi/rs/set_extension.rb +72 -0
- data/lib/ruby-agi/rs/set_music.rb +71 -0
- data/lib/ruby-agi/rs/set_priority.rb +69 -0
- data/lib/ruby-agi/rs/set_variable.rb +76 -0
- data/lib/ruby-agi/rs/stream_file.rb +138 -0
- data/lib/ruby-agi/rs/tdd_mode.rb +95 -0
- data/lib/ruby-agi/rs/verbose.rb +73 -0
- data/lib/ruby-agi/rs/wait_for_digit.rb +90 -0
- data/lib/ruby-agi/rs/wait_for_digits.rb +88 -0
- data/test/unit.rb +37 -0
- metadata +36 -6
@@ -0,0 +1,68 @@
|
|
1
|
+
#
|
2
|
+
# File: answer.rb
|
3
|
+
#
|
4
|
+
# ruby-agi: Ruby Language API for Asterisk
|
5
|
+
#
|
6
|
+
# Copyright (C) <2006> Mohammad Khan <info@beeplove.com>
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'ruby-agi/rs/return_status'
|
24
|
+
|
25
|
+
#
|
26
|
+
# class to handle return status of Command#answer
|
27
|
+
# Answers channel if not already in answer state.
|
28
|
+
#
|
29
|
+
# Command Reference: ANSWER
|
30
|
+
#
|
31
|
+
# failure: 200 result=-1
|
32
|
+
# success: 200 result=0
|
33
|
+
#
|
34
|
+
|
35
|
+
class ReturnStatus
|
36
|
+
end
|
37
|
+
|
38
|
+
class Answer < ReturnStatus
|
39
|
+
|
40
|
+
def initialize(command, response)
|
41
|
+
super(command, response)
|
42
|
+
end
|
43
|
+
|
44
|
+
def success?
|
45
|
+
if @is_success.nil?
|
46
|
+
if result == '0'
|
47
|
+
@is_success = true
|
48
|
+
else
|
49
|
+
@is_success = false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
return @is_success
|
54
|
+
end
|
55
|
+
|
56
|
+
def failure?
|
57
|
+
return (not success?)
|
58
|
+
end
|
59
|
+
|
60
|
+
def error?
|
61
|
+
return command_error?
|
62
|
+
end
|
63
|
+
|
64
|
+
def response
|
65
|
+
return message
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
#
|
2
|
+
# File: channel_status.rb
|
3
|
+
#
|
4
|
+
# ruby-agi: Ruby Language API for Asterisk
|
5
|
+
#
|
6
|
+
# Copyright (C) <2006> Mohammad Khan <info@beeplove.com>
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'ruby-agi/rs/return_status'
|
24
|
+
|
25
|
+
#
|
26
|
+
# class to handle return status of Command#channel_status
|
27
|
+
# Returns the status of the specified channel.
|
28
|
+
# If no channel name is given the returns the status of the current channel.
|
29
|
+
#
|
30
|
+
# Command Reference: CHANNEL STATUS [<channelname>]
|
31
|
+
#
|
32
|
+
# failure: 200 result=-1
|
33
|
+
# success: 200 result=<status>
|
34
|
+
# <status> values:
|
35
|
+
# 0 Channel is down and available
|
36
|
+
# 1 Channel is down, but reserved
|
37
|
+
# 2 Channel is off hook
|
38
|
+
# 3 Digits (or equivalent) have been dialed
|
39
|
+
# 4 Line is ringing
|
40
|
+
# 5 Remote end is ringing
|
41
|
+
# 6 Line is up
|
42
|
+
# 7 Line is busy
|
43
|
+
#
|
44
|
+
|
45
|
+
class ReturnStatus
|
46
|
+
end
|
47
|
+
|
48
|
+
class ChannelStatus < ReturnStatus
|
49
|
+
VALID_STATUS = ['0', '1', '2', '3', '4', '5', '6', '7']
|
50
|
+
|
51
|
+
def initialize(command, response)
|
52
|
+
super(command, response)
|
53
|
+
end
|
54
|
+
|
55
|
+
def success?
|
56
|
+
if not failure?
|
57
|
+
if VALID_STATUS.include?(result)
|
58
|
+
@is_success = true
|
59
|
+
else
|
60
|
+
@is_success = false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
return @is_success
|
65
|
+
end
|
66
|
+
|
67
|
+
def failure?
|
68
|
+
if @is_failure.nil?
|
69
|
+
if result == '-1'
|
70
|
+
@is_failure = true
|
71
|
+
else
|
72
|
+
@is_failure = false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
return @is_failure
|
77
|
+
end
|
78
|
+
|
79
|
+
# 0 Channel is down and available
|
80
|
+
def available?
|
81
|
+
return result == '0'
|
82
|
+
end
|
83
|
+
|
84
|
+
# 1 Channel is down, but reserved
|
85
|
+
def reserved?
|
86
|
+
return result == '1'
|
87
|
+
end
|
88
|
+
|
89
|
+
# 2 Channel is off hook
|
90
|
+
def off_hook?
|
91
|
+
return result == '2'
|
92
|
+
end
|
93
|
+
|
94
|
+
# 3 Digits (or equivalent) have been dialed
|
95
|
+
def dialed?
|
96
|
+
return result == '3'
|
97
|
+
end
|
98
|
+
|
99
|
+
# 4 Line is ringing
|
100
|
+
def ringing?
|
101
|
+
return result == '4'
|
102
|
+
end
|
103
|
+
|
104
|
+
# 5 Remote end is ringing
|
105
|
+
def remote_ringing?
|
106
|
+
return result == '5'
|
107
|
+
end
|
108
|
+
|
109
|
+
# 6 Line is up
|
110
|
+
def up?
|
111
|
+
return result == '6'
|
112
|
+
end
|
113
|
+
|
114
|
+
# 7 Line is busy
|
115
|
+
def busy?
|
116
|
+
return result == '7'
|
117
|
+
end
|
118
|
+
|
119
|
+
def error?
|
120
|
+
return command_error?
|
121
|
+
end
|
122
|
+
|
123
|
+
def response
|
124
|
+
return message
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#
|
2
|
+
# File: exec.rb
|
3
|
+
#
|
4
|
+
# ruby-agi: Ruby Language API for Asterisk
|
5
|
+
#
|
6
|
+
# Copyright (C) <2006> Mohammad Khan <info@beeplove.com>
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'ruby-agi/rs/return_status'
|
24
|
+
|
25
|
+
#
|
26
|
+
# class to handle return status of Command#exec
|
27
|
+
# Executes <application> with given <options>.
|
28
|
+
# Applications are the functions you use to create a dial plan in extensions.conf.
|
29
|
+
#
|
30
|
+
# Command Reference: EXEC <application> <options>
|
31
|
+
#
|
32
|
+
# failure: 200 result=-2
|
33
|
+
# success: 200 result=<ret>
|
34
|
+
#
|
35
|
+
|
36
|
+
class ReturnStatus
|
37
|
+
end
|
38
|
+
|
39
|
+
class Exec < ReturnStatus
|
40
|
+
|
41
|
+
def initialize(command, response)
|
42
|
+
super(command, response)
|
43
|
+
end
|
44
|
+
|
45
|
+
def success?
|
46
|
+
return (not @is_failure)
|
47
|
+
end
|
48
|
+
|
49
|
+
def failure?
|
50
|
+
if @is_failure.nil?
|
51
|
+
if result == '-2'
|
52
|
+
@is_failure = true
|
53
|
+
else
|
54
|
+
@is_failure = false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
return @is_failure
|
59
|
+
end
|
60
|
+
|
61
|
+
def error?
|
62
|
+
return command_error?
|
63
|
+
end
|
64
|
+
|
65
|
+
def response
|
66
|
+
return message
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#
|
2
|
+
# File: get_variable.rb
|
3
|
+
#
|
4
|
+
# ruby-agi: Ruby Language API for Asterisk
|
5
|
+
#
|
6
|
+
# Copyright (C) <2006> Mohammad Khan <info@beeplove.com>
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'ruby-agi/rs/return_status'
|
24
|
+
|
25
|
+
#
|
26
|
+
# class to handle return status of Command#get_variable
|
27
|
+
#
|
28
|
+
# Command Reference: GET VARIABLE <variablename>
|
29
|
+
#
|
30
|
+
# Does not work with global variables. Does not work with some variables that are generated by modules.
|
31
|
+
# failure or not set: 200 result=0
|
32
|
+
# success: 200 result=1 <value>
|
33
|
+
#
|
34
|
+
|
35
|
+
class ReturnStatus
|
36
|
+
end
|
37
|
+
|
38
|
+
class GetVariable < ReturnStatus
|
39
|
+
|
40
|
+
def initialize(command, response)
|
41
|
+
super(command, response)
|
42
|
+
end
|
43
|
+
|
44
|
+
def success?
|
45
|
+
if @is_success.nil?
|
46
|
+
if result == '1'
|
47
|
+
@is_success = true
|
48
|
+
else
|
49
|
+
@is_success = false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
return @is_success
|
54
|
+
end
|
55
|
+
|
56
|
+
def failure?
|
57
|
+
if @is_failure.nil?
|
58
|
+
if result == '0'
|
59
|
+
@is_failure = true
|
60
|
+
else
|
61
|
+
@is_failure = false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
return @is_failure
|
66
|
+
end
|
67
|
+
|
68
|
+
def error?
|
69
|
+
return command_error?
|
70
|
+
end
|
71
|
+
|
72
|
+
def response
|
73
|
+
return message
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#
|
2
|
+
# File: hangup.rb
|
3
|
+
#
|
4
|
+
# ruby-agi: Ruby Language API for Asterisk
|
5
|
+
#
|
6
|
+
# Copyright (C) <2006> Mohammad Khan <info@beeplove.com>
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'ruby-agi/rs/return_status'
|
24
|
+
|
25
|
+
#
|
26
|
+
# class to handle return status of Command#hangup
|
27
|
+
# If no channel name is given, hangs up the current channel.
|
28
|
+
#
|
29
|
+
# Command Reference: HANGUP [<channelname>]
|
30
|
+
#
|
31
|
+
# failure: 200 result=-1
|
32
|
+
# success: 200 result=1
|
33
|
+
#
|
34
|
+
|
35
|
+
class ReturnStatus
|
36
|
+
end
|
37
|
+
|
38
|
+
class Hangup < ReturnStatus
|
39
|
+
|
40
|
+
def initialize(command, response)
|
41
|
+
super(command, response)
|
42
|
+
end
|
43
|
+
|
44
|
+
def success?
|
45
|
+
if @is_success.nil?
|
46
|
+
if result == '1'
|
47
|
+
@is_success = true
|
48
|
+
else
|
49
|
+
@is_success = false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
return @is_success
|
54
|
+
end
|
55
|
+
|
56
|
+
def failure?
|
57
|
+
if @is_failure.nil?
|
58
|
+
if result == '-1'
|
59
|
+
@is_failure = true
|
60
|
+
else
|
61
|
+
@is_failure = false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
return @is_failure
|
66
|
+
end
|
67
|
+
|
68
|
+
def error?
|
69
|
+
return command_error?
|
70
|
+
end
|
71
|
+
|
72
|
+
def response
|
73
|
+
return message
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#
|
2
|
+
# File: noop.rb
|
3
|
+
#
|
4
|
+
# ruby-agi: Ruby Language API for Asterisk
|
5
|
+
#
|
6
|
+
# Copyright (C) <2006> Mohammad Khan <info@beeplove.com>
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'ruby-agi/rs/return_status'
|
24
|
+
|
25
|
+
#
|
26
|
+
# class to handle return status of Command#noop
|
27
|
+
#
|
28
|
+
# Command Reference: Usage: NOOP
|
29
|
+
#
|
30
|
+
# <b>Returns</b>
|
31
|
+
# - ReturnStatus object
|
32
|
+
# success: 200 result=0
|
33
|
+
#
|
34
|
+
|
35
|
+
class ReturnStatus
|
36
|
+
end
|
37
|
+
|
38
|
+
class Noop < ReturnStatus
|
39
|
+
|
40
|
+
def initialize(command, response)
|
41
|
+
super(command, response)
|
42
|
+
end
|
43
|
+
|
44
|
+
def success?
|
45
|
+
if @is_success.nil?
|
46
|
+
if result == '0'
|
47
|
+
@is_success = true
|
48
|
+
else
|
49
|
+
@is_success = false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
return @is_success
|
54
|
+
end
|
55
|
+
|
56
|
+
def failure?
|
57
|
+
return (not success?)
|
58
|
+
end
|
59
|
+
|
60
|
+
def error?
|
61
|
+
return command_error?
|
62
|
+
end
|
63
|
+
|
64
|
+
def response
|
65
|
+
return message
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|