redd 0.8.3 → 0.8.4
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/auth_strategies/auth_strategy.rb +1 -0
- data/lib/redd/error.rb +5 -0
- data/lib/redd/models/comment.rb +3 -3
- data/lib/redd/models/more_comments.rb +6 -8
- data/lib/redd/models/submission.rb +18 -1
- data/lib/redd/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce5057c5421178a5b9ad6a056b2fa33a161413f8
|
4
|
+
data.tar.gz: 11c8973bcb1fbd2786c40e3f929229c944883da0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 712701e751a6cc9e5bb552fafc451c22c3cfefd275da19305620e57b306f5645ae087484217f3049256424d3d40c55d786dbeef4f123c358845d24c94b7cec84
|
7
|
+
data.tar.gz: ac462c530eda68e27718333a386625f6b0921a99a0676a49655721b23d6ccddadf75b433a8d329d0e05f19217565d5029f607af6703b580d374323f1b1764d0d
|
@@ -54,6 +54,7 @@ module Redd
|
|
54
54
|
|
55
55
|
def request_access(grant_type, options = {})
|
56
56
|
response = post('/api/v1/access_token', { grant_type: grant_type }.merge(options))
|
57
|
+
raise AuthenticationError.new(response) if response.body.key?(:error)
|
57
58
|
Models::Access.new(self, response.body)
|
58
59
|
end
|
59
60
|
end
|
data/lib/redd/error.rb
CHANGED
@@ -22,6 +22,11 @@ module Redd
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
# An error returned by AuthStrategy.
|
26
|
+
# @note A common cause of this error is not having a bot account registered as a developer on
|
27
|
+
# the app.
|
28
|
+
class AuthenticationError < ResponseError; end
|
29
|
+
|
25
30
|
# An error with Redd, probably (let me know!)
|
26
31
|
class BadRequest < ResponseError; end
|
27
32
|
|
data/lib/redd/models/comment.rb
CHANGED
@@ -33,10 +33,10 @@ module Redd
|
|
33
33
|
|
34
34
|
def after_initialize
|
35
35
|
@attributes[:replies] =
|
36
|
-
if @attributes[:replies]
|
37
|
-
nil
|
38
|
-
else
|
36
|
+
if @attributes[:replies].is_a?(Hash)
|
39
37
|
@client.unmarshal(@attributes[:replies])
|
38
|
+
else
|
39
|
+
Models::Listing.new(@client, children: [], after: nil, before: nil)
|
40
40
|
end
|
41
41
|
@attributes[:author] = User.from_id(@client, @attributes.fetch(:author))
|
42
42
|
@attributes[:subreddit] = Subreddit.from_id(@client, @attributes.fetch(:subreddit))
|
@@ -10,13 +10,11 @@ module Redd
|
|
10
10
|
# @param link [Submission] the submission the object belongs to
|
11
11
|
# @param sort [String] the sort order of the submission
|
12
12
|
# @return [Listing<Comment, MoreComments>] the expanded children
|
13
|
-
def expand(link:, sort:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
sort: sort
|
19
|
-
)
|
13
|
+
def expand(link:, sort: nil)
|
14
|
+
params = { link_id: link.name, children: get_attribute(:children).join(',') }
|
15
|
+
params[:sort] = sort if sort
|
16
|
+
params[:sort] = link.sort_order if link.sort_order
|
17
|
+
@client.model(:get, '/api/morechildren', params)
|
20
18
|
end
|
21
19
|
|
22
20
|
# Keep expanding until all top-level MoreComments are converted to comments.
|
@@ -25,7 +23,7 @@ module Redd
|
|
25
23
|
# @param lookup [Hash] a hash of comments to add future replies to
|
26
24
|
# @param depth [Number] the maximum recursion depth
|
27
25
|
# @return [Array<Comment, MoreComments>] the expanded comments or self if past depth
|
28
|
-
def recursive_expand(link:, sort:
|
26
|
+
def recursive_expand(link:, sort: nil, lookup: {}, depth: 10)
|
29
27
|
return [self] if depth == 0
|
30
28
|
|
31
29
|
expand(link: link, sort: sort).flat_map do |thing|
|
@@ -26,6 +26,19 @@ module Redd
|
|
26
26
|
new(client, name: id)
|
27
27
|
end
|
28
28
|
|
29
|
+
# @return [Symbol] the requested sort order
|
30
|
+
def sort_order
|
31
|
+
@sort_order ||= nil
|
32
|
+
end
|
33
|
+
|
34
|
+
# Set the sort order of the comments and reload if necessary.
|
35
|
+
# @param order [:confidence, :top, :controversial, :old, :qa] the sort order
|
36
|
+
def sort_order=(order)
|
37
|
+
@sort_order = order
|
38
|
+
reload if @definitely_fully_loaded
|
39
|
+
order
|
40
|
+
end
|
41
|
+
|
29
42
|
# Get all submissions for the same url.
|
30
43
|
# @param params [Hash] A list of optional params to send with the request.
|
31
44
|
# @option params [String] :after return results after the given fullname
|
@@ -97,10 +110,14 @@ module Redd
|
|
97
110
|
def default_loader
|
98
111
|
# Ensure we have the link's id.
|
99
112
|
id = @attributes[:id] ? @attributes[:id] : @attributes.fetch(:name).sub('t3_', '')
|
100
|
-
|
113
|
+
# If a specific sort order was requested, provide it.
|
114
|
+
params = {}
|
115
|
+
params[:sort] = @sort_order if @sort_order
|
116
|
+
|
101
117
|
# `response` is a pair (2-element array):
|
102
118
|
# - response[0] is a one-item listing containing the submission
|
103
119
|
# - response[1] is listing of comments
|
120
|
+
response = @client.get("/comments/#{id}", params).body
|
104
121
|
response[0][:data][:children][0][:data].merge(comments: @client.unmarshal(response[1]))
|
105
122
|
end
|
106
123
|
|
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.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Avinash Dwarapu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|