sferik / twitter-ruby

A Ruby interface to the Twitter API.
http://www.rubydoc.info/gems/twitter
MIT License
4.58k stars 1.31k forks source link

Twitter::Cursor#reached_limit? doesn't return true #929

Closed clarkbab closed 1 year ago

clarkbab commented 6 years ago

Problem

I noticed while testing the new direct_messages_events method that the method doesn't seem to abide by the count param. E.g:

# Create client.
c = Twitter::REST::Client.new(...)

# Fetch DM events with a limit of 100.
r = c.direct_messages_events(count: 100)

r.as_json.count
# => 238

It looks as though the Twitter::Cursor#reached_limit? method never returns true and so keeps fetching new data from the Twitter DM events endpoint until there is no more to fetch.

Proposed solution

The reached_limit? method uses the length of the @collection variable as this is a cumulative collection the data retrieved from all API calls.