Beispiel #1
0
        private void CreateOrConfigureHttpClient(HummClientConfiguration config)
        {
            System.Net.Http.HttpClientHandler?handler = null;
            try
            {
                if (config.HttpClient == null)
                {
                    handler = new System.Net.Http.HttpClientHandler();
                    if (handler.SupportsAutomaticDecompression)
                    {
                        handler.AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate;
                    }

                    _Client = new System.Net.Http.HttpClient(handler);
                }
                else
                {
                    _Client = config.HttpClient;
                }

                _Client.BaseAddress = _BaseUrl;

                if (String.IsNullOrEmpty(config.UserAgentProductName) || String.IsNullOrEmpty(config.UserAgentProductVersion))
                {
                    _Client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("Yort.Humm.Instore", typeof(HummClient).Assembly.GetName().Version.ToString()));
                }
                else
                {
                    _Client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue(config.UserAgentProductName, config.UserAgentProductVersion));
                    _Client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue("(Yort.Humm.Instore/" + typeof(HummClient).Assembly.GetName().Version.ToString() + ")"));
                }
            }
            catch
            {
                handler?.Dispose();
                if (_Config.HttpClient == null)
                {
                    _Client?.Dispose();
                }

                throw;
            }
        }
Beispiel #2
0
        public HummClient(HummClientConfiguration config)
#pragma warning restore CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.
        {
            _Config  = config.GuardNull(nameof(config));
            _BaseUrl = config.BaseApiUrl.GuardNull(nameof(config), nameof(config.BaseApiUrl));

            _Serialiser = new Newtonsoft.Json.JsonSerializer()
            {
                Formatting = Newtonsoft.Json.Formatting.None,
            };

            ConfigureServicePoint();

            CreateOrConfigureHttpClient(config);

            if (!String.IsNullOrEmpty(_Config.DeviceKey))
            {
                SetDeviceKey(_Config.DeviceKey);
            }
        }