Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new OsuClient with the given configuration.
 /// </summary>
 /// <param name="configuration">
 /// Configuration of the client.
 /// </param>
 /// <param name="handler">
 /// Request handler of the client.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// Thrown when <see cref="configuration" /> is null.
 /// </exception>
 /// <exception cref="ArgumentNullException">
 /// Thrown when <see cref="handler"/> is null.
 /// </exception>
 public OsuClient(
     [NotNull] IOsuClientConfiguration configuration,
     [NotNull] IRequestHandler handler)
 {
     Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
     _handler      = handler ?? throw new ArgumentNullException(nameof(handler));
 }
Ejemplo n.º 2
0
        public DefaultRequestHandler(
            ILogger<DefaultRequestHandler> logger,
            IOsuClientConfiguration configuration,
            IJsonSerializer serializer)
        {
            _logger = logger;
            _configuration = configuration;
            _serializer = serializer ?? DefaultJsonSerializer.Instance;

            _ratelimits = new ConcurrentDictionary<string, RatelimitBucket>();
            _httpClient = new HttpClient(new RedirectHandler
            {
                InnerHandler = new HttpClientHandler
                {
                    AllowAutoRedirect = false,
                    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
                }
            })
            {
                BaseAddress = new Uri(_configuration.BaseUrl)
            };

            _httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("OsuSharp", "2.0"));
            _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        }