Class: Adhearsion::VoIP::Asterisk::Commands::QueueProxy::QueueAgentsListProxy

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/adhearsion/voip/asterisk/commands.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proxy, cached = false) ⇒ QueueAgentsListProxy

Returns a new instance of QueueAgentsListProxy.



1267
1268
1269
1270
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1267

def initialize(proxy, cached=false)
  @proxy  = proxy
  @cached = cached
end

Instance Attribute Details

#agentsObject (readonly)

Returns the value of attribute agents.



1266
1267
1268
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1266

def agents
  @agents
end

#proxyObject (readonly)

Returns the value of attribute proxy.



1266
1267
1268
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1266

def proxy
  @proxy
end

Instance Method Details

#cached?Boolean

Returns:

  • (Boolean)


1353
1354
1355
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1353

def cached?
  @cached
end

#countObject Also known as: size, length



1272
1273
1274
1275
1276
1277
1278
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1272

def count
  if cached? && @cached_count
    @cached_count
  else
    @cached_count = proxy.environment.variable("QUEUE_MEMBER_COUNT(#{proxy.name})").to_i
  end
end

#each(&block) ⇒ Object



1338
1339
1340
1341
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1338

def each(&block)
  check_agent_cache!
  agents.each(&block)
end

#firstObject



1343
1344
1345
1346
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1343

def first
  check_agent_cache!
  agents.first
end

#lastObject



1348
1349
1350
1351
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1348

def last
  check_agent_cache!
  agents.last
end

#login!(*args) ⇒ Object

Logs a pre-defined agent into this queue and waits for calls. Pass in :silent => true to stop the message which says “Agent logged in”.

Raises:

  • (ArgumentError)


1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1312

def login!(*args)
  options = args.last.kind_of?(Hash) ? args.pop : {}

  silent = options.delete(:silent).equal?(false) ? '' : 's'
  id     = args.shift
  id   &&= AgentProxy.id_from_agent_channel(id)
  raise ArgumentError, "Unrecognized Hash options to login(): #{options.inspect}" if options.any?
  raise ArgumentError, "Unrecognized argument to login(): #{args.inspect}" if args.any?

  proxy.environment.execute('AgentLogin', id, silent)
end

#logout!Object

Removes the current channel from this queue



1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1325

def logout!
  # TODO: DRY this up. Repeated in the AgentProxy...
  proxy.environment.execute 'RemoveQueueMember', proxy.name
  case proxy.environment.variable("RQMSTATUS")
    when "REMOVED"     then true
    when "NOTINQUEUE"  then false
    when "NOSUCHQUEUE"
      raise QueueDoesNotExistError.new(proxy.name)
    else
      raise "Unrecognized RQMSTATUS variable!"
  end
end

#new(*args) ⇒ Object

:name value will be viewable in the queue_log :penalty is the penalty assigned to this agent for answering calls on this queue

Parameters:

  • args (Hash)

Raises:

  • (ArgumentError)


1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1285

def new(*args)

  options   = args.last.kind_of?(Hash) ? args.pop : {}
  interface = args.shift || ''

  raise ArgumentError, "You may only supply an interface and a Hash argument!" if args.any?

  penalty = options.delete(:penalty) || ''
  name    = options.delete(:name)    || ''

  raise ArgumentError, "Unrecognized argument(s): #{options.inspect}" if options.any?

  proxy.environment.execute("AddQueueMember", proxy.name, interface, penalty, '', name)

  case proxy.environment.variable("AQMSTATUS")
    when "ADDED"         then true
    when "MEMBERALREADY" then false
    when "NOSUCHQUEUE"   then raise QueueDoesNotExistError.new(proxy.name)
    else
      raise "UNRECOGNIZED AQMSTATUS VALUE!"
  end

  # TODO: THIS SHOULD RETURN AN AGENT INSTANCE
end

#to_aObject



1357
1358
1359
1360
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1357

def to_a
  check_agent_cache!
  @agents
end