snoo 0.1.0.pre.1 → 0.1.0.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/snoo/flair.rb +0 -11
- data/lib/snoo/links_comments.rb +0 -3
- data/lib/snoo/listings.rb +0 -16
- data/lib/snoo/moderation.rb +0 -3
- data/lib/snoo/subreddits.rb +9 -15
- data/lib/snoo/version.rb +1 -1
- metadata +2 -2
data/lib/snoo/flair.rb
CHANGED
@@ -12,8 +12,6 @@ module Snoo
|
|
12
12
|
# @return (see #clear_sessions)
|
13
13
|
def clear_flair_templates type, subreddit
|
14
14
|
logged_in?
|
15
|
-
tests = ['USER_FLAIR', 'LINK_FLAIR']
|
16
|
-
raise ArgumentError, 'type needs to be either USER_FLAIR or LINK_FLAIR' unless tests.include?(type)
|
17
15
|
post('/api/clearflairtemplates', body: { flair_type: type, r: subreddit, uh: @modhash})
|
18
16
|
end
|
19
17
|
|
@@ -47,7 +45,6 @@ module Snoo
|
|
47
45
|
# @return (see #clear_sessions)
|
48
46
|
def flair subreddit, opts = {}
|
49
47
|
logged_in?
|
50
|
-
raise ArgumentError, "link or name, not both" if opts[:link] && opts[:name]
|
51
48
|
params = {
|
52
49
|
r: subreddit,
|
53
50
|
uh: @modhash,
|
@@ -103,7 +100,6 @@ module Snoo
|
|
103
100
|
# @return (see #clear_sessions)
|
104
101
|
def get_flair_list subreddit, opts = {}
|
105
102
|
logged_in?
|
106
|
-
raise ArgumentError, 'limit is too high/low' unless (1..1000).include?(opts[:limit]) or opts[:limit].nil?
|
107
103
|
query = {
|
108
104
|
limit: 1000,
|
109
105
|
uh: @modhash
|
@@ -131,10 +127,6 @@ module Snoo
|
|
131
127
|
r: subreddit
|
132
128
|
}
|
133
129
|
params.merge! opts
|
134
|
-
test = ['USER_FLAIR', 'LINK_FLAIR']
|
135
|
-
raise ArgumentError, 'type is either USER_FLAIR or LINK_FLAIR' unless test.include?(params[:flair_type])
|
136
|
-
test = [true, false]
|
137
|
-
raise ArgumentError, 'user_editable needs to be true or false' unless test.include?(params[:text_editable])
|
138
130
|
|
139
131
|
post('/api/flairtemplate', body: params)
|
140
132
|
end
|
@@ -150,7 +142,6 @@ module Snoo
|
|
150
142
|
# @return (see #clear_sessions)
|
151
143
|
def select_flair_template template_id, subreddit, opts = {}
|
152
144
|
logged_in?
|
153
|
-
raise ArgumentError, 'link or user, not both' if opts[:link] && opts[:user]
|
154
145
|
params = {
|
155
146
|
flair_template_id: template_id,
|
156
147
|
uh: @modhash,
|
@@ -167,8 +158,6 @@ module Snoo
|
|
167
158
|
# @return (see #clear_sessions)
|
168
159
|
def flair_toggle enabled, subreddit
|
169
160
|
logged_in?
|
170
|
-
test = [true, false]
|
171
|
-
raise ArgumentError, 'enabled must be boolean' unless test.include?(enabled)
|
172
161
|
post('/api/setflairenabled', body: {flair_enabled: enabled, uh: @modhash, r: subreddit})
|
173
162
|
end
|
174
163
|
|
data/lib/snoo/links_comments.rb
CHANGED
@@ -52,7 +52,6 @@ module Snoo
|
|
52
52
|
# @option opts [Fixnum] :limit The number of things to return. Go too high and the API will ignore you
|
53
53
|
# @return (see #clear_sessions)
|
54
54
|
def info opts = {}
|
55
|
-
raise ArgumentError, 'url or id, not both' if opts[:id] && opts[:url]
|
56
55
|
query = { limit: 100 }
|
57
56
|
query.merge! opts
|
58
57
|
get('/api/info.json', query: query)
|
@@ -95,7 +94,6 @@ module Snoo
|
|
95
94
|
# @return (see #clear_sessions)
|
96
95
|
def submit title, subreddit, opts = {}
|
97
96
|
logged_in?
|
98
|
-
raise ArgumentError, 'url or text, not both' if opts[:url] && opts[:text]
|
99
97
|
post = {
|
100
98
|
title: title,
|
101
99
|
sr: subreddit,
|
@@ -132,7 +130,6 @@ module Snoo
|
|
132
130
|
# @return (see #clear_sessions)
|
133
131
|
def vote direction, id
|
134
132
|
logged_in?
|
135
|
-
raise ArgumentError, "direction needs to be one of -1, 0, or 1 (was #{direction}" unless (-1..1).include?(direction)
|
136
133
|
post('/api/vote', body: {id: id, dir: direction, uh: @modhash})
|
137
134
|
end
|
138
135
|
|
data/lib/snoo/listings.rb
CHANGED
@@ -17,8 +17,6 @@ module Snoo
|
|
17
17
|
# @option opts [old, new, hot, top, controversial, best] :sort The sort used.
|
18
18
|
# @return (see #clear_sessions)
|
19
19
|
def get_comments opts = {}
|
20
|
-
sorts = %w{old new hot top controversial best}
|
21
|
-
raise ArgumentError, "sort cannot be #{sort}" unless sorts.include?(opts[:sort]) or opts[:sort].nil?
|
22
20
|
query = { limit: 100 }
|
23
21
|
query.merge! opts
|
24
22
|
url = "%s/comments/%s%s.json" % [('/r/' + opts[:subreddit] if opts[:subreddit]), opts[:link_id], ('/' + opts[:comment_id] if opts[:comment_id])]
|
@@ -37,20 +35,6 @@ module Snoo
|
|
37
35
|
# @option opts [String] :before Get things *before* this thing id
|
38
36
|
# @return (see #clear_sessions)
|
39
37
|
def get_listing opts = {}
|
40
|
-
pages = %w{new controversial top saved}
|
41
|
-
sorts = %w{new rising}
|
42
|
-
times = %w{hour day week month year}
|
43
|
-
# Invalid Page
|
44
|
-
raise ArgumentError, "page must be #{pages * ', '}, is #{opts[:page]}" unless pages.include?(opts[:page]) or opts[:page].nil?
|
45
|
-
# Invalid Sort
|
46
|
-
raise ArgumentError, "sort must be one of #{sorts * ', '}, is #{opts[:sort]}" unless sorts.include?(opts[:sort]) or opts[:sort].nil?
|
47
|
-
# Sort on useless page
|
48
|
-
raise ArgumentError, "sort can only be used on page = 'new'" if opts[:page] != 'new' && opts[:sort]
|
49
|
-
# Invalid time
|
50
|
-
raise ArgumentError, "time can only be one of #{times * ', '}, is #{opts[:time]}" unless times.include?(opts[:time]) or opts[:time].nil?
|
51
|
-
# Invalid limit
|
52
|
-
raise ArgumentError, "limit cannot be outside 1..100, is #{opts[:limit]}" unless (1..100).include?(opts[:limit]) or opts[:limit].nil?
|
53
|
-
|
54
38
|
# Build the basic url
|
55
39
|
url = "%s/%s.json" % [('/r/' + opts[:subreddit] if opts[:subreddit] ), (opts[:page] if opts[:page])]
|
56
40
|
# Delete subreddit and page from the hash, they dont belong in the query
|
data/lib/snoo/moderation.rb
CHANGED
@@ -21,7 +21,6 @@ module Snoo
|
|
21
21
|
def distinguish id, how = "yes"
|
22
22
|
logged_in?
|
23
23
|
hows = %w{yes no admin special}
|
24
|
-
raise ArgumentError, "how should be one of #{hows * ', '}, is #{how}" unless hows.include?(how)
|
25
24
|
post('/api/distinguish', body: {id: id, how: how, uh: @modhash})
|
26
25
|
end
|
27
26
|
|
@@ -52,8 +51,6 @@ module Snoo
|
|
52
51
|
# @return (see #clear_sessions)
|
53
52
|
def remove id, spam = false
|
54
53
|
logged_in?
|
55
|
-
spams = [true, false]
|
56
|
-
raise ArgumentError, "spam should be boolean, is #{spam}" unless spams.include?(spam)
|
57
54
|
post('/api/remove', body: {id: id, spam: spam, uh: @modhash})
|
58
55
|
end
|
59
56
|
|
data/lib/snoo/subreddits.rb
CHANGED
@@ -23,6 +23,14 @@ module Snoo
|
|
23
23
|
post('/api/delete_sr_image', body: {r: subreddit, img_name: image_name, uh: @modhash})
|
24
24
|
end
|
25
25
|
|
26
|
+
# Gets a hash of the subreddit settings
|
27
|
+
# Returns a webserver error (404) if you don't have moderator permissions on said subreddit
|
28
|
+
#
|
29
|
+
# @param subreddit [String] the subreddit to fetch data from
|
30
|
+
def get_subreddit_settings subreddit
|
31
|
+
logged_in?
|
32
|
+
get("/r/#{subreddit}/about/edit/.json")
|
33
|
+
end
|
26
34
|
# @todo test if every param is actually required
|
27
35
|
# Sets subreddit settings.
|
28
36
|
#
|
@@ -41,12 +49,6 @@ module Snoo
|
|
41
49
|
# @return (see #clear_sessions)
|
42
50
|
def subreddit_settings subreddit, opts = {}
|
43
51
|
logged_in?
|
44
|
-
bool = [true, false]
|
45
|
-
raise ArgumentError, "type must be one of public, private, restricted, is #{opts[:type]}" unless %w{public private restricted}.include?(opts[:type]) or opts[:type].nil?
|
46
|
-
raise ArgumentError, "post_type must be one of any, link, self; is #{opts[:link_type]}" unless %w{any link self}.include?(opts[:link_type]) or opts[:link_type].nil?
|
47
|
-
raise ArgumentError, "allow_frontpage must be boolean" unless bool.include?(opts[:allow_top]) or opts[:allow_top].nil?
|
48
|
-
raise ArgumentError, "show_media must be boolean" unless bool.include?(opts[:show_media]) or opts[:show_media].nil?
|
49
|
-
raise ArgumentError, "adult must be boolean" unless bool.include?(opts[:over_18]) or opts[:over_18].nil?
|
50
52
|
params = {
|
51
53
|
type: 'public',
|
52
54
|
link_type: 'any',
|
@@ -68,7 +70,7 @@ module Snoo
|
|
68
70
|
# @return (see #clear_sessions)
|
69
71
|
def set_stylesheet stylesheet, subreddit
|
70
72
|
logged_in?
|
71
|
-
post('/api/subreddit_stylesheet', body: {op:
|
73
|
+
post('/api/subreddit_stylesheet', body: {op: 'save', r: subreddit, stylesheet_contents: stylesheet, uh: @modhash})
|
72
74
|
end
|
73
75
|
|
74
76
|
# Subscribe to a subreddit
|
@@ -78,7 +80,6 @@ module Snoo
|
|
78
80
|
# @return (see #clear_sessions)
|
79
81
|
def subscribe subreddit, action = "sub"
|
80
82
|
logged_in?
|
81
|
-
raise ArgumentError, "action must be one of sub, unsub; is #{action}" unless %w{sub unsub}.include?(action)
|
82
83
|
post('/api/subscribe', body: {action: action, sr: subreddit, uh: @modhash})
|
83
84
|
end
|
84
85
|
|
@@ -119,8 +120,6 @@ module Snoo
|
|
119
120
|
# @return (see #clear_sessions)
|
120
121
|
def my_reddits opts = {}
|
121
122
|
logged_in?
|
122
|
-
raise ArgumentError, "condition must be one of subscriber, contributor, moderator; is #{opts[:condition]}" unless %w{subscriber contributor moderator}.include?(opts[:condition]) or opts[:condition].nil?
|
123
|
-
raise ArgumentError, "limit must be within 1..100; is #{opts[:limit]}" unless (1..100).include?(opts[:limit]) or opts[:limit].nil?
|
124
123
|
url = "/reddits/mine/%s.json" % (opts[:condition] if opts[:condition])
|
125
124
|
opts.delete :condition
|
126
125
|
query = opts
|
@@ -136,9 +135,6 @@ module Snoo
|
|
136
135
|
# @option opts [String] :before Return subreddits *before* this id.
|
137
136
|
# @return (see #clear_sessions)
|
138
137
|
def get_reddits opts = {}
|
139
|
-
raise ArgumentError, "condition must be one of popular, new, banned; is #{opts[:condition]}" unless %w{popular new banned}.include?(opts[:condition]) or opts[:condition].nil?
|
140
|
-
raise ArgumentError, "limit must be within 1..100; is #{opts[:limit]}" unless (1..100).include?(opts[:limit]) or opts[:limit].nil?
|
141
|
-
|
142
138
|
url = "/reddits/%s.json" % (opts[:condition] if opts[:condition])
|
143
139
|
opts.delete :condition
|
144
140
|
query = opts
|
@@ -155,8 +151,6 @@ module Snoo
|
|
155
151
|
# @option opts [String] :before Return subreddits *before* this id.
|
156
152
|
# @return (see #clear_sessions)
|
157
153
|
def search_reddits q, opts = {}
|
158
|
-
raise ArgumentError, "limit must be within 1..100; is #{opts[:limit]}" unless (1..100).include?(opts[:limit]) or opts[:limit].nil?
|
159
|
-
|
160
154
|
query = {q: q}
|
161
155
|
query.merge! opts
|
162
156
|
get('/reddits/search.json', query: query)
|
data/lib/snoo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.
|
4
|
+
version: 0.1.0.pre.2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|