Example #1
0
        /// <summary>
        /// Create an instance of <see cref="R6StatsClient"/>
        /// </summary>
        /// <param name="config"><see cref="Config"/>Object containing the necessary information to instanciate the client</param>
        /// <param name="headers">Optional request headers to be used while making REST API requests</param>
        public R6StatsClient(Config config, IDictionary <string, IEnumerable <string> > headers) : this(config)
        {
            _headers = headers.ToImmutableDictionary();

            foreach (var header in _headers)
            {
                _httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
            }
        }
Example #2
0
        /// <summary>
        /// Create an instance of <see cref="R6StatsClient"/>
        /// </summary>
        /// <param name="config"><see cref="Config"/> containing the necessary information to instanciate the client </param>
        public R6StatsClient(Config config)
        {
            _key = config.ApiKey;

            if (string.IsNullOrEmpty(_key))
            {
                throw new ArgumentException("API key not found.");
            }

            _httpClient = new HttpClient()
            {
                BaseAddress = new Uri(_baseUrl)
            };
            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _key);
            _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            _defaultSerializerSettings = new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Ignore
            };
        }