Skip to content

Commit

Permalink
Merge pull request #4 from beatak/adding-site-admin
Browse files Browse the repository at this point in the history
adding site_admin (and about_edit and comments)
  • Loading branch information
avidw committed Dec 1, 2014
2 parents 02c58ec + 6a862e2 commit ad736d6
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions lib/redd/client/authenticated/subreddits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def get_special_users(where, subreddit, params = {})
Redd::Object::Listing.new(data: {children: things})
end

# Edit Subreddit's stylesheet
#
# @param subreddit [Redd::Object::Subreddit, String] The subreddit to
# submit.
# @param contents [String] css
# @param reason [String]
# @note https://www.reddit.com/r/***/about/stylesheet/ is good place
# to test if you have an error
def edit_stylesheet(subreddit, contents, reason = nil)
name = extract_attribute(subreddit, :display_name)
path = "/r/#{name}/api/subreddit_stylesheet"
Expand All @@ -83,6 +91,70 @@ def edit_stylesheet(subreddit, contents, reason = nil)
post path, params
end

# Edit Subreddit's settings
#
# @param attrs [Hash] Settings for subrredit
# @note these links might useful: https://www.reddit.com/dev/api and
# https://github.com/alaycock/MeetCal-bot/blob/master/serverInfo.conf
def site_admin(attrs)
path = "/api/site_admin"
params = {
allow_top: nil, # boolean
api_type: "json", # always "json"
collapse_deleted_comments: nil, # boolean
comment_score_hide_mins: nil, # int 0..1440 def: 0
css_on_cname: nil, # boolean
description: nil, # markdown string
exclude_banned_modqueue: nil, # boolean
lang: nil, # valid IETF lang tag, eg: en
link_type: nil, # string [any, link, self]
name: nil, # string subreddit name
over_18: nil, # boolean
public_description: nil, # markdown string
public_traffic: nil, # boolean
show_cname_sidebar: nil, # boolean
show_media: nil, # boolean
spam_comments: nil, # string [low, high, all]
spam_links: nil, # string [low, high, all]
spam_selfposts: nil, # string [low, high, all]
sr: nil, # string, for subreddit it should start like "t5_"
submit_link_label: nil, # string max 60 chars
submit_text: nil, # markdown string
submit_text_label: nil, # string max 60 chars
title: nil, # string max 100 chars
type: nil, # string [public, private, restricted, gold_restricted, archived]
wiki_edit_age: nil, # int 0+, def: 0
wiki_edit_karma: nil, # int 0+, def: 0
wikimode: nil # string [disabled, modonly, anyone]
}
params["header-title"] = '' # string max 500 chars

params.keys.each{|key|
if !attrs[key].nil?
params[key] = attrs[key]
end
}

empties = params.map{ |obj|
obj.last.nil? ? obj.first.to_s : nil
}
empties = empties.reject!{ |elm| elm.nil? }
if !empties.empty?
raise "The following item should not be nil => [" + empties.join(', ') + ']'
end

post path, params
end

# Get the current settings of a subreddit.
#
# @param subreddit [Redd::Object::Subreddit, String] The subreddit to
# submit.
def about_edit(subreddit)
name = extract_attribute(subreddit, :display_name)
object_from_response :get, "/r/#{name}/about/edit.json"
end

private

# Subscribe or unsubscribe to a subreddit.
Expand Down

0 comments on commit ad736d6

Please sign in to comment.