sferik / x-ruby

A Ruby interface to the X API.
MIT License
63 stars 13 forks source link

Access to RateLimit before there's an error? #30

Closed pgib closed 1 week ago

pgib commented 2 weeks ago

Or maybe a better question would be: is there a novel way to access the response headers for a given request? It would be nice to peek at the x-rate-limit headers when posting a tweet, for example. Some of the other x-* headers could be of interest, too.

-> "x-rate-limit-limit: 200\r\n" -> "x-rate-limit-reset: 1714423929\r\n" -> "x-rate-limit-remaining: 197\r\n"

sferik commented 2 weeks ago

You could do this by implementing a custom response handler for your request. There aren't currently parameters or accessor methods to do this, but it is possible with some Ruby hackery. I could add such parameters/methods in future version of the gem but before I start writing code, I'm interested to understand your use case better.

Are you aware that the API has a GET application/rate_limit_status resource?

This question has come up before in a previous implementation of this library, but it was ultimately deemed unnecessary. If you have a new and different use case, I’d like to understand it better.

pgib commented 1 week ago

@sferik Thanks for the response – yeah, I think the application/rate_limit_status should serve any such purposes just fine. Thanks!