reddit_api 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reddit_api/comments.rb +13 -2
- data/lib/reddit_api/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: 7784713e1ccff6488f9690819d545378ba494ccc
|
4
|
+
data.tar.gz: 57a410a81036adea1216bc57183cf829e166bd16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d912c1be0ccdd7172a54d56ba5ad9dce9f72f71e44933685197e888d5663c6d111baaf4572efaa0bfa8b1270453e27a94047bb2526c84e3bb59f0da1e094c2b8
|
7
|
+
data.tar.gz: c7ab36fc31d79d7cd1a8782388832a7c4c8775f8035052ccf4999a49aaeb1571e1ffceee2317beae8283fa06f1c216449e38b3397ffe6a387a912da2e4515afb
|
data/lib/reddit_api/comments.rb
CHANGED
@@ -2,17 +2,20 @@
|
|
2
2
|
module RedditApi
|
3
3
|
class Comments
|
4
4
|
|
5
|
+
MAX_FAILURES = 5
|
6
|
+
|
5
7
|
def initialize(args = {})
|
6
8
|
@client = args.fetch(:client, RedditApi::Client.new)
|
7
9
|
@comment_factory = RedditApi::Comment
|
8
10
|
@offset = nil
|
11
|
+
@failures = 0
|
9
12
|
end
|
10
13
|
|
11
14
|
def most_recent_subreddits(user, count)
|
12
15
|
subreddits = {}
|
13
|
-
while subreddits.length < count
|
16
|
+
while subreddits.length < count && failures < MAX_FAILURES
|
14
17
|
comments = most_recent_comments(user, 100, offset)
|
15
|
-
|
18
|
+
update_progress(comments)
|
16
19
|
collect_subreddits(comments, count, subreddits)
|
17
20
|
end
|
18
21
|
subreddits.keys
|
@@ -28,6 +31,14 @@ module RedditApi
|
|
28
31
|
private
|
29
32
|
attr_reader :client, :comment_factory, :offset
|
30
33
|
|
34
|
+
def update_progress(comments)
|
35
|
+
if offset == comments.last.reddit_id
|
36
|
+
failures += 1
|
37
|
+
else
|
38
|
+
self.offset = comments.last.reddit_id
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
31
42
|
def most_recent_comment_data(username, count, offset)
|
32
43
|
return [] if username == "[deleted]"
|
33
44
|
endpoint = "user/#{username}/comments.json"
|
data/lib/reddit_api/version.rb
CHANGED