reddit_api 0.1.0 → 0.1.1

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: 534315886359d1f8cd0b3ff3f5c10491e6bfa054
4
- data.tar.gz: 4127d3e358af94f0ffbb9efca924e4130142d7b8
3
+ metadata.gz: 919510f0c547f9602c3b8088f6fd0cf620124309
4
+ data.tar.gz: 0f22724e0997d152dbb37b830776b51978e0df78
5
5
  SHA512:
6
- metadata.gz: cf17e29d9e1f191ad92b10d69fd3fd84b4fc359052a4aaf4166fc250ec8bb6b980010f058a18d461a896c3848fb68166fb285b312c9896da848e2da469fb0c5c
7
- data.tar.gz: 86dec1f544fb1b4bbbba71283f224867210ea2ff31e530095cea8f5f33a840bba166b8ffeff8fd0996c51870c3b683044629d8f624efd2305e6a1faf9053d07a
6
+ metadata.gz: 6df053500672572c228bb8b11e503fa82dfe2898347304f1af19f28dbfefcfc5fcf11d73542278e09054b0f7ca23495a900b6a00ecdff4afde3d7c12a1a88f26
7
+ data.tar.gz: 483498298d91f1e888d631677076ff4dd065d59c97bb83e26cba1702ef6b9f29784ca1f75c3c3c71b2c8193b80b4a8f17dbe8911541721e7773f1ef88ef56421
@@ -2,22 +2,31 @@
2
2
  module RedditApi
3
3
  class Users
4
4
 
5
- def initialize
5
+ attr_reader :misses
6
+
7
+ def initialize(args = {})
6
8
  @post_api = RedditApi::Posts.new
7
9
  @user_factory = RedditApi::User
10
+ @misses = args.fetch(:misses, 0)
11
+ @last_count = 0
8
12
  end
9
13
 
14
+ MAX_MISSES = 5
15
+
10
16
  def top_posters(subreddit, count)
11
17
  users = {}
12
- while users.length < count
18
+ while users.length < count && misses < MAX_MISSES
13
19
  posts = post_api.top(subreddit, count)
14
20
  collect_users(posts, count, users)
21
+ update_misses(users.length)
15
22
  end
16
23
  users.values
17
24
  end
18
25
 
26
+ protected
27
+ attr_writer :misses, :last_count
19
28
  private
20
- attr_reader :post_api, :user_factory
29
+ attr_reader :post_api, :user_factory, :last_count
21
30
 
22
31
  def collect_users(posts, count, users)
23
32
  usernames = get_usernames(posts, count, users)
@@ -57,6 +66,13 @@ module RedditApi
57
66
  end
58
67
  end
59
68
 
69
+ def update_misses(length)
70
+ if (length - last_count).zero?
71
+ self.misses += 1
72
+ self.last_count = length
73
+ end
74
+ end
75
+
60
76
  end
61
77
  end
62
78
 
@@ -1,3 +1,3 @@
1
1
  module RedditApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Fuentes