Skip to content

Commit 90d511d

Browse files
committed
standard oauth method
1 parent 89d9bf4 commit 90d511d

File tree

1 file changed

+25
-67
lines changed

1 file changed

+25
-67
lines changed

parsons/zoom/zoom.py

Lines changed: 25 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import uuid
44
from typing import Dict, Literal, Optional
5+
56
from oauthlib.oauth2.rfc6749.errors import InvalidClientError
67

78
from parsons import Table
@@ -35,7 +36,10 @@ def __init__(self, account_id=None, client_id=None, client_secret=None):
3536
self.account_id = check_env.check("ZOOM_ACCOUNT_ID", account_id)
3637
self.client_id = check_env.check("ZOOM_CLIENT_ID", client_id)
3738
self.__client_secret = check_env.check("ZOOM_CLIENT_SECRET", client_secret)
38-
self.client = OAuth2APIConnector(
39+
self.client = self.get_oauth_client()
40+
41+
def get_oauth_client(self) -> OAuth2APIConnector:
42+
return OAuth2APIConnector(
3943
uri=ZOOM_URI,
4044
client_id=self.client_id,
4145
client_secret=self.__client_secret,
@@ -62,9 +66,7 @@ def _get_request(self, endpoint, data_key, params=None, **kwargs):
6266
Parsons Table of API responses
6367
"""
6468

65-
logger.warning(
66-
"This version of the Zoom connector uses a deprecated pagination method."
67-
)
69+
logger.warning("This version of the Zoom connector uses a deprecated pagination method.")
6870
logger.info("Consider switching to V2!")
6971
logger.info(
7072
"See docs for more information: https://move-coop.github.io/parsons/html/latest/zoom.html"
@@ -92,9 +94,7 @@ def _get_request(self, endpoint, data_key, params=None, **kwargs):
9294
data.extend(self.client.data_parse(r))
9395
return Table(data)
9496

95-
def __handle_nested_json(
96-
self, table: Table, column: str, version: int = 1
97-
) -> Table:
97+
def __handle_nested_json(self, table: Table, column: str, version: int = 1) -> Table:
9898
"""
9999
This function unpacks JSON values from Zoom's API, which are often
100100
objects nested in lists
@@ -146,9 +146,7 @@ def __process_poll_results(self, tbl: Table) -> Table:
146146
tbl.remove_column("question_details")
147147

148148
# Unpack question values
149-
tbl = tbl.unpack_dict(
150-
"question_details_value", include_original=True, prepend=False
151-
)
149+
tbl = tbl.unpack_dict("question_details_value", include_original=True, prepend=False)
152150

153151
# Remove column from API response
154152
tbl.remove_column("question_details_value")
@@ -258,9 +256,7 @@ def get_past_meeting_participants(self, meeting_id):
258256
See :ref:`parsons-table` for output options.
259257
"""
260258

261-
tbl = self._get_request(
262-
f"report/meetings/{meeting_id}/participants", "participants"
263-
)
259+
tbl = self._get_request(f"report/meetings/{meeting_id}/participants", "participants")
264260
logger.info(f"Retrieved {tbl.num_rows} participants.")
265261
return tbl
266262

@@ -325,9 +321,7 @@ def get_past_webinar_participants(self, webinar_id):
325321
See :ref:`parsons-table` for output options.
326322
"""
327323

328-
tbl = self._get_request(
329-
f"report/webinars/{webinar_id}/participants", "participants"
330-
)
324+
tbl = self._get_request(f"report/webinars/{webinar_id}/participants", "participants")
331325
logger.info(f"Retrieved {tbl.num_rows} webinar participants.")
332326
return tbl
333327

@@ -375,12 +369,8 @@ def get_meeting_poll_metadata(self, meeting_id, poll_id, version: int = 1) -> Ta
375369
)
376370

377371
if "prompts" in tbl.columns:
378-
logger.info(
379-
f"Unnesting columns 'prompts' from existing table columns: {tbl.columns}"
380-
)
381-
return self.__handle_nested_json(
382-
table=tbl, column="prompts", version=version
383-
)
372+
logger.info(f"Unnesting columns 'prompts' from existing table columns: {tbl.columns}")
373+
return self.__handle_nested_json(table=tbl, column="prompts", version=version)
384374
else:
385375
return tbl
386376

@@ -435,9 +425,7 @@ def get_past_meeting_poll_metadata(self, meeting_id, version: int = 1) -> Table:
435425
f"Unnesting columns 'question_details' from existing table columns: {tbl.columns}"
436426
)
437427

438-
return self.__handle_nested_json(
439-
table=tbl, column="question_details", version=version
440-
)
428+
return self.__handle_nested_json(table=tbl, column="question_details", version=version)
441429

442430
def get_webinar_poll_metadata(self, webinar_id, poll_id, version: int = 1) -> Table:
443431
"""
@@ -516,9 +504,7 @@ def get_past_webinar_poll_metadata(self, webinar_id, version: int = 1) -> Table:
516504

517505
logger.info(f"Retrieved {tbl.num_rows} polls for meeting ID {webinar_id}")
518506

519-
return self.__handle_nested_json(
520-
table=tbl, column="question_details", version=version
521-
)
507+
return self.__handle_nested_json(table=tbl, column="question_details", version=version)
522508

523509
def get_meeting_poll_results(self, meeting_id) -> Table:
524510
"""
@@ -623,15 +609,7 @@ def _get_request(self, endpoint: str, data_key: str, params: dict = {}, **kwargs
623609
try:
624610
r = self.client.get_request(endpoint, params=params, **kwargs)
625611
except InvalidClientError:
626-
self.client = OAuth2APIConnector(
627-
uri=ZOOM_URI,
628-
client_id=self.client_id,
629-
client_secret=self._ZoomV1__client_secret,
630-
token_url=ZOOM_AUTH_CALLBACK,
631-
auto_refresh_url=ZOOM_AUTH_CALLBACK,
632-
grant_type="account_credentials",
633-
authorization_kwargs={"account_id": self.account_id},
634-
)
612+
self.client = self.get_oauth_client()
635613
r = self.client.get_request(endpoint, params=params, **kwargs)
636614
parsed_resp = self.client.data_parse(r)
637615
if isinstance(parsed_resp, dict):
@@ -676,9 +654,7 @@ def get_past_meeting_participants(self, meeting_id: int):
676654
See :ref:`parsons-table` for output options.
677655
"""
678656

679-
tbl = self._get_request(
680-
f"past_meetings/{meeting_id}/participants", "participants"
681-
)
657+
tbl = self._get_request(f"past_meetings/{meeting_id}/participants", "participants")
682658
logger.info(f"Retrieved {tbl.num_rows} participants.")
683659
return tbl
684660

@@ -694,9 +670,7 @@ def get_past_webinar_participants(self, webinar_id: int):
694670
See :ref:`parsons-table` for output options.
695671
"""
696672

697-
tbl = self._get_request(
698-
f"past_webinars/{webinar_id}/participants", "participants"
699-
)
673+
tbl = self._get_request(f"past_webinars/{webinar_id}/participants", "participants")
700674
logger.info(f"Retrieved {tbl.num_rows} participants.")
701675
return tbl
702676

@@ -718,9 +692,7 @@ def get_meeting_poll(self, meeting_id: int, poll_id: str):
718692

719693
endpoint = f"meetings/{meeting_id}/polls/{poll_id}"
720694
tbl = self._get_request(endpoint=endpoint, data_key=None)
721-
logger.info(
722-
f"Retrieved {tbl.num_rows} for [poll {poll_id}, meeting {meeting_id}]"
723-
)
695+
logger.info(f"Retrieved {tbl.num_rows} for [poll {poll_id}, meeting {meeting_id}]")
724696
return tbl
725697

726698
def get_meeting_poll_metadata(self, meeting_id, poll_id, version=1):
@@ -794,9 +766,7 @@ def get_webinar_poll(self, webinar_id: int, poll_id: str):
794766

795767
endpoint = f"webinars/{webinar_id}/polls/{poll_id}"
796768
tbl = self._get_request(endpoint=endpoint, data_key=None)
797-
logger.info(
798-
f"Retrieved {tbl.num_rows} for [poll {poll_id}, webinar {webinar_id}]"
799-
)
769+
logger.info(f"Retrieved {tbl.num_rows} for [poll {poll_id}, webinar {webinar_id}]")
800770
return tbl
801771

802772
def get_webinar_poll_metadata(self, webinar_id, poll_id, version=1):
@@ -844,9 +814,7 @@ def get_past_webinar_poll_results(self, webinar_id: int):
844814

845815
endpoint = f"past_webinars/{webinar_id}/polls"
846816
tbl = self._get_request(endpoint=endpoint, data_key=None)
847-
logger.info(
848-
f"Retrieved {tbl.num_rows} poll results for webinar ID {webinar_id}"
849-
)
817+
logger.info(f"Retrieved {tbl.num_rows} poll results for webinar ID {webinar_id}")
850818
return tbl
851819

852820
def get_past_webinar_poll_metadata(self, webinar_id, version=1):
@@ -869,9 +837,7 @@ def get_meeting_poll_reports(self, meeting_id: int):
869837

870838
endpoint = f"report/meetings/{meeting_id}/polls"
871839
tbl = self._get_request(endpoint=endpoint, data_key=None)
872-
logger.info(
873-
f"Retrieved {tbl.num_rows} poll reports for meeting ID {meeting_id}"
874-
)
840+
logger.info(f"Retrieved {tbl.num_rows} poll reports for meeting ID {meeting_id}")
875841
return tbl
876842

877843
def get_meeting_poll_results(self, meeting_id):
@@ -894,9 +860,7 @@ def get_webinar_poll_reports(self, webinar_id: int):
894860

895861
endpoint = f"report/webinars/{webinar_id}/polls"
896862
tbl = self._get_request(endpoint=endpoint, data_key=None)
897-
logger.info(
898-
f"Retrieved {tbl.num_rows} poll reports for webinar ID {webinar_id}"
899-
)
863+
logger.info(f"Retrieved {tbl.num_rows} poll reports for webinar ID {webinar_id}")
900864
return tbl
901865

902866
def get_webinar_poll_results(self, webinar_id):
@@ -906,9 +870,7 @@ def get_webinar_poll_results(self, webinar_id):
906870

907871

908872
class Zoom:
909-
def __new__(
910-
cls, account_id=None, client_id=None, client_secret=None, parsons_version="v1"
911-
):
873+
def __new__(cls, account_id=None, client_id=None, client_secret=None, parsons_version="v1"):
912874
"""
913875
Create and return Zoom instance base on chosen version (1 or 2)
914876
@@ -932,11 +894,7 @@ def __new__(
932894
logger.info(
933895
"See docs for more information: https://move-coop.github.io/parsons/html/latest/zoom.html"
934896
)
935-
return ZoomV1(
936-
account_id=account_id, client_id=client_id, client_secret=client_secret
937-
)
897+
return ZoomV1(account_id=account_id, client_id=client_id, client_secret=client_secret)
938898
if parsons_version == "v2":
939-
return ZoomV2(
940-
account_id=account_id, client_id=client_id, client_secret=client_secret
941-
)
899+
return ZoomV2(account_id=account_id, client_id=client_id, client_secret=client_secret)
942900
raise ValueError(f"{parsons_version} not supported")

0 commit comments

Comments
 (0)