See changes in Changelog
authorMarek Marecki <marekjm@taistelu.com>
Tue, 20 Aug 2013 12:33:52 +0000 (14:33 +0200)
committerMarek Marecki <marekjm@taistelu.com>
Tue, 20 Aug 2013 12:33:52 +0000 (14:33 +0200)
Changelog.markdown
diaspy/__init__.py
diaspy/conversations.py [deleted file]
diaspy/messages.py [new file with mode: 0644]
diaspy/models.py
tests.py

index edf3c1ce5f65eba7d1167d2b9f71582646bf8afd..92eb64353e0a892cbed6cd6f4783fe9974f51c22 100644 (file)
@@ -21,7 +21,21 @@ up-to-date than manual and if conflicts appear they should follow the order:
 
 ----
 
-Version `0.3.2` (2013-08-):
+#### Version `0.4.0` (2013-08-20):
+
+This release is **not backwards compatible with `0.3.x` line**! You'll have to check your code for corrections.
+Also, this release if first to officially released fork version.
+
+* __dep__:  `diaspy.client` is officially deprecated (will be removed in `0.4.1`),
+
+* __upd__:  `diaspy.conversations` renamed to `diaspy.messages`,
+* __udp__:  `diaspy.conversations.Conversation` moved to `diaspy.models`,
+
+* __new__:  `diaspy.messages.Mailbox()` object representing diaspora\* mailbox,
+
+----
+
+Version `0.3.2` (2013-08-20):
 
 * __upd__:  `diaspy.connection.getUserData()` raises `DiaspyError` when it cannot find user data,
 
index b6f722ad69e9315b554c5937a808900fc04fd3a7..1a7d7c460e2422a061fdaafe17b257ede2dac7df 100644 (file)
@@ -1,7 +1,7 @@
 import diaspy.connection as connection
 import diaspy.models as models
 import diaspy.streams as streams
-import diaspy.conversations as conversations
+import diaspy.messages as messages
 import diaspy.people as people
 import diaspy.notifications as notifications
 import diaspy.settings as settings
diff --git a/diaspy/conversations.py b/diaspy/conversations.py
deleted file mode 100644 (file)
index 0351106..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-#!/usr/bin/env python3
-
-
-from diaspy import errors
-
-
-class Conversation():
-    """This class represents a conversation.
-
-    .. note::
-        Remember that you need to have access to the conversation.
-    """
-    def __init__(self, connection, id, fetch=True):
-        """
-        :param conv_id: id of the post and not the guid!
-        :type conv_id: str
-        :param connection: connection object used to authenticate
-        :type connection: connection.Connection
-        """
-        self._connection = connection
-        self.id = id
-        self.data = {}
-        if fetch: self._fetch()
-
-    def _fetch(self):
-        """Fetches JSON data representing conversation.
-        """
-        request = self._connection.get('conversations/{}.json'.format(self.id))
-        if request.status_code == 200:
-            self.data = request.json()['conversation']
-        else:
-            raise errors.ConversationError('cannot download conversation data: {0}'.format(request.status_code))
-
-    def answer(self, text):
-        """Answer that conversation
-
-        :param text: text to answer.
-        :type text: str
-        """
-        data = {'message[text]': text,
-                'utf8': '&#x2713;',
-                'authenticity_token': repr(self._connection)}
-
-        request = self._connection.post('conversations/{}/messages'.format(self.id),
-                                        data=data,
-                                        headers={'accept': 'application/json'})
-        if request.status_code != 200:
-            raise errors.ConversationError('{0}: Answer could not be posted.'
-                            .format(request.status_code))
-        return request.json()
-
-    def delete(self):
-        """Delete this conversation.
-        Has to be implemented.
-        """
-        data = {'authenticity_token': repr(self._connection)}
-
-        request = self._connection.delete('conversations/{0}/visibility/'
-                                    .format(self.id),
-                                    data=data,
-                                    headers={'accept': 'application/json'})
-
-        if request.status_code != 404:
-            raise errors.ConversationError('{0}: Conversation could not be deleted.'
-                            .format(request.status_code))
-
-    def get_subject(self):
-        """Returns the subject of this conversation
-        """
-        return self.data['subject']
diff --git a/diaspy/messages.py b/diaspy/messages.py
new file mode 100644 (file)
index 0000000..a81afca
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+
+
+from diaspy import errors, models
+
+
+class Mailbox():
+    """Object implementing diaspora* mailbox.
+    """
+    def __init__(self, connection, fetch=True):
+        self._connection = connection
+        self._mailbox = []
+        if fetch: self._fetch()
+
+    def __len__(self):
+        return len(self._mailbox)
+
+    def __iter__(self):
+        return iter(self._mailbox)
+
+    def __getitem__(self, n):
+        return self._mailbox[n]
+
+    def _fetch(self):
+        """This method will fetch messages from user's mailbox.
+        """
+        request = self._connection.get('conversations.json')
+
+        if request.status_code != 200:
+            raise errors.DiaspyError('wrong status code: {0}'.format(r.status_code))
+        mailbox = request.json()
+        self._mailbox = [models.Conversation(self._connection, c['conversation']['id']) for c in mailbox]
index 1d0156f06c469c82287371b54151961b492d276c..9df0ae752204d93e59ce07dd73f10b2fc6e41993 100644 (file)
@@ -209,6 +209,72 @@ class Notification():
         self.data['unread'] = unread
 
 
+class Conversation():
+    """This class represents a conversation.
+
+    .. note::
+        Remember that you need to have access to the conversation.
+    """
+    def __init__(self, connection, id, fetch=True):
+        """
+        :param conv_id: id of the post and not the guid!
+        :type conv_id: str
+        :param connection: connection object used to authenticate
+        :type connection: connection.Connection
+        """
+        self._connection = connection
+        self.id = id
+        self.data = {}
+        if fetch: self._fetch()
+
+    def _fetch(self):
+        """Fetches JSON data representing conversation.
+        """
+        request = self._connection.get('conversations/{}.json'.format(self.id))
+        if request.status_code == 200:
+            self.data = request.json()['conversation']
+        else:
+            raise errors.ConversationError('cannot download conversation data: {0}'.format(request.status_code))
+
+    def answer(self, text):
+        """Answer that conversation
+
+        :param text: text to answer.
+        :type text: str
+        """
+        data = {'message[text]': text,
+                'utf8': '&#x2713;',
+                'authenticity_token': repr(self._connection)}
+
+        request = self._connection.post('conversations/{}/messages'.format(self.id),
+                                        data=data,
+                                        headers={'accept': 'application/json'})
+        if request.status_code != 200:
+            raise errors.ConversationError('{0}: Answer could not be posted.'
+                            .format(request.status_code))
+        return request.json()
+
+    def delete(self):
+        """Delete this conversation.
+        Has to be implemented.
+        """
+        data = {'authenticity_token': repr(self._connection)}
+
+        request = self._connection.delete('conversations/{0}/visibility/'
+                                    .format(self.id),
+                                    data=data,
+                                    headers={'accept': 'application/json'})
+
+        if request.status_code != 404:
+            raise errors.ConversationError('{0}: Conversation could not be deleted.'
+                            .format(request.status_code))
+
+    def get_subject(self):
+        """Returns the subject of this conversation
+        """
+        return self.data['subject']
+
+
 class Comment():
     """Represents comment on post.
     
index 5e0adfa06c444d0972846c03d18167d849ad45a7..83c9e39cf2d76b3f1416e034b69b343f57fe8f34 100644 (file)
--- a/tests.py
+++ b/tests.py
@@ -60,18 +60,12 @@ class ConnectionTest(unittest.TestCase):
         self.assertEqual(dict, type(info))
 
 
-class ClientTests(unittest.TestCase):
-    def testGettingTag(self):
-        client = dclient.Client(test_connection)
-        tag = client.get_tag('foo')
-        self.assertEqual(diaspy.streams.Generic, type(tag))
-        if tag: self.assertEqual(diaspy.models.Post, type(tag[0]))
-
+class MessagesTests(unittest.TestCase):
     def testGettingMailbox(self):
-        client = dclient.Client(test_connection)
-        mailbox = client.get_mailbox()
-        self.assertEqual(list, type(mailbox))
-        self.assertEqual(diaspy.conversations.Conversation, type(mailbox[0]))
+        mailbox = diaspy.messages.Mailbox(test_connection)
+        if mailbox: 
+            for i in range(len(mailbox)):
+                self.assertEqual(diaspy.models.Conversation, type(mailbox[i]))
 
 
 class StreamTest(unittest.TestCase):