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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc908201324aea927202ad7e528f0fbf32ae56be
4
- data.tar.gz: 92b74d29e18b82bd9f378b5eb44f84bfac519c6f
3
+ metadata.gz: 48bf9a93a4b969191c7ca64548fb6a56e5b7fda2
4
+ data.tar.gz: 7423344e98a55f189dcd4fdae0c81c9cf88a2793
5
5
  SHA512:
6
- metadata.gz: c4c793e73a7d8a65722678da3069cc3affe66d14b19195283dfc9b6fdcc29b183e1e67ea673f0ed5f68b069515a41f7d2fd6e46bb8cb80c36c70a6db225bb9c0
7
- data.tar.gz: 69ba345a72d015d9e44a44c46de2ae26b57b4ff8474c48d270d4976caf1131f7d458ef184538f1108dd92f6e40547077d6a59bc1c0aec9ca3ef987cd99257639
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 "ruby", "~> 0.7.0"
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
- session_access = Access.from_json(session[:access])
47
- w.with(session_access) do |client|
48
- client.refresh_access! if session_access.expired?
49
- "Your username is #{client.me.name}"
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
 
@@ -19,7 +19,7 @@ module Redd
19
19
  # @param iden [String] The captcha identifier.
20
20
  # @return The url for the captcha image.
21
21
  def captcha_url(iden)
22
- "http://www.reddit.com/captcha/#{identifier}.png"
22
+ "http://www.reddit.com/captcha/#{iden}.png"
23
23
  end
24
24
  end
25
25
  end
@@ -13,6 +13,7 @@ module Redd
13
13
  attr_reader :redirect_uri
14
14
 
15
15
  # @param [Hash] options The options to create the client with.
16
+ # @see Base#initialize
16
17
  # @see Redd.it
17
18
  def initialize(client_id, redirect_uri, **options)
18
19
  @client_id = client_id
@@ -11,6 +11,7 @@ module Redd
11
11
  attr_reader :username
12
12
 
13
13
  # @param [Hash] options The options to create the client with.
14
+ # @see Base#initialize
14
15
  # @see Redd.it
15
16
  def initialize(client_id, secret, username, password, **options)
16
17
  @client_id = client_id
@@ -9,6 +9,7 @@ module Redd
9
9
  attr_reader :client_id
10
10
 
11
11
  # @param [Hash] options The options to create the client with.
12
+ # @see Base#initialize
12
13
  # @see Redd.it
13
14
  def initialize(client_id, secret, **options)
14
15
  @client_id = client_id
@@ -12,6 +12,7 @@ module Redd
12
12
  attr_reader :redirect_uri
13
13
 
14
14
  # @param [Hash] options The options to create the client with.
15
+ # @see Base#initialize
15
16
  # @see Redd.it
16
17
  def initialize(client_id, secret, redirect_uri, **options)
17
18
  @client_id = client_id
@@ -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(:get, "/r/#{display_name}/about/#{sort}", params)
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
@@ -37,7 +37,7 @@ module Redd
37
37
  ).each do |type|
38
38
  define_method :"get_#{type}" do |**params|
39
39
  client.request_object(
40
- :get, "/user/#{name}/#{type}.json",
40
+ :get, "/user/#{name}/#{type}.json", **params
41
41
  )
42
42
  end
43
43
  end
data/lib/redd/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Redd # rubocop:disable Style/Documentation
2
2
  # The semantic version number.
3
- VERSION = "0.7.0"
3
+ VERSION = "0.7.1"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avinash Dwarapu