Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting rate_limit resets_in to 0 if it goes negative #536

Merged
merged 2 commits into from
Dec 2, 2014
Merged

Setting rate_limit resets_in to 0 if it goes negative #536

merged 2 commits into from
Dec 2, 2014

Conversation

markphelps
Copy link
Contributor

Fixes #504

Setting rate limit resets_in to 0 if resets_at is in the past

@@ -24,7 +24,7 @@ def self.from_response(response)
info.limit = (response.headers['X-RateLimit-Limit'] || 1).to_i
info.remaining = (response.headers['X-RateLimit-Remaining'] || 1).to_i
info.resets_at = Time.at((response.headers['X-RateLimit-Reset'] || Time.now).to_i)
info.resets_in = (info.resets_at - Time.now).to_i
info.resets_in = (info.resets_at - Time.now).to_i > 0 ? (info.resets_at - Time.now).to_i : 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could just be:

info.resets_in = [(info.resets_at - Time.now).to_i, 0].max

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah you are correct. I knew there was a shorter way to do this. thanks!

@pengwynn
Copy link
Collaborator

pengwynn commented Dec 2, 2014

Thanks for the patch. 🍰

pengwynn added a commit that referenced this pull request Dec 2, 2014
Setting rate_limit resets_in to 0 if it goes negative
@pengwynn pengwynn merged commit 702152a into octokit:master Dec 2, 2014
@markphelps markphelps deleted the resets_in_should_not_be_negative branch December 2, 2014 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rate_limit doesn't always return valid information
2 participants