From 5c2b6162f5e8df4b4593493c8da03a19d72b9f3d Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Sat, 2 Feb 2013 23:32:12 +0100 Subject: [PATCH] Add functions to add and remove users to/from aspects --- diaspy/client.py | 43 +++++++++++++++++++++++++++++++++++++++++++ diaspy/models.py | 2 -- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/diaspy/client.py b/diaspy/client.py index 7a8fa73..8aa7e0c 100644 --- a/diaspy/client.py +++ b/diaspy/client.py @@ -178,3 +178,46 @@ class Client: posts.append(diaspy.models.Post(str(post['id']), self)) return posts + + def add_user_to_aspect(self, user_id, aspect_id): + """ this function adds a user to an aspect. + + :param user_id: User ID + :type user_id: str + :param aspect_id: Aspect ID + :type aspect_id: str + + """ + + data = {'authenticity_token': self.get_token(), + 'aspect_id': aspect_id, + 'person_id': user_id} + + r = self.session.post(self.pod + '/aspect_memberships.json', + data=data) + + if r.status_code != 201: + raise Exception('wrong status code: ' + str(r.status_code)) + return r.json() + + def remove_user_from_aspect(self, user_id, aspect_id): + """ this function removes a user from an aspect. + + :param user_id: User ID + :type user_id: str + :param aspect_id: Aspect ID + :type aspect_id: str + + """ + + data = {'authenticity_token': self.get_token(), + 'aspect_id': aspect_id, + 'person_id': user_id} + + r = self.session.delete(self.pod + '/aspect_memberships/42.json', + data=data) + + if r.status_code != 200: + raise Exception('wrong status code: ' + str(r.status_code)) + + return r.json() diff --git a/diaspy/models.py b/diaspy/models.py index 20001ce..44f2762 100644 --- a/diaspy/models.py +++ b/diaspy/models.py @@ -157,5 +157,3 @@ class Post: self.post_id, data=data, headers={'accept': 'application/json'}) - - return r -- 2.25.1