Module: T::Collectable
Constant Summary collapse
- MAX_NUM_RESULTS =
200
Instance Method Summary collapse
- #collect_with_count(count, &block) ⇒ Object
- #collect_with_max_id(collection = [], max_id = nil, &block) ⇒ Object
- #collect_with_page(collection = [], page = 1, &block) ⇒ Object
Instance Method Details
#collect_with_count(count, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/t/collectable.rb', line 17 def collect_with_count(count, &block) opts = {} opts[:count] = MAX_NUM_RESULTS collect_with_max_id do |max_id| opts[:max_id] = max_id unless max_id.nil? opts[:count] = count unless count >= MAX_NUM_RESULTS if count > 0 tweets = yield opts count -= tweets.length tweets end end.flatten.compact end |
#collect_with_max_id(collection = [], max_id = nil, &block) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/t/collectable.rb', line 8 def collect_with_max_id(collection = [], max_id = nil, &block) tweets = retryable(:tries => 3, :on => Twitter::Error, :sleep => 0) do yield(max_id) end return collection if tweets.nil? collection += tweets tweets.empty? ? collection.flatten : collect_with_max_id(collection, tweets.last.id - 1, &block) end |
#collect_with_page(collection = [], page = 1, &block) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/t/collectable.rb', line 31 def collect_with_page(collection = [], page = 1, &block) tweets = retryable(:tries => 3, :on => Twitter::Error, :sleep => 0) do yield page end return collection if tweets.nil? collection += tweets tweets.empty? ? collection.flatten.uniq : collect_with_page(collection, page + 1, &block) end |