internal static ISonarrClient GenerateClient(HttpClientHandler handler, ISonarrUrl url, IApiKey apiKey, bool allowRedirects, WebProxy proxy = null) { if (proxy != null) { handler.Proxy = proxy; } handler.AllowAutoRedirect = allowRedirects; var client = new SonarrRestClient(handler) { BaseAddress = url.Url }; client.AddApiKey(apiKey); return(client); }
/// <summary> /// Creates a new <see cref="ISonarrClient"/> instance with the provided handler and details. /// </summary> /// <param name="handler">The <see cref="HttpClientHandler"/> used when constructing the internal HTTP client.</param> /// <param name="url">The URL of the Sonarr instance the <see cref="ISonarrClient"/> will target.</param> /// <param name="apiKey">The api key used in all RESTful requests for authentication.</param> /// <param name="allowRedirects">Instructs the <see cref="ISonarrClient"/> whether or not it should follow redirects.</param> /// <param name="proxyUrl">A proxy URL used by the <see cref="ISonarrClient"/> when sending requests.</param> /// <param name="proxyCredentials">A set of credentials to authenticate to the proxy.</param> /// <param name="bypassOnLocal">Indicates to bypass the proxy when a destination is determined to be local to the client.</param> /// <returns>An <see cref="ISonarrClient"/> instance with the specified settings.</returns> public static ISonarrClient GenerateClient(HttpClientHandler handler, ISonarrUrl url, IApiKey apiKey, bool allowRedirects, string proxyUrl, ICredentials proxyCredentials, bool bypassOnLocal) { WebProxy proxy = null; if (!string.IsNullOrEmpty(proxyUrl)) { proxy = new WebProxy(proxyUrl, bypassOnLocal); if (proxyCredentials != null) { proxy.Credentials = proxyCredentials; } else { proxy.UseDefaultCredentials = true; } } return(GenerateClient(handler, url, apiKey, allowRedirects, proxy)); }