From cea0852a42200553a8dc5d04db7c7ab919d49475 Mon Sep 17 00:00:00 2001 From: Mike Helmick Date: Fri, 3 May 2013 17:33:17 -0400 Subject: [PATCH] Updating file structure and HISTORY.rst --- HISTORY.rst | 4 +- twython/streaming/__init__.py | 1 + twython/{streaming.py => streaming/api.py} | 86 ++-------------------- twython/streaming/types.py | 71 ++++++++++++++++++ 4 files changed, 81 insertions(+), 81 deletions(-) create mode 100644 twython/streaming/__init__.py rename twython/{streaming.py => streaming/api.py} (66%) create mode 100644 twython/streaming/types.py diff --git a/HISTORY.rst b/HISTORY.rst index 3a2853c..a0df760 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,10 +1,10 @@ History ------- -2.9.0 (2013-05-xx) +2.9.0 (2013-05-04) ++++++++++++++++++ -- Fixed streaming issue #144, added ``TwythonStreamer`` and ``TwythonStreamHandler`` to aid users in a friendly streaming experience +- Fixed streaming issue #144, added ``TwythonStreamer`` to aid users in a friendly streaming experience (streaming examples in ``examples`` and README's have been updated as well) 2.8.0 (2013-04-29) ++++++++++++++++++ diff --git a/twython/streaming/__init__.py b/twython/streaming/__init__.py new file mode 100644 index 0000000..b12e8d1 --- /dev/null +++ b/twython/streaming/__init__.py @@ -0,0 +1 @@ +from .api import TwythonStreamer diff --git a/twython/streaming.py b/twython/streaming/api.py similarity index 66% rename from twython/streaming.py rename to twython/streaming/api.py index 2c04cd3..541aa07 100644 --- a/twython/streaming.py +++ b/twython/streaming/api.py @@ -1,6 +1,7 @@ -from . import __version__ -from .compat import json -from .exceptions import TwythonStreamError +from .. import __version__ +from ..compat import json +from ..exceptions import TwythonStreamError +from .types import TwythonStreamerTypes import requests from requests_oauthlib import OAuth1 @@ -8,79 +9,6 @@ from requests_oauthlib import OAuth1 import time -class TwythonStreamStatuses(object): - """Class for different statuses endpoints - - Available so TwythonStreamer.statuses.filter() is available. - Just a bit cleaner than TwythonStreamer.statuses_filter(), - statuses_sample(), etc. all being single methods in TwythonStreamer - """ - def __init__(self, streamer): - self.streamer = streamer - - def filter(self, **params): - """Stream statuses/filter - - Accepted params found at: - https://dev.twitter.com/docs/api/1.1/post/statuses/filter - """ - url = 'https://stream.twitter.com/%s/statuses/filter.json' \ - % self.streamer.api_version - self.streamer._request(url, 'POST', params=params) - - def sample(self, **params): - """Stream statuses/sample - - Accepted params found at: - https://dev.twitter.com/docs/api/1.1/get/statuses/sample - """ - url = 'https://stream.twitter.com/%s/statuses/sample.json' \ - % self.streamer.api_version - self.streamer._request(url, params=params) - - def firehose(self, **params): - """Stream statuses/filter - - Accepted params found at: - https://dev.twitter.com/docs/api/1.1/get/statuses/firehose - """ - url = 'https://stream.twitter.com/%s/statuses/firehose.json' \ - % self.streamer.api_version - self.streamer._request(url, params=params) - - -class TwythonStreamTypes(object): - """Class for different stream endpoints - - Not all streaming endpoints have nested endpoints. - User Streams and Site Streams are single streams with no nested endpoints - Status Streams include filter, sample and firehose endpoints - """ - def __init__(self, streamer): - self.streamer = streamer - self.statuses = TwythonStreamStatuses(streamer) - - def user(self, **params): - """Stream user - - Accepted params found at: - https://dev.twitter.com/docs/api/1.1/get/user - """ - url = 'https://userstream.twitter.com/%s/user.json' \ - % self.streamer.api_version - self.streamer._request(url, params=params) - - def site(self, **params): - """Stream site - - Accepted params found at: - https://dev.twitter.com/docs/api/1.1/get/site - """ - url = 'https://sitestream.twitter.com/%s/site.json' \ - % self.streamer.api_version - self.streamer._request(url, params=params) - - class TwythonStreamer(object): def __init__(self, app_key, app_secret, oauth_token, oauth_token_secret, timeout=300, retry_count=None, retry_in=10, headers=None): @@ -122,10 +50,10 @@ class TwythonStreamer(object): self.retry_count = retry_count # Set up type methods - StreamTypes = TwythonStreamTypes(self) + StreamTypes = TwythonStreamerTypes(self) self.statuses = StreamTypes.statuses - self.__dict__['user'] = StreamTypes.user - self.__dict__['site'] = StreamTypes.site + self.user = StreamTypes.user + self.site = StreamTypes.site def _request(self, url, method='GET', params=None): """Internal stream request handling""" diff --git a/twython/streaming/types.py b/twython/streaming/types.py new file mode 100644 index 0000000..fd02f81 --- /dev/null +++ b/twython/streaming/types.py @@ -0,0 +1,71 @@ +class TwythonStreamerTypes(object): + """Class for different stream endpoints + + Not all streaming endpoints have nested endpoints. + User Streams and Site Streams are single streams with no nested endpoints + Status Streams include filter, sample and firehose endpoints + """ + def __init__(self, streamer): + self.streamer = streamer + self.statuses = TwythonStreamerTypesStatuses(streamer) + + def user(self, **params): + """Stream user + + Accepted params found at: + https://dev.twitter.com/docs/api/1.1/get/user + """ + url = 'https://userstream.twitter.com/%s/user.json' \ + % self.streamer.api_version + self.streamer._request(url, params=params) + + def site(self, **params): + """Stream site + + Accepted params found at: + https://dev.twitter.com/docs/api/1.1/get/site + """ + url = 'https://sitestream.twitter.com/%s/site.json' \ + % self.streamer.api_version + self.streamer._request(url, params=params) + + +class TwythonStreamerTypesStatuses(object): + """Class for different statuses endpoints + + Available so TwythonStreamer.statuses.filter() is available. + Just a bit cleaner than TwythonStreamer.statuses_filter(), + statuses_sample(), etc. all being single methods in TwythonStreamer + """ + def __init__(self, streamer): + self.streamer = streamer + + def filter(self, **params): + """Stream statuses/filter + + Accepted params found at: + https://dev.twitter.com/docs/api/1.1/post/statuses/filter + """ + url = 'https://stream.twitter.com/%s/statuses/filter.json' \ + % self.streamer.api_version + self.streamer._request(url, 'POST', params=params) + + def sample(self, **params): + """Stream statuses/sample + + Accepted params found at: + https://dev.twitter.com/docs/api/1.1/get/statuses/sample + """ + url = 'https://stream.twitter.com/%s/statuses/sample.json' \ + % self.streamer.api_version + self.streamer._request(url, params=params) + + def firehose(self, **params): + """Stream statuses/filter + + Accepted params found at: + https://dev.twitter.com/docs/api/1.1/get/statuses/firehose + """ + url = 'https://stream.twitter.com/%s/statuses/firehose.json' \ + % self.streamer.api_version + self.streamer._request(url, params=params)