Added sitestream endpoint
authorAaron Hill <aa1ronham@gmail.com>
Tue, 20 Aug 2013 10:25:37 +0000 (06:25 -0400)
committerAaron Hill <aa1ronham@gmail.com>
Sat, 21 Dec 2013 03:08:20 +0000 (22:08 -0500)
tests/test_streaming.py
tweepy/streaming.py

index fdeb2c929af6d522a8610eb23223e9f7fc94e72a..f796417d32353122adbdac0ba5744af26bf6ab7b 100644 (file)
@@ -45,15 +45,23 @@ class TweepyStreamTests(unittest.TestCase):
     def tearDown(self):
         self.stream.disconnect()
 
+    def on_connect():
+        API(self.auth).update_status(mock_tweet())
+
+
     def test_userstream(self):
         # Generate random tweet which should show up in the stream.
-        def on_connect():
-            API(self.auth).update_status(mock_tweet())
-
-        self.listener.connect_cb = on_connect
+        
+        self.listener.connect_cb = self.on_connect
         self.listener.status_stop_count = 1
         self.stream.userstream()
         self.assertEqual(self.listener.status_count, 1)
+    
+    def test_sitestream(self):
+        self.listener.connect_cb = self.on_connect
+        self.listener.status_stop_count = 1
+        self.sitestream(follow=[self.auth.get_username()])
+        self.assertEqual(self.listener.status_count, 1)
 
     def test_sample(self):
         self.listener.status_stop_count = 10
index cd6bffb95b3a586271fbadce4fe69d141b7f277f..6f9a5067d56ff9efa2062576714ec4e48fb2137f 100644 (file)
@@ -296,6 +296,22 @@ class Stream(object):
         self.parameters['delimited'] = 'length'
         self._start(async)
 
+    def sitestream(self, follow, stall_warnings=False, with_='user', replies=False, async=False):
+        self.parameters = {}
+        if self.running:
+            raise TweepError('Stream object already connected!')
+        self.url = '/%s/site.json' % STREAM_VERSION
+        self.parameters['follow'] = ','.join(map(str, follow))
+        self.parameters['delimited'] = 'length'
+        if stall_warnings:
+            self.parameters['stall_warnings'] = stall_warnings
+        if with_:
+            self.parameters['with'] = with_
+        if replies:
+            self.parameters['replies'] = replies
+        self.body = urlencode_noplus(self.parameters)
+        self._start(async)
+
     def disconnect(self):
         if self.running is False:
             return