Merge branch 'master' of https://github.com/Javafant/diaspora-api into contacts
[diaspy.git] / diaspy / client.py
index 1db18f98fadc98bafcf5db8ef0b06215f21703b8..ce07990a70cf33be9fbcfaf94e89de21b47d9a44 100644 (file)
@@ -1,6 +1,7 @@
 import diaspy.models
 import diaspy.streams
 import diaspy.connection
+from diaspy import notifications
 
 
 class Client:
@@ -10,7 +11,7 @@ class Client:
     def __init__(self, pod, username='', password=''):
         """
         `pod` can also be a diaspy.connection.Connection type and
-        Client() will detect it. When giving a connection there is no need 
+        Client() will detect it. When giving a connection there is no need
         to pass username and password.
 
         :param pod: The complete url of the diaspora pod to use
@@ -28,34 +29,26 @@ class Client:
             self.connection.login()
         self.stream = diaspy.streams.Stream(self.connection, 'stream.json')
 
-    def post(self, text, aspect_ids='public', photos=None):
+    def post(self, text, aspect_ids='public', photos=None, photo=''):
         """This function sends a post to an aspect
 
-        :param text: Text to post.
+        :param text: text to post
         :type text: str
         :param aspect_ids: Aspect ids to send post to.
         :type aspect_ids: str
-
+        :param photo: path to picture file
+        :type photo: str
         :returns: diaspy.models.Post -- the Post which has been created
         """
-        post = self.stream.post(text, aspect_ids, photos)
+        post = self.stream.post(text, aspect_ids, photos, photo)
         return post
 
-    def post_picture(self, filename):
-        """This method posts a picture to D*.
-
-        :param filename: Path to picture file.
-        :type filename: str
-        """
-        return self.stream.post_picture(filename)
-
     def get_activity(self):
         """This function returns activity stream.
 
         :returns: diaspy.streams.Activity
         """
-        activity = diaspy.streams.Activity(self.connection, 'activity.json')
-        return activity
+        return diaspy.streams.Activity(self.connection, 'activity.json')
 
     def get_stream(self):
         """This functions returns stream.
@@ -100,13 +93,7 @@ class Client:
 
         :returns: list -- list of json formatted notifications
         """
-        r = self.connection.get('notifications.json')
-
-        if r.status_code != 200:
-            raise Exception('wrong status code: {0}'.format(r.status_code))
-
-        notifications = r.json()
-        return notifications
+        return notifications.Notifications(self.connection)
 
     def get_mailbox(self):
         """This functions returns a list of messages found in the conversation.