Add functions to add and remove users to/from aspects
authorMoritz Kiefer <moritz.kiefer@gmail.com>
Sat, 2 Feb 2013 22:32:12 +0000 (23:32 +0100)
committerMoritz Kiefer <moritz.kiefer@gmail.com>
Sat, 2 Feb 2013 22:32:12 +0000 (23:32 +0100)
diaspy/client.py
diaspy/models.py

index 7a8fa73f6c3cbc3c5686cb76e47a16d5bea1138b..8aa7e0cf5c46da53e13a3444b136333537f79a1d 100644 (file)
@@ -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()
index 20001cee59f7fb6a90bb8606d53afaeb02d424ed..44f2762f6efacd736cdd1ab7e6b54c6326e2ad9c 100644 (file)
@@ -157,5 +157,3 @@ class Post:
                                         self.post_id,
                                         data=data,
                                         headers={'accept': 'application/json'})
-
-        return r