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 +4 -4
- data/lib/reddit_api/users.rb +19 -3
- 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: 919510f0c547f9602c3b8088f6fd0cf620124309
|
4
|
+
data.tar.gz: 0f22724e0997d152dbb37b830776b51978e0df78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6df053500672572c228bb8b11e503fa82dfe2898347304f1af19f28dbfefcfc5fcf11d73542278e09054b0f7ca23495a900b6a00ecdff4afde3d7c12a1a88f26
|
7
|
+
data.tar.gz: 483498298d91f1e888d631677076ff4dd065d59c97bb83e26cba1702ef6b9f29784ca1f75c3c3c71b2c8193b80b4a8f17dbe8911541721e7773f1ef88ef56421
|
data/lib/reddit_api/users.rb
CHANGED
@@ -2,22 +2,31 @@
|
|
2
2
|
module RedditApi
|
3
3
|
class Users
|
4
4
|
|
5
|
-
|
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
|
|
data/lib/reddit_api/version.rb
CHANGED