// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
// Boston, MA 02110-1301, USA.
+#nullable enable
+
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
{
public TwitterApiAccessLevel AccessLevel { get; set; }
public EndpointLimits AccessLimit { get; }
- public ApiLimit MediaUploadLimit { get; set; }
+ public ApiLimit? MediaUploadLimit { get; set; }
public class AccessLimitUpdatedEventArgs : EventArgs
{
- public string EndpointName { get; }
+ public string? EndpointName { get; }
- public AccessLimitUpdatedEventArgs(string endpointName)
+ public AccessLimitUpdatedEventArgs(string? endpointName)
=> this.EndpointName = endpointName;
}
public event EventHandler<AccessLimitUpdatedEventArgs> AccessLimitUpdated;
this.MediaUploadLimit = null;
}
- internal static ApiLimit ParseRateLimit(IDictionary<string, string> header, string prefix)
+ internal static ApiLimit? ParseRateLimit(IDictionary<string, string> header, string prefix)
{
var limitCount = (int?)ParseHeaderValue(header, prefix + "Limit");
var limitRemain = (int?)ParseHeaderValue(header, prefix + "Remaining");
public EndpointLimits(TwitterApiStatus owner)
=> this.Owner = owner;
- public ApiLimit this[string endpoint]
+ public ApiLimit? this[string endpoint]
{
get => this.innerDict.TryGetValue(endpoint, out var limit) ? limit : null;
set
{
- this.innerDict[endpoint] = value;
+ if (value == null)
+ this.innerDict.TryRemove(endpoint, out var _);
+ else
+ this.innerDict[endpoint] = value;
+
this.Owner.OnAccessLimitUpdated(new AccessLimitUpdatedEventArgs(endpoint));
}
}