Class: AGISelection
- Inherits:
-
Object
- Object
- AGISelection
- Defined in:
- lib/AGISelection.rb
Overview
AGISelection implements the AGI function get_data via an externally configurable YAML file
Constant Summary collapse
- @@sounds_dir =
nil
Instance Attribute Summary collapse
-
#audio ⇒ Object
:audio The name of the file that you wish to play.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
-
#configure(input) ⇒ Object
Configure all the basic variables that AGISelection needs * :audio The name of the file that you wish to play * :default_timeout set to 600 seconds.
-
#initialize(input = nil) ⇒ AGISelection
constructor
-
:max_digits no maximum (nil) by default.
-
-
#read(conf = {:timeout => @default_timeout, :max_digits => @max_digits}) ⇒ Object
(also: #execute, #get, #get_data)
Read returns the result of executing agi.get_data() You must pass an AGI object as a parameter in your YAML hash For example: require ‘AGI’ require ‘AGISelection’.
Constructor Details
#initialize(input = nil) ⇒ AGISelection
-
:max_digits no maximum (nil) by default
54 55 56 57 58 59 60 |
# File 'lib/AGISelection.rb', line 54 def initialize(input=nil) @audio = nil @default_timeout = 600 @max_digits = nil @params = input configure(input) end |
Instance Attribute Details
#audio ⇒ Object
:audio The name of the file that you wish to play
48 49 50 |
# File 'lib/AGISelection.rb', line 48 def audio @audio end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
49 50 51 |
# File 'lib/AGISelection.rb', line 49 def params @params end |
Class Method Details
.sounds_dir=(sounds_dir) ⇒ Object
121 122 123 |
# File 'lib/AGISelection.rb', line 121 def AGISelection.sounds_dir=(sounds_dir) @@sounds_dir = sounds_dir end |
Instance Method Details
#configure(input) ⇒ Object
Configure all the basic variables that AGISelection needs
-
:audio The name of the file that you wish to play
-
:default_timeout set to 600 seconds. This can be overridden by passing a :timeout paramerter in your YAML hash
-
:max_digits no maximum (nil) by default
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/AGISelection.rb', line 66 def configure(input) if input.respond_to?('read') config = YAML::load(input) elsif input.respond_to?(:to_hash) config = input elsif input.respond_to?(:to_s) and File.exists?(input.to_s) and File.readable?(input.to_s) config = File.open( input.to_s ) { |f| YAML::load( f ) } end if config.respond_to?(:to_hash) @params = config @audio = config[:audio] @default_timeout = config[:timeout] || @default_timeout @max_digits = config[:max_digits] || @max_digits end end |
#read(conf = {:timeout => @default_timeout, :max_digits => @max_digits}) ⇒ Object Also known as: execute, get, get_data
Read returns the result of executing agi.get_data() You must pass an AGI object as a parameter in your YAML hash For example: require ‘AGI’ require ‘AGISelection’
agi = AGI.new({}) # Initialize the AGI or bad things will happen agi.init() yaml_hash = => ‘tt-monkeys’, :max_digits => 4 foo = AGISelection.new(yaml_hash) # Override the Audio file from the YAML hash foo.audio = ‘somethingelse’ foo.read(:agi => agi)
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/AGISelection.rb', line 96 def read(conf={:timeout => @default_timeout, :max_digits => @max_digits}) if !conf[:agi].respond_to?(:get_data) raise ArgumentError, "agi required, must be an AsteriskAGI" elsif @audio.nil? raise ArgumentError, "You must supply an audio file" end conf[:timeout] = @default_timeout unless conf.has_key?(:timeout) conf[:max_digits] = @max_digits unless conf.has_key?(:max_digits) agi = conf[:agi] if @@sounds_dir then audio = @@sounds_dir + '/' + @audio else audio = @audio end begin result = agi.get_data(audio, conf[:timeout], conf[:max_digits]) rescue AGITimeoutError nil end end |