Class: ElectricSlide::Agent
- Inherits:
-
Object
- Object
- ElectricSlide::Agent
- Defined in:
- lib/electric_slide/agent.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#call ⇒ Object
Returns the value of attribute call.
-
#id ⇒ Object
Returns the value of attribute id.
-
#presence ⇒ Object
readonly
Returns the value of attribute presence.
-
#queue ⇒ Object
Returns the value of attribute queue.
Class Method Summary collapse
-
.on_connect(&block) ⇒ Object
Provide a block to be called when this agent is connected to a caller The block will be passed the queue, the agent call and the client call.
-
.on_connection_failed(&block) ⇒ Object
Provide a block to be called when the agent connection to the callee fails The block will be passed the queue, the agent call and the client call.
-
.on_disconnect(&block) ⇒ Object
Provide a block to be called when this agent is disconnected to a caller The block will be passed the queue, the agent call and the client call.
-
.on_presence_change(&block) ⇒ Object
Provide a block to be called when this agent’s presence changes The block will be passed the queue, the agent call, and the new presence.
Instance Method Summary collapse
-
#callable? ⇒ Boolean
Returns ‘true` if the agent can be called, i.e., has a contact address.
- #callback(type, *args) ⇒ Object
-
#dial_options_for(queue, queued_call) ⇒ Object
Called to provide options for calling this agent that are passed to #dial.
-
#from ⇒ Object
FIXME: Use delegator?.
-
#initialize(opts = {}) ⇒ Agent
constructor
A new instance of Agent.
- #join(queued_call) ⇒ Object
- #on_call? ⇒ Boolean
-
#update(attrs = {}) ⇒ Agent
Updates an agent instance’s attributes.
- #update_presence(new_presence, extra_params = {}) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Agent
Returns a new instance of Agent.
12 13 14 15 16 |
# File 'lib/electric_slide/agent.rb', line 12 def initialize(opts = {}) @id = opts[:id] @address = opts[:address] @presence = opts[:presence] || :available end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
5 6 7 |
# File 'lib/electric_slide/agent.rb', line 5 def address @address end |
#call ⇒ Object
Returns the value of attribute call.
5 6 7 |
# File 'lib/electric_slide/agent.rb', line 5 def call @call end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/electric_slide/agent.rb', line 5 def id @id end |
#presence ⇒ Object (readonly)
Returns the value of attribute presence.
6 7 8 |
# File 'lib/electric_slide/agent.rb', line 6 def presence @presence end |
#queue ⇒ Object
Returns the value of attribute queue.
5 6 7 |
# File 'lib/electric_slide/agent.rb', line 5 def queue @queue end |
Class Method Details
.on_connect(&block) ⇒ Object
Provide a block to be called when this agent is connected to a caller The block will be passed the queue, the agent call and the client call
47 48 49 |
# File 'lib/electric_slide/agent.rb', line 47 def self.on_connect(&block) @connect_callback = block end |
.on_connection_failed(&block) ⇒ Object
Provide a block to be called when the agent connection to the callee fails The block will be passed the queue, the agent call and the client call
65 66 67 |
# File 'lib/electric_slide/agent.rb', line 65 def self.on_connection_failed(&block) @connection_failed_callback = block end |
.on_disconnect(&block) ⇒ Object
Provide a block to be called when this agent is disconnected to a caller The block will be passed the queue, the agent call and the client call
53 54 55 |
# File 'lib/electric_slide/agent.rb', line 53 def self.on_disconnect(&block) @disconnect_callback = block end |
.on_presence_change(&block) ⇒ Object
Provide a block to be called when this agent’s presence changes The block will be passed the queue, the agent call, and the new presence
59 60 61 |
# File 'lib/electric_slide/agent.rb', line 59 def self.on_presence_change(&block) @presence_change_callback = block end |
Instance Method Details
#callable? ⇒ Boolean
Returns ‘true` if the agent can be called, i.e., has a contact address
89 90 91 |
# File 'lib/electric_slide/agent.rb', line 89 def callable? address.present? end |
#callback(type, *args) ⇒ Object
40 41 42 43 |
# File 'lib/electric_slide/agent.rb', line 40 def callback(type, *args) callback = self.class.instance_variable_get "@#{type}_callback" instance_exec *args, &callback if callback && callback.respond_to?(:call) end |
#dial_options_for(queue, queued_call) ⇒ Object
Called to provide options for calling this agent that are passed to #dial
74 75 76 |
# File 'lib/electric_slide/agent.rb', line 74 def (queue, queued_call) {} end |
#from ⇒ Object
FIXME: Use delegator?
84 85 86 |
# File 'lib/electric_slide/agent.rb', line 84 def from @call.from end |
#join(queued_call) ⇒ Object
78 79 80 81 |
# File 'lib/electric_slide/agent.rb', line 78 def join(queued_call) # For use in queues that need bridge connections @call.join queued_call end |
#on_call? ⇒ Boolean
69 70 71 |
# File 'lib/electric_slide/agent.rb', line 69 def on_call? @presence == :on_call end |
#update(attrs = {}) ⇒ Agent
Updates an agent instance’s attributes.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/electric_slide/agent.rb', line 21 def update(attrs = {}) unless Hash === attrs raise ArgumentError.new('Agent attributes must be a hash') end attrs.each do |attr, value| setter = "#{attr}=" send setter, value end self end |
#update_presence(new_presence, extra_params = {}) ⇒ Object
34 35 36 37 38 |
# File 'lib/electric_slide/agent.rb', line 34 def update_presence(new_presence, extra_params = {}) old_presence = @presence @presence = new_presence callback :presence_change, queue, @call, new_presence, old_presence, extra_params end |