Work done to improve notifications
authorMarek Marecki <triviuss@gmail.com>
Sat, 8 Jun 2013 23:06:59 +0000 (01:06 +0200)
committerMarek Marecki <triviuss@gmail.com>
Sat, 8 Jun 2013 23:06:59 +0000 (01:06 +0200)
Makefile
diaspy/__init__.py
diaspy/models.py
diaspy/people.py
diaspy/streams.py
manual/contacts.mdown [new file with mode: 0644]
tests.py

index 34c92e12ae15637d5eb390161ef062b1ea2f700e..4bb76175aedb0414914e1b093eb5638a25833d56 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,5 +10,4 @@ test-python2:
        python2 -m unittest --verbose --catch --failfast tests.py
 
 clean:
-       rm -rv {*/,}__pycache__/
-       rm -rv {*/,}*.pyc
+       rm -rv {*,.}/__pycache__/
index ace13e20edf37b5086414d0fa8c12552d05ae515..172431a92f052ce29cd3f0bad715b738bb08577c 100644 (file)
@@ -3,3 +3,4 @@ import diaspy.conversations as conversations
 import diaspy.streams as streams
 import diaspy.client as client
 import diaspy.people as people
+import diaspy.notifications as notifications
index 5d3922695eeac539154be6302b3764f8cf856464..28a16d62839000bfe957fe987c0148a81fe53d15 100644 (file)
@@ -1,6 +1,47 @@
 #!/usr/bin/env python3
 
 
+class Aspect():
+    """This class represents an aspect.
+    """
+    def __init__(self, connection, id=-1):
+        self._connection = connection
+        self.id = id
+        self.name = ''
+
+    def addUser(self, user_id):
+        """Add user to current aspect.
+
+        :param user_id: user to add to aspect
+        :type user: int
+        """
+        data = {'authenticity_token': self._connection.get_token(),
+                'aspect_id': self.id,
+                'person_id': user_id}
+
+        request = self._connection.post('aspect_memberships.json', data=data)
+
+        if request.status_code != 201:
+            raise Exception('wrong status code: {0}'.format(request.status_code))
+        return request.json()
+
+    def removeUser(self, user_id):
+        """Remove user from current aspect.
+
+        :param user_id: user to remove from aspect
+        :type user: int
+        """
+        data = {'authenticity_token': self._connection.get_token(),
+                'aspect_id': self.id,
+                'person_id': user_id}
+
+        request = self.connection.delete('aspect_memberships/{0}.json'.format(self.id), data=data)
+
+        if request.status_code != 200:
+            raise Exception('wrong status code: {0}'.format(request.status_code))
+        return request.json()
+
+
 class Post():
     """This class represents a post.
 
@@ -136,62 +177,3 @@ class Post():
                                     headers={'accept': 'application/json'})
         if r.status_code != 204:
             raise Exception('{0}: Post could not be deleted'.format(r.status_code))
-
-
-class Aspect():
-    """This class represents an aspect.
-    """
-    def __init__(self, connection, id=-1):
-        self._connection = connection
-        self.id = id
-        self.name = ''
-
-    def addUser(self, user_id):
-        """Add user to current aspect.
-
-        :param user_id: user to add to aspect
-        :type user: int
-        """
-        data = {'authenticity_token': self._connection.get_token(),
-                'aspect_id': self.id,
-                'person_id': user_id}
-
-        request = self._connection.post('aspect_memberships.json', data=data)
-
-        if request.status_code != 201:
-            raise Exception('wrong status code: {0}'.format(request.status_code))
-        return request.json()
-
-    def removeUser(self, user_id):
-        """Remove user from current aspect.
-
-        :param user_id: user to remove from aspect
-        :type user: int
-        """
-        data = {'authenticity_token': self._connection.get_token(),
-                'aspect_id': self.id,
-                'person_id': user_id}
-
-        request = self.connection.delete('aspect_memberships/{0}.json'.format(self.id), data=data)
-
-        if request.status_code != 200:
-            raise Exception('wrong status code: {0}'.format(request.status_code))
-        return request.json()
-
-
-class Notifications():
-    """This class represents notifications of a user.
-    """
-    def __init__(self, connection):
-        self._connection = connection
-
-    def get(self):
-        """Returns list of notifications.
-        """
-        request = self._connection.get('notifications.json')
-        
-        if r.status_code != 200:
-            raise Exception('status code: {0}: cannot retreive notifications'.format(r.status_code))
-
-        notifications = request.json()
-        return notifications
index 79e2582e9436cdab7f6768b29b36ff1dca89a3a6..9377b48ac27c3459344ff4cc6b7af923bbbfcefe 100644 (file)
@@ -97,8 +97,7 @@ class Contacts():
         :param aspect_ids: list of aspect ids
         :type aspect_ids: list
         """
-        for aid in aspect_ids:
-            Aspect(self._connection, aid).addUser(user_id)
+        for aid in aspect_ids: Aspect(self._connection, aid).addUser(user_id)
 
     def remove(self, user_id, aspect_ids):
         """Remove user from aspects of given ids.
@@ -108,18 +107,19 @@ class Contacts():
         :param aspect_ids: list of aspect ids
         :type aspect_ids: list
         """
-        for aid in aspect_ids:
-            Aspect(self._connection, aid).removeUser(user_id)
+        for aid in aspect_ids: Aspect(self._connection, aid).removeUser(user_id)
 
     def get(self, set=''):
         """Returns list of user contacts.
         Contact is a User() who is in one or more of user's
         aspects.
 
-        By default, it will return list of users who are in logged
-        user aspects.
+        By default, it will return list of users who are in
+        user's aspects.
+
         If `set` is `all` it will also include users who only share
         with logged user and are not in his/hers aspects.
+
         If `set` is `only_sharing` it will return users who are only
         sharing with logged user and ARE NOT in his/hers aspects.
 
index 64d5c8487ff79ee1827beab1d281009b506d4b8d..e1cae151127066ebf383f400c985b89435b44fc7 100644 (file)
@@ -10,9 +10,8 @@ http://pad.spored.de/ro/r.qWmvhSZg7rk4OQam
 """
 
 
-class Generic:
-    """Object representing generic stream. Used in Tag(),
-    Stream(), Activity() etc.
+class Generic():
+    """Object representing generic stream.
     """
     _location = 'stream.json'
     _stream = []
@@ -348,3 +347,18 @@ class FollowedTags(Generic):
         if request.status_code not in [201, 403]:
             raise Exception('wrong error code: {0}'.format(request.status_code))
         return request.status_code
+
+class Tag(Generic):
+    """This stream contains all posts containing a tag.
+    """
+    def __init__(connection, tag):
+        """
+        :param connection: Connection() object
+        :type connection: diaspy.connection.Connection
+        :param tag: tag name
+        :type tag: str
+        """
+        self._connection = connection
+        self._location = 'tags/{0}'.format(tag)
+        self.fill()
diff --git a/manual/contacts.mdown b/manual/contacts.mdown
new file mode 100644 (file)
index 0000000..e69de29
index a136ee57d0cd990ce9404552c846016d2336f6c3..66a54eb047875aa40df9128a9bb458a78784db89 100644 (file)
--- a/tests.py
+++ b/tests.py
@@ -178,20 +178,20 @@ class UserTests(unittest.TestCase):
 class ContactsTest(unittest.TestCase):
     def testGetOnlySharing(self):
         contacts = diaspy.people.Contacts(test_connection)
-        only_sharing = contacts.get_only_sharing()
-        for i in only_sharing:
+        result = contacts.get(set='only_sharing')
+        for i in result:
             self.assertEqual(diaspy.people.User, type(i))
 
     def testGetAll(self):
         contacts = diaspy.people.Contacts(test_connection)
-        only_sharing = contacts.get_all()
-        for i in only_sharing:
+        result = contacts.get(set='all')
+        for i in result:
             self.assertEqual(diaspy.people.User, type(i))
 
     def testGet(self):
         contacts = diaspy.people.Contacts(test_connection)
-        only_sharing = contacts.get()
-        for i in only_sharing:
+        result = contacts.get()
+        for i in result:
             self.assertEqual(diaspy.people.User, type(i))