/// <summary> /// Constructs a new instance of <see cref="RestfulBusinessApiClient"/> /// </summary> /// <param name="apiConfig"></param> public RestfulBusinessApiClient(RqlApiConfiguration apiConfig) { if (apiConfig == null) { throw new ArgumentNullException("apiConfig"); } if (string.IsNullOrEmpty(apiConfig.Site)) { throw new ArgumentException("SiteName cannot be null or empty", "apiConfig"); } if (string.IsNullOrEmpty(apiConfig.UserName)) { throw new ArgumentException("UserName cannot be null or empty", "apiConfig"); } if (string.IsNullOrEmpty(apiConfig.Password)) { throw new ArgumentException("Password cannot be null or empty", "apiConfig"); } _apiConfig = apiConfig; _httpClient = CreateHttpClient(apiConfig); EnableTls(); InitializeConnectionLeaseTimeout(); }
private HttpClient CreateHttpClient(RqlApiConfiguration apiConfig) { var httpClient = new HttpClient { BaseAddress = apiConfig.GetBusinessApiBaseUri(), Timeout = apiConfig.RequestTimeout }; if (!string.IsNullOrEmpty(apiConfig.UserAgent)) { httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(apiConfig.UserAgent); } httpClient.DefaultRequestHeaders.Accept .Add(new MediaTypeWithQualityHeaderValue(ContentType.Json)); //ACCEPT header return(httpClient); }