-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsubscription_all_extensions.rb
65 lines (50 loc) · 1.54 KB
/
subscription_all_extensions.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!ruby
require 'multi_json'
require 'pp'
require 'ringcentral_sdk'
# Set your credentials in the .env file
# Use the credentials_sample.env.txt file as a scaffold
client = RingCentralSdk::REST::Client.new do |config|
config.load_env = true
config.logger = Logger.new STDOUT
config.logger.level = Logger::INFO
end
# Create an array of event_filters from the array of extensions
def get_event_filters_for_extensions(extension_ids, account_id = '~')
event_filters = []
extension_ids.each do |extension_id|
next unless extension_id
event_filter = "/restapi/v1.0/account/#{account_id}/extension/#{extension_id}" \
<< '/presence?detailedTelephonyState=true'
event_filters.push event_filter
end
event_filters
end
# An example observer object
class MyObserver
def update(message)
puts 'Subscription Message Received'
puts JSON.dump(message)
end
end
def run_subscription(client, event_filters)
# Create an observable subscription and add your observer
sub = client.create_subscription
res = sub.subscribe(event_filters)
pp(res)
# Add observer
sub.add_observer MyObserver.new
# Run until user clicks key to finish
puts 'Click any key to finish'
gets
# End the subscription
sub.destroy
end
# Get all extensions
extensions = RingCentralSdk::REST::Cache::Extensions.new client
extensions.retrieve_all
# Get event filters for extensions
event_filters = get_event_filters_for_extensions(extensions.extensions_hash.keys)
# Make a subscription for all event_filters
run_subscription(client, event_filters)
puts 'DONE'