Class: RingCentralSdk::REST::ExtensionPresence

Inherits:
Object
  • Object
show all
Defined in:
lib/ringcentral_sdk/rest/extension_presence.rb

Overview

ExtensionPresence is a helper class to manage presence info

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(extension_id, opts = {}) ⇒ ExtensionPresence

Returns a new instance of ExtensionPresence.



10
11
12
13
14
15
# File 'lib/ringcentral_sdk/rest/extension_presence.rb', line 10

def initialize(extension_id, opts = {})
  @client = opts.key?(:client) ? opts[:client] : nil
  @account_id = '~'
  @extension_id = extension_id.to_s
  @presence_data = {}
end

Instance Attribute Details

#account_idObject

Returns the value of attribute account_id.



6
7
8
# File 'lib/ringcentral_sdk/rest/extension_presence.rb', line 6

def 
  @account_id
end

#clientObject

Returns the value of attribute client.



5
6
7
# File 'lib/ringcentral_sdk/rest/extension_presence.rb', line 5

def client
  @client
end

#extension_idObject

Returns the value of attribute extension_id.



7
8
9
# File 'lib/ringcentral_sdk/rest/extension_presence.rb', line 7

def extension_id
  @extension_id
end

#presence_dataObject

Returns the value of attribute presence_data.



8
9
10
# File 'lib/ringcentral_sdk/rest/extension_presence.rb', line 8

def presence_data
  @presence_data
end

Instance Method Details

#department_calls_enable(enable) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ringcentral_sdk/rest/extension_presence.rb', line 29

def department_calls_enable(enable)
  retrieve

  unless @presence.is_a?(Hash) && @presence_data.key?('dndStatus')
    raise 'invalid presence info'
  end

  current_status = @presence_data['dndStatus']
  new_status = new_status_dnd_department_calls(current_status, enable)

  update(dndStatus: new_status) if current_status != new_status
  new_status
end

#department_calls_enabled?(reload = false) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ringcentral_sdk/rest/extension_presence.rb', line 43

def department_calls_enabled?(reload = false)
  if reload
    retrieve
  elsif !@presence_data.key?('dndStatus')
    retrieve
  end

  current_status = @presence_data['dndStatus']

  status_enabled = {
    'DoNotAcceptAnyCalls' => false,
    'DoNotAcceptDepartmentCalls' => false,
    'TakeAllCalls' => true,
    'TakeDepartmentCallsOnly' => true
  }

  status_enabled.key?(current_status) ? status_enabled[current_status] : nil
end

#new_status_dnd_department_calls(current_status, enable) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ringcentral_sdk/rest/extension_presence.rb', line 76

def new_status_dnd_department_calls(current_status, enable)
  new_statuses = {
    enable: {
      'DoNotAcceptAnyCalls' => 'TakeDepartmentCallsOnly',
      'DoNotAcceptDepartmentCalls' => 'TakeAllCalls'
    },
    disable: {
      'TakeAllCalls' => 'DoNotAcceptDepartmentCalls',
      'TakeDepartmentCallsOnly' => 'DoNotAcceptAnyCalls'
    }
  }

  action = enable ? :enable : :disable

  new_status = current_status

  new_status = new_statuses[action][current_status.to_s] \
    if new_statuses[action].key?(current_status.to_s)

  new_status
end

#retrieveObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ringcentral_sdk/rest/extension_presence.rb', line 17

def retrieve
  raise 'extension_id is not an integer' if @extension_id !~ /^[0-9]+$/

  res = @client.http.get do |req|
    req.url "account/#{@account_id}/extension/#{@extension_id}/presence"
  end

  @presence_data = res.body

  @presence_data
end

#update(body = nil) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ringcentral_sdk/rest/extension_presence.rb', line 62

def update(body = nil)
  raise 'HTTP request body is required to update presence' if body.nil?

  res = @client.http.put do |req|
    req.url "account/#{@account_id}/extension/#{@extension_id}/presence"
    req.headers['Content-Type'] = 'application/json'
    req.body = body
  end

  @presence_data = res.body

  @presence_data
end