Sha256: 5337702d5730e2184701d20667619eff3e72489673c5bc0d19ffff6e6835238b
Contents?: true
Size: 1.2 KB
Versions: 19
Compression:
Stored size: 1.2 KB
Contents
# encoding: utf-8 require 'active_support/core_ext/string/filters' require 'punchblock/translator/asterisk/ami_error_converter' module Punchblock module Translator class Asterisk class AGICommand ARG_QUOTER = /["\\]/.freeze attr_reader :id def initialize(id, channel, command, *params) @id, @channel, @command, @params = id, channel, command, params end # @raises RubyAMI::Error, ChannelGoneError def execute(ami_client) AMIErrorConverter.convert { ami_client.send_action 'AGI', 'Channel' => @channel, 'Command' => agi_command, 'CommandID' => id } end def parse_result(event) parser = RubyAMI::AGIResultParser.new event['Result'] {code: parser.code, result: parser.result, data: parser.data} end private def agi_command "#{@command} #{@params.map { |arg| quote_arg(arg) }.join(' ')}".squish end # Arguments surrounded by quotes; quotes backslash-escaped. # See parse_args in asterisk/res/res_agi.c (Asterisk 1.4.21.1) def quote_arg(arg) '"' + arg.to_s.gsub(ARG_QUOTER) { |m| "\\#{m}" } + '"' end end end end end
Version data entries
19 entries across 19 versions & 1 rubygems