redd 0.7.8 → 0.7.9
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.
- checksums.yaml +4 -4
- data/.gitignore +34 -34
- data/.rspec +3 -3
- data/.rubocop.yml +5 -5
- data/.travis.yml +9 -9
- data/LICENSE.md +22 -22
- data/README.md +143 -143
- data/Rakefile +5 -5
- data/RedditKit.LICENSE.md +8 -8
- data/lib/redd.rb +50 -50
- data/lib/redd/access.rb +76 -76
- data/lib/redd/clients/base.rb +181 -181
- data/lib/redd/clients/base/account.rb +20 -20
- data/lib/redd/clients/base/identity.rb +22 -22
- data/lib/redd/clients/base/none.rb +27 -27
- data/lib/redd/clients/base/privatemessages.rb +33 -33
- data/lib/redd/clients/base/read.rb +113 -113
- data/lib/redd/clients/base/stream.rb +81 -81
- data/lib/redd/clients/base/submit.rb +19 -19
- data/lib/redd/clients/base/utilities.rb +104 -104
- data/lib/redd/clients/base/wikiread.rb +33 -33
- data/lib/redd/clients/installed.rb +56 -56
- data/lib/redd/clients/script.rb +41 -41
- data/lib/redd/clients/userless.rb +32 -32
- data/lib/redd/clients/web.rb +58 -58
- data/lib/redd/error.rb +151 -151
- data/lib/redd/objects/base.rb +39 -39
- data/lib/redd/objects/comment.rb +22 -22
- data/lib/redd/objects/labeled_multi.rb +13 -13
- data/lib/redd/objects/listing.rb +29 -29
- data/lib/redd/objects/more_comments.rb +11 -10
- data/lib/redd/objects/private_message.rb +28 -28
- data/lib/redd/objects/submission.rb +139 -139
- data/lib/redd/objects/subreddit.rb +330 -319
- data/lib/redd/objects/thing.rb +26 -26
- data/lib/redd/objects/thing/editable.rb +22 -22
- data/lib/redd/objects/thing/hideable.rb +18 -18
- data/lib/redd/objects/thing/inboxable.rb +25 -25
- data/lib/redd/objects/thing/messageable.rb +34 -34
- data/lib/redd/objects/thing/moderatable.rb +43 -43
- data/lib/redd/objects/thing/refreshable.rb +14 -14
- data/lib/redd/objects/thing/saveable.rb +21 -21
- data/lib/redd/objects/thing/votable.rb +33 -33
- data/lib/redd/objects/user.rb +52 -52
- data/lib/redd/objects/wiki_page.rb +15 -15
- data/lib/redd/rate_limit.rb +88 -88
- data/lib/redd/response/parse_json.rb +18 -18
- data/lib/redd/response/raise_error.rb +16 -16
- data/lib/redd/version.rb +4 -4
- data/redd.gemspec +31 -31
- data/spec/redd/objects/base_spec.rb +1 -1
- data/spec/redd/response/raise_error_spec.rb +11 -11
- data/spec/redd_spec.rb +5 -5
- data/spec/spec_helper.rb +71 -71
- metadata +21 -21
data/lib/redd/objects/thing.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
require_relative "base"
|
2
|
-
|
3
|
-
module Redd
|
4
|
-
module Objects
|
5
|
-
# A reddit thing.
|
6
|
-
# @see http://www.reddit.com/dev/api#fullnames
|
7
|
-
class Thing < Base
|
8
|
-
# Load up all the possible mixins for the thing.
|
9
|
-
Dir[File.join(File.dirname(__FILE__), "thing", "*.rb")].each do |file|
|
10
|
-
require(file)
|
11
|
-
end
|
12
|
-
|
13
|
-
# Check for equality.
|
14
|
-
# @param other The other object.
|
15
|
-
# @return [Boolean]
|
16
|
-
def ==(other)
|
17
|
-
other.is_a?(Thing) && fullname == other.fullname
|
18
|
-
end
|
19
|
-
|
20
|
-
# @return [String] The fullname of the thing.
|
21
|
-
def fullname
|
22
|
-
self[:name] || "#{kind}_#{id}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
module Redd
|
4
|
+
module Objects
|
5
|
+
# A reddit thing.
|
6
|
+
# @see http://www.reddit.com/dev/api#fullnames
|
7
|
+
class Thing < Base
|
8
|
+
# Load up all the possible mixins for the thing.
|
9
|
+
Dir[File.join(File.dirname(__FILE__), "thing", "*.rb")].each do |file|
|
10
|
+
require(file)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Check for equality.
|
14
|
+
# @param other The other object.
|
15
|
+
# @return [Boolean]
|
16
|
+
def ==(other)
|
17
|
+
other.is_a?(Thing) && fullname == other.fullname
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [String] The fullname of the thing.
|
21
|
+
def fullname
|
22
|
+
self[:name] || "#{kind}_#{id}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,22 +1,22 @@
|
|
1
|
-
module Redd
|
2
|
-
module Objects
|
3
|
-
class Thing
|
4
|
-
# Things that can be edited and deleted.
|
5
|
-
module Editable
|
6
|
-
# Edit a thing.
|
7
|
-
# @param text [String] The new text.
|
8
|
-
# @return [Thing] The edited thing.
|
9
|
-
def edit(text)
|
10
|
-
post("/api/editusertext", thing_id: fullname, text: text)
|
11
|
-
self[(self.is_a?(Submission) ? :selftext : :body)] = text
|
12
|
-
self
|
13
|
-
end
|
14
|
-
|
15
|
-
# Delete the thing
|
16
|
-
def delete!
|
17
|
-
post("/api/del", id: fullname)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
1
|
+
module Redd
|
2
|
+
module Objects
|
3
|
+
class Thing
|
4
|
+
# Things that can be edited and deleted.
|
5
|
+
module Editable
|
6
|
+
# Edit a thing.
|
7
|
+
# @param text [String] The new text.
|
8
|
+
# @return [Thing] The edited thing.
|
9
|
+
def edit(text)
|
10
|
+
post("/api/editusertext", thing_id: fullname, text: text)
|
11
|
+
self[(self.is_a?(Submission) ? :selftext : :body)] = text
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
# Delete the thing
|
16
|
+
def delete!
|
17
|
+
post("/api/del", id: fullname)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
module Redd
|
2
|
-
module Objects
|
3
|
-
class Thing
|
4
|
-
# Things that can be hidden from the user.
|
5
|
-
module Hideable
|
6
|
-
# Hide a link from the user.
|
7
|
-
def hide
|
8
|
-
post("/api/hide", id: fullname)
|
9
|
-
end
|
10
|
-
|
11
|
-
# Unhide a previously hidden link.
|
12
|
-
def unhide
|
13
|
-
post("/api/unhide", id: fullname)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
1
|
+
module Redd
|
2
|
+
module Objects
|
3
|
+
class Thing
|
4
|
+
# Things that can be hidden from the user.
|
5
|
+
module Hideable
|
6
|
+
# Hide a link from the user.
|
7
|
+
def hide
|
8
|
+
post("/api/hide", id: fullname)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Unhide a previously hidden link.
|
12
|
+
def unhide
|
13
|
+
post("/api/unhide", id: fullname)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
module Redd
|
2
|
-
module Objects
|
3
|
-
class Thing
|
4
|
-
# Things that can be sent to a user's inbox.
|
5
|
-
module Inboxable
|
6
|
-
# Mark this thing as read.
|
7
|
-
def mark_as_read
|
8
|
-
post("/api/read_message", id: fullname)
|
9
|
-
end
|
10
|
-
|
11
|
-
# Mark one or more messages as unread.
|
12
|
-
def mark_as_unread
|
13
|
-
post("/api/unread_message", id: fullname)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Reply to the thing.
|
17
|
-
# @param text [String] The text to comment.
|
18
|
-
# @return [Objects::Comment, Objects::PrivateMessage] The reply.
|
19
|
-
def reply(text)
|
20
|
-
client.add_comment(self, text)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
module Redd
|
2
|
+
module Objects
|
3
|
+
class Thing
|
4
|
+
# Things that can be sent to a user's inbox.
|
5
|
+
module Inboxable
|
6
|
+
# Mark this thing as read.
|
7
|
+
def mark_as_read
|
8
|
+
post("/api/read_message", id: fullname)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Mark one or more messages as unread.
|
12
|
+
def mark_as_unread
|
13
|
+
post("/api/unread_message", id: fullname)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Reply to the thing.
|
17
|
+
# @param text [String] The text to comment.
|
18
|
+
# @return [Objects::Comment, Objects::PrivateMessage] The reply.
|
19
|
+
def reply(text)
|
20
|
+
client.add_comment(self, text)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,34 +1,34 @@
|
|
1
|
-
module Redd
|
2
|
-
module Objects
|
3
|
-
class Thing
|
4
|
-
# Things that can be sent a message.
|
5
|
-
module Messageable
|
6
|
-
# Compose a message to a person or the moderators of a subreddit.
|
7
|
-
#
|
8
|
-
# @param [String] subject The subject of the message.
|
9
|
-
# @param [String] text The message text.
|
10
|
-
# @param [String] from_sr The subreddit to send the message on behalf
|
11
|
-
# of or nil if from the user.
|
12
|
-
# @param [String] captcha A possible captcha result to send if one
|
13
|
-
# is required.
|
14
|
-
# @param [String] identifier The identifier for the captcha if one
|
15
|
-
# is required.
|
16
|
-
def send_message(
|
17
|
-
subject, text, from_sr = nil, captcha = nil, identifier = nil
|
18
|
-
)
|
19
|
-
params = {subject: subject, text: text}
|
20
|
-
params.merge!(captcha: captcha, iden: identifier) if captcha
|
21
|
-
params[:from_sr] = client.property(from_sr, :display_name) if from_sr
|
22
|
-
params[:to] =
|
23
|
-
if respond_to?(:display_name)
|
24
|
-
"/r/#{self[:display_name]}"
|
25
|
-
else
|
26
|
-
self[:name]
|
27
|
-
end
|
28
|
-
|
29
|
-
post("/api/compose", params)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
module Redd
|
2
|
+
module Objects
|
3
|
+
class Thing
|
4
|
+
# Things that can be sent a message.
|
5
|
+
module Messageable
|
6
|
+
# Compose a message to a person or the moderators of a subreddit.
|
7
|
+
#
|
8
|
+
# @param [String] subject The subject of the message.
|
9
|
+
# @param [String] text The message text.
|
10
|
+
# @param [String] from_sr The subreddit to send the message on behalf
|
11
|
+
# of or nil if from the user.
|
12
|
+
# @param [String] captcha A possible captcha result to send if one
|
13
|
+
# is required.
|
14
|
+
# @param [String] identifier The identifier for the captcha if one
|
15
|
+
# is required.
|
16
|
+
def send_message(
|
17
|
+
subject, text, from_sr = nil, captcha = nil, identifier = nil
|
18
|
+
)
|
19
|
+
params = {subject: subject, text: text}
|
20
|
+
params.merge!(captcha: captcha, iden: identifier) if captcha
|
21
|
+
params[:from_sr] = client.property(from_sr, :display_name) if from_sr
|
22
|
+
params[:to] =
|
23
|
+
if respond_to?(:display_name)
|
24
|
+
"/r/#{self[:display_name]}"
|
25
|
+
else
|
26
|
+
self[:name]
|
27
|
+
end
|
28
|
+
|
29
|
+
post("/api/compose", params)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,43 +1,43 @@
|
|
1
|
-
module Redd
|
2
|
-
module Objects
|
3
|
-
class Thing
|
4
|
-
# Things that a moderator can manage.
|
5
|
-
module Moderatable
|
6
|
-
# Approve a submission.
|
7
|
-
def approve!
|
8
|
-
post("/api/approve", id: fullname)
|
9
|
-
end
|
10
|
-
|
11
|
-
# Remove a submission.
|
12
|
-
# @param [Boolean] spam Whether or not this item is removed due to it
|
13
|
-
# being spam.
|
14
|
-
def remove!(spam = false)
|
15
|
-
post("/api/remove", id: fullname, spam: spam)
|
16
|
-
end
|
17
|
-
|
18
|
-
# Distinguish a link or comment with a sigil to show that it has
|
19
|
-
# been created by a moderator.
|
20
|
-
# @param [:yes, :no, :admin, :special] how How to distinguish the
|
21
|
-
# thing.
|
22
|
-
def distinguish(how = :yes)
|
23
|
-
post("/api/distinguish", id: fullname, how: how)
|
24
|
-
end
|
25
|
-
|
26
|
-
# Remove the sigil that shows a thing was created by a moderator.
|
27
|
-
def undistinguish
|
28
|
-
distinguish(:no)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Stop getting any moderator-related reports on the thing.
|
32
|
-
def ignore_reports
|
33
|
-
post("/api/ignore_reports", id: fullname)
|
34
|
-
end
|
35
|
-
|
36
|
-
# Start getting moderator-related reports on the thing again.
|
37
|
-
def unignore_reports
|
38
|
-
post("/api/unignore_reports", id: fullname)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
1
|
+
module Redd
|
2
|
+
module Objects
|
3
|
+
class Thing
|
4
|
+
# Things that a moderator can manage.
|
5
|
+
module Moderatable
|
6
|
+
# Approve a submission.
|
7
|
+
def approve!
|
8
|
+
post("/api/approve", id: fullname)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Remove a submission.
|
12
|
+
# @param [Boolean] spam Whether or not this item is removed due to it
|
13
|
+
# being spam.
|
14
|
+
def remove!(spam = false)
|
15
|
+
post("/api/remove", id: fullname, spam: spam)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Distinguish a link or comment with a sigil to show that it has
|
19
|
+
# been created by a moderator.
|
20
|
+
# @param [:yes, :no, :admin, :special] how How to distinguish the
|
21
|
+
# thing.
|
22
|
+
def distinguish(how = :yes)
|
23
|
+
post("/api/distinguish", id: fullname, how: how)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Remove the sigil that shows a thing was created by a moderator.
|
27
|
+
def undistinguish
|
28
|
+
distinguish(:no)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Stop getting any moderator-related reports on the thing.
|
32
|
+
def ignore_reports
|
33
|
+
post("/api/ignore_reports", id: fullname)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Start getting moderator-related reports on the thing again.
|
37
|
+
def unignore_reports
|
38
|
+
post("/api/unignore_reports", id: fullname)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
module Redd
|
2
|
-
module Objects
|
3
|
-
class Thing
|
4
|
-
# Things that can be refreshed with the current data.
|
5
|
-
module Refreshable
|
6
|
-
# Refresh the thing.
|
7
|
-
def refresh!
|
8
|
-
body = get("/api/info", id: fullname).body[:data][:children][0]
|
9
|
-
deep_merge!(body[:data])
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
1
|
+
module Redd
|
2
|
+
module Objects
|
3
|
+
class Thing
|
4
|
+
# Things that can be refreshed with the current data.
|
5
|
+
module Refreshable
|
6
|
+
# Refresh the thing.
|
7
|
+
def refresh!
|
8
|
+
body = get("/api/info", id: fullname).body[:data][:children][0]
|
9
|
+
deep_merge!(body[:data])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
module Redd
|
2
|
-
module Objects
|
3
|
-
class Thing
|
4
|
-
# Things that can be saved to a user's account.
|
5
|
-
module Saveable
|
6
|
-
# Save a link or comment (if gilded) to the user's account.
|
7
|
-
# @param [String] category A category to save to (if gilded).
|
8
|
-
def save(category = nil)
|
9
|
-
params = {id: fullname}
|
10
|
-
params.merge!(category: category) if category
|
11
|
-
post("/api/save", params)
|
12
|
-
end
|
13
|
-
|
14
|
-
# Remove the link or comment from the user's saved links.
|
15
|
-
def unsave
|
16
|
-
post("/api/unsave", id: fullname)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
1
|
+
module Redd
|
2
|
+
module Objects
|
3
|
+
class Thing
|
4
|
+
# Things that can be saved to a user's account.
|
5
|
+
module Saveable
|
6
|
+
# Save a link or comment (if gilded) to the user's account.
|
7
|
+
# @param [String] category A category to save to (if gilded).
|
8
|
+
def save(category = nil)
|
9
|
+
params = {id: fullname}
|
10
|
+
params.merge!(category: category) if category
|
11
|
+
post("/api/save", params)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Remove the link or comment from the user's saved links.
|
15
|
+
def unsave
|
16
|
+
post("/api/unsave", id: fullname)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,33 +1,33 @@
|
|
1
|
-
module Redd
|
2
|
-
module Objects
|
3
|
-
class Thing
|
4
|
-
# Things that can be voted upon.
|
5
|
-
module Votable
|
6
|
-
# Upvote the thing.
|
7
|
-
def upvote
|
8
|
-
vote(1)
|
9
|
-
end
|
10
|
-
|
11
|
-
# Downvote the thing.
|
12
|
-
def downvote
|
13
|
-
vote(-1)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Remove your vote on the thing.
|
17
|
-
def clear_vote
|
18
|
-
vote(0)
|
19
|
-
end
|
20
|
-
alias_method :unvote, :clear_vote
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
# Send a vote.
|
25
|
-
# @param [-1, 0, 1] direction The direction to vote in.
|
26
|
-
def vote(direction)
|
27
|
-
post("/api/vote", id: fullname, dir: direction)
|
28
|
-
self[:ups] += direction
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
1
|
+
module Redd
|
2
|
+
module Objects
|
3
|
+
class Thing
|
4
|
+
# Things that can be voted upon.
|
5
|
+
module Votable
|
6
|
+
# Upvote the thing.
|
7
|
+
def upvote
|
8
|
+
vote(1)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Downvote the thing.
|
12
|
+
def downvote
|
13
|
+
vote(-1)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Remove your vote on the thing.
|
17
|
+
def clear_vote
|
18
|
+
vote(0)
|
19
|
+
end
|
20
|
+
alias_method :unvote, :clear_vote
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# Send a vote.
|
25
|
+
# @param [-1, 0, 1] direction The direction to vote in.
|
26
|
+
def vote(direction)
|
27
|
+
post("/api/vote", id: fullname, dir: direction)
|
28
|
+
self[:ups] += direction
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|