Class: Adhearsion::Asterisk::QueueProxy::AgentProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/adhearsion/asterisk/queue_proxy/agent_proxy.rb

Constant Summary collapse

SUPPORTED_METADATA_NAMES =
%w[status password name mohclass exten channel]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interface, proxy) ⇒ AgentProxy

Returns a new instance of AgentProxy.



16
17
18
19
20
# File 'lib/adhearsion/asterisk/queue_proxy/agent_proxy.rb', line 16

def initialize(interface, proxy)
  @interface, @proxy = interface, proxy
  @id         = self.class.id_from_agent_channel interface
  @queue_name = proxy.name
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



15
16
17
# File 'lib/adhearsion/asterisk/queue_proxy/agent_proxy.rb', line 15

def id
  @id
end

#interfaceObject (readonly)

Returns the value of attribute interface.



15
16
17
# File 'lib/adhearsion/asterisk/queue_proxy/agent_proxy.rb', line 15

def interface
  @interface
end

#proxyObject (readonly)

Returns the value of attribute proxy.



15
16
17
# File 'lib/adhearsion/asterisk/queue_proxy/agent_proxy.rb', line 15

def proxy
  @proxy
end

#queue_nameObject (readonly)

Returns the value of attribute queue_name.



15
16
17
# File 'lib/adhearsion/asterisk/queue_proxy/agent_proxy.rb', line 15

def queue_name
  @queue_name
end

Class Method Details

.id_from_agent_channel(id) ⇒ Object



9
10
11
12
# File 'lib/adhearsion/asterisk/queue_proxy/agent_proxy.rb', line 9

def id_from_agent_channel(id)
  id = id.to_s
  id.starts_with?('Agent/') ? id[%r[^Agent/(.+)$],1] : id
end

Instance Method Details

#logged_in?Boolean

Returns true/false depending on whether this agent is logged in.

Returns:

  • (Boolean)


63
64
65
# File 'lib/adhearsion/asterisk/queue_proxy/agent_proxy.rb', line 63

def logged_in?
  status == 'LOGGEDIN'
end

#pause!(options = {}) ⇒ Object

Pauses the given agent for this queue only. If you wish to pause this agent for all queues, pass in :everywhere => true. Returns true if the agent was successfully paused and false if the agent was not found.



37
38
39
40
41
42
43
44
45
46
# File 'lib/adhearsion/asterisk/queue_proxy/agent_proxy.rb', line 37

def pause!(options = {})
  args = [(options.delete(:everywhere) ? nil : queue_name), interface]
  proxy.environment.execute 'PauseQueueMember', *args
  case proxy.environment.get_variable("PQMSTATUS")
  when "PAUSED"   then true
  when "NOTFOUND" then false
  else
    raise "Unrecognized PQMSTATUS value!"
  end
end

#remove!Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/adhearsion/asterisk/queue_proxy/agent_proxy.rb', line 22

def remove!
  proxy.environment.execute 'RemoveQueueMember', queue_name, interface
  case proxy.environment.get_variable("RQMSTATUS")
  when "REMOVED"     then true
  when "NOTINQUEUE"  then false
  when "NOSUCHQUEUE"
    raise QueueDoesNotExistError.new(queue_name)
  else
    raise "Unrecognized RQMSTATUS variable!"
  end
end

#unpause!(options = {}) ⇒ Object

Pauses the given agent for this queue only. If you wish to pause this agent for all queues, pass in :everywhere => true. Returns true if the agent was successfully paused and false if the agent was not found.



51
52
53
54
55
56
57
58
59
60
# File 'lib/adhearsion/asterisk/queue_proxy/agent_proxy.rb', line 51

def unpause!(options = {})
  args = [(options.delete(:everywhere) ? nil : queue_name), interface]
  proxy.environment.execute 'UnpauseQueueMember', *args
  case proxy.environment.get_variable("UPQMSTATUS")
  when "UNPAUSED" then true
  when "NOTFOUND" then false
  else
    raise "Unrecognized UPQMSTATUS value!"
  end
end