Class: Adhearsion::Translator::Asterisk::AGICommand

Inherits:
Object
  • Object
show all
Defined in:
lib/adhearsion/translator/asterisk/agi_command.rb

Constant Summary collapse

ARG_QUOTER =
/["\\]/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, channel, command, *params) ⇒ AGICommand

Returns a new instance of AGICommand.



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

def initialize(id, channel, command, *params)
  @id, @channel, @command, @params = id, channel, command, params
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

Instance Method Details

#execute(ami_client) ⇒ Object



19
20
21
# File 'lib/adhearsion/translator/asterisk/agi_command.rb', line 19

def execute(ami_client)
  AMIErrorConverter.convert { ami_client.send_action 'AGI', 'Channel' => @channel, 'Command' => agi_command, 'CommandID' => id }
end

#parse_result(event) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/adhearsion/translator/asterisk/agi_command.rb', line 23

def parse_result(event)
  parser = RubyAMI::AGIResultParser.new event['Result']
  {code: parser.code, result: parser.result, data: parser.data}
rescue ArgumentError => e
  logger.warn "Illegal message received from Asterisk: #{e.message}"
  {code: -1, result: nil, data: nil}
end