Skip to content

Instantly share code, notes, and snippets.

@jphpsf
Created May 6, 2012 19:12
Show Gist options
  • Select an option

  • Save jphpsf/2623897 to your computer and use it in GitHub Desktop.

Select an option

Save jphpsf/2623897 to your computer and use it in GitHub Desktop.

Revisions

  1. jphpsf revised this gist May 6, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion collect_with_number.rb
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ def collect_with_number(number, key, &block)
    if number > 0
    # Instead of this:
    # number -= MAX_NUM_RESULTS
    statuses = tmp = retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
    statuses = retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
    yield opts
    end
    # Do this:
  2. jphpsf created this gist May 6, 2012.
    18 changes: 18 additions & 0 deletions collect_with_number.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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 = tmp = retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
    yield opts
    end
    # Do this:
    number -= statuses.length
    statuses
    end
    end.flatten.compact
    end