picqer / picqer-php

PHP Client for the Picqer API
https://picqer.com/en/api
MIT License
18 stars 23 forks source link

Account for RateLimits in getAllResults method #14

Closed TheodoorP closed 5 years ago

TheodoorP commented 5 years ago

This sleep function should make sure that whenever the ratelimit is reached it'll wait till a new request can be made, maybe add this as a parameter to allow the developer using this to turn it off or on?

Edit: Just to further explain, what was happening before is that whenever the getAllResults method would encounter a ratelimit the entire getAllResults method would become useless, as sendRequest would throw a RateLimitException which isn't being handled in any way or form in getAllResults.

casperbakker commented 5 years ago

Good idea, but I think it would be better if we throw an exception by default and with a setting you can configure to just wait on rate limits like your PR.

I will tweak this PR a bit and then merge it.

casperbakker commented 5 years ago

@HuntingVillager I just committed a more robust implementation of the same idea. If the client hits a rate limit, it will try again later with the same request. This makes the handling of rate limits seamless with the only drawback a longer time of execution, instead of failing.