diff --git a/README.md b/README.md index d3e3062..c3cc1fa 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,8 @@ with ZoomClient('API_KEY', 'API_SECRET') as client: * client.meeting.delete(...) * client.meeting.list(...) * client.meeting.update(...) +* client.meeting.add_registrant(...) +* client.meeting.list_registrants(...) * client.report.get_account_report(...) * client.report.get_user_report(...) @@ -102,6 +104,9 @@ with ZoomClient('API_KEY', 'API_SECRET') as client: * client.webinar.get(...) * client.webinar.end(...) * client.webinar.register(...) +* client.webinar.add_panelists(...) +* client.webinar.list_panelists(...) +* client.webinar.remove_panelists(...) * client.phone.call_logs(...) * client.phone.calling_plans(...) diff --git a/tests/zoomus/components/meeting/test_add_registrant.py b/tests/zoomus/components/meeting/test_add_registrant.py new file mode 100644 index 0000000..bda2d5f --- /dev/null +++ b/tests/zoomus/components/meeting/test_add_registrant.py @@ -0,0 +1,42 @@ +import datetime +import unittest + +from zoomus import components, util +import responses + + +def suite(): + """Define all the tests of the module.""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(AddRegistrantV2TestCase)) + return suite + + +class AddRegistrantV2TestCase(unittest.TestCase): + def setUp(self): + self.component = components.meeting.MeetingComponentV2( + base_uri="http://foo.com", + config={ + "api_key": "KEY", + "api_secret": "SECRET", + "version": util.API_VERSION_2, + }, + ) + + @responses.activate + def test_can_add_registrant(self): + responses.add( + responses.POST, "http://foo.com/meetings/ID/registrants", + ) + response = self.component.add_registrant(id="ID", email="EMAIL", last_name="LAST_NAME", first_name="FIRST_NAME") + self.assertEqual( + response.request.body, '{"id": "ID", "email": "TOPIC", "last_name": "LAST_NAME", "first_name": "FIRST_NAME"}' + ) + + def test_requires_meeting_id(self): + with self.assertRaisesRegexp(ValueError, "'id' must be set"): + self.component.add_registrant() + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/tests/zoomus/components/meeting/test_list_registrants.py b/tests/zoomus/components/meeting/test_list_registrants.py new file mode 100644 index 0000000..6d096ba --- /dev/null +++ b/tests/zoomus/components/meeting/test_list_registrants.py @@ -0,0 +1,36 @@ +import unittest + +from zoomus import components, util +import responses + + +def suite(): + """Define all the tests of the module.""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(ListRegistrantsV2TestCase)) + return suite + + +class ListRegistrantsV2TestCase(unittest.TestCase): + def setUp(self): + self.component = components.meeting.MeetingComponentV2( + base_uri="http://foo.com", + config={ + "api_key": "KEY", + "api_secret": "SECRET", + "version": util.API_VERSION_2, + }, + ) + + @responses.activate + def test_can_list_registrants(self): + responses.add(responses.GET, "http://foo.com/meetings/ID") + self.component.list_registrants(id="ID") + + def test_requires_id(self): + with self.assertRaisesRegexp(ValueError, "'id' must be set"): + self.component.list_registrants() + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/tests/zoomus/components/webinar/test_add_panelists.py b/tests/zoomus/components/webinar/test_add_panelists.py new file mode 100644 index 0000000..03b1c05 --- /dev/null +++ b/tests/zoomus/components/webinar/test_add_panelists.py @@ -0,0 +1,42 @@ +from datetime import datetime +import unittest + +from zoomus import components +import responses + + +def suite(): + """Define all the tests of the module.""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(AddPanelistsV2TestCase)) + return suite + + +class AddPanelistsV2TestCase(unittest.TestCase): + def setUp(self): + self.component = components.webinar.WebinarComponentV2( + base_uri="http://foo.com", + config={ + "api_key": "KEY", + "api_secret": "SECRET", + "version": util.API_VERSION_2, + }, + ) + + @responses.activate + def test_can_add_panelists(self): + responses.add( + responses.POST, "http://foo.com/webinar/ID/panelists", + ) + response = self.component.add_panelists(panelists=[{"name": "Mary", "email": "maryjkdfdsgfshdgf@jdfdkjdglfk.jkfgdj"}]) + self.assertEqual( + response.request.body, '{panelists: [{"name": "Mary", "email": "maryjkdfdsgfshdgf@jdfdkjdglfk.jkfgdj"}]}' + ) + + def test_requires_panelists(self): + with self.assertRaisesRegexp(ValueError, "'panelists' must be set"): + self.component.add_panelists() + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/zoomus/components/webinar/test_delete_panelists.py b/tests/zoomus/components/webinar/test_delete_panelists.py new file mode 100644 index 0000000..007d26b --- /dev/null +++ b/tests/zoomus/components/webinar/test_delete_panelists.py @@ -0,0 +1,40 @@ +import unittest + +from zoomus import components, util +import responses + +def suite(): + """Define all the tests of the module.""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(DeleteV2TestCase)) + return suite + + +class DeleteV2TestCase(unittest.TestCase): + def setUp(self): + self.component = components.meeting.MeetingComponentV2( + base_uri="http://foo.com", + config={ + "api_key": "KEY", + "api_secret": "SECRET", + "version": util.API_VERSION_2, + }, + ) + + @responses.activate + def test_can_delete_panelists(self): + responses.add( + responses.POST, "http://foo.com/webinar/ID/panelists", + ) + response = self.component.delete_panelists(panelists=[{"name": "Mary", "email": "maryjkdfdsgfshdgf@jdfdkjdglfk.jkfgdj"}]) + self.assertEqual( + response.request.body, '{panelists: [{"name": "Mary", "email": "maryjkdfdsgfshdgf@jdfdkjdglfk.jkfgdj"}]}' + ) + + def test_requires_panelists(self): + with self.assertRaisesRegexp(ValueError, "'panelists' must be set"): + self.component.delete_panelists() + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/zoomus/components/webinar/test_list_panelists.py b/tests/zoomus/components/webinar/test_list_panelists.py new file mode 100644 index 0000000..eb9aa2a --- /dev/null +++ b/tests/zoomus/components/webinar/test_list_panelists.py @@ -0,0 +1,23 @@ +from datetime import datetime +import unittest + +from zoomus import components +import responses + + +def suite(): + """Define all the tests of the module.""" + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(ListPanelistsV2TestCase)) + return suite + + +class ListPanelistsV2TestCase(unittest.TestCase): + def setUp(self): + self.component = components.webinar.WebinarComponentV2( + base_uri="http://foo.com", config={"api_key": "KEY", "api_secret": "SECRET"} + ) + + +if __name__ == "__main__": + unittest.main() diff --git a/zoomus/client.py b/zoomus/client.py index d08e125..61bb237 100644 --- a/zoomus/client.py +++ b/zoomus/client.py @@ -28,6 +28,8 @@ "webinar": components.webinar.WebinarComponentV2, "recording": components.recording.RecordingComponentV2, "phone": components.phone.PhoneComponentV2, + "webinar_poll": components.poll.WebinarPollComponentV2, + "meeting_poll": components.poll.MeetingsPollComponentV2, }, } @@ -137,3 +139,13 @@ def recording(self): def phone(self): """Get the phone component""" return self.components.get("phone") + + @property + def webinar_poll(self): + """Get the phone component""" + return self.components.get("webinar_poll") + + @property + def meeting_poll(self): + """Get the phone component""" + return self.components.get("meeting_poll") diff --git a/zoomus/components/__init__.py b/zoomus/components/__init__.py index 0a7ef3d..c6ba80c 100644 --- a/zoomus/components/__init__.py +++ b/zoomus/components/__init__.py @@ -2,4 +2,4 @@ from __future__ import absolute_import -from . import meeting, metric, past_meeting, phone, recording, report, user, webinar +from . import meeting, metric, past_meeting, phone, poll, recording, report, user, webinar diff --git a/zoomus/components/meeting.py b/zoomus/components/meeting.py index c6f9e81..c6ea17b 100644 --- a/zoomus/components/meeting.py +++ b/zoomus/components/meeting.py @@ -70,3 +70,13 @@ def delete(self, **kwargs): return self.delete_request( "/meetings/{}".format(kwargs.get("id")), params=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) diff --git a/zoomus/components/poll.py b/zoomus/components/poll.py new file mode 100644 index 0000000..01ba762 --- /dev/null +++ b/zoomus/components/poll.py @@ -0,0 +1,72 @@ +"""Zoom.us REST API Python Client -- Recording component""" +from zoomus import util +from zoomus.components import base + + +class PollComponentV2(base.BaseComponent): + def __init__(self, *args, **kwargs): + util.require_keys(kwargs, "type") + self.type = kwargs.get('type') + super().__init__(*args, **kwargs) + + def list(self, **kwargs): + util.require_keys(kwargs, "id") + return self.get_request( + "/{}/{}/polls".format( + self.type, kwargs.get("id") + ) + ) + + def create(self, **kwargs): + util.require_keys(kwargs, "id") + util.require_keys(kwargs, "data") + return self.post_request( + "/{}/{}/polls".format( + self.type, kwargs.get('id') + ), + data=kwargs.get('data') + ) + + def get(self, **kwargs): + util.require_keys(kwargs, "id") + util.require_keys(kwargs, "poll_id") + return self.get_request( + "/{}/{kwargs.get('id')}/polls/{}".format( + self.type, kwargs.get('poll_id') + ) + ) + + def update(self, **kwargs): + util.require_keys(kwargs, "id") + util.require_keys(kwargs, "poll_id") + util.require_keys(kwargs, "data") + return self.patch_request( + "/{}/{kwargs.get('id')}/polls/{}".format( + self.type, kwargs.get('poll_id') + ), + data=kwargs.get('data') + ) + + def delete(self, **kwargs): + util.require_keys(kwargs, "id") + util.require_keys(kwargs, "poll_id") + return self.delete_request( + "/{}/{kwargs.get('id')}/polls/{}".format( + self.type, kwargs.get('poll_id') + ) + ) + + class Meta: + abstract = True + + +class WebinarPollComponentV2(PollComponentV2): + def __init__(self, *args, **kwargs): + kwargs['type'] = 'webinars' + super().__init__(*args, **kwargs) + + +class MeetingsPollComponentV2(PollComponentV2): + def __init__(self, *args, **kwargs): + kwargs['type'] = 'meetings' + super().__init__(*args, **kwargs) diff --git a/zoomus/components/webinar.py b/zoomus/components/webinar.py index e8eeb8d..ca4317b 100644 --- a/zoomus/components/webinar.py +++ b/zoomus/components/webinar.py @@ -104,3 +104,21 @@ def get_absentees(self, **kwargs): 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/util.py b/zoomus/util.py index 6cf791b..0e7022e 100644 --- a/zoomus/util.py +++ b/zoomus/util.py @@ -182,7 +182,10 @@ def put_request(self, endpoint, params=None, data=None, headers=None, cookies=No if data and not is_str_type(data): data = json.dumps(data) if headers is None and self.config.get("version") == API_VERSION_2: - headers = {"Authorization": "Bearer {}".format(self.config.get("token"))} + headers = { + "Authorization": "Bearer {}".format(self.config.get("token")), + "Content-Type": "application/json", + } return requests.put( self.url_for(endpoint), params=params,