Created
March 26, 2018 03:16
-
-
Save hoelzro/87e3fcbe66b15a3694ff0c2a8d2972a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Local::Twitter::API::RateLimiting { | |
use Moo::Role; | |
use HTTP::Status qw(HTTP_TOO_MANY_REQUESTS); | |
use namespace::clean; | |
around send_request => sub { | |
my $orig = shift; | |
my $self = shift; | |
my $res = $self->$orig(@_); | |
while($res->code == HTTP_TOO_MANY_REQUESTS) { | |
my $sleep_time = $res->header('x-rate-limit-reset') - time; | |
sleep $sleep_time; # XXX modifiable, please | |
$res = $self->$orig(@_); | |
} | |
return $res; | |
}; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment