Completed
Push — master ( 13432f...78215f )
by John
59s
created

MyObserverGroups.update()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
1
#!ruby
2
3
require 'dotenv'
4
require 'logger'
5
require 'multi_json'
6
require 'ringcentral_sdk'
7
require 'glip_sdk'
8
9
Dotenv.load
10
11
rc = RingCentralSdk::REST::Client.new do |config|
12
  config.server_url = RingCentralSdk::RC_SERVER_PRODUCTION
13
  config.app_key = ENV['RC_APP_KEY']
14
  config.app_secret = ENV['RC_APP_SECRET']
15
16
  config.username = ENV['RC_USER_USERNAME']
17
  config.extension = ENV['RC_USER_EXTENSION']
18
  config.password = ENV['RC_USER_PASSWORD']
19
20
  config.logger = Logger.new STDOUT
21
  config.logger.level = Logger::INFO
22
end
23
24
glip = GlipSdk::REST::Client.new rc
25
26
# Get all groups and teams
27
groups = glip.groups.all_groups
28
glip.logger.info "#{groups.length} groups/teams were found."
29
30
# Get all groups
31
groups = glip.groups.all_groups type: 'Group'
32
glip.logger.info "#{groups.length} groups were found."
33
34
# Get all teams
35
teams = glip.groups.all_groups type: 'Team'
36
glip.logger.info "#{teams.length} teams were found."
37
38
# Get one team
39
if teams.length
40
  team = glip.groups.get groupId: teams[0]['id']
41
  glip.logger.info MultiJson.encode(team.body)
42
else
43
  glip.logger.info 'No teams to retrieve'
44
end
45
46
# Subscribe to group events including: GroupAdded, GroupChanged and GroupRemoved
47
class MyObserverGroups
48
  def initialize(logger)
49
    @logger = logger
50
  end
51
52
  def update(message)
53
    @logger.info 'Subscription Group Message Received'
54
    @logger.info MultiJson.encode(message)
55
  end
56
end
57
58
glip.groups.observe MyObserverGroups.new(glip.logger)
59
60
glip.logger.info("Hit any key to end")
61
62
gets
63
64
glip.groups.subscription.destroy
65