From: Baŝto Date: Fri, 1 Mar 2013 21:22:41 +0000 (+0100) Subject: the rest: create new conversations and get a list of existing conversations X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=91d2d5dc21d280212d83f217bc6e7bd0d4e1152a;p=diaspy.git the rest: create new conversations and get a list of existing conversations --- diff --git a/diaspy/__init__.py b/diaspy/__init__.py index f10e231..fd6b6ab 100644 --- a/diaspy/__init__.py +++ b/diaspy/__init__.py @@ -1,2 +1,3 @@ import diaspy.client import diaspy.models +import diaspy.conversations \ No newline at end of file diff --git a/diaspy/client.py b/diaspy/client.py index 3d3ea26..7d1678d 100644 --- a/diaspy/client.py +++ b/diaspy/client.py @@ -268,3 +268,54 @@ class Client: if r.status_code != 404: raise Exception('wrong status code: ' + str(r.status_code)) + + + def get_mailbox(self): + """This functions returns a list of messages found in the conversation. + + :returns: list -- list of Conversation objects. + + """ + + data = {'authenticity_token': self.get_token()} + r = self.session.get(self.pod + "/conversations.json") + + if r.status_code != 200: + raise Exception('wrong status code: ' + str(r.status_code)) + + mailbox = r.json() + + conversations = [] + + for conversation in mailbox: + conversations.append(diaspy.conversations.Conversation(str(conversation['conversation']['id']), self)) + + return conversations + + def new_conversation(self, contacts, subject, text): + """ start a new conversation + + :param contacts: recipients ids, no guids, comma sperated. + :type contacts: str + :param subject: subject of the message. + :type subject: str + :param text: text of the message. + :type text: str + + """ + + data = {'contact_ids': contacts, + 'conversation[subject]': subject, + 'conversation[text]': text, + 'utf8': '✓', + 'authenticity_token': self.get_token()} + + r = self.session.post(self.pod + + '/conversations/', + data=data, + headers={'accept': 'application/json'}) + if r.status_code != 200: + raise Exception(str(r.status_code) + + ': Conversation could not be started.') + + return r.json() diff --git a/diaspy/models.py b/diaspy/models.py index b83de71..572c288 100644 --- a/diaspy/models.py +++ b/diaspy/models.py @@ -99,8 +99,6 @@ class Post: def comment(self, text): """This function comments on a post - :param post_id: id of the post to comment on. - :type post_id: str :param text: text to comment. :type text: str @@ -125,10 +123,8 @@ class Post: def delete_comment(self, comment_id): """This function removes a comment from a post - :param post_id: id of the post to remove the like from. - :type post_id: str - :param like_id: id of the like to remove. - :type like_id: str + :param comment_id: id of the comment to remove. + :type comment_id: str """