redd 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -12
  3. data/lib/redd.rb +0 -12
  4. data/lib/redd/base.rb +10 -6
  5. data/lib/redd/client/authenticated.rb +2 -1
  6. data/lib/redd/client/authenticated/account.rb +2 -0
  7. data/lib/redd/client/authenticated/apps.rb +1 -0
  8. data/lib/redd/client/authenticated/flair.rb +33 -7
  9. data/lib/redd/client/authenticated/gold.rb +1 -0
  10. data/lib/redd/client/authenticated/links_comments.rb +86 -10
  11. data/lib/redd/client/authenticated/live.rb +1 -0
  12. data/lib/redd/client/authenticated/moderation.rb +65 -16
  13. data/lib/redd/client/authenticated/multis.rb +1 -1
  14. data/lib/redd/client/authenticated/private_messages.rb +50 -4
  15. data/lib/redd/client/authenticated/subreddits.rb +28 -0
  16. data/lib/redd/client/authenticated/users.rb +1 -1
  17. data/lib/redd/client/authenticated/wiki.rb +1 -1
  18. data/lib/redd/client/oauth2.rb +2 -2
  19. data/lib/redd/client/oauth2/authorization.rb +44 -11
  20. data/lib/redd/client/oauth2/identity.rb +4 -0
  21. data/lib/redd/client/unauthenticated/account.rb +13 -1
  22. data/lib/redd/client/unauthenticated/captcha.rb +7 -0
  23. data/lib/redd/client/unauthenticated/links_comments.rb +23 -4
  24. data/lib/redd/client/unauthenticated/listing.rb +43 -25
  25. data/lib/redd/client/unauthenticated/live.rb +1 -0
  26. data/lib/redd/client/unauthenticated/moderation.rb +9 -1
  27. data/lib/redd/client/unauthenticated/subreddits.rb +30 -0
  28. data/lib/redd/client/unauthenticated/utilities.rb +7 -4
  29. data/lib/redd/client/unauthenticated/wiki.rb +18 -4
  30. data/lib/redd/error.rb +5 -3
  31. data/lib/redd/oauth2_access.rb +21 -3
  32. data/lib/redd/object/more_comments.rb +1 -0
  33. data/lib/redd/object/private_message.rb +2 -1
  34. data/lib/redd/object/submission.rb +4 -0
  35. data/lib/redd/object/user.rb +1 -0
  36. data/lib/redd/response/raise_error.rb +2 -1
  37. data/lib/redd/thing/editable.rb +1 -0
  38. data/lib/redd/thing/hideable.rb +1 -0
  39. data/lib/redd/thing/inboxable.rb +1 -0
  40. data/lib/redd/thing/messageable.rb +2 -8
  41. data/lib/redd/thing/moderatable.rb +1 -0
  42. data/lib/redd/thing/reportable.rb +1 -0
  43. data/lib/redd/thing/saveable.rb +1 -0
  44. data/lib/redd/thing/voteable.rb +1 -1
  45. data/lib/redd/version.rb +1 -1
  46. data/spec/redd/client/unauthenticated_spec.rb +1 -1
  47. data/spec/redd/rate_limit_spec.rb +5 -5
  48. data/spec/redd_spec.rb +1 -1
  49. data/spec/spec_helper.rb +1 -1
  50. metadata +2 -3
  51. data/github/redd.png +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4553516b4e115c4b603eb9f378570473fed71770
4
- data.tar.gz: 37c75fce0d09befdf315579170c94915b2d8e11a
3
+ metadata.gz: 0d5b672f674cc48bf220c0a76b7074de9c509e13
4
+ data.tar.gz: 3fb2b44e36f0ed4f38c3633a4134c4cf85b0e48b
5
5
  SHA512:
6
- metadata.gz: ef8a7779756ce298e48cc1fedef4c8e8c903d8dd047c4e56ff523b8e2cee599c65afb1c5a241623918a02f0a87e5540e66978aa97c00c9ff79c05024f3bfdaa8
7
- data.tar.gz: f8e76f3d3377234c633f2240b3ae575f02d4b529cd7632426d98df69c6a91ca61b62b9ad4f81b0bedac5a7383e8d87ba07a7449c1e9776294cb77a4dececb0fd
6
+ metadata.gz: 884382cf0fa1c690f9743e30992fc58b09bc7310660057034505b8c66ccea813c8442dde09e610ca610a6a21122c62cde61fdb5f33abfcc81a15efc2fa63d366
7
+ data.tar.gz: a7db6250cbdf1a3e3b5613af36245d5fcb44eb824d340cfa025b920caea59d3d99d2cfdc30052762ac2c594a955eb710e9baecd5116a2a5a8e5cff91ebc63820
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  <p align="center">
2
- <img src="github/redd.png?raw=true" alt="redd"><br>
2
+ <img src="https://i.imgur.com/2JfE4M1.png" alt="redd"><br>
3
3
  <a href="http://badge.fury.io/rb/redd"><img src="https://badge.fury.io/rb/redd.svg" alt="Gem Version" height="18"></a>
4
4
  <a href="https://travis-ci.org/avidw/redd"><img src="https://travis-ci.org/avidw/redd.svg?branch=master" alt="Build Status"></a>
5
5
  </p>
6
6
 
7
- **redd** is an API wrapper for [reddit](http://reddit.com/dev/api) written in ruby that focuses on being *simple and extensible*.
7
+ **redd** is an API wrapper for [reddit](http://reddit.com/dev/api) written in ruby that focuses on being *simple and extensible*.
8
+ Check out the latest documentation on [RubyDoc](http://rubydoc.info/github/avidw/redd/master/frames).
8
9
 
9
10
  ---
10
11
 
@@ -36,20 +37,16 @@ Ruby and redd make creating reddit bots accessible and fun. To demonstrate, let'
36
37
  require "redd"
37
38
  #=> true
38
39
 
39
- r = Redd.client "HelloWorldBot", "hunter2"
40
+ r = Redd.client "HelloWorldBot", "hunter2",
41
+ user_agent: "HelloWorldBot v1.0 by /u/you"
40
42
  # => #<Redd::Client::Authenticated:0xY4D4y4D4y4dA ...
41
-
42
- # This is generally a good thing to do:
43
- r.user_agent = "HelloWorldBot v1.0 (Redd), written by /u/Mustermind"
44
43
  ```
45
44
 
46
45
  3. **Scouting**
47
46
  Redd has a really cool method similar to praw's `helpers.comment_stream` that "streams" comments to you while avoiding duplicates. You won't have to take care of rate-limiting either; Redd `sleep`s after requests to avoid ratelimit errors. If you want to write a rate limiting class yourself, take a look at `lib/redd/rate_limit.rb`
48
47
  ```ruby
49
48
  r.comment_stream "test" do |comment|
50
- if comment.body =~ /^Hello\?$/i
51
- comment.reply "World!"
52
- end
49
+ comment.reply "World!" if comment.body =~ /^Hello\?$/i
53
50
  end
54
51
  ```
55
52
 
@@ -58,9 +55,7 @@ Ruby and redd make creating reddit bots accessible and fun. To demonstrate, let'
58
55
  ```ruby
59
56
  begin
60
57
  r.comment_stream "test" do |comment|
61
- if comment.body =~ /^Hello\?$/i
62
- comment.reply "World!"
63
- end
58
+ comment.reply "World!" if comment.body =~ /^Hello\?$/i
64
59
  end
65
60
  rescue Redd::Error::RateLimited => e
66
61
  time_left = e.time
@@ -1,15 +1,3 @@
1
1
  require "redd/client/unauthenticated"
2
2
  require "redd/client/authenticated"
3
3
  require "redd/client/oauth2"
4
-
5
- module Redd
6
- def self.client(username = nil, password = nil, redirect_uri = nil, options = {})
7
- if redirect_uri
8
- Redd::Client::OAuth2.new(username, password, redirect_uri, options)
9
- elsif username && password
10
- Redd::Client::Authenticated.new_from_credentials(username, password, options)
11
- else
12
- Redd::Client::Unauthenticated.new
13
- end
14
- end
15
- end
@@ -6,22 +6,25 @@ module Redd
6
6
  include Memoizable
7
7
 
8
8
  # @!attribute [r] attributes
9
- # @return [Hash] A list of attributes returned by reddit for this object.
9
+ # @return [Hash] A list of attributes returned by reddit for this object.
10
10
  attr_reader :attributes
11
11
  alias_method :to_h, :attributes
12
12
 
13
13
  # @!attribute [r] client
14
- # @return The client instance used to make requests with this object.
14
+ # @return The client instance used to make requests with this object.
15
15
  attr_reader :client
16
16
 
17
- # Define and memoize the method that returns a key from the
18
- # attributes hash.
17
+ # Define and memoize the method that returns a key from the attributes
18
+ # hash.
19
+ #
19
20
  # @param [Symbol, String] attr The attribute to construct a method out of.
20
21
  def self.attr_reader(attr)
21
22
  define_attribute_method(attr)
22
23
  define_predicate_method(attr)
23
24
  end
24
25
 
26
+ # @param method [#to_sym] An attribute of the class
27
+ # @return The attribute requested
25
28
  def [](method)
26
29
  send(method.to_sym)
27
30
  rescue NoMethodError
@@ -37,13 +40,14 @@ module Redd
37
40
  @attributes[:kind] = attributes[:kind]
38
41
  end
39
42
 
40
- private
41
-
43
+ # Create a new method with the given name that accesses the @attributes.
42
44
  def self.define_attribute_method(method)
43
45
  define_method(method) { @attributes[method] }
44
46
  memoize method
45
47
  end
46
48
 
49
+ # Create a new method with the given name that accesses the @attributes.
50
+ # @return [Boolean]
47
51
  def self.define_predicate_method(method)
48
52
  define_method(:"#{method}?") { !!@attributes[method] }
49
53
  memoize :"#{method}?"
@@ -41,7 +41,8 @@ module Redd
41
41
  # @return [String] The returned modhash used when making requests.
42
42
  attr_reader :modhash
43
43
 
44
- def new_from_credentials(username, password, options = {})
44
+ def self.new_from_credentials(username, password, options = {})
45
+ @username = username
45
46
  Redd::Client::Unauthenticated.new.login(username, password, options)
46
47
  end
47
48
 
@@ -1,7 +1,9 @@
1
1
  module Redd
2
2
  module Client
3
3
  class Authenticated
4
+ # Methods to manage the logged-in user
4
5
  module Account
6
+ # @return [Redd::Object::User] The logged-in user.
5
7
  def me
6
8
  object_from_response :get, "/api/me.json"
7
9
  end
@@ -1,6 +1,7 @@
1
1
  module Redd
2
2
  module Client
3
3
  class Authenticated
4
+ # Methods to interact with OAuth2 Apps
4
5
  module Apps
5
6
  # Low-Priority
6
7
  #
@@ -1,7 +1,22 @@
1
1
  module Redd
2
2
  module Client
3
3
  class Authenticated
4
+ # Methods to interact with link and user flairs.
4
5
  module Flair
6
+ # Get a list of everbody on the subreddit with a user flair.
7
+ #
8
+ # @param subreddit [Redd::Object::Subreddit, String] The subreddit to
9
+ # find the users in.
10
+ # @param params [Hash] A list of params to send with the request.
11
+ # @option params [String] :after Return results after the given
12
+ # fullname.
13
+ # @option params [String] :before Return results before the given
14
+ # fullname.
15
+ # @option params [Integer] :count (0) The number of items already seen
16
+ # in the listing.
17
+ # @option params [1..1000] :limit (25) The maximum number of things to
18
+ # return.
19
+ # @return [Array<Hash>] An array of users.
5
20
  def get_flair_list(subreddit, params = {})
6
21
  name = extract_attribute(subreddit, :display_name)
7
22
 
@@ -11,21 +26,32 @@ module Redd
11
26
  get(path, params)[:users]
12
27
  end
13
28
 
14
- # @see http://ruby-doc.org/core-1.9.3/String.html#method-i-casecmp
29
+ # Get the flair of a user.
30
+ #
31
+ # @param subreddit [Redd::Object::Subreddit, String] The subreddit to
32
+ # find the user in.
33
+ # @param user [Redd::Object::User, String] The user to find.
34
+ # @return [Hash, nil] Flair info about the user or nil if nobody was
35
+ # found.
15
36
  def get_flair(subreddit, user)
37
+ display_name = extract_attribute(subreddit, :display_name)
16
38
  username = extract_attribute(user, :name)
17
39
  options = {name: username}
18
40
 
19
- flair = get_flair_list(subreddit, options).first
41
+ flair = get_flair_list(display_name, options).first
20
42
  flair if flair[:user].casecmp(username.downcase) == 0
21
43
  end
22
44
 
45
+ # Set the flair of a user or link.
46
+ # @param subreddit [Redd::Object::Subreddit, String] The subreddit to
47
+ # find the user in.
48
+ # @param user_or_link [Redd::Object::Subreddit, Redd::Object::User]
49
+ # The user or link to set the flair to.
50
+ # @param text [String] The text to set the flair to.
51
+ # @param css_class [String] The css_class of the flair.
23
52
  def set_flair(subreddit, user_or_link, text = "", css_class = "")
24
53
  name = extract_attribute(subreddit, :display_name)
25
-
26
- path = "/api/flair"
27
- path = path.prepend("/r/#{name}")
28
- params = {api_type: "json", text: text, css_class: css_class}
54
+ path = "/r/#{name}/api/flair"
29
55
 
30
56
  case user_or_link
31
57
  when Redd::Object::User
@@ -36,7 +62,7 @@ module Redd
36
62
  fail "You should provide a User or Submission object."
37
63
  end
38
64
 
39
- post path, params
65
+ post path, api_type: "json", text: text, css_class: css_class
40
66
  end
41
67
  end
42
68
  end
@@ -1,6 +1,7 @@
1
1
  module Redd
2
2
  module Client
3
3
  class Authenticated
4
+ # Methods to gild a user, link or comment
4
5
  module Gold
5
6
  # Low-Priority
6
7
  #
@@ -1,17 +1,36 @@
1
1
  module Redd
2
2
  module Client
3
3
  class Authenticated
4
+ # Methods to deal with comments and links
4
5
  module LinksComments
6
+ # Submit a link or a text post to a subreddit.
7
+ #
8
+ # @param title [String] The title of the submission.
9
+ # @param kind [:self, :link] The type of submission to make.
10
+ # @param text_or_url [String] The url of the post if :link or the
11
+ # content of the post if :text
12
+ # @param subreddit [Redd::Object::Submission, String] The subreddit
13
+ # to submit to.
14
+ # @param captcha [String] A possible captcha result to send if one
15
+ # is required.
16
+ # @param identifier [String] The identifier for the captcha if one
17
+ # is required.
18
+ # @param options [Hash] A hash of additional options to send.
19
+ # @option options [Boolean] :resubmit (false) Whether to post a link
20
+ # to a subreddit despite it having been posted there before.
21
+ # @option options [Boolean] :resubmit (false) Whether to automatically
22
+ # save the post to the user's account after posting.
5
23
  def submit(
6
- title, kind, text_or_url, captcha = nil, identifier = nil,
24
+ title, kind, text_or_url, subreddit, captcha = nil, identifier = nil,
7
25
  options = {}
8
26
  )
9
- # Set required parameters
27
+
10
28
  params = {
11
29
  api_type: "json", extension: "json", title: title, kind: kind
12
30
  }
31
+ sr_name = extract_attribute(subreddit, :display_name)
32
+ params << {sr: sr_name}
13
33
 
14
- # Set url or selftext depending on kind
15
34
  case kind.to_sym
16
35
  when :self
17
36
  params[:text] = text_or_url
@@ -19,16 +38,18 @@ module Redd
19
38
  params[:url] = text_or_url
20
39
  end
21
40
 
22
- # Optional captcha
23
41
  params << {captcha: captcha, iden: identifier} if captcha
24
-
25
- # Fill in the rest of the options
26
42
  params << options
27
43
 
28
44
  post "/api/submit", params
29
45
  end
30
46
 
31
- # @todo return the edited object.
47
+ # Add a comment to a link, reply to a comment or reply to a message.
48
+ # Bit of an all-purpose method, this one.
49
+ #
50
+ # @param thing [Redd::Object::Submission, Redd::Object::Comment,
51
+ # Redd::Object::PrivateMessage, String] A thing to add a comment to.
52
+ # @param text [String] The text to comment.
32
53
  def add_comment(thing, text)
33
54
  fullname = extract_fullname(thing)
34
55
  post "/api/comment", api_type: "json", text: text, thing_id: fullname
@@ -36,33 +57,54 @@ module Redd
36
57
 
37
58
  alias_method :reply, :add_comment
38
59
 
60
+ # Delete a thing.
61
+ #
62
+ # @param thing [Redd::Object::Submission, Redd::Object::Comment,
63
+ # String] A thing to delete.
39
64
  def delete(thing)
40
65
  fullname = extract_fullname(thing)
41
66
  post "/api/del", id: fullname
42
67
  end
43
68
 
44
- # @todo return the edited object.
69
+ # Edit a thing.
70
+ #
71
+ # @param thing [Redd::Object::Submission, Redd::Object::Comment,
72
+ # String] A thing to delete.
73
+ # @param text [String] The new text.
45
74
  def edit(thing, text)
46
75
  fullname = extract_fullname(thing)
47
- post "/api/editusertext",
48
- api_type: "json", text: text, thing_id: fullname
76
+ post "/api/editusertext", api_type: "json",
77
+ thing_id: fullname,
78
+ text: text
49
79
  end
50
80
 
81
+ # Hide a link from the logged-in user.
82
+ #
83
+ # @param thing [Redd::Object::Submission, String] A link to hide.
51
84
  def hide(thing)
52
85
  fullname = extract_fullname(thing)
53
86
  post "/api/hide", id: fullname
54
87
  end
55
88
 
89
+ # Unhide a previously hidden link.
90
+ #
91
+ # @param thing [Redd::Object::Submission, String] A link to show.
56
92
  def unhide(thing)
57
93
  fullname = extract_fullname(thing)
58
94
  post "/api/unhide", id: fullname
59
95
  end
60
96
 
97
+ # Mark a link as "NSFW" (Not Suitable For Work)
98
+ #
99
+ # @param thing [Redd::Object::Submission, String] A link to mark.
61
100
  def mark_as_nsfw(thing)
62
101
  fullname = extract_fullname(thing)
63
102
  post "/api/marknsfw", id: fullname
64
103
  end
65
104
 
105
+ # Remove the NSFW label from the link.
106
+ #
107
+ # @param thing [Redd::Object::Submission, String] A link to mark.
66
108
  def unmark_as_nsfw(thing)
67
109
  fullname = extract_fullname(thing)
68
110
  post "/api/unmarknsfw", id: fullname
@@ -70,11 +112,20 @@ module Redd
70
112
 
71
113
  alias_method :mark_as_safe, :unmark_as_nsfw
72
114
 
115
+ # Report the link or comment to the subreddit moderators.
116
+ #
117
+ # @param thing [Redd::Object::Submission, Redd::Object::Comment,
118
+ # String] A link to report.
73
119
  def report(thing)
74
120
  fullname = extract_fullname(thing)
75
121
  post "/api/report", id: fullname
76
122
  end
77
123
 
124
+ # Save a link or comment (if gilded) to the user's account.
125
+ #
126
+ # @param thing [Redd::Object::Submission, Redd::Object::Comment,
127
+ # String] A link to save.
128
+ # @param category [String] A category to save to (if gilded).
78
129
  def save(thing, category = nil)
79
130
  fullname = extract_fullname(thing)
80
131
  params = {id: fullname}
@@ -82,19 +133,38 @@ module Redd
82
133
  post "/api/save", params
83
134
  end
84
135
 
136
+ # Remove the link or comment from the user's saved links.
137
+ #
138
+ # @param thing [Redd::Object::Submission, Redd::Object::Comment,
139
+ # String] A link to unsave.
85
140
  def unsave(thing)
86
141
  fullname = extract_fullname(thing)
87
142
  post "/api/unsave", id: fullname
88
143
  end
89
144
 
145
+ # Upvote the thing.
146
+ #
147
+ # @param thing [Redd::Object::Submission, Redd::Object::Comment,
148
+ # String] A link or comment to upvote.
149
+ # @see #vote
90
150
  def upvote(thing)
91
151
  vote(thing, 1)
92
152
  end
93
153
 
154
+ # Downvote the thing.
155
+ #
156
+ # @param thing [Redd::Object::Submission, Redd::Object::Comment,
157
+ # String] A link or comment to downvote.
158
+ # @see #vote
94
159
  def downvote(thing)
95
160
  vote(thing, -1)
96
161
  end
97
162
 
163
+ # Clear the user's vote on the thing.
164
+ #
165
+ # @param thing [Redd::Object::Submission, Redd::Object::Comment,
166
+ # String] A link or comment to remove the vote on.
167
+ # @see #vote
98
168
  def unvote(thing)
99
169
  vote(thing, 0)
100
170
  end
@@ -103,6 +173,12 @@ module Redd
103
173
 
104
174
  private
105
175
 
176
+ # Set a vote on the thing.
177
+ #
178
+ # @param thing [Redd::Object::Submission, Redd::Object::Comment,
179
+ # String] A link or comment to set a vote on.
180
+ # @note Votes must be cast by humans only! Your script can proxy a
181
+ # user's actions, but it cannot decide what to vote.
106
182
  def vote(thing, direction)
107
183
  fullname = extract_fullname(thing)
108
184
  post "/api/vote", id: fullname, dir: direction
@@ -1,6 +1,7 @@
1
1
  module Redd
2
2
  module Client
3
3
  class Authenticated
4
+ # Methods to interact with /r/live threads
4
5
  module Live
5
6
  # Low-priority
6
7
  #
@@ -1,69 +1,118 @@
1
1
  module Redd
2
2
  module Client
3
3
  class Authenticated
4
+ # Methods for moderating subreddits
4
5
  module Moderation
6
+ # Approve a submission.
7
+ # @param thing [Redd::Object::Submission] The link to approve.
5
8
  def approve(thing)
6
9
  fullname = extract_fullname(thing)
7
10
  post "/api/approve", id: fullname
8
11
  end
9
12
 
13
+ # Remove a submission.
14
+ # @param thing [Redd::Object::Submission] The link to remove.
10
15
  def remove(thing)
11
16
  fullname = extract_fullname(thing)
12
17
  post "/api/remove", id: fullname
13
18
  end
14
19
 
20
+ # Distinguish a link or comment with a sigil to show that it has
21
+ # been created by a moderator.
22
+ #
23
+ # @param thing [Redd::Object::Submission, Redd::Object::Comment]
24
+ # The link or comment to distinguish.
25
+ # @param how [:yes, :no, :admin, :special] How to distinguish the
26
+ # thing.
15
27
  def distinguish(thing, how = :yes)
16
28
  fullname = extract_fullname(thing)
17
29
  post "/api/distinguish", api_type: "json", id: fullname, how: how
18
30
  end
19
31
 
32
+ # Remove the sigil that shows a thing was created by a moderator.
33
+ # @param thing [Redd::Object::Submission, Redd::Object::Comment]
34
+ # The link or comment to undistinguish.
20
35
  def undistinguish(thing)
21
36
  distinguish(thing, :no)
22
37
  end
23
38
 
39
+ # Accept a moderator invite from a subreddit.
40
+ # @param subreddit [Redd::Object::Subreddit] The subreddit to accept
41
+ # the invitation from.
24
42
  def accept_moderator_invite(subreddit)
25
43
  name = extract_attribute(subreddit, :display_name)
26
44
  post "/r/#{name}/api/accept_moderator_invite", api_type: "json"
27
45
  end
28
46
 
47
+ # Stop being a contributor of the subreddit.
48
+ # @param subreddit [Redd::Object::Subreddit] The subreddit to stop
49
+ # being a contributor of.
29
50
  def leave_contributor_status(subreddit)
30
51
  fullname = extract_fullname(subreddit)
31
52
  post "/api/leavecontributor", id: fullname
32
53
  end
33
54
 
55
+ # Stop being a moderator of the subreddit.
56
+ # @param subreddit [Redd::Object::Subreddit] The subreddit to stop
57
+ # being a moderator of.
34
58
  def leave_moderator_status(subreddit)
35
59
  fullname = extract_fullname(subreddit)
36
60
  post "/api/leavemoderator", id: fullname
37
61
  end
38
62
 
63
+ # Stop getting any moderator-related reports on the thing.
64
+ # @param thing [Redd::Object::Submission, Redd::Object::Comment]
65
+ # The thing to stop getting reports on.
39
66
  def ignore_reports(thing)
40
- fullname = extract_fullname(subreddit)
67
+ fullname = extract_fullname(thing)
41
68
  post "/api/ignore_reports", id: fullname
42
69
  end
43
70
 
71
+ # Start getting moderator-related reports on the thing again.
72
+ # @param thing [Redd::Object::Submission, Redd::Object::Comment]
73
+ # The thing to start getting reports on.
44
74
  def unignore_reports(thing)
45
- fullname = extract_fullname(subreddit)
75
+ fullname = extract_fullname(thing)
46
76
  post "/api/unignore_reports", id: fullname
47
77
  end
48
78
 
49
- def get_reports(*args)
50
- get_submissions(:reports, *args)
51
- end
52
-
53
- def get_spam(*args)
54
- get_submissions(:spam, *args)
55
- end
56
-
57
- def get_modqueue(*args)
58
- get_submissions(:modqueue, *args)
59
- end
60
-
61
- def get_unmoderated(*args)
62
- get_submissions(:unmoderated, *args)
79
+ # @!method get_reports
80
+ # @!method get_spam
81
+ # @!method get_modqueue
82
+ # @!method get_unmoderated
83
+ #
84
+ # Get the appropriate listing.
85
+ # @param subreddit [Redd::Object::Subreddit] The subreddit to query.
86
+ # @param params [Hash] A list of params to send with the request.
87
+ #
88
+ # @see #get_submissions
89
+ %w(reports spam modqueue unmoderated).each do |sort|
90
+ define_method :"get_#{sort}" do |subreddit = nil, params = {}|
91
+ get_submissions(sort, subreddit, params)
92
+ end
63
93
  end
64
94
 
65
95
  private
66
96
 
97
+ # Get a listing to moderator-related subreddits.
98
+ #
99
+ # @param type [:reports, :spam, :modqueue, :unmoderated] How the
100
+ # results are sorted.
101
+ # @param subreddit [Redd::Object::Subreddit, String] The subreddit to
102
+ # query.
103
+ # @param params [Hash] A list of params to send with the request.
104
+ # @option params [String] :after Return results after the given
105
+ # fullname.
106
+ # @option params [String] :before Return results before the given
107
+ # fullname.
108
+ # @option params [Integer] :count (0) The number of items already seen
109
+ # in the listing.
110
+ # @option params [1..100] :limit (25) The maximum number of things to
111
+ # return.
112
+ # @option params :location No idea what this does.
113
+ # @option params [:links, :comments] :only The type of things to show.
114
+ # @return [Redd::Object::Listing] A listing of submissions or comments.
115
+ #
67
116
  def get_submissions(type, subreddit = nil, params = {})
68
117
  subreddit_name = extract_attribute(subreddit, :display_name)
69
118
  path = "/about/#{type}.json"