From 10835b5f5f65f06ca2628838f9095286c3d94fc7 Mon Sep 17 00:00:00 2001 From: Andrew Matsukov Date: Thu, 7 Nov 2024 14:30:06 +0100 Subject: [PATCH] CSC-6074 Add MasterCategoriesService --- office365_api/v2/services.py | 53 +++++++++++++++++++++++++++++++++--- setup.py | 4 +-- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/office365_api/v2/services.py b/office365_api/v2/services.py index fd397f4..45fe372 100644 --- a/office365_api/v2/services.py +++ b/office365_api/v2/services.py @@ -113,11 +113,16 @@ class BaseBetaService(BaseService): class ServicesCollection(object): - """Wrap a collection of services in a context.""" - def __init__(self, client, prefix): self.client = client self.prefix = prefix + + +class UserServicesCollection(ServicesCollection): + """Wrap a collection of services in a context.""" + + def __init__(self, client, prefix): + super().__init__(client, prefix) self.calendar = CalendarService(self.client, self.prefix) self.calendarview = CalendarViewService(self.client, self.prefix) self.event = EventService(self.client, self.prefix) @@ -129,6 +134,14 @@ def __init__(self, client, prefix): self.mailfolder = MailFolderService(self.client, self.prefix) self.user = UserService(self.client, self.prefix) self.mailboxSettings = MailboxSettingsService(self.client, self.prefix) + self.outlook = OutlookServicesCollection(self.client, self.prefix) + + +class OutlookServicesCollection(ServicesCollection): + """Wrap a collection of services grouped by 'outlook' context.""" + def __init__(self, client, prefix): + super().__init__(client, prefix + '/outlook') + self.masterCategories = MasterCategoriesService(self.client, self.prefix) class BaseFactory(object): @@ -272,9 +285,9 @@ def __call__(self, user_id): self.user_id = user_id if user_id == 'me': # special case for 'me' - return ServicesCollection(self.client, 'me') + return UserServicesCollection(self.client, 'me') else: - return ServicesCollection(self.client, 'users/' + user_id) + return UserServicesCollection(self.client, 'users/' + user_id) class UserService(BaseService): @@ -710,3 +723,35 @@ def get(self): method = 'get' resp = self.execute_request(method, path) return resp + + +class MasterCategoriesService(BaseService): + def list(self, max_entries=DEFAULT_MAX_ENTRIES): + path = '/masterCategories' + method = 'get' + query_params = {'$top': max_entries} + resp = self.execute_request(method, path, query_params=query_params) + next_link = resp.get('@odata.nextLink') + return resp, next_link + + def create(self, **kwargs): + path = '/masterCategories' + method = 'post' + body = json.dumps(kwargs) + return self.execute_request(method, path, body=body) + + def get(self, category_id): + path = '/masterCategories/' + category_id + method = 'get' + return self.execute_request(method, path) + + def update(self, category_id, **kwargs): + path = '/masterCategories/' + category_id + method = 'patch' + body = json.dumps(kwargs) + return self.execute_request(method, path, body=body) + + def delete(self, category_id): + path = '/masterCategories/' + category_id + method = 'delete' + return self.execute_request(method, path) diff --git a/setup.py b/setup.py index 6bad3ae..63b3fdb 100644 --- a/setup.py +++ b/setup.py @@ -2,8 +2,8 @@ from setuptools import find_packages, setup setup(name='office365-rest-client', - version='3.3.4', - description='Python api wrapper for Office365 API v3.3.4', + version='3.3.5', + description='Python api wrapper for Office365 API v3.3.5', author='SugarCRM', packages=find_packages(), install_requires=[