Additional changes to support rate_limit API call

This commit is contained in:
Mark Taylor
2015-07-26 22:03:19 +01:00
parent d88f180cd6
commit e092a109ea
17 changed files with 94 additions and 117 deletions
+31
View File
@@ -2,17 +2,22 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using Octokit.Helpers;
using System.Diagnostics;
using System.Globalization;
using Octokit.Internal;
namespace Octokit
{
#if !NETFX_CORE
[Serializable]
#endif
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class RateLimit
#if !NETFX_CORE
: ISerializable
#endif
{
public RateLimit() {}
public RateLimit(IDictionary<string, string> responseHeaders)
{
@@ -23,6 +28,17 @@ namespace Octokit
Reset = GetHeaderValueAsInt32Safe(responseHeaders, "X-RateLimit-Reset").FromUnixTime();
}
public RateLimit(int limit, int remaining, long reset)
{
Ensure.ArgumentNotNull(limit, "limit");
Ensure.ArgumentNotNull(remaining, "remaining");
Ensure.ArgumentNotNull(reset, "reset");
Limit = limit;
Remaining = remaining;
Reset = reset.FromUnixTime();
}
/// <summary>
/// The maximum number of requests that the consumer is permitted to make per hour.
/// </summary>
@@ -36,8 +52,16 @@ namespace Octokit
/// <summary>
/// The date and time at which the current rate limit window resets
/// </summary>
[ParameterAttribute(Key = "ignoreThisField")]
public DateTimeOffset Reset { get; private set; }
/// <summary>
/// The date and time at which the current rate limit window resets - in UTC epoch seconds
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[ParameterAttribute(Key = "reset")]
public long ResetAsUtcEpochSeconds { get { return Reset.ToUnixTime(); } private set { Reset = value.FromUnixTime(); } }
static long GetHeaderValueAsInt32Safe(IDictionary<string, string> responseHeaders, string key)
{
string value;
@@ -66,5 +90,12 @@ namespace Octokit
info.AddValue("Reset", Reset.Ticks);
}
#endif
internal string DebuggerDisplay
{
get
{
return String.Format(CultureInfo.InvariantCulture, "Limit {0}, Remaining {1}, Reset {2} ", Limit, Remaining, Reset);
}
}
}
}