Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contact center #371

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
243 changes: 243 additions & 0 deletions client.py
Original file line number Diff line number Diff line change
@@ -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")
20 changes: 20 additions & 0 deletions components/__init__.py
Original file line number Diff line number Diff line change
@@ -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
)
56 changes: 56 additions & 0 deletions components/base.py
Original file line number Diff line number Diff line change
@@ -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
)
30 changes: 30 additions & 0 deletions components/contact_center.py
Original file line number Diff line number Diff line change
@@ -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)





21 changes: 21 additions & 0 deletions components/contacts.py
Original file line number Diff line number Diff line change
@@ -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
)
Loading