From 35e0d1068e33e3ec9f4a66337ae4d586ecf64f38 Mon Sep 17 00:00:00 2001 From: emorell96 Date: Tue, 23 Mar 2021 23:20:26 -0700 Subject: [PATCH] added a HttpClientFactoryRestClientProvider to avoid having to expose a HttpClientFactoryRestClient. --- .../HttpClientFactoryRestClientProvider.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/Discord.Net.Rest/Net/HttpClientFactoryRestClientProvider.cs diff --git a/src/Discord.Net.Rest/Net/HttpClientFactoryRestClientProvider.cs b/src/Discord.Net.Rest/Net/HttpClientFactoryRestClientProvider.cs new file mode 100644 index 000000000..3da937f6f --- /dev/null +++ b/src/Discord.Net.Rest/Net/HttpClientFactoryRestClientProvider.cs @@ -0,0 +1,25 @@ +using System; +using System.Net.Http; + +namespace Discord.Net.Rest +{ + public static class HttpClientFactoryRestClientProvider + { + + /// The default RestClientProvider is not supported on this platform. + public static RestClientProvider Create(HttpClient httpClient, bool useProxy = false) + { + return url => + { + try + { + return new HttpClientFactoryRestClient(url, httpClient, useProxy); + } + catch (PlatformNotSupportedException ex) + { + throw new PlatformNotSupportedException("The default RestClientProvider is not supported on this platform.", ex); + } + }; + } + } +}