Created
May 6, 2012 19:12
-
-
Save jphpsf/2623897 to your computer and use it in GitHub Desktop.
alternative collect_with_number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def collect_with_number(number, key, &block) | |
opts = {} | |
opts[key] = MAX_NUM_RESULTS | |
statuses = collect_with_max_id do |max_id| | |
opts[:max_id] = max_id unless max_id.nil? | |
opts[key] = number unless number >= MAX_NUM_RESULTS | |
if number > 0 | |
# Instead of this: | |
# number -= MAX_NUM_RESULTS | |
statuses = retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do | |
yield opts | |
end | |
# Do this: | |
number -= statuses.length | |
statuses | |
end | |
end.flatten.compact | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment