Class: FSR::Cmd::CallCenter
Constant Summary
Constants inherited
from Command
FSR::Cmd::Command::DEFAULT_OPTIONS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(fs_socket = nil, config_type = :agent) ⇒ CallCenter
Returns a new instance of CallCenter.
6
7
8
9
10
11
|
# File 'lib/fsr/cmd/call_center.rb', line 6
def initialize(fs_socket = nil, config_type = :agent)
@fs_socket = fs_socket @config_type = config_type
@last_repsonse = nil
@cmd = []
end
|
Instance Attribute Details
#cmd ⇒ Object
Returns the value of attribute cmd.
5
6
7
|
# File 'lib/fsr/cmd/call_center.rb', line 5
def cmd
@cmd
end
|
Instance Method Details
#add(agent, *args) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/fsr/cmd/call_center.rb', line 86
def add(agent, *args)
@listing = false
@cmd = case @config_type
when :agent
add_agent(agent, *args)
when :tier
add_tier(agent, *args)
else
raise "Cannot add to #{@config_type}"
end
self
end
|
#del(agent, queue = nil) ⇒ Object
100
101
102
103
104
|
# File 'lib/fsr/cmd/call_center.rb', line 100
def del(agent, queue = nil)
@listing = false
@cmd = ["del", queue, agent].compact
self
end
|
#last_response ⇒ Object
17
18
19
|
# File 'lib/fsr/cmd/call_center.rb', line 17
def last_response
responses.last
end
|
#list(*args) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/fsr/cmd/call_center.rb', line 39
def list(*args)
@listing = true
@cmd = case @config_type
when :agent
list_agent(*args)
when :tier
list_tier(*args)
when :queue
list_queue(*args)
else
raise "no such config_type #{@config_type}"
end
self
end
|
#list_tiers(queue = nil) ⇒ Object
33
34
35
36
37
|
# File 'lib/fsr/cmd/call_center.rb', line 33
def list_tiers(queue=nil)
@listing = true
@cmd = ["list tiers", queue].compact
self
end
|
#raw ⇒ Object
This method builds the API command to send to the freeswitch event socket
155
156
157
|
# File 'lib/fsr/cmd/call_center.rb', line 155
def raw
["callcenter_config", @config_type, *@cmd].join(" ")
end
|
#responses ⇒ Object
21
22
23
|
# File 'lib/fsr/cmd/call_center.rb', line 21
def responses
@responses ||= []
end
|
#run(api_method = :api) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/fsr/cmd/call_center.rb', line 106
def run(api_method = :api)
orig_command = "%s %s" % [api_method, raw]
resp = @fs_socket.say(orig_command)
responses << resp
if @listing
if resp["body"].match(/^([^|]*\|[^|]*)+/)
require "csv"
csv = CSV.parse(resp["body"], :col_sep => '|', :headers => true)
case @config_type
when :tier
require "fsr/model/tier"
csv.to_a[1 .. -2].map { |c| FSR::Model::Tier.new(csv., *c) }
when :queue
require "fsr/model/queue"
csv.to_a[1 .. -2].map { |c| FSR::Model::Queue.new(csv., *c) }
when :agent
require "fsr/model/agent"
csv.to_a[1 .. -2].map { |c| FSR::Model::Agent.new(csv., *c) }
end
else
[]
end
else
resp["body"].to_s =~ /\+OK$/
end
end
|
#set(agent, *args) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/fsr/cmd/call_center.rb', line 64
def set(agent, *args)
@listing = false
@cmd = case @config_type
when :agent
set_agent(agent, *args)
when :tier
set_tier(agent, *args)
else
raise "Cannot run set on #{@config_type}"
end
self
end
|