redd 0.8.3 → 0.8.4

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: a8d7432aa8e8e95a979a1beda6cd0b029968bc47
4
- data.tar.gz: a64f085356bee811050a5036567eb48bad118363
3
+ metadata.gz: ce5057c5421178a5b9ad6a056b2fa33a161413f8
4
+ data.tar.gz: 11c8973bcb1fbd2786c40e3f929229c944883da0
5
5
  SHA512:
6
- metadata.gz: 52a9e1c3605c7c9b50fee521a7d792e01c2f9e878ce91ef3e8042da02620eb04dd61576930a0b6b67ecf7c526ae6f7861876c48bc2f27339dabf431af8d30a63
7
- data.tar.gz: f284a123a0e135a5647d83ceda77a602f56281d24a62a1355c540ad4c196fcdec3bc33ece6c786b8153fe552aa608e76f35625c0c6f5451ef641e54934d61939
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
@@ -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
 
@@ -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: 'best')
14
- @client.model(
15
- :get, '/api/morechildren',
16
- link_id: link.name,
17
- children: get_attribute(:children).join(','),
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: 'best', lookup: {}, depth: 10)
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
- response = @client.get("/comments/#{id}").body
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Redd
4
- VERSION = '0.8.3'
4
+ VERSION = '0.8.4'
5
5
  end
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.3
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-04 00:00:00.000000000 Z
11
+ date: 2017-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http