Exemplo n.º 1
0
        internal RateLimiter(RateLimiterConfiguration rateLimiterConfiguration)
        {
            Configuration = rateLimiterConfiguration;

            Semaphore = new SemaphoreSlim(1);

            RequestCount = 0;

            TimeReference = DateTimeOffset.Now + Configuration.Interval;
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Initializes a new instance of <see cref="OsuClient"/> with the given configuration and the one for the rate limiter.
        /// </summary>
        /// <param name="osuSharpConfiguration">Configuration to use for this instance.</param>
        /// <param name="rateLimiterConfiguration">Rate limiting configuration.</param>
        public OsuClient(OsuSharpConfiguration osuSharpConfiguration, RateLimiterConfiguration rateLimiterConfiguration)
        {
            OsuSharpConfiguration = osuSharpConfiguration;
            RateLimiter           = new RateLimiter(rateLimiterConfiguration);
            ReplayRateLimiter     = new RateLimiter(new RateLimiterConfiguration
            {
                MaxRequest          = 10,
                ThrowOnRatelimitHit = rateLimiterConfiguration.ThrowOnRatelimitHit
            });

            if (string.IsNullOrWhiteSpace(OsuSharpConfiguration.ApiKey))
            {
                throw new OsuSharpException("The given api key is not valid.", HttpStatusCode.Unauthorized);
            }

            if (OsuSharpConfiguration.HttpClient is null)
            {
                OsuSharpConfiguration.HttpClient = new HttpClient();
            }

            Logger = new OsuSharpLogger();
        }