diff --git a/tweepy/api.py b/tweepy/api.py index 74188093d..daacbfe9e 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -675,6 +675,33 @@ def test(self): allowed_param = ['lat', 'long', 'name', 'contained_within'] ) + """ site stream info """ + stream_info = bind_api( + path = '{stream_id}/info.json', + payload_type = 'json', + require_auth = True, + allowed_param = ['stream_id'] + ) + + """ site stream add user """ + add_users = bind_api( + path = '{stream_id}/add_user.json', + payload_type = None, + require_auth = True, + method = 'POST', + allowed_param = ['stream_id','user_id'] + ) + + """ site stream remove user """ + remove_users = bind_api( + path = '{stream_id}/remove_user.json', + payload_type = None, + require_auth = True, + method = 'POST', + allowed_param = ['stream_id','user_id'] + ) + + """ Internal use only """ @staticmethod def _pack_image(filename, max_size): diff --git a/tweepy/streaming.py b/tweepy/streaming.py index f6d37f450..98e865a0d 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -84,6 +84,7 @@ def __init__(self, auth, listener, **options): self.retry_time = options.get("retry_time", 10.0) self.snooze_time = options.get("snooze_time", 5.0) self.buffer_size = options.get("buffer_size", 1500) + self.method = 'POST' if options.get("secure", True): self.scheme = "https" else: @@ -111,10 +112,10 @@ def _run(self): conn = httplib.HTTPConnection(self.host) else: conn = httplib.HTTPSConnection(self.host) - self.auth.apply_auth(url, 'POST', self.headers, self.parameters) + self.auth.apply_auth(url, self.method, self.headers, self.parameters) conn.connect() conn.sock.settimeout(self.timeout) - conn.request('POST', self.url, self.body, headers=self.headers) + conn.request(self.method, self.url, self.body, headers=self.headers) resp = conn.getresponse() if resp.status != 200: if self.listener.on_error(resp.status) is False: @@ -210,6 +211,7 @@ def retweet(self, async=False): def sample(self, count=None, async=False): self.parameters = {'delimited': 'length'} + self.method = 'GET' if self.running: raise TweepError('Stream object already connected!') self.url = '/%s/statuses/sample.json?delimited=length' % STREAM_VERSION @@ -246,3 +248,21 @@ def disconnect(self): return self.running = False + def follow(self, follow, async=False): + if self.running: + raise TweepError('Stream object already connected!') + + self.scheme = "https" + self.parameters = {} + self.headers['Content-type'] = "application/x-www-form-urlencoded" + self.host = 'sitestream.twitter.com' + self.url = '/%s/site.json?delimited=length' % STREAM_VERSION + + if follow: + self.parameters['follow'] = ','.join(map(str, follow)) + + self.body = urlencode_noplus(self.parameters) + self.parameters['delimited'] = 'length' + self._start(async) + +