ruby-agi 1.1.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. data/ChangeLog +0 -9
  2. data/DOWNLOAD +1 -1
  3. data/INSTALL +1 -6
  4. data/README +10 -7
  5. data/Release-Notes +18 -9
  6. data/lib/ruby-agi/asterisk_variable.rb +2 -2
  7. data/lib/ruby-agi/command.rb +40 -37
  8. data/lib/ruby-agi/error.rb +3 -0
  9. data/lib/ruby-agi/return_status.rb +31 -92
  10. data/lib/ruby-agi/rs/answer.rb +68 -0
  11. data/lib/ruby-agi/rs/channel_status.rb +127 -0
  12. data/lib/ruby-agi/rs/exec.rb +69 -0
  13. data/lib/ruby-agi/rs/get_variable.rb +76 -0
  14. data/lib/ruby-agi/rs/hangup.rb +76 -0
  15. data/lib/ruby-agi/rs/noop.rb +68 -0
  16. data/lib/ruby-agi/rs/receive_char.rb +112 -0
  17. data/lib/ruby-agi/rs/receive_text.rb +73 -0
  18. data/lib/ruby-agi/rs/record_file.rb +184 -0
  19. data/lib/ruby-agi/rs/result.rb +47 -0
  20. data/lib/ruby-agi/rs/return_status.rb +98 -0
  21. data/lib/ruby-agi/rs/say_digits.rb +85 -0
  22. data/lib/ruby-agi/rs/say_number.rb +88 -0
  23. data/lib/ruby-agi/rs/say_phonetic.rb +88 -0
  24. data/lib/ruby-agi/rs/say_time.rb +90 -0
  25. data/lib/ruby-agi/rs/send_image.rb +83 -0
  26. data/lib/ruby-agi/rs/send_text.rb +83 -0
  27. data/lib/ruby-agi/rs/set_auto_hangup.rb +69 -0
  28. data/lib/ruby-agi/rs/set_caller_id.rb +72 -0
  29. data/lib/ruby-agi/rs/set_context.rb +71 -0
  30. data/lib/ruby-agi/rs/set_extension.rb +72 -0
  31. data/lib/ruby-agi/rs/set_music.rb +71 -0
  32. data/lib/ruby-agi/rs/set_priority.rb +69 -0
  33. data/lib/ruby-agi/rs/set_variable.rb +76 -0
  34. data/lib/ruby-agi/rs/stream_file.rb +138 -0
  35. data/lib/ruby-agi/rs/tdd_mode.rb +95 -0
  36. data/lib/ruby-agi/rs/verbose.rb +73 -0
  37. data/lib/ruby-agi/rs/wait_for_digit.rb +90 -0
  38. data/lib/ruby-agi/rs/wait_for_digits.rb +88 -0
  39. data/test/unit.rb +37 -0
  40. metadata +36 -6
@@ -0,0 +1,138 @@
1
+ #
2
+ # File: stream_file.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
+ # stream file: Sends audio file on channel
27
+ # Send the given file, allowing playback to be interrupted by the given digits, if any.
28
+ # Use double quotes for the digits if you wish none to be permitted.
29
+ # If sample offset is provided then the audio will seek to sample offset before play starts.
30
+ # Remember, the file extension must not be included in the filename.
31
+ #
32
+ # Command Reference: STREAM FILE <filename> <escape digits> [sample offset]
33
+ #
34
+ # - filename : location of the file to be played
35
+ # - escape_digit: digit to be pressed to escape from playback
36
+ #
37
+ # failure: 200 result=-1 endpos=<sample offset>
38
+ # failure on open: 200 result=0 endpos=0
39
+ # success: 200 result=0 endpos=<offset>
40
+ # digit pressed: 200 result=<digit> endpos=<offset>
41
+ # <offset> is the stream position streaming stopped. If it equals <sample offset> there was probably an error.
42
+ # <digit> is the ascii code for the digit pressed.
43
+ #
44
+
45
+ class ReturnStatus
46
+ end
47
+
48
+ class StreamFile < ReturnStatus
49
+
50
+ def initialize(command, response)
51
+ super(command, response)
52
+ end
53
+
54
+ def failure?
55
+ if @is_failure.nil?
56
+ if result == '-1'
57
+ @is_failure = true
58
+ elsif result == '0'
59
+ if offset == '0'
60
+ @is_failure = true
61
+ @is_failure_on_open = true
62
+ @is_success = false
63
+ else
64
+ @is_success = true
65
+ end
66
+ else
67
+ @is_failure = false
68
+ end
69
+ end
70
+
71
+ return @is_failure
72
+ end
73
+
74
+ def success?
75
+ if @is_success.nil?
76
+ if ((not failure?) and (offset.to_i > 0))
77
+ @is_success = true
78
+ else
79
+ @is_success = false
80
+ end
81
+ end
82
+
83
+ return @is_success
84
+ end
85
+
86
+ def interrupted?
87
+ if @is_interrupted.nil?
88
+ @is_interrupted = false
89
+ if ((success?) and (result.to_i > 0))
90
+ @is_interrupted = true
91
+ end
92
+ end
93
+
94
+ return @is_interrupted
95
+ end
96
+
97
+ def offset
98
+ if @offset.nil?
99
+ rgx = Regexp.new(/^endpos/)
100
+ response.split(' ').each do | pair |
101
+ if rgx.match(pair)
102
+ @offset = pair.split('=').last
103
+ end
104
+ end
105
+ @offset = '' if @offset.nil?
106
+ end
107
+
108
+ return @offset
109
+ end
110
+
111
+ def digit
112
+ if @digit.nil?
113
+ if interrupted?
114
+ @digit = result.to_i.chr
115
+ end
116
+ @digit = '' if @digit.nil?
117
+ end
118
+
119
+ return @digit
120
+ end
121
+
122
+ def error
123
+ if random_error?
124
+ return result
125
+ else
126
+ return ''
127
+ end
128
+ end
129
+
130
+ def error?
131
+ return command_error?
132
+ end
133
+
134
+ def response
135
+ return message
136
+ end
137
+
138
+ end
@@ -0,0 +1,95 @@
1
+ #
2
+ # File: tdd_mode.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
+ # tdd mode: Activates TDD mode on channels supporting it, to enable communication with TDDs.
27
+ # Enable/Disable TDD transmission/reception on a channel.
28
+ # This function is currently (01July2005) only supported on Zap channels.
29
+ # As of 02July2005, this function never returns 0 (Not Capable).
30
+ # If it fails for any reason, -1 (Failure) will be returned, otherwise 1 (Success) will be returned.
31
+ # The capability for returning 0 if the channel is not capable of TDD MODE is a future plan.
32
+ #
33
+ # Command Reference: TDD MODE <on|off|mate>
34
+ #
35
+ # failure: 200 result=-1
36
+ # not capable: 200 result=0
37
+ # success: 200 result=1
38
+ #
39
+
40
+ class ReturnStatus
41
+ end
42
+
43
+ class TDDMode < ReturnStatus
44
+
45
+ def initialize(command, response)
46
+ super(command, response)
47
+ end
48
+
49
+ def success?
50
+ if @is_success.nil?
51
+ if result == '1'
52
+ @is_success = true
53
+ @is_capable = true
54
+ @is_failure = false
55
+ end
56
+ end
57
+
58
+ return @is_success
59
+ end
60
+
61
+ def failure?
62
+ if @is_failure.nil?
63
+ if result == '-1'
64
+ @is_failure = true
65
+ @is_capable = true
66
+ @is_success = false
67
+ end
68
+ end
69
+
70
+ return @is_failure
71
+ end
72
+
73
+ def capable?
74
+ if @is_capable.nil?
75
+ if result == '0'
76
+ @is_capable = false
77
+ @is_success = false
78
+ @is_failure = true
79
+ else
80
+ @is_capable = true
81
+ end
82
+ end
83
+
84
+ return @is_capable
85
+ end
86
+
87
+ def error?
88
+ return command_error?
89
+ end
90
+
91
+ def response
92
+ return message
93
+ end
94
+
95
+ end
@@ -0,0 +1,73 @@
1
+ #
2
+ # File: verbose.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
+ # Sends <message> to the console via verbose message system.
27
+ # The Asterisk verbosity system works as follows.
28
+ # The Asterisk user gets to set the desired verbosity at startup time
29
+ # or later using the console 'set verbose' command.
30
+ # Messages are displayed on the console if their verbose level
31
+ # is less than or equal to desired verbosity set by the user.
32
+ # More important messages should have a low verbose level;
33
+ # less important messages should have a high verbose level.
34
+ #
35
+ # Command Reference: VERBOSE <message> [level]
36
+ #
37
+ # 200 result=1
38
+ #
39
+
40
+ class ReturnStatus
41
+ end
42
+
43
+ class Verbose < ReturnStatus
44
+
45
+ def initialize(command, response)
46
+ super(command, response)
47
+ end
48
+
49
+ def success?
50
+ if @is_success.nil?
51
+ if result == '1'
52
+ @is_success = true
53
+ else
54
+ @is_success = false
55
+ end
56
+ end
57
+
58
+ return @is_success
59
+ end
60
+
61
+ def failure?
62
+ return (not success?)
63
+ end
64
+
65
+ def error?
66
+ return command_error?
67
+ end
68
+
69
+ def response
70
+ return message
71
+ end
72
+
73
+ end
@@ -0,0 +1,90 @@
1
+ #
2
+ # File: wait_for_digit.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
+ # wait for digit: Waits for a digit to be pressed
27
+ # Waits up to <timeout> milliseconds for channel to receive a DTMF digit.
28
+ #
29
+ # Command Reference: WAIT FOR DIGIT <timeout>
30
+ #
31
+ # failure: 200 result=-1
32
+ # timeout: 200 result=0
33
+ # success: 200 result=<digit>
34
+ # <digit> is the ascii code for the digit received.
35
+ #
36
+
37
+ class ReturnStatus
38
+ end
39
+
40
+ class WaitForDigit < ReturnStatus
41
+
42
+ def initialize(command, response)
43
+ super(command, response)
44
+ end
45
+
46
+ def failure?
47
+ if @is_failure.nil?
48
+ if result == '-1'
49
+ @is_failure = true
50
+ else
51
+ @is_failure = false
52
+ end
53
+ end
54
+
55
+ return @is_failure
56
+ end
57
+
58
+ def timeout?
59
+ if @is_timeout.nil?
60
+ if result == '0'
61
+ @is_timeout = true
62
+ else
63
+ @is_timeout = false
64
+ end
65
+ end
66
+
67
+ return @is_timeout
68
+ end
69
+
70
+ def digit
71
+ if success?
72
+ return result.to_i.chr
73
+ else
74
+ return nil
75
+ end
76
+ end
77
+
78
+ def success?
79
+ return ((not timeout?) and (not failure?))
80
+ end
81
+
82
+ def error?
83
+ return command_error?
84
+ end
85
+
86
+ def response
87
+ return message
88
+ end
89
+
90
+ end
@@ -0,0 +1,88 @@
1
+ #
2
+ # File: wait_for_digits.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 from Command#wait_for_digits
27
+ # pressing '#' will always terminate the input process
28
+ #
29
+ # Command Reference: GET DATA <file to be streamed> [timeout] [max digits]
30
+ #
31
+ # failure: 200 result=-1
32
+ # timeout: 200 result=<digits> (timeout)
33
+ # success: 200 result=<digits>
34
+ # <digits> is the digits pressed.
35
+ #
36
+
37
+ class ReturnStatus
38
+ end
39
+
40
+ class WaitForDigits < ReturnStatus
41
+
42
+ def initialize(command, response)
43
+ super(command, response)
44
+ end
45
+
46
+ def success?
47
+ return ((not failure?) and (not timeout?))
48
+ end
49
+
50
+ def failure?
51
+ if @is_failure.nil?
52
+ if result == '-1'
53
+ @is_failure = true
54
+ else
55
+ @is_failure = false
56
+ end
57
+ end
58
+
59
+ return @is_failure
60
+ end
61
+
62
+ public
63
+ def timeout?
64
+ if @is_timeout.nil?
65
+ rgx = Regexp.new(/\(timeout\)$/)
66
+ if rgx.match(response)
67
+ @is_timeout = true
68
+ else
69
+ @is_timeout = false
70
+ end
71
+ end
72
+
73
+ return @is_timeout
74
+ end
75
+
76
+ def digits
77
+ return result
78
+ end
79
+
80
+ def error?
81
+ return ((not timeout?) and command_error?)
82
+ end
83
+
84
+ def response
85
+ return message
86
+ end
87
+
88
+ end