Class: RedditApi::Users

Inherits:
Object
  • Object
show all
Defined in:
lib/reddit_api/users.rb

Constant Summary collapse

MAX_MISSES =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Users

Returns a new instance of Users.


7
8
9
10
11
12
# File 'lib/reddit_api/users.rb', line 7

def initialize(args = {})
  @post_api = RedditApi::Posts.new
  @user_factory = RedditApi::User
  @misses = args.fetch(:misses, 0)
  @last_count = 0
end

Instance Attribute Details

#missesObject

Returns the value of attribute misses.


5
6
7
# File 'lib/reddit_api/users.rb', line 5

def misses
  @misses
end

Instance Method Details

#top_posters(subreddit, count) ⇒ Object


16
17
18
19
20
21
22
23
24
# File 'lib/reddit_api/users.rb', line 16

def top_posters(subreddit, count)
  users = {}
  while users.length < count && misses < MAX_MISSES
    posts = post_api.top(subreddit, count)
    collect_users(posts, count, users)
    update_misses(users.length)
  end
  users.values
end