Add functions to add and remove aspects
authorMoritz Kiefer <moritz.kiefer@gmail.com>
Sat, 2 Feb 2013 23:01:10 +0000 (00:01 +0100)
committerMoritz Kiefer <moritz.kiefer@gmail.com>
Sat, 2 Feb 2013 23:01:10 +0000 (00:01 +0100)
diaspy/client.py

index 8aa7e0cf5c46da53e13a3444b136333537f79a1d..70af42ffcf189d34fcf2e2fe2146a7e3734297c5 100644 (file)
@@ -221,3 +221,29 @@ class Client:
             raise Exception('wrong status code: ' + str(r.status_code))
 
         return r.json()
+
+    def add_aspect(self, aspect_name, visible=0):
+        """ This function adds a new aspect.
+        """
+
+        data = {'authenticity_token': self.get_token(),
+                'aspect[name]': aspect_name,
+                'aspect[contacts_visible]': visible}
+
+        r = self.session.post(self.pod + '/aspects',
+                              data=data)
+
+        if r.status_code != 200:
+            raise Exception('wrong status code: ' + str(r.status_code))
+
+    def remove_aspect(self, aspect_id):
+        """ This function adds a new aspect.
+        """
+
+        data = {'authenticity_token': self.get_token()}
+
+        r = self.session.delete(self.pod + '/aspects/' + aspect_id,
+                              data=data}
+
+        if r.status_code != 404:
+            raise Exception('wrong status code: ' + str(r.status_code))