Net::T...Result(3pm)

πŸ“¦
version 0.12008 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Net::Twitter::Lite::WrapResult β€” bestie edition πŸ’–

okay so literally the manual name is Net::Twitter::Lite::WrapResult and what it does is wrap the HTTP response and the Twitter result together so you're not out here digging through headers like a raccoon in a trash can. it's giving "one object, all the tea." πŸ«–βœ¨


πŸ¦‹ VERSION πŸ¦‹

version 0.12008 β€” yes bestie, that's the one. no cap.


✨ SYNOPSIS ✨

like, here's the whole vibe in code form, don't touch a single character of it:

use Net::Twitter::Lite::WithAPIv1_1;

my $nt = Net::Twitter::Lite::WithAPIv1_1->new(
    consumer_key        => $consumer_key,
    consumer_secret     => $consumer_secret,
    access_token        => $access_token,
    access_token_secret => $access_token_secret,
    wrap_result         => 1,
);

my $r = $nt->verify_credentials;

my $http_response        = $r->http_response;
my $twitter_result       = $r->result;
my $rate_limit_remaining = $r->rate_limit_remaining;

see how wrap_result => 1 is doing the heavy lifting? that one little flag is the moment everything changed. πŸ’…


🌸 DESCRIPTION 🌸

so here's the situation, and honestly? it's a whole thing.

often, the result of a Twitter API call β€” the one that gets inflated from the JSON body of the HTTP response β€” does not contain all the information you need. 😭 like, it's missing stuff. it's incomplete. it's not serving.

and the reason is that Twitter puts meta data, like rate limiting information, in the HTTP response headers, not in the body. so if you're only looking at the JSON, you're literally missing half the story. it's giving "read the room but also read the headers."

this object wraps both the inflated Twitter result and the HTTP response, so you the caller get full access to all the meta data. πŸŽ€ and on top of that, it also gives you accessors for the rate limit information, because of course it does, it's an icon.


πŸ‘‘ METHODS πŸ‘‘

new($twitter_result, $http_response)

constructs an object wrapping the Twitter result and the HTTP response. that's it, that's the job. two things go in, one adorable little wrapper comes out. 🫢

result

returns the inflated Twitter API result. the actual content, the main character, the payload. 🌈

http_response

returns the HTTP::Response object for the API call. all the header lore lives in here. iykyk. πŸ’œ

rate_limit

returns the rate limit, per 15 minute window, for the API endpoint called. and listen β€” it returns undef if no suitable rate limit header is available. so like, check before you assume, bestie. πŸ™ˆ

rate_limit_remaining

returns the calls remaining in the current 15 minute window for the API endpoint called. also returns undef if no suitable header is available. don't come for me, that's just what it does. πŸ’€

rate_limit_reset

returns the unix epoch time time of the next 15 minute window, i.e., when the rate limit will be reset, for the API endpoint called. (yes, "time time" β€” that's what the original says, i'm not editing the queen's grammar. πŸ‘‘) and yeah, returns undef if no suitable header is available. same energy as the other two, fr fr.


πŸŽ€ AUTHOR πŸŽ€

Marc Mims <marc@questright.com> β€” shoutout to the legend, no notes. 🌟


Copyright (c) 2014 Marc Mims <marc@questright.com>

This program is free software; you can redistribute it and/or modify it under the same terms as perl itself. slay, open source, we love to see it. πŸ”₯


heads up bestie: those undef returns on the rate limit methods are not a bug, they're just what happens when the header isn't there. plan accordingly. πŸ’…

and that's the whole page, periodt. 🧚 this was perl v5.34.0, dated 2022-06-16, and it's the Net::T...Result(3pm) of our hearts. mwah. πŸ’‹βœ¨

πŸ“¦ where this page comes from