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

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

Defined Under Namespace

Classes: AgentProxy, QueueAgentsListProxy, QueueDoesNotExistError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, environment) ⇒ QueueProxy

Returns a new instance of QueueProxy.



1213
1214
1215
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1213

def initialize(name, environment)
  @name, @environment = name, environment
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



1212
1213
1214
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1212

def environment
  @environment
end

#nameObject (readonly)

Returns the value of attribute name.



1212
1213
1214
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1212

def name
  @name
end

Class Method Details

.format_join_hash_key_arguments(options) ⇒ Object

Raises:

  • (ArgumentError)


1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1164

def format_join_hash_key_arguments(options)

  bad_argument = lambda do |(key, value)|
    raise ArgumentError, "Unrecognize value for #{key.inspect} -- #{value.inspect}"
  end

  # Direct Queue() arguments:
  timeout        = options.delete :timeout
  announcement   = options.delete :announce

  # Terse single-character options
  ring_style     = options.delete :play
  allow_hangup   = options.delete :allow_hangup
  allow_transfer = options.delete :allow_transfer
  agi            = options.delete :agi

  raise ArgumentError, "Unrecognized args to join!: #{options.inspect}" if options.any?

  ring_style = case ring_style
    when :ringing then 'r'
    when :music then   ''
    when nil
    else bad_argument[:play => ring_style]
  end.to_s

  allow_hangup = case allow_hangup
    when :caller then   'H'
    when :agent then    'h'
    when :everyone then 'Hh'
    when nil
    else bad_argument[:allow_hangup => allow_hangup]
  end.to_s

  allow_transfer = case allow_transfer
    when :caller then   'T'
    when :agent then    't'
    when :everyone then 'Tt'
    when nil
    else bad_argument[:allow_transfer => allow_transfer]
  end.to_s

  terse_character_options = ring_style + allow_transfer + allow_hangup

  [terse_character_options, '', announcement, timeout, agi].map(&:to_s)
end

Instance Method Details

#agents(options = {}) ⇒ QueueAgentsListProxy

Get the agents associated with a queue

Parameters:

  • options (Hash) (defaults to: {})

Returns:

Raises:

  • (ArgumentError)


1261
1262
1263
1264
1265
1266
1267
1268
1269
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1261

def agents(options={})
  cached = options.has_key?(:cache) ? options.delete(:cache) : true
  raise ArgumentError, "Unrecognized arguments to agents(): #{options.inspect}" if options.keys.any?
  if cached
    @cached_proxy ||= QueueAgentsListProxy.new(self, true)
  else
    @uncached_proxy ||=  QueueAgentsListProxy.new(self, false)
  end
end

#any?Boolean

Check whether any calls are waiting in the queue

Returns:

  • (Boolean)


1287
1288
1289
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1287

def any?
  waiting_count > 0
end

#empty?Boolean

Check whether the waiting count is zero

Returns:

  • (Boolean)


1281
1282
1283
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1281

def empty?
  waiting_count == 0
end

#exists?Boolean

Check whether a queue exists/is defined in Asterisk

Returns:

  • (Boolean)


1293
1294
1295
1296
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1293

def exists?
  environment.execute('RemoveQueueMember', name, 'SIP/AdhearsionQueueExistenceCheck')
  environment.variable("RQMSTATUS") != 'NOSUCHQUEUE'
end

#join!(options = {}) ⇒ Object

Makes the current channel join the queue.

@example
  queue('sales').join!
@example
  queue('sales').join! :timeout => 1.minute
@example
  queue('sales').join! :play => :music
@example
  queue('sales').join! :play => :ringing
@example
  queue('sales').join! :announce => "custom/special-queue-announcement"
@example
  queue('sales').join! :allow_transfer => :caller
@example
  queue('sales').join! :allow_transfer => :agent
@example
  queue('sales').join! :allow_hangup   => :caller
@example
  queue('sales').join! :allow_hangup   => :agent
@example
  queue('sales').join! :allow_hangup   => :everyone
@example
  queue('sales').join! :agi            => 'agi://localhost/sales_queue_callback'
@example
  queue('sales').join! :allow_transfer => :agent, :timeout => 30.seconds,

Parameters:

  • options (Hash) (defaults to: {})

    :timeout - The number of seconds to wait for an agent to answer :play - Can be :ringing or :music. :announce - A sound file to play instead of the normal queue announcement. :allow_transfer - Can be :caller, :agent, or :everyone. Allow someone to transfer the call. :allow_hangup - Can be :caller, :agent, or :everyone. Allow someone to hangup with the * key. :agi - An AGI script to be called on the calling parties channel just before being connected.



1252
1253
1254
1255
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1252

def join!(options={})
  environment.execute("Queue", name, *self.class.format_join_hash_key_arguments(options))
 normalize_queue_status_variable environment.variable("QUEUESTATUS")
end

#waiting_countInteger

Check how many channels are waiting in the queue

Returns:

  • (Integer)

Raises:

  • QueueDoesNotExistError



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

def waiting_count
  raise QueueDoesNotExistError.new(name) unless exists?
  environment.variable("QUEUE_WAITING_COUNT(#{name})").to_i
end