|
1
|
|
|
module RingCentralSdk::REST |
|
2
|
|
|
class ExtensionPresence |
|
3
|
|
|
attr_accessor :client |
|
4
|
|
|
attr_accessor :account_id |
|
5
|
|
|
attr_accessor :extension_id |
|
6
|
|
|
attr_accessor :presence_data |
|
7
|
|
|
|
|
8
|
|
|
def initialize(extension_id, opts={}) |
|
9
|
|
|
@client = opts.key?(:client) ? opts[:client] : nil |
|
10
|
|
|
@account_id = '~' |
|
11
|
|
|
@extension_id = extension_id.to_s |
|
12
|
|
|
@presence_data = {} |
|
13
|
|
|
end |
|
14
|
|
|
|
|
15
|
|
|
def retrieve() |
|
16
|
|
|
if @extension_id !~ /^[0-9]+$/ |
|
17
|
|
|
raise "extension_id is not an integer" |
|
18
|
|
|
end |
|
19
|
|
|
|
|
20
|
|
|
res = @client.http.get do |req| |
|
21
|
|
|
req.url "account/#{@account_id}/extension/#{@extension_id}/presence" |
|
22
|
|
|
end |
|
23
|
|
|
|
|
24
|
|
|
@presence_data = res.body |
|
25
|
|
|
|
|
26
|
|
|
return @presence_data |
|
27
|
|
|
end |
|
28
|
|
|
|
|
29
|
|
|
def department_calls_enable(enable) |
|
30
|
|
|
retrieve() |
|
31
|
|
|
|
|
32
|
|
|
if !@presence_data.key?('dndStatus') |
|
33
|
|
|
raise 'invalid presence info' |
|
34
|
|
|
end |
|
35
|
|
|
|
|
36
|
|
|
current_status = @presence_data['dndStatus'] |
|
37
|
|
|
new_status = new_status_dnd_department_calls(current_status, enable) |
|
38
|
|
|
|
|
39
|
|
|
if current_status != new_status |
|
40
|
|
|
update({:dndStatus => new_status}) |
|
41
|
|
|
end |
|
42
|
|
|
end |
|
43
|
|
|
|
|
44
|
|
|
def department_calls_enabled?(reload=false) |
|
45
|
|
|
if reload |
|
46
|
|
|
retrieve() |
|
47
|
|
|
elsif !@presence_data.key?('dndStatus') |
|
48
|
|
|
retrieve() |
|
49
|
|
|
end |
|
50
|
|
|
|
|
51
|
|
|
current_status = @presence_data['dndStatus'] |
|
52
|
|
|
|
|
53
|
|
|
status_enabled = { |
|
54
|
|
|
'DoNotAcceptAnyCalls' => false, |
|
55
|
|
|
'DoNotAcceptDepartmentCalls' => false, |
|
56
|
|
|
'TakeAllCalls' => true, |
|
57
|
|
|
'TakeDepartmentCallsOnly' => true |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return status_enabled.key?(current_status) ? |
|
61
|
|
|
status_enabled[current_status] : nil |
|
62
|
|
|
end |
|
63
|
|
|
|
|
64
|
|
|
=begin |
|
65
|
|
|
def disable_department_calls() |
|
66
|
|
|
retrieve() |
|
67
|
|
|
|
|
68
|
|
|
if !@presence_data.key?('dndStatus') |
|
69
|
|
|
raise 'invalid presence info' |
|
70
|
|
|
end |
|
71
|
|
|
|
|
72
|
|
|
current_status = @presence_data['dndStatus'] |
|
73
|
|
|
new_status = new_status_dnd_department_calls(current_status, false) |
|
74
|
|
|
|
|
75
|
|
|
if current_status != new_status |
|
76
|
|
|
update({:dndStatus => new_status}) |
|
77
|
|
|
end |
|
78
|
|
|
end |
|
79
|
|
|
=end |
|
80
|
|
|
def update(body=nil) |
|
81
|
|
|
if body.nil? |
|
82
|
|
|
raise 'HTTP request body is required to update presence' |
|
83
|
|
|
end |
|
84
|
|
|
|
|
85
|
|
|
res = @client.http.put do |req| |
|
86
|
|
|
req.url "account/#{@account_id}/extension/#{@extension_id}/presence" |
|
87
|
|
|
req.headers['Content-Type'] = 'application/json' |
|
88
|
|
|
req.body = body |
|
89
|
|
|
end |
|
90
|
|
|
|
|
91
|
|
|
@presence_data = res.body |
|
92
|
|
|
|
|
93
|
|
|
return @presence_data |
|
94
|
|
|
end |
|
95
|
|
|
|
|
96
|
|
|
def new_status_dnd_department_calls(current_status, enable) |
|
97
|
|
|
new_statuses = { |
|
98
|
|
|
:enable => { |
|
99
|
|
|
'DoNotAcceptAnyCalls' => 'TakeDepartmentCallsOnly', |
|
100
|
|
|
'DoNotAcceptDepartmentCalls' => 'TakeAllCalls' |
|
101
|
|
|
}, |
|
102
|
|
|
:disable => { |
|
103
|
|
|
'TakeAllCalls' => 'DoNotAcceptDepartmentCalls', |
|
104
|
|
|
'TakeDepartmentCallsOnly' => 'DoNotAcceptAnyCalls' |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
action = enable ? :enable : :disable |
|
109
|
|
|
|
|
110
|
|
|
new_status = current_status |
|
111
|
|
|
|
|
112
|
|
|
new_status = new_statuses[action][current_status.to_s] \ |
|
113
|
|
|
if new_statuses[action].key?(current_status.to_s) |
|
114
|
|
|
|
|
115
|
|
|
return new_status |
|
116
|
|
|
end |
|
117
|
|
|
=begin |
|
118
|
|
|
def status_enable_dnd_department_calls(current_status) |
|
119
|
|
|
new_status = current_status |
|
120
|
|
|
|
|
121
|
|
|
new_statuses = { |
|
122
|
|
|
'DoNotAcceptAnyCalls' => 'TakeDepartmentCallsOnly', |
|
123
|
|
|
'DoNotAcceptDepartmentCalls' => 'TakeAllCalls' |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
if new_statuses.key?(current_status.to_s) |
|
127
|
|
|
new_status = new_statuses[current_status.to_s] |
|
128
|
|
|
end |
|
129
|
|
|
|
|
130
|
|
|
return new_status |
|
131
|
|
|
end |
|
132
|
|
|
|
|
133
|
|
|
def status_disable_dnd_department_calls(current_status) |
|
134
|
|
|
new_status = current_status |
|
135
|
|
|
|
|
136
|
|
|
new_statuses = { |
|
137
|
|
|
'TakeAllCalls' => 'DoNotAcceptDepartmentCalls', |
|
138
|
|
|
'TakeDepartmentCallsOnly' => 'DoNotAcceptAnyCalls' |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
if new_statuses.key?(current_status.to_s) |
|
142
|
|
|
new_status = new_statuses[current_status.to_s] |
|
143
|
|
|
end |
|
144
|
|
|
|
|
145
|
|
|
return new_status |
|
146
|
|
|
end |
|
147
|
|
|
=end |
|
148
|
|
|
end |
|
149
|
|
|
end |