Class: Adhearsion::DialPlan::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/adhearsion/voip/dial_plan.rb

Defined Under Namespace

Classes: NoContextError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.



86
87
88
# File 'lib/adhearsion/voip/dial_plan.rb', line 86

def initialize
  @dial_plan = DialPlan.new
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



85
86
87
# File 'lib/adhearsion/voip/dial_plan.rb', line 85

def context
  @context
end

#dial_planObject

Returns the value of attribute dial_plan.



85
86
87
# File 'lib/adhearsion/voip/dial_plan.rb', line 85

def dial_plan
  @dial_plan
end

Class Method Details

.handle(call) ⇒ Object



80
81
82
# File 'lib/adhearsion/voip/dial_plan.rb', line 80

def handle(call)
  new.handle(call)
end

Instance Method Details

#entry_point_for(call) ⇒ Object

Find the dialplan by the context name from the call or from the first path entry in the AGI URL



110
111
112
113
114
115
116
# File 'lib/adhearsion/voip/dial_plan.rb', line 110

def entry_point_for(call)
  if entry_point = dial_plan.lookup(call.context.to_sym)
    entry_point
  elsif call.respond_to?(:request) && m = call.request.path.match(%r{/([^/]+)})
    dial_plan.lookup(m[1].to_sym)
  end
end

#handle(call) ⇒ Object

Raises:



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/adhearsion/voip/dial_plan.rb', line 90

def handle(call)
  if call.failed_call?
    environment = ExecutionEnvironment.create(call, nil)
    call.extract_failed_reason_from environment
    raise FailedExtensionCallException.new(environment)
  end
  
  if call.hungup_call?
    raise HungupExtensionCallException.new(ExecutionEnvironment.new(call, nil))
  end
  
  starting_entry_point = entry_point_for call
  raise NoContextError, "No dialplan entry point for call context '#{call.context}' -- Ignoring call!" unless starting_entry_point
  @context = ExecutionEnvironment.create(call, starting_entry_point)
  inject_context_names_into_environment @context
  @context.run
end