redd 0.7.2 → 0.7.3
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/lib/redd/clients/base/utilities.rb +23 -1
- data/lib/redd/objects/listing.rb +1 -1
- data/lib/redd/objects/submission.rb +8 -8
- data/lib/redd/objects/thing/moderatable.rb +2 -2
- 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: 41d1b17c6950acfb37e70062b5ef884ccd842b48
|
4
|
+
data.tar.gz: f5d053a918a167558cb3b4d22bf0939d42fb8f5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57df8f09c68ab163d15c4589a2f268b3fd393c63d4afcb04977dd89842af88d6c0b4d84f2e76e35e289ca878430cfa4e810611c399714e3062c11ebdc6c423fd
|
7
|
+
data.tar.gz: 341a6eae53925c15d7a70fa07e241fdba578fc099c0c11d2e3a0b18c1e4bd59f4daf46d502e24fa664a9073221869edd0943776a8f7355d837a0049300f1dd8f
|
@@ -43,12 +43,34 @@ module Redd
|
|
43
43
|
# @param [Hash] body A JSON hash.
|
44
44
|
# @return [Objects::Thing, Objects::Listing]
|
45
45
|
def object_from_body(body)
|
46
|
-
return
|
46
|
+
return nil unless body.is_a?(Hash) && body.key?(:kind)
|
47
47
|
object = object_from_kind(body[:kind])
|
48
48
|
flat = flatten_body(body)
|
49
49
|
object.new(self, flat)
|
50
50
|
end
|
51
51
|
|
52
|
+
# @param [Objects::Submission, Objects::Comment] base The start of the
|
53
|
+
# comment tree.
|
54
|
+
# @author Bryce Boe (@bboe) in Python
|
55
|
+
# @return [Array<Objects::Comment, Objects::MoreComments>] A linear
|
56
|
+
# array of the submission's comments or the comments' replies.
|
57
|
+
def flat_comments(base)
|
58
|
+
meth = (base.is_a?(Objects::Submission) ? :comments : :replies)
|
59
|
+
stack = base.send(meth).dup
|
60
|
+
flattened = []
|
61
|
+
|
62
|
+
until stack.empty?
|
63
|
+
comment = stack.shift
|
64
|
+
if comment.is_a?(Objects::Comment)
|
65
|
+
replies = comment.replies
|
66
|
+
stack += replies if replies
|
67
|
+
end
|
68
|
+
flattened << comment
|
69
|
+
end
|
70
|
+
|
71
|
+
flattened
|
72
|
+
end
|
73
|
+
|
52
74
|
private
|
53
75
|
|
54
76
|
# Get a given property of a given object.
|
data/lib/redd/objects/listing.rb
CHANGED
@@ -25,6 +25,13 @@ module Redd
|
|
25
25
|
self[:gilded] > 0
|
26
26
|
end
|
27
27
|
|
28
|
+
# Reply to the thing.
|
29
|
+
# @param text [String] The text to comment.
|
30
|
+
# @return [Objects::Comment] The reply.
|
31
|
+
def add_comment(text)
|
32
|
+
client.add_comment(self, text)
|
33
|
+
end
|
34
|
+
|
28
35
|
# @return [Listing] The submission's comments.
|
29
36
|
# @todo Allow for various depths and contexts and what not. Maybe a
|
30
37
|
# get_comment method?
|
@@ -32,14 +39,7 @@ module Redd
|
|
32
39
|
refresh! unless @comments
|
33
40
|
@comments
|
34
41
|
end
|
35
|
-
|
36
|
-
# @return [Array<Comment, MoreComments>] A linear array of the
|
37
|
-
# submission's comments.
|
38
|
-
# @todo Somehow implement. Maybe a recursive method belonging to a
|
39
|
-
# CommentListing<Comment, MoreComments>?
|
40
|
-
def flat_comments
|
41
|
-
fail NotImplementedError
|
42
|
-
end
|
42
|
+
alias_method :replies, :comments
|
43
43
|
|
44
44
|
# Refresh the submission AND its comments.
|
45
45
|
# @return [Submission] The updated submission.
|
@@ -4,14 +4,14 @@ module Redd
|
|
4
4
|
# Things that a moderator can manage.
|
5
5
|
module Moderatable
|
6
6
|
# Approve a submission.
|
7
|
-
def approve
|
7
|
+
def approve!
|
8
8
|
post("/api/approve", id: fullname)
|
9
9
|
end
|
10
10
|
|
11
11
|
# Remove a submission.
|
12
12
|
# @param [Boolean] spam Whether or not this item is removed due to it
|
13
13
|
# being spam.
|
14
|
-
def remove(spam = false)
|
14
|
+
def remove!(spam = false)
|
15
15
|
post("/api/remove", id: fullname, spam: spam)
|
16
16
|
end
|
17
17
|
|
data/lib/redd/version.rb
CHANGED