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
data/ChangeLog CHANGED
@@ -1,12 +1,3 @@
1
- 2006-03-05
2
- -- ruby-agi-1.1.2 released
3
- -- bug # 3733 fixed.
4
- -- AGI#initialize will make sure the above bug won't happen.
5
-
6
- 2006-02-08
7
- -- method AsteriskVariable#init_caller_variable updated to have correct callerid
8
- -- method ReturnStatus#timeout? updated
9
-
10
1
  2006-01-16 (revision 23)
11
2
  -- ruby-agi-1.1.0 released
12
3
  -- method calleridnumber added and is generated from callerid
data/DOWNLOAD CHANGED
@@ -1,3 +1,3 @@
1
1
  To download ruby-agi or ruby-agi dependent application, please visit
2
- http://ruby-agi.rubyforge.org
2
+ http://www.ruby-agi.org
3
3
 
data/INSTALL CHANGED
@@ -1,10 +1,5 @@
1
1
  I strongly suggest to install ruby-agi using gem,
2
- % gem install ruby-agi
3
- To update your existing ruby-agi using gem, try
4
- % gem update ruby-agi
5
-
6
- If you don't have gem intalled on your computer, download it from here
7
- http://www.rubygems.org
2
+ gem install ruby-agi
8
3
 
9
4
  Alternatively, do
10
5
  1. ruby extconf.rb
data/README CHANGED
@@ -1,14 +1,17 @@
1
1
  This library comes with absolutely no warranty.
2
2
 
3
- ruby-agi is a library to write AGI scripts in ruby language for Asterisk. ruby-agi does not depend of Asterisk Manager.
4
- There have a very simple AGI script in example/call_log.rb
5
- I couldn't write any tutorial for ruby-agi and I am not good at it, if anybody want to give me a hand on writing documentation and tutorial, would be greatly appreciated.
3
+ I wanted to write couple of AGI scripts in ruby for myself.
4
+ But I didn't see any AGI library written in ruby available.
5
+ So, I decided to develop one and share with everybody.
6
6
 
7
- Here are a sites that may help to know more about ruby-agi
8
- http://ruby-agi.rubyforge.org (ruby-agi homepage)
7
+ Hopefully, you already understood I am not good at documentation.
8
+ I truely appolize for that.
9
+ If anybody want to give a hand to write documentation for this project would be greatly appreciated.
9
10
 
10
- Feel free to send me email, if you don't find any answer related to ruby-agi.
11
+ Project homepage: http://www.ruby-agi.org
12
+
13
+ Please feel free to email me with your feature request, bug report or any suggession.
11
14
 
12
15
  Thank you,
13
16
  Mohammad Khan,
14
- email: info <AT> beeplove <DOT> com
17
+ email: info at beeplove dot com
@@ -1,11 +1,20 @@
1
- Release notes of ruby-agi-1.1.2
2
- March 06, 2006
1
+ 1.1.0 (2006-01-17)
2
+ addition of method 'jump_to'
3
+ jump_to would take three arguments ex. jump_to(context, extension, priority)
4
+ enhanced callerid, calleridname and calleridnumber. calleridnumber is an addtional method to this release.
5
+ Regardless of Asterisk version above three caller variables would return uniform value.
6
+ Such as, callerid would return "John Smith" <1234567890> or empty string, if unidentified
7
+ calleridnumber would return number part of callerid (as string) ex. 1234567890 or empty string, if unidentified
8
+ calleridname would return name part of callerid ex. John Smith or emtpy string, if unidentified
9
+
10
+ 1.0.2 (2006-01-09)
11
+ Because of a yaml bug in ruby-1.8.3, rubyforge server doesn't support any package that were built on ruby-1.8.3
12
+ This version is basically re-build of version 1.0.1 on ruby-1.8.4 instead of ruby-1.8.3
3
13
 
4
- In this release bug # 3722 has been fixed
14
+ 1.0.1 (2006-01-08)
15
+ This release have minor a minor change.
16
+ There have an example file in examples/call_log.rb
17
+ You can use call_log.rb to keep your incoming call history in syslog.
5
18
 
6
- Feedback, suggestion, feature request, bug report is always appreciated.
7
-
8
-
9
- Thanks,
10
- Mohammad Khan
11
- info <AT> beeplove <DOT> com
19
+ 1.0.0 (2006-01-08)
20
+ This is the first stable version of ruby-agi
@@ -75,8 +75,8 @@ class AsteriskVariable < AGI
75
75
  def read_env(name)
76
76
  if debug?
77
77
  semaphore do
78
- $stderr.puts " -- ruby-agi << Read asterisk variable '#{name}'"
79
- $stderr.puts " -- ruby-agi >> Asterisk variable #{name} = #{env[name].to_s}"
78
+ $stderr.puts " -- ruby-agi-trunk << Read asterisk variable '#{name}'"
79
+ $stderr.puts " -- ruby-agi-trunk >> Asterisk variable #{name} = #{env[name].to_s}"
80
80
  end
81
81
  end
82
82
 
@@ -36,12 +36,18 @@
36
36
  require 'sync'
37
37
 
38
38
  require 'ruby-agi/agi.rb'
39
- require 'ruby-agi/return_status.rb'
40
39
  require 'ruby-agi/error.rb'
40
+ require 'ruby-agi/return_status.rb'
41
41
 
42
42
  class AGI
43
43
  end
44
44
 
45
+ class ReturnStatus
46
+ end
47
+
48
+ class Answer < ReturnStatus
49
+ end
50
+
45
51
 
46
52
  class Command < AGI
47
53
  def initialize
@@ -63,7 +69,7 @@ class Command < AGI
63
69
  public
64
70
  def answer
65
71
  cmd = "ANSWER"
66
- rs = exec_command(cmd)
72
+ rs = exec_command(cmd, Answer)
67
73
  raise CommandError, rs.to_s if rs.command_error?
68
74
  return rs
69
75
  end
@@ -85,7 +91,7 @@ class Command < AGI
85
91
  public
86
92
  def set_auto_hangup(secs=0)
87
93
  cmd = "SET AUTOHANGUP #{secs.to_s}"
88
- rs = exec_command(cmd)
94
+ rs = exec_command(cmd, SetAutoHangup)
89
95
  raise CommandError, rs.to_s if rs.command_error?
90
96
  return rs
91
97
  end
@@ -120,7 +126,7 @@ class Command < AGI
120
126
  end
121
127
 
122
128
  cmd = "CHANNEL STATUS #{channel.to_s}"
123
- rs = exec_command(cmd)
129
+ rs = exec_command(cmd, ChannelStatus)
124
130
  raise CommandError, rs.to_s if rs.command_error?
125
131
  return rs
126
132
  end
@@ -146,7 +152,7 @@ class Command < AGI
146
152
  options = ""
147
153
  end
148
154
  cmd = "EXEC #{application.to_s} #{options.to_s}"
149
- rs = exec_command(cmd)
155
+ rs = exec_command(cmd, Exec)
150
156
  raise CommandError, rs.to_s if rs.command_error?
151
157
  return rs
152
158
  end
@@ -179,7 +185,7 @@ class Command < AGI
179
185
 
180
186
  cmd = "GET DATA #{filename.to_s} #{timeout.to_s} #{max_digit.to_s}"
181
187
 
182
- rs = exec_command(cmd)
188
+ rs = exec_command(cmd, WaitForDigits)
183
189
  raise CommandError, rs.to_s if rs.command_error?
184
190
  return rs
185
191
  end
@@ -201,7 +207,7 @@ class Command < AGI
201
207
  public
202
208
  def get_variable(name)
203
209
  cmd = "GET VARIABLE #{name.to_s}"
204
- rs = exec_command(cmd)
210
+ rs = exec_command(cmd, GetVariable)
205
211
  raise CommandError, rs.to_s if rs.command_error?
206
212
  return rs
207
213
  end
@@ -226,7 +232,7 @@ class Command < AGI
226
232
  end
227
233
 
228
234
  cmd = "HANGUP #{channel.to_s}"
229
- rs = exec_command(cmd)
235
+ rs = exec_command(cmd, Hangup)
230
236
  raise CommandError, rs.to_s if rs.command_error?
231
237
  return rs
232
238
  end
@@ -245,7 +251,7 @@ class Command < AGI
245
251
  public
246
252
  def noop(msg)
247
253
  cmd = "NOOP #{msg.to_s}"
248
- rs = exec_command(cmd)
254
+ rs = exec_command(cmd, Noop)
249
255
  raise CommandError, rs.to_s if rs.command_error?
250
256
  return rs
251
257
  end
@@ -273,7 +279,7 @@ class Command < AGI
273
279
  raise(ArgumentError, "timeout need to be positive") if (timeout < 1)
274
280
 
275
281
  cmd = "RECEIVE CHAR #{timeout.to_s}"
276
- rs = exec_command(cmd)
282
+ rs = exec_command(cmd, ReceiveChar)
277
283
  raise CommandError, rs.to_s if rs.command_error?
278
284
  return rs
279
285
  end
@@ -300,7 +306,7 @@ class Command < AGI
300
306
  raise(ArgumentError, "timeout need to be positive") if (timeout < 1)
301
307
 
302
308
  cmd = "RECEIVE TEXT #{timeout.to_s}"
303
- rs = exec_command(cmd)
309
+ rs = exec_command(cmd, ReceiveText)
304
310
  raise CommandError, rs.to_s if rs.command_error?
305
311
  return rs
306
312
  end
@@ -349,7 +355,7 @@ class Command < AGI
349
355
 
350
356
  cmd = "RECORD FILE #{filename} #{format} #{escape_digits} #{timeout}"
351
357
  cmd = "#{cmd} beep" if beep == true
352
- rs = exec_command(cmd)
358
+ rs = exec_command(cmd, RecordFile)
353
359
  raise CommandError, rs.to_s if rs.command_error?
354
360
  return rs
355
361
  end
@@ -377,7 +383,7 @@ class Command < AGI
377
383
  escape_digits = sanitize_escape_digits(escape_digits)
378
384
 
379
385
  cmd = "SAY DIGITS #{digit_string.to_s} #{escape_digits}"
380
- rs = exec_command(cmd)
386
+ rs = exec_command(cmd, SayDigits)
381
387
  raise CommandError, rs.to_s if rs.command_error?
382
388
  return rs
383
389
  end
@@ -403,7 +409,7 @@ class Command < AGI
403
409
  def say_number(number, escape_digits=nil)
404
410
  escape_digits = sanitize_escape_digits(escape_digits)
405
411
  cmd = "SAY NUMBER #{number.to_s} #{escape_digits.to_s}"
406
- rs = exec_command(cmd)
412
+ rs = exec_command(cmd, SayNumber)
407
413
  raise CommandError, rs.to_s if rs.command_error?
408
414
  return rs
409
415
  end
@@ -429,7 +435,7 @@ class Command < AGI
429
435
  def say_phonetic(string, escape_digits=nil)
430
436
  escape_digits = sanitize_escape_digits(escape_digits)
431
437
  cmd = "SAY PHONETIC #{string.to_s} #{escape_digits}"
432
- rs = exec_command(cmd)
438
+ rs = exec_command(cmd, SayPhonetic)
433
439
  raise CommandError, rs.to_s if rs.command_error?
434
440
  return rs
435
441
  end
@@ -455,7 +461,7 @@ class Command < AGI
455
461
  def say_time(time=Time.now.to_i, escape_digits='#')
456
462
  escape_digits = sanitize_escape_digits(escape_digits)
457
463
  cmd = "SAY TIME #{time.to_s} #{escape_digits.to_s}"
458
- rs = exec_command(cmd)
464
+ rs = exec_command(cmd, SayTime)
459
465
  raise CommandError, rs.to_s if rs.command_error?
460
466
  return rs
461
467
  end
@@ -479,7 +485,7 @@ class Command < AGI
479
485
  public
480
486
  def send_image(image)
481
487
  cmd = "SEND IMAGE #{image.to_s}"
482
- rs = exec_command(cmd)
488
+ rs = exec_command(cmd, SendImage)
483
489
  raise CommandError, rs.to_s if rs.command_error?
484
490
  return rs
485
491
  end
@@ -503,7 +509,7 @@ class Command < AGI
503
509
  public
504
510
  def send_text(text)
505
511
  cmd = "SEND TEXT #{text.to_s}"
506
- rs = exec_command(cmd)
512
+ rs = exec_command(cmd, SendText)
507
513
  raise CommandError, rs.to_s if rs.command_error?
508
514
  return rs
509
515
  end
@@ -524,7 +530,7 @@ class Command < AGI
524
530
  public
525
531
  def set_caller_id(number)
526
532
  cmd = "SET CALLERID #{number.to_s}"
527
- rs = exec_command(cmd)
533
+ rs = exec_command(cmd, SetCallerID)
528
534
  raise CommandError, rs.to_s if rs.command_error?
529
535
  return rs
530
536
  end
@@ -547,7 +553,7 @@ class Command < AGI
547
553
  public
548
554
  def set_context(context)
549
555
  cmd = "SET CONTEXT #{context.to_s}"
550
- rs = exec_command(cmd)
556
+ rs = exec_command(cmd, SetContext)
551
557
  raise CommandError, rs.to_s if rs.command_error?
552
558
  return rs
553
559
  end
@@ -571,7 +577,7 @@ class Command < AGI
571
577
  public
572
578
  def set_extension(extension)
573
579
  cmd = "SET EXTENSION #{extension.to_s}"
574
- rs = exec_command(cmd)
580
+ rs = exec_command(cmd, SetExtension)
575
581
  raise CommandError, rs.to_s if rs.command_error?
576
582
  return rs
577
583
  end
@@ -598,7 +604,7 @@ class Command < AGI
598
604
  mode = 'OFF'
599
605
  end
600
606
  cmd = "SET MUSIC #{mode.to_s} #{moh_class.to_s}"
601
- rs = exec_command(cmd)
607
+ rs = exec_command(cmd, SetMusic)
602
608
  raise CommandError, rs.to_s if rs.command_error?
603
609
  return rs
604
610
  end
@@ -618,7 +624,7 @@ class Command < AGI
618
624
  public
619
625
  def set_priority(priority)
620
626
  cmd = "SET PRIORITY #{priority.to_s}"
621
- rs = exec_command(cmd)
627
+ rs = exec_command(cmd, SetPriority)
622
628
  raise CommandError, rs.to_s if rs.command_error?
623
629
  return rs
624
630
  end
@@ -644,7 +650,7 @@ class Command < AGI
644
650
  public
645
651
  def set_variable(name, value)
646
652
  cmd = "SET VARIABLE #{name.to_s} \"#{value.to_s}\""
647
- rs = exec_command(cmd)
653
+ rs = exec_command(cmd, SetVariable)
648
654
  raise CommandError, rs.to_s if rs.command_error?
649
655
  return rs
650
656
  end
@@ -678,7 +684,7 @@ class Command < AGI
678
684
  escape_digits = sanitize_escape_digits(escape_digits)
679
685
 
680
686
  cmd = "STREAM FILE #{filename.to_s} #{escape_digits}"
681
- rs = exec_command(cmd)
687
+ rs = exec_command(cmd, StreamFile)
682
688
  raise CommandError, rs.to_s if rs.command_error?
683
689
 
684
690
  return rs
@@ -712,7 +718,7 @@ class Command < AGI
712
718
  mode = 'OFF'
713
719
  end
714
720
  cmd = "TDD MODE #{mode.to_s}"
715
- rs = exec_command(cmd)
721
+ rs = exec_command(cmd, TDDMode)
716
722
  raise CommandError, rs.to_s if rs.command_error?
717
723
  return rs
718
724
  end
@@ -745,7 +751,7 @@ class Command < AGI
745
751
  public
746
752
  def verbose(message, level=3)
747
753
  cmd = "VERBOSE \"#{message.to_s}\" #{level.to_s}"
748
- rs = exec_command(cmd)
754
+ rs = exec_command(cmd, Verbose)
749
755
  raise CommandError, rs.to_s if rs.command_error?
750
756
  return rs
751
757
  end
@@ -772,7 +778,7 @@ class Command < AGI
772
778
  timeout = sanitize_timeout(timeout)
773
779
 
774
780
  cmd = "WAIT FOR DIGIT #{timeout.to_s}"
775
- rs = exec_command(cmd)
781
+ rs = exec_command(cmd, WaitForDigit)
776
782
  raise CommandError, rs.to_s if rs.command_error?
777
783
  return rs
778
784
  end
@@ -823,14 +829,8 @@ class Command < AGI
823
829
  return rs
824
830
  end
825
831
 
826
- #private
827
- #def escape(str)
828
- # rxp = Regexp.new(/\"/)
829
- # return str.gsub(rxp, '\"')
830
- #end
831
-
832
832
  protected
833
- def exec_command(cmd)
833
+ def exec_command(cmd, return_status=nil)
834
834
  rs = nil
835
835
  begin
836
836
  semaphore do
@@ -838,8 +838,11 @@ class Command < AGI
838
838
  $stdout.puts cmd
839
839
  responses = $stdin.gets
840
840
  $stderr.puts " -- ruby-agi >> #{responses}" if debug?
841
- rs = ReturnStatus.new(cmd, responses)
842
-
841
+ if return_status.nil?
842
+ rs = ReturnStatus.new(cmd, responses)
843
+ else
844
+ rs = return_status.new(cmd, responses)
845
+ end
843
846
  end
844
847
 
845
848
  rescue Errno::EPIPE
@@ -41,5 +41,8 @@ end
41
41
  class CommandError < Exception
42
42
  end
43
43
 
44
+ class UnknownError < Exception
45
+ end
46
+
44
47
  class AGIError < Exception
45
48
  end
@@ -1,92 +1,31 @@
1
- #
2
- # File: return_status.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
-
24
- # every method of this class would return string or boolean
25
- # methods of command class usually return ReturnStatus object
26
-
27
- class ReturnStatus
28
-
29
- def initialize(command, message)
30
- @command = command.chomp
31
- @message = message
32
- @result = nil
33
- @digit = nil
34
- @digits = nil
35
- @return_code = nil
36
- @command_error = false
37
-
38
- if message.nil?
39
- @messsage = "No responses !!"
40
- else
41
- str = @message.split(' ')
42
- @return_code = str[0]
43
- if @return_code == '200'
44
- @result = str[1].split('=')[1]
45
- end
46
- end
47
- end
48
-
49
- public
50
- def to_s
51
- return @command.to_s + ' >> ' + @message.to_s
52
- end
53
-
54
- public
55
- def result
56
- return @result.to_s
57
- end
58
-
59
- public
60
- def digit
61
- if (@result == '0')
62
- return nil
63
- else
64
- return @result.to_i.chr
65
- end
66
- end
67
-
68
- public
69
- def digits
70
- return @result.to_s
71
- end
72
-
73
- public
74
- def message
75
- return @message.to_s
76
- end
77
-
78
- public
79
- def command_error?
80
- return (result.nil? or (not (@return_code == '200')))
81
- end
82
-
83
- public
84
- def timeout?
85
- rgx = Regexp.new(/\(timeout\)/)
86
- if rgx.match(@message)
87
- return true
88
- else
89
- return false
90
- end
91
- end
92
- end
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/'