Fixed some bugs in streams
authorMarek Marecki <marekjm@taistelu.com>
Sat, 10 Aug 2013 09:27:47 +0000 (11:27 +0200)
committerMarek Marecki <marekjm@taistelu.com>
Sat, 10 Aug 2013 09:27:47 +0000 (11:27 +0200)
diaspy/streams.py
setup.py

index 6da1d828c17782ba19d2edb0969873fa8114aebd..36ff2362fc58c909349bccb45ebcb6bba8e8b152 100644 (file)
@@ -55,7 +55,9 @@ class Generic():
         """Obtains stream from pod.
         """
         params = {}
-        if max_time: params['max_time'] = max_time
+        if max_time:
+            params['max_time'] = max_time
+            params['_'] = self.max_time
         request = self._connection.get(self._location, params=params)
         if request.status_code != 200:
             raise errors.StreamError('wrong status code: {0}'.format(request.status_code))
@@ -64,12 +66,12 @@ class Generic():
     def _expand(self, new_stream):
         """Appends older posts to stream.
         """
-        ids = [post.post_id for post in self._stream]
+        ids = [post.id for post in self._stream]
         stream = self._stream
         for post in new_stream:
-            if post.post_id not in ids:
+            if post.id not in ids:
                 stream.append(post)
-                ids.append(post.post_id)
+                ids.append(post.id)
         self._stream = stream
 
     def _update(self, new_stream):
@@ -125,17 +127,24 @@ class Generic():
         new_stream = self._obtain(max_time=max_time)
         self._expand(new_stream)
 
+    def copy(self):
+        """Returns copy (list of posts) of current stream.
+        """
+        return [p for p in self._stream]
+
 
 class Outer(Generic):
     """Object used by diaspy.models.User to represent
     stream of other user.
     """
-    def _obtain(self):
-        """Obtains stream of other user.
+    def _obtain(self, max_time=0):
+        """Obtains stream from pod.
         """
-        request = self._connection.get(self._location)
+        params = {}
+        if max_time: params['max_time'] = max_time
+        request = self._connection.get(self._location, params=params)
         if request.status_code != 200:
-            raise error.StreamError('wrong status code: {0}'.format(request.status_code))
+            raise errors.StreamError('wrong status code: {0}'.format(request.status_code))
         return [Post(self._connection, post['id']) for post in request.json()]
 
 
index e09a7097de9055ff19b54046c4df90262e8b2652..663a1b2872d9190ca09bdf764764ac9702dc432e 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
 from setuptools import setup, find_packages
 setup(name='diaspy',
-      version='0.3.0',
+      version='0.3.1',
       author='Moritz Kiefer',
       author_email='moritz.kiefer@gmail.com',
       url='https://github.com/Javafant/diaspora-api',