lib/social_profile/people/facebook.rb in social_profile-0.2.1 vs lib/social_profile/people/facebook.rb in social_profile-0.2.2

- old
+ new

@@ -68,15 +68,20 @@ # Get last post by days from feed with comments, shares and likes counters # def last_post_by_days(days, options={}) date = (options[:date_end] || Time.now) - days.days limit = options[:limit] || 100 + max_iteration = options[:max_iteration] || 100 + iteration = 0 posts = collection = last_posts(limit, options) + return [] if posts.blank? + last_created_time = posts.last.created_time - while last_created_time > date + while last_created_time > date && !last_created_time.blank? && iteration < max_iteration + iteration += 1 collection = collection.next posts += collection last_created_time = posts.last.created_time end @@ -84,18 +89,32 @@ end # Get all friends list # def friends(options={}) - limit = options[:limit] || 500000 + limit = options[:limit] || 5000 user.friends(:limit => limit) end # Get all followers list # def followers(options={}) - limit = options[:limit] || 500000 - user.subscribers(:limit => limit) + limit = options[:limit] || 5000 + fetch_all = options[:fetch_all] || false + iteration = 0 + + _followers = collection = user.subscribers(:limit => limit) + max_iteration = _followers.total_count / limit + 1 + + if fetch_all + while iteration < max_iteration + iteration += 1 + collection = collection.next + _followers += collection + end + end + + _followers end protected def user \ No newline at end of file