Permalink
Browse files

Cleaned up all other exceptions

  • Loading branch information...
paradox460 committed Jun 20, 2012
1 parent 39b1250 commit 4c4c021908d1edf9c1b50e6d85f91ccee97afbaf
Showing with 39 additions and 39 deletions.
  1. +7 −7 lib/snoo/flair.rb
  2. +3 −3 lib/snoo/links_comments.rb
  3. +10 −10 lib/snoo/listings.rb
  4. +2 −2 lib/snoo/moderation.rb
  5. +3 −3 lib/snoo/pms.rb
  6. +11 −11 lib/snoo/subreddits.rb
  7. +3 −3 lib/snoo/users.rb
View
@@ -13,7 +13,7 @@ module Flair
def clear_flair_templates type, subreddit
logged_in?
tests = ['USER_FLAIR', 'LINK_FLAIR']
- raise 'parameter error: type needs to be either USER_FLAIR or LINK_FLAIR' unless tests.include?(type)
+ raise ArgumentError, 'type needs to be either USER_FLAIR or LINK_FLAIR' unless tests.include?(type)
post('/api/clearflairtemplates', body: { flair_type: type, r: subreddit, uh: @modhash})
end
@@ -46,7 +46,7 @@ def delete_flair_template id, subreddit
# @return (see #clear_sessions)
def flair css_class, text, subreddit, name = nil, link = nil
logged_in?
- raise "parameter error: either link or name, not both" if link && name
+ raise ArgumentError, "link or name, not both" if link && name
params = {
css_class: css_class,
text: text,
@@ -107,7 +107,7 @@ def flair_csv csv, subreddit
# @return (see #clear_sessions)
def get_flair_list subreddit, limit = 1000, before = nil, after = nil
logged_in?
- raise 'parameter error: limit is too high/low' unless (1..1000).include?(limit)
+ raise ArgumentError, 'limit is too high/low' unless (1..1000).include?(limit)
query = {
limit: limit,
uh: @modhash
@@ -129,9 +129,9 @@ def get_flair_list subreddit, limit = 1000, before = nil, after = nil
def flair_template css_class, type, text, user_editable, subreddit, template_id = nil
logged_in?
test = ['USER_FLAIR', 'LINK_FLAIR']
- raise 'parameter error: type is either USER_FLAIR or LINK_FLAIR' unless test.include?(type)
+ raise ArgumentError, 'type is either USER_FLAIR or LINK_FLAIR' unless test.include?(type)
test = [true, false]
- raise 'parameter error: user_editable needs to be true or false' unless test.include?(user_editable)
+ raise ArgumentError, 'user_editable needs to be true or false' unless test.include?(user_editable)
params = {
css_class: css_class,
@@ -155,7 +155,7 @@ def flair_template css_class, type, text, user_editable, subreddit, template_id
# @return (see #clear_sessions)
def select_flair_template template_id, text, subreddit, link = nil, user = nil
logged_in?
- raise 'parameter error: link or user, not both' if link && user
+ raise ArgumentError, 'link or user, not both' if link && user
params = {
flair_template_id: template_id,
text: text,
@@ -175,7 +175,7 @@ def select_flair_template template_id, text, subreddit, link = nil, user = nil
def flair_toggle enabled, subreddit
logged_in?
test = [true, false]
- raise 'parameter error: enabled must be boolean' unless test.include?(enabled)
+ raise ArgumentError, 'enabled must be boolean' unless test.include?(enabled)
post('/api/setflairenabled', body: {flair_enabled: enabled, uh: @modhash, r: subreddit})
end
@@ -52,7 +52,7 @@ def hide id
# @param limit [Fixnum] The number of things to return. Go too high and the API will ignore you
# @return (see #clear_sessions)
def info id = nil, url = nil, limit = 100
- raise 'parameter error: url or id, not both' if id && url
+ raise ArgumentError, 'url or id, not both' if id && url
query = { limit: limit }
query[:id] = id if id
query[:url] = url if url
@@ -95,7 +95,7 @@ def save id
# @return (see #clear_sessions)
def submit title, subreddit, url = nil, text = nil
logged_in?
- raise 'parameter error: either url or text, not both' if url && text
+ raise ArgumentError, 'url or text, not both' if url && text
post = {
title: title,
sr: subreddit,
@@ -132,7 +132,7 @@ def unmark_nsfw id
# @return (see #clear_sessions)
def vote direction, id
logged_in?
- raise "parameter error: direction needs to be one of -1, 0, or 1 (was #{direction}" unless (-1..1).include?(direction)
+ raise ArgumentError, "direction needs to be one of -1, 0, or 1 (was #{direction}" unless (-1..1).include?(direction)
post('/api/vote', body: {id: id, dir: direction, uh: @modhash})
end
View
@@ -15,7 +15,7 @@ module Listings
# @return (see #clear_sessions)
def get_comments link_id, comment_id = nil, context = nil, limit = 100, depth = nil, sort = nil
sorts = %w{old new hot top controversial best}
- raise "parameter error: sort cannot be #{sort}" unless sorts.include?(sort) or sort.nil?
+ raise ArgumentError, "sort cannot be #{sort}" unless sorts.include?(sort) or sort.nil?
query = {}
query[:context] = context if context
query[:limit] = limit if limit
@@ -40,15 +40,15 @@ def get_listing subreddit = nil, page = nil, sort = nil, time = nil, limit = nil
sorts = %w{new rising}
times = %w{hour day week month year}
# Invalid Page
- raise "parameter error: page must be #{pages * ', '}, is #{page}" unless pages.include?(page) or page.nil?
+ raise ArgumentError, "page must be #{pages * ', '}, is #{page}" unless pages.include?(page) or page.nil?
# Invalid Sort
- raise "parameter error: sort must be one of #{sorts * ', '}, is #{sort}" unless sorts.include?(sort) or sort.nil?
+ raise ArgumentError, "sort must be one of #{sorts * ', '}, is #{sort}" unless sorts.include?(sort) or sort.nil?
# Sort on useless page
- raise "parameter error: sort can only be used on page = 'new'" if page != 'new' && sort
+ raise ArgumentError, "sort can only be used on page = 'new'" if page != 'new' && sort
# Invalid time
- raise "parameter error: time can only be one of #{times * ', '}, is #{time}" unless times.include?(time) or time.nil?
+ raise ArgumentError, "time can only be one of #{times * ', '}, is #{time}" unless times.include?(time) or time.nil?
# Invalid limit
- raise "parameter error: limit cannot be outside 1..100, is #{limit}" unless (1..100).include?(limit) or limit.nil?
+ raise ArgumentError, "limit cannot be outside 1..100, is #{limit}" unless (1..100).include?(limit) or limit.nil?
# Build the basic url
url = "%s/%s.json" % [('/r/' + subreddit if subreddit ), (page if page)]
@@ -77,10 +77,10 @@ def get_listing subreddit = nil, page = nil, sort = nil, time = nil, limit = nil
# @param syntax [cloudsearch, lucene] The search syntax.
# @return (see #clear_sessions)
def search query, restrict_subreddit = false, subreddit = nil, limit = nil, before = nil, after = nil, sort = nil, syntax = 'lucene'
- raise 'parameter error: restrict_subreddit needs to be boolean' unless [true, false].include?(restrict_subreddit)
- raise "parameter error: limit needs to be 1..100, is #{limit}" unless (1..100).include?(limit) or limit.nil?
- raise "parameter error: sort needs to be one of relevance, new, top, is #{sort}" unless %w{relevance new top}.include?(sort) or sort.nil?
- raise "parameter error: syntax needs to be one of cloudsearch, lucene; is #{syntax}" if %w{cloudsearch lucene}.include?(syntax)
+ raise ArgumentError, 'restrict_subreddit needs to be boolean' unless [true, false].include?(restrict_subreddit)
+ raise ArgumentError, "limit needs to be 1..100, is #{limit}" unless (1..100).include?(limit) or limit.nil?
+ raise ArgumentError, "sort needs to be one of relevance, new, top, is #{sort}" unless %w{relevance new top}.include?(sort) or sort.nil?
+ raise ArgumentError, "syntax needs to be one of cloudsearch, lucene; is #{syntax}" if %w{cloudsearch lucene}.include?(syntax)
# This supports searches with and without a subreddit
url = "%s/search.json" % (subreddit if subreddit)
View
@@ -21,7 +21,7 @@ def approve id
def distinguish id, how
logged_in?
hows = %w{yes no admin special}
- raise "parameter error: how should be one of #{hows * ', '}, is #{how}" if hows.include?(how)
+ raise ArgumentError, "how should be one of #{hows * ', '}, is #{how}" if hows.include?(how)
post('/api/distinguish', body: {id: id, how: how, uh: @modhash})
end
@@ -53,7 +53,7 @@ def leave_moderator id
def remove id, spam
logged_in?
spams = [true, false]
- raise "parameter error: spam should be boolean, is #{spam}" unless spams.include?(spam)
+ raise ArgumentError, "spam should be boolean, is #{spam}" unless spams.include?(spam)
post('/api/remove', body: {id: id, spam: spam, uh: @modhash})
end
View
@@ -54,9 +54,9 @@ def mark_unread id
def get_messages where, mark = false, limit = nil, before = nil, after = nil
bools = [true, false]
wheres = %w{inbox unread sent}
- raise "parameter error: where must be #{wheres * ', '}, is #{where}" unless wheres.include?(where)
- raise "parameter error: mark must be boolean, is #{mark}" unless bools.include?(mark)
- raise "parameter error: limit must be 1..100, is #{limit}" unless (1..100).include?(limit) or limit.nil?
+ raise ArgumentError, "where must be #{wheres * ', '}, is #{where}" unless wheres.include?(where)
+ raise ArgumentError, "mark must be boolean, is #{mark}" unless bools.include?(mark)
+ raise ArgumentError, "limit must be 1..100, is #{limit}" unless (1..100).include?(limit) or limit.nil?
query = {}
query[:mark] = mark if mark
View
@@ -42,11 +42,11 @@ def delete_image subreddit, image_name
def subreddit_settings title, subreddit, description = nil, sidebar = nil, lang = en, type = 'public', post_type = 'any', allow_frontpage = true, show_media = true, header = nil, adult = false
logged_in?
bool = [true, false]
- raise "parameter error: type must be one of public, private, restricted, is #{type}" unless %w{public private restricted}.include?(type)
- raise "parameter error: post_type must be one of any, link, self; is #{type}" unless %w{any link self}.include?(post_type)
- raise "parameter error: allow_frontpage must be boolean" unless bool.include?(allow_frontpage)
- raise "parameter error: show_media must be boolean" unless bool.include?(show_media)
- raise "parameter error: adult must be boolean" unless bool.include?(adult)
+ raise ArgumentError, "type must be one of public, private, restricted, is #{type}" unless %w{public private restricted}.include?(type)
+ raise ArgumentError, "post_type must be one of any, link, self; is #{type}" unless %w{any link self}.include?(post_type)
+ raise ArgumentError, "allow_frontpage must be boolean" unless bool.include?(allow_frontpage)
+ raise ArgumentError, "show_media must be boolean" unless bool.include?(show_media)
+ raise ArgumentError, "adult must be boolean" unless bool.include?(adult)
params = {title: title, description: sidebar, public_description: description, lang: lang, type: type, link_type: post_type, allow_top: allow_frontpage, show_media: show_media, "header-title" => header, r: subreddit, uh: @modhash}
post('/api/site_admin', body: params)
end
@@ -68,7 +68,7 @@ def set_stylesheet stylesheet, subreddit
# @return (see #clear_sessions)
def subscribe subreddit, action = "sub"
logged_in?
- raise "parameter error: action must be one of sub, unsub; is #{action}" unless %w{sub unsub}.include?(action)
+ raise ArgumentError, "action must be one of sub, unsub; is #{action}" unless %w{sub unsub}.include?(action)
post('/api/subscribe', body: {action: action, sr: subreddit, uh: @modhash})
end
@@ -108,8 +108,8 @@ def get_stylesheet subreddit
# @return (see #clear_sessions)
def my_reddits condition = nil, limit = nil, after = nil, before = nil
logged_in?
- raise "parameter error: condition must be one of subscriber, contributor, moderator; is #{condition}" unless %w{subscriber contributor moderator}.include?(condition) or condition.nil?
- raise "parameter error: limit must be within 1..100; is #{limit}" unless (1..100).include?(limit) or limit.nil?
+ raise ArgumentError, "condition must be one of subscriber, contributor, moderator; is #{condition}" unless %w{subscriber contributor moderator}.include?(condition) or condition.nil?
+ raise ArgumentError, "limit must be within 1..100; is #{limit}" unless (1..100).include?(limit) or limit.nil?
query = {}
query[:limit] = limit if limit
query[:after] = after if after
@@ -126,8 +126,8 @@ def my_reddits condition = nil, limit = nil, after = nil, before = nil
# @param before [String] Return subreddits *before* this id.
# @return (see #clear_sessions)
def get_reddits condition = nil, limit = nil, after = nil, before = nil
- raise "parameter error: condition must be one of popular, new, banned; is #{condition}" unless %w{popular new banned}.include?(condition) or condition.nil?
- raise "parameter error: limit must be within 1..100; is #{limit}" unless (1..100).include?(limit) or limit.nil?
+ raise ArgumentError, "condition must be one of popular, new, banned; is #{condition}" unless %w{popular new banned}.include?(condition) or condition.nil?
+ raise ArgumentError, "limit must be within 1..100; is #{limit}" unless (1..100).include?(limit) or limit.nil?
url = "/reddits/%s.json" % (condition if condition)
query = {}
@@ -146,7 +146,7 @@ def get_reddits condition = nil, limit = nil, after = nil, before = nil
# @param before [String] Return subreddits *before* this id.
# @return (see #clear_sessions)
def search_reddits q, limit = nil, after = nil, before = nil
- raise "parameter error: limit must be within 1..100; is #{limit}" unless (1..100).include?(limit) or limit.nil?
+ raise ArgumentError, "limit must be within 1..100; is #{limit}" unless (1..100).include?(limit) or limit.nil?
query = {q: q}
query[:limit] = limit if limit
View
@@ -46,9 +46,9 @@ def get_user_info username
# @param limit [1..100] Number of results to return
# @return (see #clear_sessions)
def get_user_listing username, type = 'overview', sort = 'new', after = nil, before = nil, limit = nil
- raise "parameter error: type must be one of overview, submitted, commented, liked, disliked, hidden, saved; is #{type}" unless %w{overview submitted commented liked disliked hidden saved}.include?(type)
- raise "parameter error: sort must be one of new, hot, top, controversial; is #{sort}" unless %w{new hot top controversial}.include?(sort)
- raise "parameter error: limit must be within 1..100; is #{limit}" unless (1..100).include?(limit) or limit.nil?
+ raise ArgumentError, "type must be one of overview, submitted, commented, liked, disliked, hidden, saved; is #{type}" unless %w{overview submitted commented liked disliked hidden saved}.include?(type)
+ raise ArgumentError, "sort must be one of new, hot, top, controversial; is #{sort}" unless %w{new hot top controversial}.include?(sort)
+ raise ArgumentError, "limit must be within 1..100; is #{limit}" unless (1..100).include?(limit) or limit.nil?
query = {}
query[:sort] = sort if sort != 'new'
query[:after] = after if after

0 comments on commit 4c4c021

Please sign in to comment.