redd 0.6.1 → 0.6.2
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/README.md +3 -2
- data/lib/redd/client/unauthenticated/links_comments.rb +6 -21
- data/lib/redd/object/comment.rb +9 -2
- data/lib/redd/object/more_comments.rb +4 -0
- data/lib/redd/object/submission.rb +2 -0
- data/lib/redd/thing.rb +1 -1
- data/lib/redd/thing/commentable.rb +27 -0
- data/lib/redd/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1c9095dc0fc6208e07728e40a724e40a0c0a24d
|
4
|
+
data.tar.gz: 7a752d0341708cbd837e1ae23e486aaa6c29f468
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56bc149cb63a27a6bd6531f85a4ad56491dd888270cc70963d82cfd748445641e9d404bbea4cc0100dd673800d14fec1b5edcd5311e456ddf77854a271436574
|
7
|
+
data.tar.gz: 490cc65032031f6d0ed56b69eeef554773865b5503a47bae20ffea12bd8314b083ffbb43b537e8650a749b241e6f6b58721cb38968dc9b01c6cd3f07dbccbbd3
|
data/README.md
CHANGED
@@ -15,6 +15,7 @@
|
|
15
15
|
<a href="#getting-started">Getting Started</a> |
|
16
16
|
<a href="#oauth2">OAuth2</a> |
|
17
17
|
<a href="#extending-redd">Extending Redd</a> |
|
18
|
+
<a href="#contributing">Contributing</a> |
|
18
19
|
<a href="#supported-rubies">Supported Rubies</a> |
|
19
20
|
<a href="#copyright">Copyright</a>
|
20
21
|
</p>
|
@@ -217,8 +218,8 @@ Extending any ruby library, including redd is incredibly easy. Let's try this ou
|
|
217
218
|
Redd::Object::Comment.include(Gildable)
|
218
219
|
```
|
219
220
|
|
220
|
-
|
221
|
-
|
221
|
+
## Contributing
|
222
|
+
[Fork the repository](https://github.com/avidw/redd/fork), [create a pull request](https://github.com/avidw/redd/compare) and [go nuts](https://i.imgur.com/lz7hOlC.jpg).
|
222
223
|
|
223
224
|
## Supported Rubies
|
224
225
|
This gem aims to work on the following rubies:
|
@@ -6,13 +6,12 @@ module Redd
|
|
6
6
|
# @option params [String] :id The fullname of a thing.
|
7
7
|
# @option params [String] :url The url of a thing. If an id is also
|
8
8
|
# provided, the id will take precedence.
|
9
|
-
# @return [Redd::Object::
|
9
|
+
# @return [Redd::Object::Listing] Listing of the object or objects.
|
10
10
|
#
|
11
11
|
# @note Reddit does accept a subreddit, but with fullnames and urls, I
|
12
12
|
# assumed that was unnecessary.
|
13
13
|
def get_info(params = {})
|
14
|
-
|
15
|
-
object.first
|
14
|
+
object_from_response :get, "/api/info.json", params
|
16
15
|
end
|
17
16
|
|
18
17
|
# Get the comments for a submission.
|
@@ -36,38 +35,24 @@ module Redd
|
|
36
35
|
object_from_body(replies)
|
37
36
|
end
|
38
37
|
|
39
|
-
def
|
38
|
+
def expand_morecomments(morecomments, submission = nil)
|
40
39
|
parent_id = morecomments.parent_id
|
41
40
|
link_id =
|
42
41
|
if submission
|
43
|
-
submission
|
42
|
+
extract_fullname(submission)
|
44
43
|
elsif parent_id.start_with?("t3_")
|
45
44
|
parent_id
|
46
45
|
elsif parent_id.start_with?("t1_")
|
47
46
|
get_info(id: parent_id).first.link_id
|
48
47
|
end
|
49
48
|
|
50
|
-
response = post "/api/morechildren",
|
49
|
+
response = post "/api/morechildren.json",
|
51
50
|
api_type: "json",
|
52
51
|
link_id: link_id,
|
53
52
|
children: morecomments.children.join(",")
|
54
53
|
comments = response[:json][:data][:things]
|
55
54
|
|
56
|
-
|
57
|
-
comments.select! { |comment| comment[:kind] == "t1" }
|
58
|
-
|
59
|
-
comments.map do |comment|
|
60
|
-
object_from_body(
|
61
|
-
kind: comment[:kind],
|
62
|
-
data: {
|
63
|
-
parent_id: comment[:data][:parent],
|
64
|
-
body: comment[:data][:contentText],
|
65
|
-
body_html: comment[:data][:contentHTML],
|
66
|
-
link_id: comment[:data][:link],
|
67
|
-
name: comment[:data][:id]
|
68
|
-
}
|
69
|
-
)
|
70
|
-
end
|
55
|
+
object_from_body(kind: "Listing", data: {children: comments})
|
71
56
|
end
|
72
57
|
end
|
73
58
|
end
|
data/lib/redd/object/comment.rb
CHANGED
@@ -4,12 +4,14 @@ module Redd
|
|
4
4
|
module Object
|
5
5
|
# A comment made on links.
|
6
6
|
class Comment < Redd::Thing
|
7
|
+
require "redd/thing/commentable"
|
7
8
|
require "redd/thing/editable"
|
8
9
|
require "redd/thing/inboxable"
|
9
10
|
require "redd/thing/moderatable"
|
10
11
|
require "redd/thing/reportable"
|
11
12
|
require "redd/thing/voteable"
|
12
13
|
|
14
|
+
include Redd::Thing::Commentable
|
13
15
|
include Redd::Thing::Editable
|
14
16
|
include Redd::Thing::Inboxable
|
15
17
|
include Redd::Thing::Moderatable
|
@@ -43,14 +45,19 @@ module Redd
|
|
43
45
|
|
44
46
|
alias_method :reports_count, :num_reports
|
45
47
|
|
46
|
-
def
|
47
|
-
@
|
48
|
+
def comments
|
49
|
+
@comments ||= client.get_replies(self)
|
48
50
|
end
|
51
|
+
alias_method :replies, :comments
|
49
52
|
|
50
53
|
def subreddit
|
51
54
|
@subreddit ||= client.subreddit(@attributes[:subreddit])
|
52
55
|
end
|
53
56
|
|
57
|
+
def submission
|
58
|
+
@submission ||= client.get_info(id: link_id).first
|
59
|
+
end
|
60
|
+
|
54
61
|
def created
|
55
62
|
@created ||= Time.at(@attributes[:created_utc])
|
56
63
|
end
|
@@ -4,6 +4,7 @@ module Redd
|
|
4
4
|
module Object
|
5
5
|
# A submission made in a subreddit.
|
6
6
|
class Submission < Redd::Thing
|
7
|
+
require "redd/thing/commentable"
|
7
8
|
require "redd/thing/editable"
|
8
9
|
require "redd/thing/hideable"
|
9
10
|
require "redd/thing/moderatable"
|
@@ -11,6 +12,7 @@ module Redd
|
|
11
12
|
require "redd/thing/saveable"
|
12
13
|
require "redd/thing/voteable"
|
13
14
|
|
15
|
+
include Redd::Thing::Commentable
|
14
16
|
include Redd::Thing::Editable
|
15
17
|
include Redd::Thing::Hideable
|
16
18
|
include Redd::Thing::Moderatable
|
data/lib/redd/thing.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "redd/thing"
|
2
|
+
|
3
|
+
module Redd
|
4
|
+
class Thing
|
5
|
+
# A Redd::Object that can be commented on.
|
6
|
+
# This means that the comments could contain a MoreComments object.
|
7
|
+
module Commentable
|
8
|
+
def expand_morecomments
|
9
|
+
comments.things.map! do |comment|
|
10
|
+
if comment.is_a?(Redd::Object::MoreComments)
|
11
|
+
comment.expand.things
|
12
|
+
else
|
13
|
+
comment
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
comments.things.flatten!
|
18
|
+
end
|
19
|
+
|
20
|
+
def remove_morecomments
|
21
|
+
while comments.map { |c| c.class }.include? Redd::Object::MoreComments
|
22
|
+
expand_morecomments
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/redd/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Avinash Dwarapu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -223,6 +223,7 @@ files:
|
|
223
223
|
- lib/redd/response/parse_json.rb
|
224
224
|
- lib/redd/response/raise_error.rb
|
225
225
|
- lib/redd/thing.rb
|
226
|
+
- lib/redd/thing/commentable.rb
|
226
227
|
- lib/redd/thing/editable.rb
|
227
228
|
- lib/redd/thing/hideable.rb
|
228
229
|
- lib/redd/thing/inboxable.rb
|