1
|
|
|
module RingCentralSdk::Helpers |
2
|
|
|
class ExtensionPresence |
3
|
|
|
|
4
|
|
|
attr_accessor :rc_api |
5
|
|
|
attr_accessor :account_id |
6
|
|
|
attr_accessor :exension_id |
7
|
|
|
attr_accessor :presence_info |
8
|
|
|
|
9
|
|
|
def initialize(rc_api, extension_id=nil) |
10
|
|
|
@rc_api = rc_api |
11
|
|
|
@account_id = '~' |
12
|
|
|
@extension_id = extension_id.to_s |
13
|
|
|
@presence_info = {} |
14
|
|
|
end |
15
|
|
|
|
16
|
|
|
def retrieve() |
17
|
|
|
if @extension_id !~ /^[0-9]+$/ |
18
|
|
|
raise "extension_id is not an integer" |
19
|
|
|
end |
20
|
|
|
|
21
|
|
|
res = @rc_api.client.get do |req| |
22
|
|
|
req.url "account/#{@account_id}/extension/#{@extension_id}/presence" |
23
|
|
|
end |
24
|
|
|
|
25
|
|
|
if res.status != 200 |
26
|
|
|
raise 'Cannot retrieve extension presence info' |
27
|
|
|
end |
28
|
|
|
|
29
|
|
|
@presence_info = res.body |
30
|
|
|
|
31
|
|
|
return @presence_info |
32
|
|
|
end |
33
|
|
|
|
34
|
|
|
def enable_dnd_department_calls() |
35
|
|
|
retrieve() |
36
|
|
|
if !@presence_info.has_key?('dndStatus') |
37
|
|
|
raise 'invalid presence info' |
38
|
|
|
end |
39
|
|
|
current_status = @presence_info['dndStatus'] |
40
|
|
|
new_status = status_enable_dnd_department_calls(current_status) |
41
|
|
|
if current_status != new_status |
42
|
|
|
|
43
|
|
|
end |
44
|
|
|
end |
45
|
|
|
|
46
|
|
|
def disable_dnd_department_calls() |
47
|
|
|
retrieve() |
48
|
|
|
if !@presence_info.has_key?('dndStatus') |
49
|
|
|
raise 'invalid presence info' |
50
|
|
|
end |
51
|
|
|
current_status = @presence_info['dndStatus'] |
52
|
|
|
new_status = status_disable_dnd_department_calls(current_status) |
53
|
|
|
if current_status != new_status |
54
|
|
|
update_presence({:dndStatus => new_status}) |
55
|
|
|
end |
56
|
|
|
end |
57
|
|
|
|
58
|
|
|
def update_presence(body=nil) |
59
|
|
|
if body.nil? |
60
|
|
|
raise 'cannot update presence with no body' |
61
|
|
|
end |
62
|
|
|
res = @rc_api.client.put do |req| |
63
|
|
|
req.url "account/#{@account_id}/extension/#{@extension_id}/presence" |
64
|
|
|
req.headers['Content-Type'] = 'application/json' |
65
|
|
|
req.body = body |
66
|
|
|
end |
67
|
|
|
return res |
68
|
|
|
end |
69
|
|
|
|
70
|
|
|
def status_enable_dnd_department_calls(current_status) |
71
|
|
|
new_status = current_status |
72
|
|
|
if current_status == 'DoNotAcceptAnyCalls' |
73
|
|
|
new_status = 'TakeDepartmentCallsOnly' |
74
|
|
|
elsif current_status == 'DoNotAcceptDepartmentCalls' |
75
|
|
|
new_status = 'TakeAllCalls' |
76
|
|
|
end |
77
|
|
|
return new_status |
78
|
|
|
end |
79
|
|
|
|
80
|
|
|
def status_disable_dnd_department_calls(current_status) |
81
|
|
|
new_status = current_status |
82
|
|
|
if current_status == 'TakeAllCalls' |
83
|
|
|
new_status = 'DoNotAcceptDepartmentCalls' |
84
|
|
|
elsif current_status == 'TakeDepartmentCallsOnly' |
85
|
|
|
new_status = 'DoNotAcceptAnyCalls' |
86
|
|
|
end |
87
|
|
|
return new_status |
88
|
|
|
end |
89
|
|
|
|
90
|
|
|
end |
91
|
|
|
end |