Module: Snoo::Subreddit
- Defined in:
- lib/snoo/subreddits.rb
Overview
Methods for administering a subreddit, as well as looking up subreddits (subreddit search)
Instance Method Summary collapse
-
#accept_moderator(subreddit) ⇒ Object
Accept a moderatorship.
-
#add_contributor(container, user, subreddit) ⇒ Object
Add a contributor to the subreddit.
-
#add_moderator(container, user, subreddit) ⇒ Object
Add a moderator to the subreddit.
-
#ban_user(container, user, subreddit) ⇒ Object
Ban a user from a subreddit.
-
#delete_header(subreddit) ⇒ Object
Deletes the header image of a subreddit.
-
#delete_image(subreddit, image_name) ⇒ Object
Deletes an image from a subreddit.
-
#get_banned_users(subreddit) ⇒ Object
List banned users of a subreddit.
-
#get_contributors(subreddit) ⇒ Object
List contributors of a subreddit.
-
#get_moderators(subreddit) ⇒ Object
List moderators of a subreddit.
-
#get_reddits(opts = {}) ⇒ Object
Get a list of subreddits.
-
#get_stylesheet(subreddit) ⇒ Object
Get subreddit stylesheet and images.
-
#get_subreddit_settings(subreddit) ⇒ Object
Gets a hash of the subreddit settings Returns a webserver error (404) if you don't have moderator permissions on said subreddit.
-
#my_reddits(opts = {}) ⇒ Object
Get subreddits I have.
-
#remove_contributor(container, user, subreddit) ⇒ Object
Remove a contributor from a subreddit.
-
#remove_moderator(container, user, subreddit) ⇒ Object
Remove a moderator from a subreddit.
-
#search_reddits(q, opts = {}) ⇒ Object
Search subreddits.
-
#set_stylesheet(stylesheet, subreddit) ⇒ Object
Set the subreddit stylesheet.
-
#subreddit_info(subreddit) ⇒ Object
Get subreddit info.
-
#subreddit_settings(subreddit, opts = {}) ⇒ Object
Sets subreddit settings.
-
#subscribe(subreddit, action = "sub") ⇒ Object
Subscribe to a subreddit.
-
#unban_user(container, user, subreddit) ⇒ Object
Unban a user from a subreddit.
-
#unsubscribe(subreddit) ⇒ Object
Unsubscribe from a subreddit This is an alias for
subscribe "unsub"
.
Instance Method Details
#accept_moderator(subreddit) ⇒ Object
Accept a moderatorship
239 240 241 242 |
# File 'lib/snoo/subreddits.rb', line 239 def accept_moderator subreddit logged_in? post('/api/accept_moderator_invite', body: {r: subreddit, uh: @modhash, api_type: 'json'}) end |
#add_contributor(container, user, subreddit) ⇒ Object
Add a contributor to the subreddit
174 175 176 |
# File 'lib/snoo/subreddits.rb', line 174 def add_contributor container, user, subreddit friend_wrapper container: container, name: user, r: subreddit, type: "contributor" end |
#add_moderator(container, user, subreddit) ⇒ Object
Add a moderator to the subreddit
166 167 168 |
# File 'lib/snoo/subreddits.rb', line 166 def add_moderator container, user, subreddit friend_wrapper container: container, name: user, r: subreddit, type: "moderator" end |
#ban_user(container, user, subreddit) ⇒ Object
Ban a user from a subreddit
182 183 184 |
# File 'lib/snoo/subreddits.rb', line 182 def ban_user container, user, subreddit friend_wrapper container: container, name: user, r: subreddit, type: "banned" end |
#delete_header(subreddit) ⇒ Object
Deletes the header image of a subreddit
11 12 13 14 |
# File 'lib/snoo/subreddits.rb', line 11 def delete_header subreddit logged_in? post('/api/delete_sr_header', body: {r: subreddit, uh: @modhash, api_type: 'json'}) end |
#delete_image(subreddit, image_name) ⇒ Object
Deletes an image from a subreddit. This is for css, not removing posts
21 22 23 24 |
# File 'lib/snoo/subreddits.rb', line 21 def delete_image subreddit, image_name logged_in? post('/api/delete_sr_image', body: {r: subreddit, img_name: image_name, uh: @modhash, api_type: 'json'}) end |
#get_banned_users(subreddit) ⇒ Object
List banned users of a subreddit
231 232 233 234 |
# File 'lib/snoo/subreddits.rb', line 231 def get_banned_users subreddit logged_in? get("/r/#{subreddit}/about/banned.json") end |
#get_contributors(subreddit) ⇒ Object
List contributors of a subreddit
222 223 224 225 |
# File 'lib/snoo/subreddits.rb', line 222 def get_contributors subreddit logged_in? get("/r/#{subreddit}/about/contributors.json") end |
#get_moderators(subreddit) ⇒ Object
List moderators of a subreddit
214 215 216 |
# File 'lib/snoo/subreddits.rb', line 214 def get_moderators subreddit get("/r/#{subreddit}/about/moderators.json") end |
#get_reddits(opts = {}) ⇒ Object
Get a list of subreddits
138 139 140 141 142 143 144 |
# File 'lib/snoo/subreddits.rb', line 138 def get_reddits opts = {} url = "/reddits/%s.json" % (opts[:condition] if opts[:condition]) opts.delete :condition query = opts get(url, query: query) end |
#get_stylesheet(subreddit) ⇒ Object
Get subreddit stylesheet and images
109 110 111 112 |
# File 'lib/snoo/subreddits.rb', line 109 def get_stylesheet subreddit logged_in? get("/r/#{subreddit}/about/stylesheet.json") end |
#get_subreddit_settings(subreddit) ⇒ Object
Gets a hash of the subreddit settings Returns a webserver error (404) if you don't have moderator permissions on said subreddit
30 31 32 33 |
# File 'lib/snoo/subreddits.rb', line 30 def get_subreddit_settings subreddit logged_in? get("/r/#{subreddit}/about/edit/.json") end |
#my_reddits(opts = {}) ⇒ Object
Get subreddits I have
122 123 124 125 126 127 128 |
# File 'lib/snoo/subreddits.rb', line 122 def my_reddits opts = {} logged_in? url = "/reddits/mine/%s.json" % (opts[:condition] if opts[:condition]) opts.delete :condition query = opts get(url, query: query) end |
#remove_contributor(container, user, subreddit) ⇒ Object
Remove a contributor from a subreddit
198 199 200 |
# File 'lib/snoo/subreddits.rb', line 198 def remove_contributor container, user, subreddit unfriend_wrapper container: container, name: user, r: subreddit, type: "contributor" end |
#remove_moderator(container, user, subreddit) ⇒ Object
Remove a moderator from a subreddit
190 191 192 |
# File 'lib/snoo/subreddits.rb', line 190 def remove_moderator container, user, subreddit unfriend_wrapper container: container, name: user, r: subreddit, type: "moderator" end |
#search_reddits(q, opts = {}) ⇒ Object
Search subreddits
154 155 156 157 158 |
# File 'lib/snoo/subreddits.rb', line 154 def search_reddits q, opts = {} query = {q: q} query.merge! opts get('/reddits/search.json', query: query) end |
#set_stylesheet(stylesheet, subreddit) ⇒ Object
Set the subreddit stylesheet
72 73 74 75 |
# File 'lib/snoo/subreddits.rb', line 72 def set_stylesheet stylesheet, subreddit logged_in? post('/api/subreddit_stylesheet', body: {op: 'save', r: subreddit, stylesheet_contents: stylesheet, uh: @modhash, api_type: 'json'}) end |
#subreddit_info(subreddit) ⇒ Object
Get subreddit info
101 102 103 |
# File 'lib/snoo/subreddits.rb', line 101 def subreddit_info subreddit get("/r/#{subreddit}/about.json") end |
#subreddit_settings(subreddit, opts = {}) ⇒ Object
test if every param is actually required
Sets subreddit settings.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/snoo/subreddits.rb', line 50 def subreddit_settings subreddit, opts = {} logged_in? params = { type: 'public', link_type: 'any', lang: 'en', r: subreddit, uh: @modhash, allow_top: true, show_media: true, over_18: false, api_type: 'json' } params.merge! opts post('/api/site_admin', body: params) end |
#subscribe(subreddit, action = "sub") ⇒ Object
Subscribe to a subreddit
82 83 84 85 |
# File 'lib/snoo/subreddits.rb', line 82 def subscribe subreddit, action = "sub" logged_in? post('/api/subscribe', body: {action: action, sr: subreddit, uh: @modhash, api_type: 'json'}) end |
#unban_user(container, user, subreddit) ⇒ Object
Unban a user from a subreddit
206 207 208 |
# File 'lib/snoo/subreddits.rb', line 206 def unban_user container, user, subreddit unfriend_wrapper container: container, name: user, r: subreddit, type: "banned" end |
#unsubscribe(subreddit) ⇒ Object
Unsubscribe from a subreddit
This is an alias for subscribe "unsub"
92 93 94 |
# File 'lib/snoo/subreddits.rb', line 92 def unsubscribe subreddit subscribe("unsub", subreddit) end |