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,48 @@
1
+ #
2
+ # File: error.rb
3
+ #
4
+ # ruby-agi: Ruby Language API for Asterisk
5
+ #
6
+ # Copyright (C) <2005> 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
+ # all the subclass of Exception is defined here
24
+
25
+
26
+ class Error < Exception
27
+ end
28
+
29
+ class DigitError < Exception
30
+ end
31
+
32
+ class HangupError < Exception
33
+ end
34
+
35
+ class TimeoutError < Exception
36
+ end
37
+
38
+ class ChannelError < Exception
39
+ end
40
+
41
+ class CommandError < Exception
42
+ end
43
+
44
+ class UnknownError < Exception
45
+ end
46
+
47
+ class AGIError < Exception
48
+ end
@@ -0,0 +1,31 @@
1
+ require 'ruby-agi/rs/return_status.rb'
2
+ require 'ruby-agi/rs/answer.rb'
3
+ require 'ruby-agi/rs/answer.rb'
4
+ require 'ruby-agi/rs/channel_status.rb'
5
+ require 'ruby-agi/rs/exec.rb'
6
+ require 'ruby-agi/rs/get_variable.rb'
7
+ require 'ruby-agi/rs/hangup.rb'
8
+ require 'ruby-agi/rs/noop.rb'
9
+ require 'ruby-agi/rs/receive_char.rb'
10
+ require 'ruby-agi/rs/receive_text.rb'
11
+ require 'ruby-agi/rs/record_file.rb'
12
+ require 'ruby-agi/rs/return_status.rb'
13
+ require 'ruby-agi/rs/say_digits.rb'
14
+ require 'ruby-agi/rs/say_number.rb'
15
+ require 'ruby-agi/rs/say_phonetic.rb'
16
+ require 'ruby-agi/rs/say_time.rb'
17
+ require 'ruby-agi/rs/send_image.rb'
18
+ require 'ruby-agi/rs/send_text.rb'
19
+ require 'ruby-agi/rs/set_auto_hangup.rb'
20
+ require 'ruby-agi/rs/set_caller_id.rb'
21
+ require 'ruby-agi/rs/set_context.rb'
22
+ require 'ruby-agi/rs/set_extension.rb'
23
+ require 'ruby-agi/rs/set_music.rb'
24
+ require 'ruby-agi/rs/set_priority.rb'
25
+ require 'ruby-agi/rs/set_variable.rb'
26
+ require 'ruby-agi/rs/stream_file.rb'
27
+ require 'ruby-agi/rs/tdd_mode.rb'
28
+ require 'ruby-agi/rs/verbose.rb'
29
+ require 'ruby-agi/rs/wait_for_digit.rb'
30
+ require 'ruby-agi/rs/wait_for_digits.rb'
31
+ #require 'ruby-agi/rs/'
@@ -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