-
Notifications
You must be signed in to change notification settings - Fork 133
/
client.py
139 lines (112 loc) · 3.97 KB
/
client.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"""Zoom.us REST API Python Client"""
from __future__ import absolute_import, unicode_literals
from zoomus import components, util
from zoomus.util import API_VERSION_1, API_VERSION_2
API_BASE_URIS = {
API_VERSION_1: "https://api.zoom.us/v1",
API_VERSION_2: "https://api.zoom.us/v2",
}
COMPONENT_CLASSES = {
API_VERSION_1: {
"user": components.user.UserComponent,
"meeting": components.meeting.MeetingComponent,
"report": components.report.ReportComponent,
"webinar": components.webinar.WebinarComponent,
"recording": components.recording.RecordingComponent,
},
API_VERSION_2: {
"user": components.user.UserComponentV2,
"meeting": components.meeting.MeetingComponentV2,
"metric": components.metric.MetricComponentV2,
"past_meeting": components.past_meeting.PastMeetingComponentV2,
"report": components.report.ReportComponentV2,
"webinar": components.webinar.WebinarComponentV2,
"recording": components.recording.RecordingComponentV2,
"phone": components.phone.PhoneComponentV2,
},
}
class ZoomClient(util.ApiClient):
"""Zoom.us REST API Python Client"""
"""Base URL for Zoom API"""
def __init__(
self, api_key, api_secret, data_type="json", timeout=15, version=API_VERSION_2
):
"""Create a new Zoom client
:param api_key: The Zooom.us API key
:param api_secret: The Zoom.us API secret
:param data_type: The expected return data type. Either 'json' or 'xml'
:param timeout: The time out to use for API requests
"""
try:
BASE_URI = API_BASE_URIS[version]
self.components = COMPONENT_CLASSES[version].copy()
except KeyError:
raise RuntimeError("API version not supported: %s" % version)
super(ZoomClient, self).__init__(base_uri=BASE_URI, timeout=timeout)
# Setup the config details
self.config = {
"api_key": api_key,
"api_secret": api_secret,
"data_type": data_type,
"version": version,
"token": util.generate_jwt(api_key, api_secret),
}
# Instantiate the components
for key in self.components.keys():
self.components[key] = self.components[key](
base_uri=BASE_URI, config=self.config
)
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
return
def refresh_token(self):
self.config["token"] = (
util.generate_jwt(self.config["api_key"], self.config["api_secret"]),
)
@property
def api_key(self):
"""The Zoom.us api_key"""
return self.config.get("api_key")
@api_key.setter
def api_key(self, value):
"""Set the api_key"""
self.config["api_key"] = value
self.refresh_token()
@property
def api_secret(self):
"""The Zoom.us api_secret"""
return self.config.get("api_secret")
@api_secret.setter
def api_secret(self, value):
"""Set the api_secret"""
self.config["api_secret"] = value
self.refresh_token()
@property
def meeting(self):
"""Get the meeting component"""
return self.components.get("meeting")
@property
def metric(self):
"""Get the metric component"""
return self.components.get("metric")
@property
def report(self):
"""Get the report component"""
return self.components.get("report")
@property
def user(self):
"""Get the user component"""
return self.components.get("user")
@property
def webinar(self):
"""Get the webinar component"""
return self.components.get("webinar")
@property
def recording(self):
"""Get the recording component"""
return self.components.get("recording")
@property
def phone(self):
"""Get the phone component"""
return self.components.get("phone")