private void Initialise(string username, string password, HttpMessageHandler messageHandler = null) { if (string.IsNullOrEmpty(username)) { throw new ArgumentException($"{UsernameConfigKey} has not been set."); } if (string.IsNullOrEmpty(password)) { throw new ArgumentException($"{PasswordConfigKey} has not been set."); } Account = new Account(this); Inbound = new Inbound(this); Outbound = new Outbound(this); Documents = new Documents(this); HttpClient = messageHandler == null ? new HttpClient() : new HttpClient(messageHandler); HttpClient.BaseAddress = new Uri("https://rest.interfax.net/"); HttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpClient.DefaultRequestHeaders.Add("Authorization", new List <string> { $"Basic {Utils.Base64Encode($"{username}:{password}")}" }); JsonConvert.DefaultSettings = () => { var settings = new JsonSerializerSettings(); settings.Converters.Add(new StringEnumConverter { CamelCaseText = true }); return(settings); }; }
private void Initialise(string username, string password, ApiRoot apiRoot, HttpMessageHandler messageHandler = null, HttpClient httpClient = null) { if (string.IsNullOrEmpty(username)) { throw new ArgumentException($"{UsernameConfigKey} has not been set."); } if (string.IsNullOrEmpty(password)) { throw new ArgumentException($"{PasswordConfigKey} has not been set."); } Account = new Account(this); Inbound = new Inbound(this); Outbound = new Outbound(this); Documents = new Documents(this); HttpClient = messageHandler == null ? new HttpClient() : new HttpClient(messageHandler); HttpClient = httpClient != null ? httpClient : HttpClient; var root = ""; switch (apiRoot) { case ApiRoot.InterFAX_PCI: root = "https://rest-sl.interfax.net"; break; case ApiRoot.InterFAX_Default: root = "https://rest.interfax.net"; break; } HttpClient.BaseAddress = new Uri(root); HttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpClient.DefaultRequestHeaders.Add("Authorization", new List <string> { $"Basic {Utils.Base64Encode($"{username}:{password}")}" }); JsonConvert.DefaultSettings = () => { var settings = new JsonSerializerSettings(); //Required StringEnumConverter moved to Documents.cs as Custom settings, instead of overriding defaults. //settings.Converters.Add(new StringEnumConverter { CamelCaseText = true }); return(settings); }; }