Closed TheWatcher closed 10 years ago
This won't quite work, because the Twitter API result isn't always a hash ref. It is often an array ref.
I think there's a better way to handle this. I haven't written any tests for it, but please have a look at the wrap-result branch and see what you think.
It returns an object that includes both the Twitter API result and the HTTP::Response object. It also includes accessors for the rate limiting meta data.
By providing ( wrap_result => 1 )
to the Net::Twitter::Lite constructor, you can then, e.g.:
my $r = $nt->verify_credentials;
say $r->rate_limit_remaining; # access rate limit meta data
say $r->result->{screen_name}; # access the result
say $r->result->http_response->as_string; # access the HTTP::Response object
Care to add some tests? Once I have some tests and some sanity checking, I'd be happy to roll out a new release including this functionality.
I agree your approach is better, I'll get back to you with some tests over the next day or so.
Tests written and a separate pull request sent as #15
The Twitter API v1.1 includes x-rate-limit-limit, -remaining, and -reset fields in the response headers for all requests. Including this information in the objects returned by api methods means that applications can keep track of their remaining requests without using rate_limit_status.