diff --git a/client.py b/client.py new file mode 100644 index 0000000..15406ef --- /dev/null +++ b/client.py @@ -0,0 +1,243 @@ +"""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_GDPR + + +API_BASE_URIS = { + API_VERSION_1: "https://api.zoom.us/v1", + API_VERSION_2: "https://api.zoom.us/v2", + API_GDPR: "https://eu01api-www4local.zoom.us/v2", +} + +OAUTH_URI = "https://zoom.us/oauth/token" + +COMPONENT_CLASSES = { + API_VERSION_1: { + "meeting": components.meeting.MeetingComponent, + "recording": components.recording.RecordingComponent, + "report": components.report.ReportComponent, + "user": components.user.UserComponent, + "webinar": components.webinar.WebinarComponent, + }, + API_VERSION_2: { + "contacts": components.contacts.ContactsComponentV2, + "group": components.group.GroupComponentV2, + "live_stream": components.live_stream.LiveStreamComponentV2, + "meeting": components.meeting.MeetingComponentV2, + "metric": components.metric.MetricComponentV2, + "past_meeting": components.past_meeting.PastMeetingComponentV2, + "phone": components.phone.PhoneComponentV2, + "recording": components.recording.RecordingComponentV2, + "report": components.report.ReportComponentV2, + "role": components.role.RoleComponentV2, + "room": components.room.RoomComponentV2, + "user": components.user.UserComponentV2, + "webinar": components.webinar.WebinarComponentV2, + "contact_center": components.contact_center.ContactCenterComponentV2, + }, +} + + +class ZoomClient(util.ApiClient): + """Zoom.us REST API Python Client""" + + """Base URL for Zoom API""" + + def __init__( + self, + client_id, + client_secret, + api_account_id, + data_type="json", + timeout=15, + version=API_VERSION_2, + base_uri=None, + oauth_uri=OAUTH_URI, + ): + """Create a new Zoom client + + :param client_id: The Zooom.us OAuth Client ID + :param client_secret: The Zoom.us OAUTH Client Secret + :param api_account_id: The Zoom.us API account ID + :param data_type: The expected return data type. Either 'json' or 'xml' + :param timeout: The time out to use for API requests + :param version: The API version to use (Default is V2). The available + options are API_VERSION_1 (deprecated by Zoom), + or API_VERSION_2 (default) + :param base_uri: Set the base URI to use. By default this is chosen + based on the API version chosen, but it can be + overriden so that the GDPR compliant base URI can + be used in the EU. + :param oauth_uri: Set the URI to use to get an OAuth token. By default + this is set to what is defined by the constant + OAUTH_URI + """ + try: + base_uri = base_uri or 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 = { + "client_id": client_id, + "client_secret": client_secret, + "api_account_id": api_account_id, + "data_type": data_type, + "version": version, + "base_uri": base_uri, + "oauth_uri": oauth_uri, + "token": util.generate_token( + oauth_uri, client_id, client_secret, api_account_id + ), + } + + # 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_token( + self.config["oauth_uri"], + self.config["client_id"], + self.config["client_secret"], + self.config["api_account_id"], + ) + + @property + def client_id(self): + """The Zoom.us client_id""" + return self.config.get("client_id") + + @client_id.setter + def client_id(self, value): + """Set the client_id""" + self.config["client_id"] = value + self.refresh_token() + + @property + def api_key(self): + """The Zoom.us api_key - DEPRECATD: USE client_id""" + return self.config.get("client_id") + + @api_key.setter + def api_key(self, value): + """Set the api_key - DEPRECATD: USE client_id""" + self.config["client_id"] = value + self.refresh_token() + + @property + def client_secret(self): + """The Zoom.us client_secret""" + return self.config.get("client_secret") + + @client_secret.setter + def client_secret(self, value): + """Set the client_secret""" + self.config["client_secret"] = value + self.refresh_token() + + @property + def api_secret(self): + """The Zoom.us api_secret - DEPRECATD: USE client_secret""" + return self.config.get("client_secret") + + @api_secret.setter + def api_secret(self, value): + """Set the api_secret - DEPRECATD: USE client_secret""" + self.config["client_secret"] = value + self.refresh_token() + + @property + def api_account_id(self): + """The Zoom.us api_account_id""" + return self.config.get("api_account_id") + + @api_account_id.setter + def api_account_id(self, value): + """Set the api_account_id""" + self.config["api_account_id"] = value + self.refresh_token() + + @property + def contacts(self): + """Get the contacts component""" + return self.components.get("contacts") + + @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 live_stream(self): + """Get the live stream component""" + return self.components.get("live_stream") + + @property + def phone(self): + """Get the phone component""" + return self.components.get("phone") + + @property + def past_meeting(self): + """Get the past meeting component""" + return self.components.get("past_meeting") + + @property + def group(self): + """Get the group component""" + return self.components.get("group") + + @property + def room(self): + """Get the room component""" + return self.components.get("room") + + @property + def role(self): + """Get the role component""" + return self.components.get("role") + + @property + def contact_center(self): + """Get the contact center component""" + return self.components.get("contact_center") diff --git a/components/__init__.py b/components/__init__.py new file mode 100644 index 0000000..570be99 --- /dev/null +++ b/components/__init__.py @@ -0,0 +1,20 @@ +"""Zoom.us REST API Python Client Components""" + +from __future__ import absolute_import + +from . import ( + contacts, + group, + live_stream, + meeting, + metric, + past_meeting, + phone, + recording, + report, + role, + room, + user, + webinar, + contact_center +) diff --git a/components/base.py b/components/base.py new file mode 100644 index 0000000..06687ef --- /dev/null +++ b/components/base.py @@ -0,0 +1,56 @@ +"""Zoom.us REST API Python Client""" + +from __future__ import absolute_import, unicode_literals + +from zoomus import util + + +class BaseComponent(util.ApiClient): + """A base component""" + + def __init__(self, base_uri=None, config=None, timeout=15, **kwargs): + """Setup a base component + + :param base_uri: The base URI to the API + :param config: The config details + :param timeout: The timeout to use for requests + :param kwargs: Any other attributes. These will be added as + attributes to the ApiClient object. + """ + super(BaseComponent, self).__init__( + base_uri=base_uri, timeout=timeout, config=config, **kwargs + ) + + def post_request( + self, endpoint, params=None, data=None, headers=None, cookies=None + ): + """Helper function for POST requests + + Since the Zoom.us API only uses POST requests and each post request + must include all of the config data, this method ensures that all + of that data is there + + :param endpoint: The endpoint + :param params: The URL parameters + :param data: The data (either as a dict or dumped JSON string) to + include with the POST + :param headers: request headers + :param cookies: request cookies + :return: The :class:``requests.Response`` object for this request + """ + params = params or {} + if self.config["version"] == util.API_VERSION_1: + params.update(self.config) + params["api_key"] = params["client_id"] + params["api_secret"] = params["client_secret"] + del params["client_id"] + del params["client_secret"] + del params["version"] + if headers is None and self.config.get("version") == util.API_VERSION_2: + headers = { + "Authorization": "Bearer {}".format(self.config.get("token")), + "Content-Type": "application/json", + } + return super(BaseComponent, self).post_request( + endpoint, params=params, data=data, headers=headers, cookies=cookies + ) diff --git a/components/contact_center.py b/components/contact_center.py new file mode 100644 index 0000000..18a4cf3 --- /dev/null +++ b/components/contact_center.py @@ -0,0 +1,30 @@ +"""Zoom.us REST API Python Client -- Contact Center Component""" + +from __future__ import absolute_import + +from zoomus import util +from zoomus.components import base + + +class ContactCenterComponentV2(base.BaseComponent): + + def queues_list(self, **kwargs): + return self.get_request("/contact_center/queues", params=kwargs) + + + + + def queues_add(self, **kwargs): + util.require_keys(kwargs, "queue_name", "queue_description") + + print("adding contact center") + + + print(kwargs) + + return self.post_request("/contact_center/queues/", data=kwargs) + + + + + diff --git a/components/contacts.py b/components/contacts.py new file mode 100644 index 0000000..7d689cf --- /dev/null +++ b/components/contacts.py @@ -0,0 +1,21 @@ +"""Zoom.us REST API Python Client -- Contacts component""" + +from __future__ import absolute_import + +from zoomus import util +from zoomus.components import base + + +class ContactsComponentV2(base.BaseComponent): + def search(self, **kwargs): + util.require_keys(kwargs, ["search_key"]) + return self.get_request("/contacts", params=kwargs) + + def list_user_contacts(self, **kwargs): + return self.get_request("/chat/users/me/contacts", params=kwargs) + + def get_user_contact(self, **kwargs): + util.require_keys(kwargs, ["contact_id"]) + return self.get_request( + "/chat/users/me/contacts/{}".format(kwargs.get("contact_id")), params=kwargs + ) diff --git a/components/group.py b/components/group.py new file mode 100644 index 0000000..96c9cfb --- /dev/null +++ b/components/group.py @@ -0,0 +1,44 @@ +"""Zoom.us REST API Python Client""" + +from __future__ import absolute_import + +from zoomus import util +from zoomus.components import base + + +class GroupComponentV2(base.BaseComponent): + def list(self, **kwargs): + return self.get_request("/groups", params=kwargs) + + def create(self, **kwargs): + util.require_keys(kwargs, "name") + return self.post_request("/groups", data=kwargs) + + def get(self, **kwargs): + util.require_keys(kwargs, "id") + return self.get_request("/groups/{}".format(kwargs.get("id")), params=kwargs) + + def delete(self, **kwargs): + util.require_keys(kwargs, "id") + return self.delete_request("/groups/{}".format(kwargs.get("id")), params=kwargs) + + def list_members(self, **kwargs): + util.require_keys(kwargs, "groupid") + return self.get_request( + "/groups/{}/members".format(kwargs.get("groupid")), params=kwargs + ) + + def add_members(self, **kwargs): + util.require_keys(kwargs, ["groupid", "members"]) + return self.post_request( + "/groups/{}/members".format(kwargs.get("groupid")), data=kwargs + ) + + def delete_member(self, **kwargs): + util.require_keys(kwargs, ["groupid", "memberid"]) + return self.delete_request( + "/groups/{}/members/{}".format( + kwargs.get("groupid"), kwargs.get("memberid") + ), + params=kwargs, + ) diff --git a/components/live_stream.py b/components/live_stream.py new file mode 100644 index 0000000..87a185b --- /dev/null +++ b/components/live_stream.py @@ -0,0 +1,34 @@ +from __future__ import absolute_import + +from zoomus import util +from zoomus.components import base + + +class LiveStreamComponentV2(base.BaseComponent): + def update(self, **kwargs): + """ + Use this API to update the meeting's stream information. + Expects: + - meeting_id: int + - stream_url: string (URL) + - stream_key: string + - page_url: string (URL) + """ + util.require_keys(kwargs, "meeting_id") + return self.patch_request( + "/meetings/{}/livestream".format(kwargs.get("meeting_id")), data=kwargs + ) + + def update_status(self, **kwargs): + """ + Use this API to update the status of a meeting's live stream. + Expects: + - meeting_id: int + - action (start|stop) + - settings: dict + """ + util.require_keys(kwargs, "meeting_id") + return self.patch_request( + "/meetings/{}/livestream/status".format(kwargs.get("meeting_id")), + data=kwargs, + ) diff --git a/components/meeting.py b/components/meeting.py new file mode 100644 index 0000000..abbe3ee --- /dev/null +++ b/components/meeting.py @@ -0,0 +1,104 @@ +"""Zoom.us REST API Python Client""" + +from __future__ import absolute_import + +from zoomus import util +from zoomus.components import base + + +class MeetingComponent(base.BaseComponent): + """Component dealing with all meeting related matters""" + + def list(self, **kwargs): + util.require_keys(kwargs, "host_id") + if kwargs.get("start_time"): + kwargs["start_time"] = util.date_to_str(kwargs["start_time"]) + return self.post_request("/meeting/list", params=kwargs) + + def create(self, **kwargs): + util.require_keys(kwargs, ["host_id", "topic", "type"]) + if kwargs.get("start_time"): + kwargs["start_time"] = util.date_to_str(kwargs["start_time"]) + return self.post_request("/meeting/create", params=kwargs) + + def update(self, **kwargs): + util.require_keys(kwargs, ["id", "host_id"]) + if kwargs.get("start_time"): + kwargs["start_time"] = util.date_to_str(kwargs["start_time"]) + return self.post_request("/meeting/update", params=kwargs) + + def delete(self, **kwargs): + util.require_keys(kwargs, ["id", "host_id"]) + return self.post_request("/meeting/delete", params=kwargs) + + def end(self, **kwargs): + util.require_keys(kwargs, ["id", "host_id"]) + return self.post_request("/meeting/end", params=kwargs) + + def get(self, **kwargs): + util.require_keys(kwargs, ["id", "host_id"]) + return self.post_request("/meeting/get", params=kwargs) + + +class MeetingComponentV2(base.BaseComponent): + def list(self, **kwargs): + util.require_keys(kwargs, "user_id") + return self.get_request( + "/users/{}/meetings".format(kwargs.get("user_id")), params=kwargs + ) + + def create(self, **kwargs): + util.require_keys(kwargs, "user_id") + if kwargs.get("start_time"): + kwargs["start_time"] = util.date_to_str(kwargs["start_time"]) + return self.post_request( + "/users/{}/meetings".format(kwargs.get("user_id")), data=kwargs + ) + + def get(self, **kwargs): + util.require_keys(kwargs, "id") + return self.get_request("/meetings/{}".format(kwargs.get("id")), params=kwargs) + + def update(self, **kwargs): + util.require_keys(kwargs, "id") + if kwargs.get("start_time"): + kwargs["start_time"] = util.date_to_str(kwargs["start_time"]) + return self.patch_request("/meetings/{}".format(kwargs.get("id")), data=kwargs) + + def delete(self, **kwargs): + util.require_keys(kwargs, "id") + return self.delete_request( + "/meetings/{}".format(kwargs.get("id")), params=kwargs + ) + + def update_status(self, **kwargs): + util.require_keys(kwargs, "id") + return self.put_request( + "/meetings/{}/status".format(kwargs.pop("id")), data=kwargs + ) + + def add_registrant(self, **kwargs): + util.require_keys(kwargs, "id") + return self.post_request( + "/meetings/{}/registrants".format(kwargs.get("id")), data=kwargs + ) + + def list_registrants(self, **kwargs): + util.require_keys(kwargs, "id") + return self.get_request( + "/meetings/{}/registrants".format(kwargs.get("id")), params=kwargs + ) + + def update_registrant_status(self, **kwargs): + util.require_keys(kwargs, "id") + util.require_keys(kwargs, "action") + util.require_keys(kwargs, "registrants") + return self.put_request( + "/meetings/{}/registrants/status".format(kwargs.get("id")), data=kwargs + ) + + def list_meeting_participants(self, **kwargs): + util.require_keys(kwargs, "id") + return self.get_request( + "/metrics/meetings/{}/participants".format(kwargs.get("id")), params=kwargs + ) diff --git a/components/metric.py b/components/metric.py new file mode 100644 index 0000000..6cf482d --- /dev/null +++ b/components/metric.py @@ -0,0 +1,55 @@ +"""Zoom.us REST API Python Client""" + +from __future__ import absolute_import + +from zoomus import util +from zoomus.components import base + + +class MetricComponentV2(base.BaseComponent): + def list_meetings(self, **kwargs): + return self.get_request( + "/metrics/meetings", + params=kwargs, + ) + + def get_meeting(self, **kwargs): + util.require_keys(kwargs, "meeting_id") + kwargs["meeting_id"] = util.encode_uuid(kwargs.get("meeting_id")) + return self.get_request( + "/metrics/meetings/{}".format(kwargs.get("meeting_id")), params=kwargs + ) + + def list_participants(self, **kwargs): + util.require_keys(kwargs, "meeting_id") + kwargs["meeting_id"] = util.encode_uuid(kwargs.get("meeting_id")) + return self.get_request( + "/metrics/meetings/{}/participants".format(kwargs.get("meeting_id")), + params=kwargs, + ) + + def list_webinar_participants(self, **kwargs): + util.require_keys(kwargs, "webinar_id") + kwargs["webinar_id"] = util.encode_uuid(kwargs.get("webinar_id")) + return self.get_request( + "/metrics/webinars/{}/participants".format(kwargs.get("webinar_id")), + params=kwargs, + ) + + def get_participant_qos(self, **kwargs): + util.require_keys(kwargs, ("meeting_id", "participant_id")) + kwargs["meeting_id"] = util.encode_uuid(kwargs.get("meeting_id")) + return self.get_request( + "/metrics/meetings/{}/participants/{}/qos".format( + kwargs.get("meeting_id"), kwargs.get("participant_id") + ), + params=kwargs, + ) + + def list_participants_qos(self, **kwargs): + util.require_keys(kwargs, "meeting_id") + kwargs["meeting_id"] = util.encode_uuid(kwargs.get("meeting_id")) + return self.get_request( + "/metrics/meetings/{}/participants/qos".format(kwargs.get("meeting_id")), + params=kwargs, + ) diff --git a/components/past_meeting.py b/components/past_meeting.py new file mode 100644 index 0000000..cf79976 --- /dev/null +++ b/components/past_meeting.py @@ -0,0 +1,31 @@ +"""Zoom.us REST API Python Client""" + +from __future__ import absolute_import + +from zoomus import util +from zoomus.components import base + + +class PastMeetingComponentV2(base.BaseComponent): + def list(self, **kwargs): + util.require_keys(kwargs, "meeting_id") + kwargs["meeting_id"] = util.encode_uuid(kwargs.get("meeting_id")) + return self.get_request( + "/past_meetings/{}/instances".format(kwargs.get("meeting_id")), + params=kwargs, + ) + + def get(self, **kwargs): + util.require_keys(kwargs, "meeting_id") + kwargs["meeting_id"] = util.encode_uuid(kwargs.get("meeting_id")) + return self.get_request( + "/past_meetings/{}".format(kwargs.get("meeting_id")), params=kwargs + ) + + def get_participants(self, **kwargs): + util.require_keys(kwargs, "meeting_id") + kwargs["meeting_id"] = util.encode_uuid(kwargs.get("meeting_id")) + return self.get_request( + "/past_meetings/{}/participants".format(kwargs.get("meeting_id")), + params=kwargs, + ) diff --git a/components/phone.py b/components/phone.py new file mode 100644 index 0000000..ca0fbce --- /dev/null +++ b/components/phone.py @@ -0,0 +1,82 @@ +"""Zoom.us REST API Python Client -- Phone component""" + +from __future__ import absolute_import + +from zoomus import util +from zoomus.components import base + + +class PhoneComponentV2(base.BaseComponent): + def numbers_list(self, **kwargs): + return self.get_request("/phone/numbers", params=kwargs) + + def numbers_get(self, **kwargs): + util.require_keys(kwargs, "id") + return self.get_request( + "/phone/numbers/{}".format(kwargs.get("id")), params=kwargs + ) + + def call_logs(self, **kwargs): + """ + Retrieve call logs for an account. + + Scopes: phone:read:admin + + Prerequisite: + * Business or Enterprise account + * A Zoom Phone license + * Account Owner and a with Zoom Phone Management + + :param page_size: The number of records returned within a single API call, + default=30, max=300 + :param page_number: The current page number of returned records, default=1 + :param from: Start date from which you would like to get the call logs. The start date should be within past six months. + :param to: The end date upto which you would like to get the call logs for. + The end date should be within past six months. + :param type: The type of the call logs. The value can be either "all" or "missed". + :return: request object with json data + """ + return self.get_request("/phone/call_logs", params=kwargs) + + def calling_plans(self, **kwargs): + return self.get_request("/phone/calling_plans", params=kwargs) + + def users(self, **kwargs): + return self.get_request("/phone/users", params=kwargs) + + def call_queues(self, **kwargs): + print("calling call_queues") + return self.get_request("/phone/call_queues") + + def call_queues_create(self, **kwargs): + print("module calling call_queues_create") + util.require_keys(kwargs, ["name"]) + + + + print(kwargs) + return self.post_request("/phone/call_queues", data=kwargs) + + def call_queue_members(self, **kwargs): + util.require_keys(kwargs, "id") + + print("adding call_queue_members") + + value = kwargs.pop("id") + print(kwargs) + + return self.post_request("/phone/call_queues/{}/members".format(value), data=kwargs) + + + + def call_queue_manager(self, **kwargs): + util.require_keys(kwargs, "id") + + print("calling call_queues_manager") + + value = kwargs.pop("id") + print(kwargs) + + return self.put_request("/phone/call_queues/{}/manager".format(value), data=kwargs) + + diff --git a/components/recording.py b/components/recording.py new file mode 100644 index 0000000..35f978b --- /dev/null +++ b/components/recording.py @@ -0,0 +1,64 @@ +"""Zoom.us REST API Python Client -- Recording component""" +from zoomus import util +from zoomus.components import base + + +class RecordingComponent(base.BaseComponent): + """Component dealing with all recording related matters""" + + def list(self, **kwargs): + util.require_keys(kwargs, "host_id") + start = kwargs.pop("start", None) + if start: + kwargs["from"] = util.date_to_str(start) + end = kwargs.pop("end", None) + if end: + kwargs["to"] = util.date_to_str(end) + return self.post_request("/recording/list", params=kwargs) + + def delete(self, **kwargs): + util.require_keys(kwargs, ["meeting_id"]) + return self.post_request("/recording/delete", params=kwargs) + + def get(self, **kwargs): + util.require_keys(kwargs, ["meeting_id"]) + return self.post_request("/recording/get", params=kwargs) + + +class RecordingComponentV2(base.BaseComponent): + """Component dealing with all recording related matters""" + + def list(self, **kwargs): + util.require_keys(kwargs, "user_id") + start = kwargs.pop("start", None) + if start: + kwargs["from"] = util.date_to_str(start) + end = kwargs.pop("end", None) + if end: + kwargs["to"] = util.date_to_str(end) + return self.get_request( + "/users/{}/recordings".format(kwargs.get("user_id")), params=kwargs + ) + + def get(self, **kwargs): + util.require_keys(kwargs, "meeting_id") + return self.get_request( + "/meetings/{}/recordings".format(kwargs.get("meeting_id")), params=kwargs + ) + + def delete(self, **kwargs): + util.require_keys(kwargs, "meeting_id") + return self.delete_request( + "/meetings/{}/recordings".format(kwargs.get("meeting_id")), params=kwargs + ) + + def delete_single_recording(self, **kwargs): + util.require_keys(kwargs, "meeting_id") + util.require_keys(kwargs, "recording_id") + return self.delete_request( + "/meetings/{}/recordings/{}".format( + kwargs.get("meeting_id"), + kwargs.get("recording_id"), + ), + params=kwargs, + ) diff --git a/components/report.py b/components/report.py new file mode 100644 index 0000000..0f22c10 --- /dev/null +++ b/components/report.py @@ -0,0 +1,66 @@ +"""Zoom.us REST API Python Client -- Report component""" + +from __future__ import absolute_import + +from zoomus import util +from zoomus.components import base + + +class ReportComponent(base.BaseComponent): + """Component dealing with all report related matters""" + + def get_account_report(self, **kwargs): + util.require_keys(kwargs, ["start_time", "end_time"], kwargs) + kwargs["from"] = util.date_to_str(kwargs["start_time"]) + del kwargs["start_time"] + kwargs["to"] = util.date_to_str(kwargs["end_time"]) + del kwargs["end_time"] + return self.post_request("/report/getaccountreport", params=kwargs) + + def get_user_report(self, **kwargs): + util.require_keys(kwargs, ["start_time", "end_time"], kwargs) + kwargs["from"] = util.date_to_str(kwargs["start_time"]) + del kwargs["start_time"] + kwargs["to"] = util.date_to_str(kwargs["end_time"]) + del kwargs["end_time"] + return self.post_request("/report/getuserreport", params=kwargs) + + def get_daily_report(self, **kwargs): + util.require_keys(kwargs, ["month", "year"], kwargs) + return self.post_request("/report/getdailyreport", params=kwargs) + + +class ReportComponentV2(base.BaseComponent): + def get_user_report(self, **kwargs): + util.require_keys(kwargs, ["user_id", "start_time", "end_time"]) + kwargs["from"] = util.date_to_str(kwargs["start_time"]) + del kwargs["start_time"] + kwargs["to"] = util.date_to_str(kwargs["end_time"]) + del kwargs["end_time"] + return self.get_request( + "/report/users/{}/meetings".format(kwargs.get("user_id")), params=kwargs + ) + + def get_account_report(self, **kwargs): + util.require_keys(kwargs, ["start_time", "end_time"]) + kwargs["from"] = util.date_to_str(kwargs["start_time"]) + del kwargs["start_time"] + kwargs["to"] = util.date_to_str(kwargs["end_time"]) + del kwargs["end_time"] + return self.get_request("/report/users", params=kwargs) + + def get_daily_report(self, **kwargs): + util.require_keys(kwargs, ["month", "year"]) + return self.get_request("/report/daily", params=kwargs) + + def get_meeting_participants_report(self, **kwargs): + util.require_keys(kwargs, "id") + return self.get_request( + "/report/meetings/{}/participants".format(kwargs.get("id")), params=kwargs + ) + + def get_webinar_participants_report(self, **kwargs): + util.require_keys(kwargs, "id") + return self.get_request( + "/report/webinars/{}/participants".format(kwargs.get("id")), params=kwargs + ) diff --git a/components/role.py b/components/role.py new file mode 100644 index 0000000..12eccdc --- /dev/null +++ b/components/role.py @@ -0,0 +1,59 @@ +"""Zoom.us REST API Python Client""" + +from __future__ import absolute_import + +from zoomus import util +from zoomus.components import base + + +class RoleComponentV2(base.BaseComponent): + def assign(self, **kwargs): + util.require_keys(kwargs, ["id", "members"]) + + return self.post_request( + "/roles/{}/members".format(kwargs.pop("id")), data=kwargs + ) + + def create(self, **kwargs): + util.require_keys(kwargs, ["name", "description", "privileges"]) + + try: + util.require_keys(kwargs, "type") + except ValueError: + kwargs["type"] = "common" + + return self.post_request("/roles", data=kwargs) + + def delete(self, **kwargs): + util.require_keys(kwargs, "id") + + return self.delete_request("/roles/{}".format(kwargs.pop("id"))) + + def get(self, **kwargs): + util.require_keys(kwargs, "id") + + return self.get_request("/roles/{}/".format(kwargs.pop("id"))) + + def get_members(self, **kwargs): + util.require_keys(kwargs, "id") + + return self.get_request( + "/roles/{}/members".format(kwargs.pop("id")), params=kwargs + ) + + def list(self, **kwargs): + return self.get_request("/roles", params=kwargs) + + def unassign(self, **kwargs): + util.require_keys(kwargs, ["id", "member"]) + + return self.delete_request( + "/roles/{roleId}/members/{memberId}".format( + roleId=kwargs.pop("id"), memberId=kwargs["member"] + ) + ) + + def update(self, **kwargs): + util.require_keys(kwargs, ["id", "name", "description", "privileges"]) + + return self.patch_request("/roles/{}".format(kwargs.pop("id")), data=kwargs) diff --git a/components/room.py b/components/room.py new file mode 100644 index 0000000..1f35a4e --- /dev/null +++ b/components/room.py @@ -0,0 +1,45 @@ +"""Zoom.us REST API Python Client -- Room component""" + +from __future__ import absolute_import + +from zoomus import util +from zoomus.components import base + + +class RoomComponentV2(base.BaseComponent): + def create(self, **kwargs): + util.require_keys(kwargs, ["name", "type"]) + return self.post_request("/rooms", data=kwargs) + + def get(self, **kwargs): + util.require_keys(kwargs, "id") + return self.get_request("/rooms/{}".format(kwargs.get("id")), params=kwargs) + + def get_devices(self, **kwargs): + util.require_keys(kwargs, "id") + return self.get_request( + "/rooms/{}/devices".format(kwargs.get("id")), params=kwargs + ) + + def get_settings(self, **kwargs): + util.require_keys(kwargs, ["id", "setting_type"]) + return self.get_request( + "/rooms/{}/settings".format(kwargs.pop("id")), params=kwargs + ) + + def list(self, **kwargs): + return self.get_request("/rooms/", params=kwargs) + + def update(self, **kwargs): + util.require_keys(kwargs, "id") + return self.patch_request("/rooms/{}".format(kwargs.get("id")), data=kwargs) + + def check_in_or_out(self, **kwargs): + util.require_keys(kwargs, "id") + return self.patch_request( + "/rooms/{}/events".format(kwargs.get("id")), data=kwargs + ) + + def delete(self, **kwargs): + util.require_keys(kwargs, "id") + return self.delete_request("/rooms/{}".format(kwargs.get("id")), params=kwargs) diff --git a/components/user.py b/components/user.py new file mode 100644 index 0000000..75f18c6 --- /dev/null +++ b/components/user.py @@ -0,0 +1,114 @@ +"""Zoom.us REST API Python Client -- User component""" + +from __future__ import absolute_import + +from zoomus import util +from zoomus.components import base + + +class UserComponent(base.BaseComponent): + """Component dealing with all user related matters""" + + def me(self): + return self.get_request("/user/me") + + def list(self, **kwargs): + return self.post_request("/user/list", params=kwargs) + + def pending(self, **kwargs): + return self.post_request("/user/pending", params=kwargs) + + def create(self, **kwargs): + return self.post_request("/user/create", params=kwargs) + + def update(self, **kwargs): + util.require_keys(kwargs, "id") + return self.post_request("/user/update", params=kwargs) + + def delete(self, **kwargs): + util.require_keys(kwargs, "id") + return self.post_request("/user/delete", params=kwargs) + + def cust_create(self, **kwargs): + util.require_keys(kwargs, ["type", "email"]) + return self.post_request("/user/custcreate", params=kwargs) + + def get(self, **kwargs): + util.require_keys(kwargs, "id") + return self.post_request("/user/get", params=kwargs) + + def get_by_email(self, **kwargs): + util.require_keys(kwargs, ["email", "login_type"]) + return self.post_request("/user/getbyemail", params=kwargs) + + +class UserComponentV2(base.BaseComponent): + def me(self): + return self.get_request("/users/me") + + def list(self, **kwargs): + return self.get_request("/users", params=kwargs) + + def create(self, **kwargs): + return self.post_request("/users", data=kwargs) + + def update(self, **kwargs): + util.require_keys(kwargs, "id") + return self.patch_request("/users/{}".format(kwargs.get("id")), data=kwargs) + + def update_settings(self, **kwargs): + util.require_keys(kwargs, "id") + return self.patch_request( + "/users/{}/settings".format(kwargs.pop("id")), data=kwargs + ) + + def update_status(self, **kwargs): + util.require_keys(kwargs, ["id", "action"]) + return self.put_request( + "/users/{}/status".format(kwargs.pop("id")), data=kwargs + ) + + def check_email(self, **kwargs): + """ + Verify if a user’s email is registered with Zoom. + Expects: + - email: string (Email address) + Example: + /users/email?email=foo@baar.test + """ + util.require_keys(kwargs, "email") + return self.get_request("/users/email", params=kwargs) + + def update_email(self, **kwargs): + """ + Change a user’s on a Zoom account that has managed domain set up. + If the Zoom Account in which the user belongs, has multiple , the email to be updated must match one of the managed domains. + + Official docs: https://marketplace.zoom.us/docs/api-reference/zoom-api/users/useremailupdate + + Expects: + - id: string (User ID) + - email: string (New email address) + + Example: + /users/42/email + + json: + {"email": "foo@bar.new"} + """ + util.require_keys(kwargs, "id") + return self.put_request("/users/{}/email".format(kwargs.get("id")), data=kwargs) + + def delete(self, **kwargs): + util.require_keys(kwargs, "id") + return self.delete_request("/users/{}".format(kwargs.get("id")), params=kwargs) + + def get(self, **kwargs): + util.require_keys(kwargs, "id") + return self.get_request("/users/{}".format(kwargs.get("id")), params=kwargs) + + def get_settings(self, **kwargs): + util.require_keys(kwargs, "id") + return self.get_request( + "/users/{}/settings".format(kwargs.pop("id")), params=kwargs + ) diff --git a/components/webinar.py b/components/webinar.py new file mode 100644 index 0000000..ca4317b --- /dev/null +++ b/components/webinar.py @@ -0,0 +1,124 @@ +"""Zoom.us REST API Python Client -- Webinar component""" + +from __future__ import absolute_import + +from zoomus import util +from zoomus.components import base + + +class WebinarComponent(base.BaseComponent): + """Component dealing with all webinar related matters""" + + def list(self, **kwargs): + util.require_keys(kwargs, "host_id") + if kwargs.get("start_time"): + kwargs["start_time"] = util.date_to_str(kwargs["start_time"]) + return self.post_request("/webinar/list", params=kwargs) + + def upcoming(self, **kwargs): + util.require_keys(kwargs, "host_id") + if kwargs.get("start_time"): + kwargs["start_time"] = util.date_to_str(kwargs["start_time"]) + return self.post_request("/webinar/list/registration", params=kwargs) + + def create(self, **kwargs): + util.require_keys(kwargs, ["host_id", "topic"]) + if kwargs.get("start_time"): + kwargs["start_time"] = util.date_to_str(kwargs["start_time"]) + return self.post_request("/webinar/create", params=kwargs) + + def update(self, **kwargs): + util.require_keys(kwargs, ["id", "host_id"]) + if kwargs.get("start_time"): + kwargs["start_time"] = util.date_to_str(kwargs["start_time"]) + return self.post_request("/webinar/update", params=kwargs) + + def delete(self, **kwargs): + util.require_keys(kwargs, ["id", "host_id"]) + return self.post_request("/webinar/delete", params=kwargs) + + def end(self, **kwargs): + util.require_keys(kwargs, ["id", "host_id"]) + return self.post_request("/webinar/end", params=kwargs) + + def get(self, **kwargs): + util.require_keys(kwargs, ["id", "host_id"]) + return self.post_request("/webinar/get", params=kwargs) + + def register(self, **kwargs): + util.require_keys(kwargs, ["id", "email", "first_name", "last_name"]) + if kwargs.get("start_time"): + kwargs["start_time"] = util.date_to_str(kwargs["start_time"]) + return self.post_request("/webinar/register", params=kwargs) + + +class WebinarComponentV2(base.BaseComponent): + """Component dealing with all webinar related matters""" + + def list(self, **kwargs): + util.require_keys(kwargs, "user_id") + return self.get_request( + "/users/{}/webinars".format(kwargs.get("user_id")), params=kwargs + ) + + def create(self, **kwargs): + util.require_keys(kwargs, "user_id") + return self.post_request( + "/users/{}/webinars".format(kwargs.get("user_id")), data=kwargs + ) + + def update(self, **kwargs): + util.require_keys(kwargs, "id") + return self.patch_request("/webinars/{}".format(kwargs.get("id")), data=kwargs) + + def delete(self, **kwargs): + util.require_keys(kwargs, "id") + return self.delete_request( + "/webinars/{}".format(kwargs.get("id")), params=kwargs + ) + + def end(self, **kwargs): + util.require_keys(kwargs, "id") + return self.put_request( + "/webinars/{}/status".format(kwargs.get("id")), data={"status": "end"} + ) + + def get(self, **kwargs): + util.require_keys(kwargs, "id") + return self.get_request("/webinars/{}".format(kwargs.get("id")), params=kwargs) + + def register(self, **kwargs): + util.require_keys(kwargs, ["id", "email", "first_name", "last_name"]) + return self.post_request( + "/webinars/{}/registrants".format(kwargs.get("id")), data=kwargs + ) + + def get_registrants(self, **kwargs): + util.require_keys(kwargs, "id") + return self.get_request( + "/webinars/{}/registrants".format(kwargs.get("id")), params=kwargs + ) + + def get_absentees(self, **kwargs): + util.require_keys(kwargs, "id") + return self.get_request( + "/past_webinars/{}/absentees".format(kwargs.get("id")), params=kwargs + ) + + def add_panelists(self, **kwargs): + util.require_keys(kwargs, "id") + return self.post_request( + "/webinars/{}/panelists".format(kwargs.get("id")), data=kwargs + ) + + def list_panelists(self, **kwargs): + util.require_keys(kwargs, "id") + return self.get_request( + "/webinars/{}/panelists".format(kwargs.get("id")), params=kwargs + ) + + def remove_panelists(self, **kwargs): + util.require_keys(kwargs, "id") + return self.delete_request( + "/webinars/{}/panelists".format(kwargs.get("id")), params=kwargs + ) diff --git a/zoomus/components/__init__.py b/zoomus/components/__init__.py index 2c02e29..570be99 100644 --- a/zoomus/components/__init__.py +++ b/zoomus/components/__init__.py @@ -16,4 +16,5 @@ room, user, webinar, + contact_center ) diff --git a/zoomus/components/contact_center.py b/zoomus/components/contact_center.py new file mode 100644 index 0000000..18a4cf3 --- /dev/null +++ b/zoomus/components/contact_center.py @@ -0,0 +1,30 @@ +"""Zoom.us REST API Python Client -- Contact Center Component""" + +from __future__ import absolute_import + +from zoomus import util +from zoomus.components import base + + +class ContactCenterComponentV2(base.BaseComponent): + + def queues_list(self, **kwargs): + return self.get_request("/contact_center/queues", params=kwargs) + + + + + def queues_add(self, **kwargs): + util.require_keys(kwargs, "queue_name", "queue_description") + + print("adding contact center") + + + print(kwargs) + + return self.post_request("/contact_center/queues/", data=kwargs) + + + + + diff --git a/zoomus/components/phone.py b/zoomus/components/phone.py index 088d82d..ca0fbce 100644 --- a/zoomus/components/phone.py +++ b/zoomus/components/phone.py @@ -43,3 +43,40 @@ def calling_plans(self, **kwargs): def users(self, **kwargs): return self.get_request("/phone/users", params=kwargs) + + def call_queues(self, **kwargs): + print("calling call_queues") + return self.get_request("/phone/call_queues") + + def call_queues_create(self, **kwargs): + print("module calling call_queues_create") + util.require_keys(kwargs, ["name"]) + + + + print(kwargs) + return self.post_request("/phone/call_queues", data=kwargs) + + def call_queue_members(self, **kwargs): + util.require_keys(kwargs, "id") + + print("adding call_queue_members") + + value = kwargs.pop("id") + print(kwargs) + + return self.post_request("/phone/call_queues/{}/members".format(value), data=kwargs) + + + + def call_queue_manager(self, **kwargs): + util.require_keys(kwargs, "id") + + print("calling call_queues_manager") + + value = kwargs.pop("id") + print(kwargs) + + return self.put_request("/phone/call_queues/{}/manager".format(value), data=kwargs) + +