Fixes #19
authorMarek Marecki <marekjm@ozro.pw>
Sun, 23 Apr 2017 14:43:17 +0000 (16:43 +0200)
committerMarek Marecki <marekjm@ozro.pw>
Sun, 23 Apr 2017 14:43:17 +0000 (16:43 +0200)
diaspy/notifications.py

index 8393c7585a8e8362898d8c5c11d0da5ae3fb2bc2..983ea2bc3bd068977821fa8e1d737806cbd8f5cc 100644 (file)
@@ -24,6 +24,11 @@ class Notifications():
     def __getitem__(self, n):
         return self._notifications[n]
 
+    def _finalise(self, notifications):
+        self._data['unread_count'] = notifications['unread_count']
+        self._data['unread_count_by_type'] = notifications['unread_count_by_type']
+        return [Notification(self._connection, n) for n in notifications.get('notification_list', [])]
+
     def last(self):
         """Returns list of most recent notifications.
         """
@@ -34,7 +39,7 @@ class Notifications():
 
         if request.status_code != 200:
             raise Exception('status code: {0}: cannot retreive notifications'.format(request.status_code))
-        return [Notification(self._connection, n) for n in request.json()]
+        return self._finalise(request.json())
 
     def get(self, per_page=5, page=1):
         """Returns list of notifications.
@@ -46,8 +51,4 @@ class Notifications():
 
         if request.status_code != 200:
             raise Exception('status code: {0}: cannot retreive notifications'.format(request.status_code))
-
-        notifications = request.json()
-        self._data['unread_count'] = notifications['unread_count']
-        self._data['unread_count_by_type'] = notifications['unread_count_by_type']
-        return [Notification(self._connection, n) for n in notifications.get('notification_list', [])]
+        return self._finalise(request.json())