----
-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,
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
+++ /dev/null
-#!/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': '✓',
- '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']
--- /dev/null
+#!/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]
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': '✓',
+ '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.
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):