Class: Punchblock::Translator::Asterisk::Component::Asterisk::AGICommand

Inherits:
Component
  • Object
show all
Defined in:
lib/punchblock/translator/asterisk/component/asterisk/agi_command.rb

Instance Attribute Summary collapse

Attributes inherited from Component

#call, #id, #internal

Instance Method Summary collapse

Methods inherited from Component

#call_id, #execute_command, #initialize, #logger_id, #send_complete_event, #send_event

Constructor Details

This class inherits a constructor from Punchblock::Translator::Asterisk::Component::Component

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



10
11
12
# File 'lib/punchblock/translator/asterisk/component/asterisk/agi_command.rb', line 10

def action
  @action
end

Instance Method Details

#executeObject



16
17
18
# File 'lib/punchblock/translator/asterisk/component/asterisk/agi_command.rb', line 16

def execute
  @call.send_ami_action! @action
end

#handle_ami_event(event) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/punchblock/translator/asterisk/component/asterisk/agi_command.rb', line 20

def handle_ami_event(event)
  pb_logger.debug "Handling AMI event: #{event.inspect}"
  if event.name == 'AsyncAGI'
    if event['SubEvent'] == 'Exec'
      pb_logger.debug "Received AsyncAGI:Exec event, sending complete event."
      send_complete_event success_reason(event)
    end
  end
end

#parse_agi_result(result) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/punchblock/translator/asterisk/component/asterisk/agi_command.rb', line 30

def parse_agi_result(result)
  match = URI.decode(result).chomp.match(/^(\d{3}) result=(-?\d*) ?(\(?.*\)?)?$/)
  if match
    data = match[3] ? match[3].gsub(/(^\()|(\)$)/, '') : nil
    [match[1].to_i, match[2].to_i, data]
  end
end

#setupObject



12
13
14
# File 'lib/punchblock/translator/asterisk/component/asterisk/agi_command.rb', line 12

def setup
  @action = create_action
end