/// <summary> /// Gets the suffix for a returned response body from a <see cref="HttpStatusCode.TooManyRequests"/> HTTP response /// </summary> /// <returns></returns> /// <example>2 per 10s.</example> public string GetApiRateLimitingResponseBodySuffix() { if (RequestsAllowed <= 0) { throw new ArgumentOutOfRangeException(nameof(RequestsAllowed)); } if (RequestResetTimeInterval == TimeSpan.MinValue) { throw new ArgumentOutOfRangeException(nameof(RequestResetTimeInterval)); } return($"{RequestsAllowed} per {GetTimeValueFromTimeSpan()}{RequestResetUnitOfTime.AsString(EnumFormat.Description)}."); }
/// <summary> /// Get the time value from the TimeSpan based on the interval unit of time /// </summary> /// <returns></returns> /// <example>120</example> public int GetTimeValueFromTimeSpan() { if (RequestResetTimeInterval == TimeSpan.MinValue) { throw new ArgumentOutOfRangeException(nameof(RequestResetTimeInterval)); } return(RequestResetUnitOfTime switch { ApiRateLimitingUnitsOfTime.None => throw new ArgumentOutOfRangeException(nameof(RequestResetUnitOfTime)), ApiRateLimitingUnitsOfTime.Seconds => RequestResetTimeInterval.Seconds, ApiRateLimitingUnitsOfTime.Minutes => RequestResetTimeInterval.Minutes, ApiRateLimitingUnitsOfTime.Hours => RequestResetTimeInterval.Hours, ApiRateLimitingUnitsOfTime.Days => RequestResetTimeInterval.Days, _ => throw new NotImplementedException($"Type '{RequestResetUnitOfTime.AsString(EnumFormat.Name)}' not supported."), });