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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 004a4afe844fc852c876d856654312a3351a1412
4
- data.tar.gz: 1343c16d1c128aab75c6415b1352de8fe9073d8e
3
+ metadata.gz: 7784713e1ccff6488f9690819d545378ba494ccc
4
+ data.tar.gz: 57a410a81036adea1216bc57183cf829e166bd16
5
5
  SHA512:
6
- metadata.gz: a64b90257ca848a0fdf03171cb0d798bb6d6600a64d079c0550b2a455f1c713c966440c1ca0ad29e3345fee7e5466896190117008e97ab4770b47ec0ca38b98f
7
- data.tar.gz: 6efb3c4f163a9fcd554de328df64274ad8c95d989ddb6b3f9a6c218724ca51f5a261acd9683e338a5282cac39e89e2cea2b4b27cc14388b1296faf63be8112ef
6
+ metadata.gz: d912c1be0ccdd7172a54d56ba5ad9dce9f72f71e44933685197e888d5663c6d111baaf4572efaa0bfa8b1270453e27a94047bb2526c84e3bb59f0da1e094c2b8
7
+ data.tar.gz: c7ab36fc31d79d7cd1a8782388832a7c4c8775f8035052ccf4999a49aaeb1571e1ffceee2317beae8283fa06f1c216449e38b3397ffe6a387a912da2e4515afb
@@ -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
- self.offset = comments.last.reddit_id
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"
@@ -1,3 +1,3 @@
1
1
  module RedditApi
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reddit_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Fuentes