-
Notifications
You must be signed in to change notification settings - Fork 0
/
zoom.py
239 lines (227 loc) · 7.13 KB
/
zoom.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
"""
dlt source to load Zoom meeting and webinar data.
How to use it:
1. Create a server-to-server app: https://developers.zoom.us/docs/internal-apps/create/
2. Copy the account id, client id, and client secret into your secrets.toml
3. Add the required scopes to your app. This depends on which resources you want to load.
For example, user:read:list_users:admin, user:read:user:admin, report:read:list_meeting_participants:admin, webinar:read:list_webinars:admin
In case of errors: See the HTTP error responses, Zoom tells which scopes are missing in your app.
"""
from base64 import b64encode
from typing import (
Any,
Dict,
)
import dlt
from rest_api import RESTAPIConfig, rest_api_source
from rest_api.auth import OAuth2ImplicitFlow
from rest_api.paginators import JSONResponseCursorPaginator
class OAuth2Zoom(OAuth2ImplicitFlow):
def build_access_token_request(self) -> Dict[str, Any]:
authentication: str = b64encode(
f"{self.client_id}:{self.client_secret}".encode()
).decode()
return {
"url": "https://zoom.us/oauth/token",
"headers": {
"Authorization": f"Basic {authentication}",
"Content-Type": "application/x-www-form-urlencoded",
},
"data": self.access_token_request_data,
}
resolve_meeting_id = {
"meeting_id": {
"type": "resolve",
"resource": "meetings",
"field": "id",
}
}
resolve_user_id = {
"user_id": {
"type": "resolve",
"resource": "users",
"field": "id",
}
}
resolve_webinar_id = {
"webinar_id": {
"type": "resolve",
"resource": "webinars",
"field": "id",
}
}
config: RESTAPIConfig = {
"client": {
"base_url": "https://api.zoom.us/v2",
"auth": OAuth2Zoom(
access_token_request_data={
"grant_type": "account_credentials",
"account_id": dlt.secrets["sources.zoom.account_id"],
},
client_id=dlt.secrets["sources.zoom.client_id"],
client_secret=dlt.secrets["sources.zoom.client_secret"],
),
"paginator": JSONResponseCursorPaginator(
cursor_path="response.next_page_token",
cursor_param="next_page_token",
),
},
"resources": [
"users",
# Meetings
{
"name": "meetings",
"endpoint": {
"path": "users/{user_id}/meetings",
"params": resolve_user_id,
},
},
{
"name": "meeting_registrants",
"endpoint": {
"path": "/meetings/{meeting_id}/registrants",
"params": resolve_meeting_id,
"response_actions": [
{
"content": "Registration has not been enabled for this meeting",
"action": "ignore",
},
],
},
},
{
"name": "meeting_polls",
"endpoint": {
"path": "/meetings/{meeting_id}/polls",
"params": resolve_meeting_id,
"response_actions": [
{"status_code": 400, "action": "ignore"},
],
},
},
{
"name": "meeting_polls_results",
"endpoint": {
"path": "/past_meetings/{meeting_id}/polls",
"params": resolve_meeting_id,
"response_actions": [
{"status_code": 400, "action": "ignore"},
{"status_code": 404, "action": "ignore"},
],
},
},
{
"name": "meeting_registration_questions",
"endpoint": {
"path": "/meetings/{meeting_id}/registrants/questions",
"params": resolve_meeting_id,
"response_actions": [
{
"content": "Registration has not been enabled for this meeting",
"action": "ignore",
},
],
},
},
# Webinars
{
"name": "webinars",
"endpoint": {
"path": "/users/{user_id}/webinars",
"params": resolve_user_id,
"response_actions": [
{"content": "Webinar plan is missing", "action": "ignore"},
],
},
},
{
"name": "webinar_panelists",
"endpoint": {
"path": "/webinars/{webinar_id}/panelists",
"params": resolve_webinar_id,
},
},
{
"name": "webinar_registrants",
"endpoint": {
"path": "/webinars/{webinar_id}/registrants",
"params": resolve_webinar_id,
},
},
{
"name": "webinar_absentees",
"endpoint": {
"path": "/past_webinars/{webinar_id}/absentees",
"params": resolve_webinar_id,
},
},
{
"name": "webinar_polls",
"endpoint": {
"path": "/webinars/{webinar_id}/polls",
"params": resolve_webinar_id,
},
},
{
"name": "webinar_poll_results",
"endpoint": {
"path": "/past_webinars/{webinar_id}/polls",
"params": resolve_webinar_id,
},
},
{
"name": "webinar_registration_questions",
"endpoint": {
"path": "/webinars/{webinar_id}/registrants/questions",
"params": resolve_webinar_id,
},
},
{
"name": "webinar_tracking_sources",
"endpoint": {
"path": "/webinars/{webinar_id}/tracking_sources",
"params": resolve_webinar_id,
},
},
{
"name": "webinar_qa",
"endpoint": {
"path": "/past_webinars/{webinar_id}/qa",
"params": resolve_webinar_id,
},
},
# Reports
{
"name": "meetings_report",
"endpoint": {
"path": "/report/users/{user_id}/meetings",
"params": resolve_user_id,
},
},
{
"name": "meeting_participants_report",
"endpoint": {
"path": "/report/meetings/{meeting_id}/participants",
"params": resolve_meeting_id,
"response_actions": [
{"status_code": 404, "action": "ignore"},
],
},
},
{
"name": "webinar_details_report",
"endpoint": {
"path": "/report/webinars/{webinar_id}",
"params": resolve_webinar_id,
},
},
{
"name": "webinar_participants_report",
"endpoint": {
"path": "/report/webinars/{webinar_id}/participants",
"params": resolve_webinar_id,
},
},
],
}
source = rest_api_source(config)