Class: Adhearsion::DialPlan::ConfirmationManager
- Defined in:
- lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb
Instance Attribute Summary collapse
-
#call ⇒ Object
readonly
Returns the value of attribute call.
Class Method Summary collapse
- .confirmation_call?(call) ⇒ Boolean
- .decode_hash(encoded_hash) ⇒ Object
- .encode_hash_for_dial_macro_argument(options) ⇒ Object
- .handle(call) ⇒ Object
Instance Method Summary collapse
- #handle ⇒ Object
-
#initialize(call) ⇒ ConfirmationManager
constructor
A new instance of ConfirmationManager.
Constructor Details
#initialize(call) ⇒ ConfirmationManager
Returns a new instance of ConfirmationManager.
43 44 45 46 |
# File 'lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb', line 43 def initialize(call) @call = call extend Adhearsion::VoIP::Commands.for(call.originating_voip_platform) end |
Instance Attribute Details
#call ⇒ Object (readonly)
Returns the value of attribute call.
42 43 44 |
# File 'lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb', line 42 def call @call end |
Class Method Details
.confirmation_call?(call) ⇒ Boolean
24 25 26 |
# File 'lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb', line 24 def confirmation_call?(call) call.variables.has_key?(:network_script) && call.variables[:network_script].starts_with?('confirm!') end |
.decode_hash(encoded_hash) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb', line 28 def decode_hash(encoded_hash) encoded_hash = encoded_hash =~ /^M\((.+)\)$/ ? $1 : encoded_hash encoded_hash = encoded_hash =~ /^([^:]+\^)?(.+)$/ ? $2 : encoded_hash # Remove the macro name if it's there unencoded = URI.unescape(encoded_hash).split('!') unencoded.shift unless unencoded.first.include?(':') unencoded = unencoded.map { |pair| key, value = pair.split(':'); [key.to_sym ,value] }.flatten Hash[*unencoded].tap do |hash| hash[:timeout] &&= hash[:timeout].to_i hash[:play] &&= hash[:play].split('++') end end |
.encode_hash_for_dial_macro_argument(options) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb', line 7 def encode_hash_for_dial_macro_argument() = .clone macro_name = .delete :macro [:play] &&= [:play].kind_of?(Array) ? [:play].join('++') : [:play] = URI.escape .map { |key,value| "#{key}:#{value}" }.join('!') "M(#{macro_name}^#{})".tap do |str| if str.rindex('^') != str.index('^') raise ArgumentError, "You seem to have supplied a :confirm option with a caret (^) in it!" + " Please remove it. This will blow Asterisk up." end end end |
.handle(call) ⇒ Object
20 21 22 |
# File 'lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb', line 20 def handle(call) new(call).handle end |
Instance Method Details
#handle ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb', line 48 def handle variables = self.class.decode_hash call.variables[:network_script] answer loop do response = interruptible_play(*variables[:play]) if response && response.to_s == variables[:key].to_s # Don't set a variable to pass through to dial() break elsif response && response.to_s != variables[:key].to_s next else response = wait_for_digit variables[:timeout] if response if response.to_s == variables[:key].to_s # Don't set a variable to pass through to dial() break else next end else # By setting MACRO_RESULT to CONTINUE, we cancel the dial. variable 'MACRO_RESULT' => "CONTINUE" break end end end end |