Updating file structure and HISTORY.rst

This commit is contained in:
Mike Helmick 2013-05-03 17:33:17 -04:00
parent 97a33ce8dd
commit cea0852a42
4 changed files with 81 additions and 81 deletions

View file

@ -1,10 +1,10 @@
History 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) 2.8.0 (2013-04-29)
++++++++++++++++++ ++++++++++++++++++

View file

@ -0,0 +1 @@
from .api import TwythonStreamer

View file

@ -1,6 +1,7 @@
from . import __version__ from .. import __version__
from .compat import json from ..compat import json
from .exceptions import TwythonStreamError from ..exceptions import TwythonStreamError
from .types import TwythonStreamerTypes
import requests import requests
from requests_oauthlib import OAuth1 from requests_oauthlib import OAuth1
@ -8,79 +9,6 @@ from requests_oauthlib import OAuth1
import time 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): class TwythonStreamer(object):
def __init__(self, app_key, app_secret, oauth_token, oauth_token_secret, def __init__(self, app_key, app_secret, oauth_token, oauth_token_secret,
timeout=300, retry_count=None, retry_in=10, headers=None): timeout=300, retry_count=None, retry_in=10, headers=None):
@ -122,10 +50,10 @@ class TwythonStreamer(object):
self.retry_count = retry_count self.retry_count = retry_count
# Set up type methods # Set up type methods
StreamTypes = TwythonStreamTypes(self) StreamTypes = TwythonStreamerTypes(self)
self.statuses = StreamTypes.statuses self.statuses = StreamTypes.statuses
self.__dict__['user'] = StreamTypes.user self.user = StreamTypes.user
self.__dict__['site'] = StreamTypes.site self.site = StreamTypes.site
def _request(self, url, method='GET', params=None): def _request(self, url, method='GET', params=None):
"""Internal stream request handling""" """Internal stream request handling"""

View file

@ -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)