Skip to content

Instantly share code, notes, and snippets.

@jphpsf
Created May 6, 2012 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jphpsf/2623897 to your computer and use it in GitHub Desktop.
Save jphpsf/2623897 to your computer and use it in GitHub Desktop.
alternative collect_with_number
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