Twitte...Context(3pm)

✨ NAME ✨

Twitter::API::Context β€” bestie, this is the encapsulated state for a request/response πŸ’–


🌸 VERSION 🌸

version 1.0006 β€” yes queen, we're on 1.0006 πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

my ( $r, $c ) = $client->verify_credentials;

say sprintf '%d verify_credentials calls remaining unitl %s',
    $c->rate_limit_remaining,
    scalar localtime $c->rate_limit_reset;

# output:
74 verify_credentials_calls remaining until Sat Dec  3 22:05:41 2016

not me obsessing over how clean that two-value return is 😭


πŸ’… DESCRIPTION πŸ’…

Okay so here's the tea: every single API call you make keeps its state in a context object. It gets created automatically the second a request kicks off, and it comes back to you as the second value when you're in list context. Periodt.

What's inside this little icon? The HTTP::Request and HTTP::Response objects, a reference to the API return data, and an accessor for all your rate limit info. It's giving main character energy for your whole request lifecycle ✨

Oh and also β€” a reference to the context is included in a Twitter::API::Error exception too, so when things go wrong you still get the receipts 🧾


πŸŽ€ METHODS πŸŽ€

πŸ’œ http_request

Hands you back the HTTP::Request object for the API call. The actual ask, the raw one 🫢

πŸ’œ http_response

Hands you back the HTTP::Response object for the API call. What the server said back πŸ’¬

πŸ’œ result

Returns the result data for the API call. The actual payload, the good stuff πŸ“

πŸ’œ rate_limit

Every API endpoint has a rate limit β€” no cap, they all do. This method returns the rate limit for the endpoint of the API call. Want the full lore? See <https://developer.twitter.com/en/docs/basics/rate-limiting> for details πŸ“–

πŸ’œ rate_limit_remaining

Returns the number of API calls remaining for the endpoint in the current rate limit window. Your little countdown, your lil budget ⏳

πŸ’œ rate_limit_reset

Returns the time of the next rate limit window in UTC epoch seconds. Numbers only bestie, you're gonna want localtime for that πŸ•


πŸ‘‘ AUTHOR πŸ‘‘

Marc Mims <marc@questright.com>


This software is copyright (c) 2015-2021 by Marc Mims.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Slay, genuinely 🫢


and that's the whole page babes β€” built on perl v5.32.1, dated 2021-09-11, mwah πŸ’‹

πŸ“¦ where this page comes from