Permalink
Browse files

Remove uncessary params. Other reorganization.

  • Loading branch information...
1 parent 0fc1271 commit 2670978f26b3c8e2a47d9802b945cc73a33f7b3d @bboe bboe committed Apr 4, 2012
Showing with 165 additions and 177 deletions.
  1. +43 −46 reddit/__init__.py
  2. +0 −1 reddit/errors.py
  3. +122 −130 reddit/objects.py
View
@@ -328,6 +328,17 @@ def clear_flair_templates(self, subreddit):
return self.request_json(self.config['clearflairtemplates'], params)
@reddit.decorators.require_login
+ def flair_list(self, subreddit, limit=None):
+ """Get flair list for a subreddit.
+
+ Returns a tuple containing 'user', 'flair_text', and 'flair_css_class'.
+ """
+ return self.get_content(self.config['flairlist'] %
+ six.text_type(subreddit),
+ limit=limit, root_field=None,
+ thing_field='users', after_field='next')
+
+ @reddit.decorators.require_login
def get_banned(self, subreddit):
"""Get the list of banned users for a subreddit."""
return self.request_json(self.config['banned'] %
@@ -374,17 +385,6 @@ def get_spam(self, subreddit='mod', limit=None):
limit=limit)
@reddit.decorators.require_login
- def flair_list(self, subreddit, limit=None):
- """Get flair list for a subreddit.
-
- Returns a tuple containing 'user', 'flair_text', and 'flair_css_class'.
- """
- return self.get_content(self.config['flairlist'] %
- six.text_type(subreddit),
- limit=limit, root_field=None,
- thing_field='users', after_field='next')
-
- @reddit.decorators.require_login
def set_flair(self, subreddit, user, text='', css_class=''):
"""Set flair of user in given subreddit."""
params = {'r': six.text_type(subreddit),
@@ -464,7 +464,7 @@ def update_stylesheet(self, subreddit, stylesheet):
"""Set stylesheet in given subreddit."""
params = {'r': six.text_type(subreddit),
'stylesheet_contents': stylesheet,
- 'op': 'save'}
+ 'op': 'save'} # Options: save / preview
return self.request_json(self.config['subreddit_css'], params)
@@ -508,8 +508,7 @@ def compose_message(self, recipient, subject, message, captcha=None):
params = {'text': message,
'subject': subject,
- 'to': recipient,
- 'user': self.user.name}
+ 'to': recipient}
if captcha:
params.update(captcha)
response = self.request_json(self.config['compose'], params)
@@ -532,8 +531,7 @@ def create_subreddit(self, name, title, description='', language='en',
'over_18': 'on' if over_18 else 'off',
'allow_top': 'on' if default_set else 'off',
'show_media': 'on' if show_media else 'off',
- 'domain': domain,
- 'id': '#sr-form'}
+ 'domain': domain}
return self.request_json(self.config['site_admin'], params)
def get_redditor(self, user_name, *args, **kwargs):
@@ -592,6 +590,17 @@ class Reddit(LoggedInExtension, # pylint: disable-msg=R0904
def __init__(self, *args, **kwargs):
super(Reddit, self).__init__(*args, **kwargs)
+ @reddit.decorators.RequireCaptcha
+ def create_redditor(self, user_name, password, email='', captcha=None):
+ """Register a new user."""
+ params = {'email': email,
+ 'passwd': password,
+ 'passwd2': password,
+ 'user': user_name}
+ if captcha:
+ params.update(captcha)
+ return self.request_json(self.config['register'], params)
+
def get_all_comments(self, *args, **kwargs):
"""Returns a listing from reddit.com/comments (which provides all of
the most recent comments from all users to all submissions)."""
@@ -602,10 +611,6 @@ def get_front_page(self, limit=0):
see your own front page if you are logged in."""
return self.get_content(self.config['reddit_url'], limit=limit)
- def get_subreddit(self, subreddit_name, *args, **kwargs):
- """Returns a Subreddit object for the subreddit_name specified."""
- return reddit.objects.Subreddit(self, subreddit_name, *args, **kwargs)
-
def get_submission(self, url=None, submission_id=None):
"""Returns a Submission object for the given url or submission_id."""
if bool(url) == bool(submission_id):
@@ -614,6 +619,10 @@ def get_submission(self, url=None, submission_id=None):
url = urljoin(self.config['comments'], submission_id)
return reddit.objects.Submission.get_info(self, url)
+ def get_subreddit(self, subreddit_name, *args, **kwargs):
+ """Returns a Subreddit object for the subreddit_name specified."""
+ return reddit.objects.Subreddit(self, subreddit_name, *args, **kwargs)
+
def info(self, url=None, thing_id=None, limit=0):
"""
Given url, queries the API to see if the given URL has been submitted
@@ -624,33 +633,18 @@ def info(self, url=None, thing_id=None, limit=0):
if bool(url) == bool(thing_id):
raise TypeError('Only one of url or thing_id is required!')
if url is not None:
- params = {'url': url}
+ url_data = {'url': url}
if (url.startswith(self.config['reddit_url']) and
url != self.config['reddit_url']):
msg = ('It looks like you may be trying to get the info of a '
'self or internal link. This probably will not return '
'any useful results!')
warnings.warn_explicit(msg, UserWarning, '', 0)
else:
- params = {'id': thing_id}
- return self.get_content(self.config['info'], url_data=params,
+ url_data = {'id': thing_id}
+ return self.get_content(self.config['info'], url_data=url_data,
limit=limit)
- @reddit.decorators.RequireCaptcha
- def send_feedback(self, name, email, message, reason='feedback',
- captcha=None):
- """
- Send feedback to the admins. Please don't abuse this, read what it says
- on the send feedback page!
- """
- params = {'name': name,
- 'email': email,
- 'reason': reason,
- 'text': message}
- if captcha:
- params.update(captcha)
- return self.request_json(self.config['feedback'], params)
-
def search(self, query, subreddit=None, sort=None, limit=0, *args,
**kwargs):
url_data = {'q': query}
@@ -671,13 +665,16 @@ def search_reddit_names(self, query):
return [self.get_subreddit(name) for name in results['names']]
@reddit.decorators.RequireCaptcha
- def create_redditor(self, user_name, password, email='', captcha=None):
- """Register a new user."""
- params = {'email': email,
- 'op': 'reg',
- 'passwd': password,
- 'passwd2': password,
- 'user': user_name}
+ def send_feedback(self, name, email, message, reason='feedback',
+ captcha=None):
+ """
+ Send feedback to the admins. Please don't abuse this, read what it says
+ on the send feedback page!
+ """
+ params = {'name': name,
+ 'email': email,
+ 'reason': reason,
+ 'text': message}
if captcha:
params.update(captcha)
- return self.request_json(self.config['register'], params)
+ return self.request_json(self.config['feedback'], params)
View
@@ -14,7 +14,6 @@
# along with reddit_api. If not, see <http://www.gnu.org/licenses/>.
import inspect
-import re
import six
import sys
Oops, something went wrong.

0 comments on commit 2670978

Please sign in to comment.