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

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

Constant Summary

Constant Summary

Constants inherited from Component

Component::OptionError

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

- (Object) action (readonly)

Returns the value of attribute action



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

def action
  @action
end

Instance Method Details

- (Object) execute



18
19
20
# File 'lib/punchblock/translator/asterisk/component/asterisk/agi_command.rb', line 18

def execute
  @call.send_ami_action! @action
end

- (Object) handle_ami_event(event)



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

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

- (Object) parse_agi_result(result)



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

def parse_agi_result(result)
  match = URI::Parser.new.unescape(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

- (Object) setup



14
15
16
# File 'lib/punchblock/translator/asterisk/component/asterisk/agi_command.rb', line 14

def setup
  @action = create_action
end