Class: Adhearsion::VoIP::Asterisk::Commands::QueueProxy
- Defined in:
- lib/adhearsion/voip/asterisk/commands.rb
Defined Under Namespace
Classes: AgentProxy, QueueAgentsListProxy, QueueDoesNotExistError
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#agents(options = {}) ⇒ QueueAgentsListProxy
Get the agents associated with a queue.
-
#any? ⇒ Boolean
Check whether any calls are waiting in the queue.
-
#empty? ⇒ Boolean
Check whether the waiting count is zero.
-
#exists? ⇒ Boolean
Check whether a queue exists/is defined in Asterisk.
-
#initialize(name, environment) ⇒ QueueProxy
constructor
A new instance of QueueProxy.
-
#join!(options = {}) ⇒ Object
Makes the current channel join the queue.
-
#waiting_count ⇒ Integer
Check how many channels are waiting in the queue.
Constructor Details
#initialize(name, environment) ⇒ QueueProxy
Returns a new instance of QueueProxy.
1155 1156 1157 |
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1155 def initialize(name, environment) @name, @environment = name, environment end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
1154 1155 1156 |
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1154 def environment @environment end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1154 1155 1156 |
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1154 def name @name end |
Class Method Details
.format_join_hash_key_arguments(options) ⇒ Object
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 |
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1107 def format_join_hash_key_arguments() bad_argument = lambda do |(key, value)| raise ArgumentError, "Unrecognize value for #{key.inspect} -- #{value.inspect}" end # Direct Queue() arguments: timeout = .delete :timeout announcement = .delete :announce # Terse single-character options ring_style = .delete :play allow_hangup = .delete :allow_hangup allow_transfer = .delete :allow_transfer raise ArgumentError, "Unrecognized args to join!: #{.inspect}" if .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 = ring_style + allow_transfer + allow_hangup [, '', announcement, timeout].map(&:to_s) end |
Instance Method Details
#agents(options = {}) ⇒ QueueAgentsListProxy
Get the agents associated with a queue
1200 1201 1202 1203 1204 1205 1206 1207 1208 |
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1200 def agents(={}) cached = .has_key?(:cache) ? .delete(:cache) : true raise ArgumentError, "Unrecognized arguments to agents(): #{.inspect}" if .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
1226 1227 1228 |
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1226 def any? waiting_count > 0 end |
#empty? ⇒ Boolean
Check whether the waiting count is zero
1220 1221 1222 |
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1220 def empty? waiting_count == 0 end |
#exists? ⇒ Boolean
Check whether a queue exists/is defined in Asterisk
1232 1233 1234 1235 |
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1232 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! :allow_transfer => :agent, :timeout => 30.seconds,
1191 1192 1193 1194 |
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1191 def join!(={}) environment.execute("queue", name, *self.class.format_join_hash_key_arguments()) normalize_queue_status_variable environment.variable("QUEUESTATUS") end |
#waiting_count ⇒ Integer
Check how many channels are waiting in the queue
1213 1214 1215 1216 |
# File 'lib/adhearsion/voip/asterisk/commands.rb', line 1213 def waiting_count raise QueueDoesNotExistError.new(name) unless exists? environment.variable("QUEUE_WAITING_COUNT(#{name})").to_i end |