def list_all_my_groups(self, group_name_filter=None, **kwargs): """ Retrieve all my groups, paging through the results until exhausted :param group_name_filter: only returns groups whose names contain filter string :return: the content of the response """ groups = [] args = [] if group_name_filter: args.append(u'groupNameFilter={0}'.format(group_name_filter)) url = urljoin(self.index_url, u'/groups') + u'?' + u'&'.join(args) response, data = self.__make_request(url, u'GET', self.headers, **kwargs) groups.extend(data[u'groups']) while u'nextId' in data and data[u'nextId']: next_args = args[:] next_args.append(u'startFrom={0}'.format(data['nextId'])) url = urljoin(self.index_url, u'/groups') + u'?' + u'&'.join(next_args) response, data = self.__make_request(url, u'GET', self.headers, **kwargs) groups.extend(data[u'groups']) g = [Group.from_dict(elem) for elem in groups] return ListGroupsResponse(groups=g, group_name_filter=group_name_filter)
def update_group(self, group, **kwargs): """ Update an existing group, uses the id of the group provided :param group: A group to be updated :return: the content of the response, which should be a group json """ url = urljoin(self.index_url, u'/groups/{0}'.format(group.id)) response, data = self.__make_request(url, u'PUT', self.headers, to_json_string(group), **kwargs) return Group.from_dict(data)
def get_group(self, group_id, **kwargs): """ Get a group. :param group_id: Id of the group to get :return: the group json """ url = urljoin(self.index_url, u'/groups/' + group_id) response, data = self.__make_request(url, u'GET', self.headers, **kwargs) return Group.from_dict(data) if data is not None else None
def delete_group(self, group_id, **kwargs): """ Delete a group. :param group_id: Id of the group to delete :return: the group json """ url = urljoin(self.index_url, u'/groups/' + group_id) response, data = self.__make_request(url, u'DELETE', self.headers, **kwargs) return Group.from_dict(data)
def create_group(self, group, **kwargs): """ Create a new group. :param group: A group dictionary that can be serialized to json :return: the content of the response, which should be a group json """ url = urljoin(self.index_url, u'/groups') response, data = self.__make_request(url, u'POST', self.headers, to_json_string(group), **kwargs) return Group.from_dict(data)