redd 0.7.2 → 0.7.3

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: 72469adb099523bf28cc5d24e451a1662dbd83e5
4
- data.tar.gz: cc3cee620ae503607895c958743aa7ea7106d141
3
+ metadata.gz: 41d1b17c6950acfb37e70062b5ef884ccd842b48
4
+ data.tar.gz: f5d053a918a167558cb3b4d22bf0939d42fb8f5e
5
5
  SHA512:
6
- metadata.gz: 3cc603ceacd925867753441e49ff737da23f4375b8d92401dc4ef90f7e03f3bec5f23872e166080b27c990c631b2e35864e514940528a1d7a835da986312814b
7
- data.tar.gz: fb869857d619ba1a6484a9eeb16b0630d7b7695aae95e196ccf4a4fd6b2e2087d0b4499f4f31c4698bc7eafd6a88ee6daf995752e08f1806bdd3233569578d69
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 body unless body.is_a?(Hash) || body.key?(:kind)
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.
@@ -21,7 +21,7 @@ module Redd
21
21
  @before = attributes[:before]
22
22
  @after = attributes[:after]
23
23
  attributes[:children].each do |child|
24
- self << client.object_from_body(child)
24
+ self << client.object_from_body(child) || child
25
25
  end
26
26
  end
27
27
  end
@@ -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
@@ -1,4 +1,4 @@
1
1
  module Redd # rubocop:disable Style/Documentation
2
2
  # The semantic version number.
3
- VERSION = "0.7.2"
3
+ VERSION = "0.7.3"
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.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avinash Dwarapu