Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Trait idea: cursors #17

Description

@hoelzro

Hi there! I was thinking about implementing a new trait, and I wanted to see if you had any feedback on its design and whether it would be appropriate for inclusion with Twitter::API or it should be its own standalone thing.

Basically, there are two things that I don't like about working with the Twitter API (not this module in particular - it's great! Just the API in general):

  1. Different REST endpoints have different ways of paging through results; some use a next_cursor/cursor system, some use since_id and max_id.
  2. I rather dislike this pattern:
my $tw = Twitter::API->new(...);
my $max_id;
while(1) {
  my $favorites = $tw->favorites({
    (defined($max_id) ? (max_id => $max_id - 1) : ()),
  });

  last unless @$favorites;
  # process $favorites here...
  $max_id = min(map { $_->{'id'} } @$favorites);
}

I would much rather write code like this, which is more concise and less error prone:

my $tw = Twitter::API->new(...);
my $favorites = $tw->favorites;
while(my $tweet = $favorites->next) {
  # process $tweet here...
}
# alternatively, you could call $favorites->all to return a list of all favorites

The $favorites value would be a cursor object that you could use above, but could still be an array reference so that it's backwards compatible with traditional usage. What do you think?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions