redial-ruby-agi 2.0.1

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 (44) hide show
  1. data/ChangeLog +44 -0
  2. data/LICENSE +222 -0
  3. data/README.md +25 -0
  4. data/Rakefile +20 -0
  5. data/VERSION +1 -0
  6. data/examples/call_log.rb +18 -0
  7. data/lib/ruby-agi.rb +5 -0
  8. data/lib/ruby-agi/agi.rb +891 -0
  9. data/lib/ruby-agi/asterisk_variable.rb +242 -0
  10. data/lib/ruby-agi/command.rb +911 -0
  11. data/lib/ruby-agi/error.rb +48 -0
  12. data/lib/ruby-agi/return_status.rb +31 -0
  13. data/lib/ruby-agi/rs/answer.rb +68 -0
  14. data/lib/ruby-agi/rs/channel_status.rb +127 -0
  15. data/lib/ruby-agi/rs/exec.rb +69 -0
  16. data/lib/ruby-agi/rs/get_variable.rb +76 -0
  17. data/lib/ruby-agi/rs/hangup.rb +76 -0
  18. data/lib/ruby-agi/rs/noop.rb +68 -0
  19. data/lib/ruby-agi/rs/receive_char.rb +112 -0
  20. data/lib/ruby-agi/rs/receive_text.rb +73 -0
  21. data/lib/ruby-agi/rs/record_file.rb +184 -0
  22. data/lib/ruby-agi/rs/result.rb +47 -0
  23. data/lib/ruby-agi/rs/return_status.rb +98 -0
  24. data/lib/ruby-agi/rs/say_digits.rb +85 -0
  25. data/lib/ruby-agi/rs/say_number.rb +88 -0
  26. data/lib/ruby-agi/rs/say_phonetic.rb +88 -0
  27. data/lib/ruby-agi/rs/say_time.rb +90 -0
  28. data/lib/ruby-agi/rs/send_image.rb +83 -0
  29. data/lib/ruby-agi/rs/send_text.rb +83 -0
  30. data/lib/ruby-agi/rs/set_auto_hangup.rb +69 -0
  31. data/lib/ruby-agi/rs/set_caller_id.rb +72 -0
  32. data/lib/ruby-agi/rs/set_context.rb +71 -0
  33. data/lib/ruby-agi/rs/set_extension.rb +72 -0
  34. data/lib/ruby-agi/rs/set_music.rb +71 -0
  35. data/lib/ruby-agi/rs/set_priority.rb +69 -0
  36. data/lib/ruby-agi/rs/set_variable.rb +76 -0
  37. data/lib/ruby-agi/rs/stream_file.rb +138 -0
  38. data/lib/ruby-agi/rs/tdd_mode.rb +95 -0
  39. data/lib/ruby-agi/rs/verbose.rb +73 -0
  40. data/lib/ruby-agi/rs/wait_for_digit.rb +90 -0
  41. data/lib/ruby-agi/rs/wait_for_digits.rb +88 -0
  42. data/ruby-agi.gemspec +51 -0
  43. data/test/unit.rb +37 -0
  44. metadata +94 -0
@@ -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
@@ -0,0 +1,112 @@
1
+ #
2
+ # File: receive_char.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
+ require 'ruby-agi/error.rb'
25
+
26
+ #
27
+ # class to handle return status of Command#receive_char
28
+ # Receives a character of text on a channel, and discards any further characters after the first one waiting.
29
+ # Most channels do not support the reception of text. See Asterisk Text for details.
30
+ #
31
+ # Command Reference: RECEIVE CHAR <timeout>
32
+ #
33
+ # failure or hangup: 200 result=-1 (hangup)
34
+ # timeout: 200 result=<char> (timeout)
35
+ # success: 200 result=<char>
36
+ # <char> is the character received, or 0 if the channel does not support text reception.
37
+ #
38
+
39
+ class ReturnStatus
40
+ end
41
+
42
+ class ReceiveChar < ReturnStatus
43
+
44
+ def initialize(command, response)
45
+ super(command, response)
46
+ end
47
+
48
+ def timeout?
49
+ if @is_timeout.nil?
50
+ rgx = Regexp.new(/\(timeout\)$/)
51
+ if rgx.match(response)
52
+ @is_timeout = true
53
+ else
54
+ @is_timeout = false
55
+ end
56
+ end
57
+
58
+ return @is_timeout
59
+ end
60
+
61
+ def hangup?
62
+ if @is_hangup.nil?
63
+ rgx = Regexp.new(/\(hangup\)$/)
64
+ if rgx.match(response)
65
+ @is_hangup = true
66
+
67
+ if not failure?
68
+ raise(UnknownError, "Please report to info@beeplove.com with as much information as you can provide")
69
+ end
70
+ else
71
+ @is_hangup = false
72
+ end
73
+ end
74
+
75
+ return @is_hangup
76
+ end
77
+
78
+ def success?
79
+ return ((not timeout?) and (not failure?))
80
+ end
81
+
82
+ def failure?
83
+ if @is_failure.nil?
84
+ if result == '-1'
85
+ @is_failure = true
86
+ else
87
+ @is_failure = false
88
+ end
89
+ end
90
+
91
+ return @is_failure
92
+ end
93
+
94
+ def char
95
+ if result == '0'
96
+ return nil
97
+ elsif not failure?
98
+ return result.to_i.chr
99
+ else
100
+ return nil
101
+ end
102
+ end
103
+
104
+ def error?
105
+ return command_error?
106
+ end
107
+
108
+ def response
109
+ return message
110
+ end
111
+
112
+ end
@@ -0,0 +1,73 @@
1
+ #
2
+ # File: receive_text.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
+ # class to handle return status of Command#receive_text
26
+ # Receives a string text on a channel.
27
+ # Most channels do not support the reception of text.
28
+ #
29
+ # Command Reference: RECEIVE TEXT <timeout>
30
+ #
31
+ # failure, hangup, or timeout: 200 result=-1
32
+ # success: 200 result=<text>
33
+ # <text> is the text received on the channel.
34
+ #
35
+
36
+ class ReturnStatus
37
+ end
38
+
39
+ class ReceiveText < ReturnStatus
40
+
41
+ def initialize(command, response)
42
+ super(command, response)
43
+ end
44
+
45
+ def success?
46
+ return (not failure?)
47
+ end
48
+
49
+ def failure?
50
+ if @is_failure.nil?
51
+ if result == '-1'
52
+ @is_failure = true
53
+ else
54
+ @is_failure = false
55
+ end
56
+ end
57
+
58
+ return @is_failure
59
+ end
60
+
61
+ def text
62
+ return result
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,184 @@
1
+ #
2
+ # File: record_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
+ # class to handle return status of Command#record_file
27
+ # Record to a file until <escape digits> are received as dtmf.
28
+ #
29
+ # failure to write: 200 result=-1 (writefile)
30
+ # failure on waitfor: 200 result=-1 (waitfor) endpos=<offset>
31
+ # hangup: 200 result=0 (hangup) endpos=<offset>
32
+ # interrrupted: 200 result=<digit> (dtmf) endpos=<offset>
33
+ # timeout: 200 result=0 (timeout) endpos=<offset>
34
+ # random error: 200 result=<error> (randomerror) endpos=<offset>
35
+ # <offset> is the end offset in the file being recorded.
36
+ # <digit> is the ascii code for the digit pressed.
37
+ # <error> ?????
38
+ #
39
+ # Command Reference: RECORD FILE <filename> <format> <escape digits> <timeout> [offset samples] [BEEP] [s=<silence>]
40
+ #
41
+
42
+ class ReturnStatus
43
+ end
44
+
45
+ class RecordFile < ReturnStatus
46
+
47
+ def initialize(command, response)
48
+ super(command, response)
49
+ end
50
+
51
+ def failure?
52
+ if @is_failure.nil?
53
+ if result == '-1'
54
+ @is_failure = true
55
+ rgx_write = Regexp.new(/\(writefile\)/)
56
+ rgx_waitfor = Regexp.new(/\(waitfor\)/)
57
+ @is_failure_to_write = rgx_write.match(response).nil? ? false : true
58
+ @is_failure_on_waitfor = rgx_waitfor.match(response).nil? ? false : true
59
+ else
60
+ @is_failure = false
61
+ end
62
+ end
63
+
64
+ return @is_failure
65
+ end
66
+
67
+ def failure_to_write?
68
+ if failure?
69
+ return @is_failure_to_write
70
+ else
71
+ return false
72
+ end
73
+ end
74
+
75
+ def failure_on_waitfor?
76
+ if failure?
77
+ return @is_failure_on_waitfor
78
+ else
79
+ return false
80
+ end
81
+ end
82
+
83
+ def hangup?
84
+ if @is_hangup.nil?
85
+ @is_hangup = false
86
+ if result == '0'
87
+ rgx= Regexp.new(/\(hangup\)/)
88
+ if rgx.match(response)
89
+ @is_hangup = true
90
+ end
91
+ end
92
+ end
93
+
94
+ return @is_hangup
95
+ end
96
+
97
+ def interrupted?
98
+ if @is_interrupted.nil?
99
+ @is_interrupted = false
100
+ if ((not failure?) and (result != '0'))
101
+ rgx= Regexp.new(/\(dtmf\)/)
102
+ if rgx.match(response)
103
+ @is_interrupted = true
104
+ end
105
+ end
106
+ end
107
+
108
+ return @is_interrupted
109
+ end
110
+
111
+ def timeout?
112
+ if @is_timeout.nil?
113
+ @is_timeout = false
114
+ if result == '0'
115
+ rgx= Regexp.new(/\(timeout\)/)
116
+ if rgx.match(response)
117
+ @is_timeout = true
118
+ end
119
+ end
120
+ end
121
+
122
+ return @is_timeout
123
+ end
124
+
125
+ def random_error?
126
+ if @is_random_error.nil?
127
+ @is_random_error = false
128
+ if ((not failure?) and (result != '0'))
129
+ rgx= Regexp.new(/\(randomerror\)/)
130
+ if rgx.match(response)
131
+ @is_randomerror = true
132
+ end
133
+ end
134
+ end
135
+
136
+ return @is_randomerror
137
+ end
138
+
139
+ def offset
140
+ if @offset.nil?
141
+ rgx = Regexp.new(/^endpos/)
142
+ response.split(' ').each do | pair |
143
+ if rgx.match(pair)
144
+ @offset = pair.split('=').last
145
+ end
146
+ end
147
+ @offset = '' if @offset.nil?
148
+ end
149
+
150
+ return @offset
151
+ end
152
+
153
+ def digit
154
+ if @digit.nil?
155
+ if interrupted?
156
+ @digit = result.to_i.chr
157
+ end
158
+ @digit = '' if @digit.nil?
159
+ end
160
+
161
+ return @digit
162
+ end
163
+
164
+ def success?
165
+ return (not failure?)
166
+ end
167
+
168
+ def error
169
+ if random_error?
170
+ return result
171
+ else
172
+ return ''
173
+ end
174
+ end
175
+
176
+ def error?
177
+ return command_error?
178
+ end
179
+
180
+ def response
181
+ return message
182
+ end
183
+
184
+ end
@@ -0,0 +1,47 @@
1
+ #
2
+ # File: result.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
+
24
+ class Result
25
+
26
+ def initialize(result)
27
+ @result = result
28
+ end
29
+
30
+ def to_i
31
+ @result.to_i
32
+ end
33
+
34
+ def to_s
35
+ @result.to_s
36
+ end
37
+
38
+ def ==(val)
39
+ if ((val.to_i.to_s == val.to_s) and (val.to_s.to_i == val.to_i))
40
+ if ((@result == val) or (@result.to_s == val.to_s) or (@result.to_i == val.to_i))
41
+ return true
42
+ end
43
+ end
44
+
45
+ return false
46
+ end
47
+ end