Comments (8)
This issue is about raising a RateLimitedError
(or similar name) when Strava returns 403 Forbidden because of rate limiting along with enough information to inform the client about when to retry.
Returning rate limiting information as part of every response now that it's available would be a different work-item. What's the scenario in which you want to use that information on a successful response?
I definitely don't think we should be moving data from headers to the body of the response, however I think it should be OK to refactor the library such as instead of returning body the entire response is returned and the response is available in its raw form from every object constructed from the response, maybe something like:
activity = client.activity(1982980795)
activity.name # => 'Afternoon Run'
activity._request # http request
activity._response # http response
I would wrap Response into a new class and instead of reaching into headers
have first class methods like activity._response.rate_limit.limit
and activity._response.rate_limit.usage
.
from strava-ruby-client.
Looking forward to some PRs :)
from strava-ruby-client.
Apologies if I'm misunderstanding ... or just wrong. 😳 😬
It looks like this has since changed (in https://developers.strava.com/docs/#rate-limiting) so that X-RateLimit-Limit
and X-RateLimit-Usage
headers are included on each response.
Passing these values along to the client implementation might be suitable for most use cases (it definitely would be for mine 😄 ).
Instead of only returning the body, would it be possible to also include the limit and usage values? Something like this?
response.body.merge!(
strava_api_limit: response.headers["X-RateLimit-Limit"],
strava_api_usage: response.headers["X-RateLimit-Usage"]
)
I can't increase the size of the 🤷♂ I'd like to attach to this suggestion/question. 😄 There are probably better ways to go about this, but I was trying to think of a way to start the conversation with the least-breaking change. 🤔
from strava-ruby-client.
Ah, yeah, I can see how raising on rate limit vs returning rate limit info are two separate pieces of work. 👍
My use case on having access to these two values is to keep myself under the limit & to have a sense of where I stand.
I run a site that can have sudden spikes of API usage (many webhooks, many new signups, etc) and I'm currently relying on the 403 responses as a signal that I have to kick the workload out by 15+ minutes. It's a really messy system, and I think if I knew I had X of Y requests left I could more gracefully handle the work and do a better job of letting my users know if there's a delay.
from strava-ruby-client.
Closing via #40. that adds the rate limit info but doesn't specialize the error
from strava-ruby-client.
@simonneutert This should be fairly easy on top of #40 now, WDYT?
from strava-ruby-client.
I skimmed the Readme and the section Error would provide all info for what's needed to a proper client-side evaluation of the Error/Fault.
The header contains data about ratelimits already and we documented it, every project using this would need custom code to react to errors anyways. Digging the header hash, will allow for the precise identification.
And rereading through the issue, the reporter wanted to be able to check rate limits at any point in time and #40 (#64) does.
We can definitely add a specific error, too, but I wanted to bring this to discussion first ✌️ @dblock
from strava-ruby-client.
@simonneutert This is about being able to rescue RateLimit => e
and then the user can wait for some e.time_needed_to_wait_for_retry
and then retry
. Right now I believe we throw a generic error in that case and you'd need to rescue all errors then check what type of error it is (try writing a unit test). We can also then build a retry into the library as an optional feature next.
from strava-ruby-client.
Related Issues (20)
- Cache Faraday::Connection and use Faraday::Adapter::NetHttpPersistent
- list segment effort has been deprecated HOT 2
- Correct start_date_local HOT 1
- Question: How to get a new access token using a refresh token via backend app? HOT 2
- Activity Upload HOT 4
- Missing GroupEvents HOT 2
- Update Travis Badge or migrate to GHA HOT 1
- Remove client.running_races HOT 4
- Ensure that large IDs are not truncated HOT 4
- Add support for descent HOT 4
- Release 0.4.3 HOT 1
- Question: create_push_subscription parameters? HOT 3
- Strava V3 deprecates attribute `type` for Activities HOT 9
- Strava API v3 deprecates page and per_page params on ActivityComments
- Require Rubocop-Rspec and use it HOT 1
- Attempting to serialize an activity with `to_json` is broken (Ruby 3.1.2.p20) HOT 5
- Problem getting photo URLs via `client.activity_photos` HOT 4
- How to run the client HOT 1
- Special permissions needed to access activities HOT 1
- Add Photos Back To Activities
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from strava-ruby-client.