-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Added GetRateLimits to MiscellaneousClient #848
Changes from 1 commit
d88f180
e092a10
d5d264d
2314b62
0405718
4d9cc4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Octokit | ||
{ | ||
[DebuggerDisplay("{DebuggerDisplay,nq}")] | ||
public class MiscRateLimits | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We try to avoid abbreviations. So I'd call this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed as suggested |
||
{ | ||
public MiscRateLimits() {} | ||
|
||
public MiscRateLimits(ResourceRateLimits resources, ResourceRateLimit rate) | ||
{ | ||
Ensure.ArgumentNotNull(resources, "resource"); | ||
Ensure.ArgumentNotNull(rate, "rate"); | ||
|
||
Resources = resources; | ||
Rate = rate; | ||
} | ||
|
||
/// <summary> | ||
/// Object of resources rate limits | ||
/// </summary> | ||
public ResourceRateLimits Resources { get; private set; } | ||
|
||
/// <summary> | ||
/// Legacy rate limit - to be depreciated - https://developer.github.com/v3/rate_limit/#deprecation-notice | ||
/// </summary> | ||
public ResourceRateLimit Rate { get; private set; } | ||
|
||
internal string DebuggerDisplay | ||
{ | ||
get | ||
{ | ||
return Resources == null ? "No rates found" : String.Format(CultureInfo.InvariantCulture, Resources.DebuggerDisplay); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
|
||
using Octokit.Helpers; | ||
|
||
namespace Octokit | ||
{ | ||
[DebuggerDisplay("{DebuggerDisplay,nq}")] | ||
public class ResourceRateLimit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather we just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed now to use RateLimit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure where we ended up with this - is it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Three models in use:
Hopefully that makes sense There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
{ | ||
public ResourceRateLimit() { } | ||
|
||
public ResourceRateLimit(int limit, int remaining, long reset) | ||
{ | ||
Ensure.ArgumentNotNull(limit, "limit"); | ||
Ensure.ArgumentNotNull(remaining, "remaining"); | ||
Ensure.ArgumentNotNull(reset, "reset"); | ||
|
||
Limit = limit; | ||
Remaining = remaining; | ||
Reset = reset; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// The maximum number of requests that the consumer is permitted to make per hour. | ||
/// </summary> | ||
public int Limit { get; private set; } | ||
|
||
/// <summary> | ||
/// The number of requests remaining in the current rate limit window. | ||
/// </summary> | ||
public int Remaining { get; private set; } | ||
|
||
/// <summary> | ||
/// The date and time at which the current rate limit window resets - in UTC epoch seconds | ||
/// </summary> | ||
public long Reset { get; private set; } | ||
|
||
/// <summary> | ||
/// The date and time at which the current rate limit window resets - as DateTimeOffset | ||
/// </summary> | ||
public DateTimeOffset ResetAsDateTimeOffset { get { return Reset.FromUnixTime(); } } | ||
|
||
|
||
internal string DebuggerDisplay | ||
{ | ||
get | ||
{ | ||
return String.Format(CultureInfo.InvariantCulture, "Limit {0}, Remaining {1}, Reset {2} ", Limit, Remaining, Reset); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
|
||
using Octokit.Helpers; | ||
|
||
namespace Octokit | ||
{ | ||
[DebuggerDisplay("{DebuggerDisplay,nq}")] | ||
public class ResourceRateLimits | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per my previous suggestion, I think this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
{ | ||
public ResourceRateLimits() {} | ||
|
||
public ResourceRateLimits(ResourceRateLimit core, ResourceRateLimit search) | ||
{ | ||
Ensure.ArgumentNotNull(core, "core"); | ||
Ensure.ArgumentNotNull(search, "search"); | ||
|
||
Core = core; | ||
Search = search; | ||
} | ||
|
||
/// <summary> | ||
/// Rate limits for core API (rate limit for everything except Search API) | ||
/// </summary> | ||
public ResourceRateLimit Core { get; private set; } | ||
|
||
/// <summary> | ||
/// Rate Limits for Search API | ||
/// </summary> | ||
public ResourceRateLimit Search { get; private set; } | ||
|
||
internal string DebuggerDisplay | ||
{ | ||
get | ||
{ | ||
return String.Format(CultureInfo.InvariantCulture, "Core: {0}; Search: {1} ", Core.DebuggerDisplay, Search.DebuggerDisplay); | ||
} | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I love the explicitness here, I think letting this fall through to the Assert.Equals is totally fine to simplify the tests...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify, is this the NotNull check? What about the other NotNull tests further down - lose them as well to make more readable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed the above was yes & yes