Skip to content

Commit

Permalink
CSC-6074 Add MasterCategoriesService
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsukov-sugarcrm authored and smihaylishin-sugarcrm committed Nov 7, 2024
1 parent 543156e commit 10835b5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
53 changes: 49 additions & 4 deletions office365_api/v2/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down

0 comments on commit 10835b5

Please sign in to comment.