redd 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -7
- data/lib/redd/clients/base/none.rb +1 -1
- data/lib/redd/clients/installed.rb +1 -0
- data/lib/redd/clients/script.rb +1 -0
- data/lib/redd/clients/userless.rb +1 -0
- data/lib/redd/clients/web.rb +1 -0
- data/lib/redd/objects/subreddit.rb +70 -1
- data/lib/redd/objects/user.rb +1 -1
- data/lib/redd/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48bf9a93a4b969191c7ca64548fb6a56e5b7fda2
|
4
|
+
data.tar.gz: 7423344e98a55f189dcd4fdae0c81c9cf88a2793
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e254c453af7d312d23d86404ba7ff6b18018d717052caf4a7be0aa7031f7e2ea90994275300397c13fb7fa7f538d4d75ca07221a4b9b7d76e037591884c2da1
|
7
|
+
data.tar.gz: bbf195d1261025bc0299e48b11bf8dbf2012b05395ac3d3fa94aa361ad76076097580260e9f1b8dcc2ff467e8734990e5a2ef2a2bff07b5a8320db8478816a84
|
data/README.md
CHANGED
@@ -11,10 +11,9 @@
|
|
11
11
|
|
12
12
|
#### Gemfile
|
13
13
|
```ruby
|
14
|
-
gem "
|
15
|
-
# if you're feeling adventurous
|
16
|
-
# gem "redd", github: "avidw/redd", branch: "oauth2"
|
14
|
+
gem "redd", "~> 0.7.0"
|
17
15
|
|
16
|
+
# Optional fast JSON parser.
|
18
17
|
gem "oj", platforms: :ruby
|
19
18
|
```
|
20
19
|
|
@@ -36,17 +35,33 @@ r.authorize!
|
|
36
35
|
|
37
36
|
```ruby
|
38
37
|
# Access
|
38
|
+
require "secure_random"
|
39
|
+
require "sinatra"
|
40
|
+
|
41
|
+
enable :sessions
|
42
|
+
|
43
|
+
get "/auth" do
|
44
|
+
state = SecureRandom.urlsafe_base64
|
45
|
+
session[:state] = state
|
46
|
+
redirect w.auth_url(state, %w(identity), :permanent)
|
47
|
+
end
|
48
|
+
|
39
49
|
get "/redirect" do
|
50
|
+
halt 500, "Your state doesn't match!" unless session[:state] == params[:state]
|
40
51
|
access = w.authorize!(params[:code])
|
41
52
|
session[:access] = access.to_json
|
42
53
|
redirect to("/name")
|
43
54
|
end
|
44
55
|
|
45
56
|
get "/name" do
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
57
|
+
if session[:access]
|
58
|
+
session_access = Redd::Access.from_json(session[:access])
|
59
|
+
w.with(session_access) do |client|
|
60
|
+
client.refresh_access! if session_access.expired?
|
61
|
+
"Your username is #{client.me.name}"
|
62
|
+
end
|
63
|
+
else
|
64
|
+
redirect to("/auth")
|
50
65
|
end
|
51
66
|
end
|
52
67
|
|
data/lib/redd/clients/script.rb
CHANGED
data/lib/redd/clients/web.rb
CHANGED
@@ -14,6 +14,8 @@ module Redd
|
|
14
14
|
alias_property :type, :subreddit_type
|
15
15
|
alias_property :times_gilded, :gilded
|
16
16
|
|
17
|
+
# @!group Stylesheets
|
18
|
+
|
17
19
|
# @return [String] The url for the subreddit's stylesheet.
|
18
20
|
def stylesheet_url
|
19
21
|
get("/r/#{display_name}/stylesheet").headers["location"]
|
@@ -24,6 +26,23 @@ module Redd
|
|
24
26
|
Faraday.get(stylesheet_url).body
|
25
27
|
end
|
26
28
|
|
29
|
+
# Edit the subreddit's stylesheet
|
30
|
+
#
|
31
|
+
# @param [String] contents The new CSS.
|
32
|
+
# @param [String] reason Why you modified the stylesheet.
|
33
|
+
# @author Takashi M (@beatak) and Avinash Dwarapu (@avidw)
|
34
|
+
# @note https://www.reddit.com/r/naut/about/stylesheet/ is a good place
|
35
|
+
# to test if you have an error.
|
36
|
+
def edit_stylesheet(contents, reason = nil)
|
37
|
+
params = {op: "save", stylesheet_contents: contents}
|
38
|
+
params[:reason] = reason if reason
|
39
|
+
post("/r/#{display_name}/api/subreddit_stylesheet", params)
|
40
|
+
end
|
41
|
+
|
42
|
+
# @!endgroup
|
43
|
+
|
44
|
+
# @!group Invites
|
45
|
+
|
27
46
|
# Accept a moderator invite from a subreddit.
|
28
47
|
def accept_moderator_invite!
|
29
48
|
post("/r/#{display_name}/api/accept_moderator_invite")
|
@@ -39,6 +58,10 @@ module Redd
|
|
39
58
|
post("/api/leavemoderator", id: fullname)
|
40
59
|
end
|
41
60
|
|
61
|
+
# @!endgroup
|
62
|
+
|
63
|
+
# @!group Flairs
|
64
|
+
|
42
65
|
# Get a list of everbody on the subreddit with a user flair.
|
43
66
|
#
|
44
67
|
# @param [Hash] params A list of params to send with the request.
|
@@ -94,6 +117,10 @@ module Redd
|
|
94
117
|
post("/r/#{display_name}/api/flair", text: text, css_class: css_class)
|
95
118
|
end
|
96
119
|
|
120
|
+
# @!endgroup
|
121
|
+
|
122
|
+
# @!group Listings
|
123
|
+
|
97
124
|
# @!method get_hot(**params)
|
98
125
|
# @!method get_new(**params)
|
99
126
|
# @!method get_top(**params)
|
@@ -144,9 +171,51 @@ module Redd
|
|
144
171
|
# @see https://www.reddit.com/dev/api#GET_about_{location}
|
145
172
|
%w(reports spam modqueue unmoderated edited).each do |sort|
|
146
173
|
define_method :"get_#{sort}" do |**params|
|
147
|
-
request_object(
|
174
|
+
client.request_object(
|
175
|
+
:get, "/r/#{display_name}/about/#{sort}", params
|
176
|
+
)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# @!endgroup
|
181
|
+
|
182
|
+
# @!group Moderator Settings
|
183
|
+
|
184
|
+
# @return [Objects::Base] The current settings of a subreddit.
|
185
|
+
def admin_about
|
186
|
+
client.request_object(:get, "/r/#{display_name}/about/edit.json")
|
187
|
+
end
|
188
|
+
|
189
|
+
# Edit the subreddit's settings
|
190
|
+
# @param [Hash] attributes The subreddit's new settings.
|
191
|
+
# @author Takashi M (@beatak) and Avinash Dwarapu (@avidw)
|
192
|
+
# @note This method may make additional requests if not all of the
|
193
|
+
# required attributes are provided.
|
194
|
+
# @see https://github.com/alaycock/MeetCal-bot/blob/master/serverInfo.conf
|
195
|
+
def admin_edit(attributes)
|
196
|
+
params = {sr: fullname}
|
197
|
+
required_attributes = %i(
|
198
|
+
allow_top collapse_deleted_comments comment_score_hide_mins
|
199
|
+
css_on_cname description exclude_banned_modqueue lang name over_18
|
200
|
+
public_description public_traffic show_cname_sidebar show_media
|
201
|
+
spam_comments spam_links spam_selfposts submit_link_label
|
202
|
+
submit_text submit_text_label title type wiki_edit_age
|
203
|
+
wiki_edit_karma wikimode header-title
|
204
|
+
)
|
205
|
+
|
206
|
+
if required_attributes.all? { |key| attributes.key?(key) }
|
207
|
+
params.merge!(attributes)
|
208
|
+
else
|
209
|
+
current = admin_about
|
210
|
+
current.delete(:kind)
|
211
|
+
complete = current.merge(attributes)
|
212
|
+
params.merge!(complete)
|
148
213
|
end
|
214
|
+
|
215
|
+
post("/api/site_admin", params)
|
149
216
|
end
|
217
|
+
|
218
|
+
# @!endgroup
|
150
219
|
end
|
151
220
|
end
|
152
221
|
end
|
data/lib/redd/objects/user.rb
CHANGED
data/lib/redd/version.rb
CHANGED