From dadc44203dd4677c81fe5d4b3eed1162e2823cc5 Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Tue, 5 Mar 2024 14:45:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(microapp):=20=E6=9E=84=E9=80=A0=E5=99=A8?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DouyinMicroAppClientBuilder.cs | 94 +++++++++++++++++++ .../DouyinMicroAppOpenApiClientBuilder.cs | 94 +++++++++++++++++++ .../DouyinMicroAppProductApiClientBuilder.cs | 94 +++++++++++++++++++ .../DouyinMicroAppRoleApiClientBuilder.cs | 94 +++++++++++++++++++ 4 files changed, 376 insertions(+) create mode 100644 src/SKIT.FlurlHttpClient.ByteDance.MicroApp/DouyinMicroAppClientBuilder.cs create mode 100644 src/SKIT.FlurlHttpClient.ByteDance.MicroApp/ExtendedSDK/OpenApi/DouyinMicroAppOpenApiClientBuilder.cs create mode 100644 src/SKIT.FlurlHttpClient.ByteDance.MicroApp/ExtendedSDK/ProductApi/DouyinMicroAppProductApiClientBuilder.cs create mode 100644 src/SKIT.FlurlHttpClient.ByteDance.MicroApp/ExtendedSDK/RoleApi/DouyinMicroAppRoleApiClientBuilder.cs diff --git a/src/SKIT.FlurlHttpClient.ByteDance.MicroApp/DouyinMicroAppClientBuilder.cs b/src/SKIT.FlurlHttpClient.ByteDance.MicroApp/DouyinMicroAppClientBuilder.cs new file mode 100644 index 00000000..22efdb02 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.ByteDance.MicroApp/DouyinMicroAppClientBuilder.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; + +namespace SKIT.FlurlHttpClient.ByteDance.MicroApp +{ + /// + /// 用于构造 实例的构造器。 + /// + public partial class DouyinMicroAppClientBuilder : ICommonClientBuilder + { + private readonly DouyinMicroAppClientOptions _options; + private readonly IList> _configures; + private readonly IList _interceptors; + private HttpClient? _httpClient; + private bool? _disposeClient; + + private DouyinMicroAppClientBuilder(DouyinMicroAppClientOptions options) + { + _options = options; + _configures = new List>(); + _interceptors = new List(); + } + + ICommonClientBuilder ICommonClientBuilder.ConfigureSettings(Action configure) + { + return ConfigureSettings(configure); + } + + ICommonClientBuilder ICommonClientBuilder.UseInterceptor(HttpInterceptor interceptor) + { + return UseInterceptor(interceptor); + } + + ICommonClientBuilder ICommonClientBuilder.UseHttpClient(HttpClient httpClient, bool disposeClient) + { + return UseHttpClient(httpClient, disposeClient); + } + + public DouyinMicroAppClientBuilder ConfigureSettings(Action configure) + { + if (configure is null) throw new ArgumentNullException(nameof(configure)); + + _configures.Add(configure); + return this; + } + + public DouyinMicroAppClientBuilder UseInterceptor(HttpInterceptor interceptor) + { + if (interceptor is null) throw new ArgumentNullException(nameof(interceptor)); + + _interceptors.Add(interceptor); + return this; + } + + public DouyinMicroAppClientBuilder UseHttpClient(HttpClient httpClient, bool disposeClient = true) + { + if (httpClient is null) throw new ArgumentNullException(nameof(httpClient)); + + _httpClient = httpClient; + _disposeClient = disposeClient; + return this; + } + + public DouyinMicroAppClient Build() + { + DouyinMicroAppClient client = _disposeClient.HasValue + ? new DouyinMicroAppClient(_options, _httpClient, _disposeClient.Value) + : new DouyinMicroAppClient(_options, _httpClient); + + foreach (Action configure in _configures) + { + client.Configure(configure); + } + + foreach (HttpInterceptor interceptor in _interceptors) + { + client.Interceptors.Add(interceptor); + } + + return client; + } + } + + partial class DouyinMicroAppClientBuilder + { + public static DouyinMicroAppClientBuilder Create(DouyinMicroAppClientOptions options) + { + if (options is null) throw new ArgumentNullException(nameof(options)); + + return new DouyinMicroAppClientBuilder(options); + } + } +} diff --git a/src/SKIT.FlurlHttpClient.ByteDance.MicroApp/ExtendedSDK/OpenApi/DouyinMicroAppOpenApiClientBuilder.cs b/src/SKIT.FlurlHttpClient.ByteDance.MicroApp/ExtendedSDK/OpenApi/DouyinMicroAppOpenApiClientBuilder.cs new file mode 100644 index 00000000..b4bce120 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.ByteDance.MicroApp/ExtendedSDK/OpenApi/DouyinMicroAppOpenApiClientBuilder.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; + +namespace SKIT.FlurlHttpClient.ByteDance.MicroApp.ExtendedSDK.OpenApi +{ + /// + /// 用于构造 实例的构造器。 + /// + public partial class DouyinMicroAppOpenApiClientBuilder : ICommonClientBuilder + { + private readonly DouyinMicroAppOpenApiClientOptions _options; + private readonly IList> _configures; + private readonly IList _interceptors; + private HttpClient? _httpClient; + private bool? _disposeClient; + + private DouyinMicroAppOpenApiClientBuilder(DouyinMicroAppOpenApiClientOptions options) + { + _options = options; + _configures = new List>(); + _interceptors = new List(); + } + + ICommonClientBuilder ICommonClientBuilder.ConfigureSettings(Action configure) + { + return ConfigureSettings(configure); + } + + ICommonClientBuilder ICommonClientBuilder.UseInterceptor(HttpInterceptor interceptor) + { + return UseInterceptor(interceptor); + } + + ICommonClientBuilder ICommonClientBuilder.UseHttpClient(HttpClient httpClient, bool disposeClient) + { + return UseHttpClient(httpClient, disposeClient); + } + + public DouyinMicroAppOpenApiClientBuilder ConfigureSettings(Action configure) + { + if (configure is null) throw new ArgumentNullException(nameof(configure)); + + _configures.Add(configure); + return this; + } + + public DouyinMicroAppOpenApiClientBuilder UseInterceptor(HttpInterceptor interceptor) + { + if (interceptor is null) throw new ArgumentNullException(nameof(interceptor)); + + _interceptors.Add(interceptor); + return this; + } + + public DouyinMicroAppOpenApiClientBuilder UseHttpClient(HttpClient httpClient, bool disposeClient = true) + { + if (httpClient is null) throw new ArgumentNullException(nameof(httpClient)); + + _httpClient = httpClient; + _disposeClient = disposeClient; + return this; + } + + public DouyinMicroAppOpenApiClient Build() + { + DouyinMicroAppOpenApiClient client = _disposeClient.HasValue + ? new DouyinMicroAppOpenApiClient(_options, _httpClient, _disposeClient.Value) + : new DouyinMicroAppOpenApiClient(_options, _httpClient); + + foreach (Action configure in _configures) + { + client.Configure(configure); + } + + foreach (HttpInterceptor interceptor in _interceptors) + { + client.Interceptors.Add(interceptor); + } + + return client; + } + } + + partial class DouyinMicroAppOpenApiClientBuilder + { + public static DouyinMicroAppOpenApiClientBuilder Create(DouyinMicroAppOpenApiClientOptions options) + { + if (options is null) throw new ArgumentNullException(nameof(options)); + + return new DouyinMicroAppOpenApiClientBuilder(options); + } + } +} diff --git a/src/SKIT.FlurlHttpClient.ByteDance.MicroApp/ExtendedSDK/ProductApi/DouyinMicroAppProductApiClientBuilder.cs b/src/SKIT.FlurlHttpClient.ByteDance.MicroApp/ExtendedSDK/ProductApi/DouyinMicroAppProductApiClientBuilder.cs new file mode 100644 index 00000000..9edd2691 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.ByteDance.MicroApp/ExtendedSDK/ProductApi/DouyinMicroAppProductApiClientBuilder.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; + +namespace SKIT.FlurlHttpClient.ByteDance.MicroApp.ExtendedSDK.ProductApi +{ + /// + /// 用于构造 实例的构造器。 + /// + public partial class DouyinMicroAppProductApiClientBuilder : ICommonClientBuilder + { + private readonly DouyinMicroAppProductApiClientOptions _options; + private readonly IList> _configures; + private readonly IList _interceptors; + private HttpClient? _httpClient; + private bool? _disposeClient; + + private DouyinMicroAppProductApiClientBuilder(DouyinMicroAppProductApiClientOptions options) + { + _options = options; + _configures = new List>(); + _interceptors = new List(); + } + + ICommonClientBuilder ICommonClientBuilder.ConfigureSettings(Action configure) + { + return ConfigureSettings(configure); + } + + ICommonClientBuilder ICommonClientBuilder.UseInterceptor(HttpInterceptor interceptor) + { + return UseInterceptor(interceptor); + } + + ICommonClientBuilder ICommonClientBuilder.UseHttpClient(HttpClient httpClient, bool disposeClient) + { + return UseHttpClient(httpClient, disposeClient); + } + + public DouyinMicroAppProductApiClientBuilder ConfigureSettings(Action configure) + { + if (configure is null) throw new ArgumentNullException(nameof(configure)); + + _configures.Add(configure); + return this; + } + + public DouyinMicroAppProductApiClientBuilder UseInterceptor(HttpInterceptor interceptor) + { + if (interceptor is null) throw new ArgumentNullException(nameof(interceptor)); + + _interceptors.Add(interceptor); + return this; + } + + public DouyinMicroAppProductApiClientBuilder UseHttpClient(HttpClient httpClient, bool disposeClient = true) + { + if (httpClient is null) throw new ArgumentNullException(nameof(httpClient)); + + _httpClient = httpClient; + _disposeClient = disposeClient; + return this; + } + + public DouyinMicroAppProductApiClient Build() + { + DouyinMicroAppProductApiClient client = _disposeClient.HasValue + ? new DouyinMicroAppProductApiClient(_options, _httpClient, _disposeClient.Value) + : new DouyinMicroAppProductApiClient(_options, _httpClient); + + foreach (Action configure in _configures) + { + client.Configure(configure); + } + + foreach (HttpInterceptor interceptor in _interceptors) + { + client.Interceptors.Add(interceptor); + } + + return client; + } + } + + partial class DouyinMicroAppProductApiClientBuilder + { + public static DouyinMicroAppProductApiClientBuilder Create(DouyinMicroAppProductApiClientOptions options) + { + if (options is null) throw new ArgumentNullException(nameof(options)); + + return new DouyinMicroAppProductApiClientBuilder(options); + } + } +} diff --git a/src/SKIT.FlurlHttpClient.ByteDance.MicroApp/ExtendedSDK/RoleApi/DouyinMicroAppRoleApiClientBuilder.cs b/src/SKIT.FlurlHttpClient.ByteDance.MicroApp/ExtendedSDK/RoleApi/DouyinMicroAppRoleApiClientBuilder.cs new file mode 100644 index 00000000..44d6d817 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.ByteDance.MicroApp/ExtendedSDK/RoleApi/DouyinMicroAppRoleApiClientBuilder.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; + +namespace SKIT.FlurlHttpClient.ByteDance.MicroApp.ExtendedSDK.RoleApi +{ + /// + /// 用于构造 实例的构造器。 + /// + public partial class DouyinMicroAppRoleApiClientBuilder : ICommonClientBuilder + { + private readonly DouyinMicroAppRoleApiClientOptions _options; + private readonly IList> _configures; + private readonly IList _interceptors; + private HttpClient? _httpClient; + private bool? _disposeClient; + + private DouyinMicroAppRoleApiClientBuilder(DouyinMicroAppRoleApiClientOptions options) + { + _options = options; + _configures = new List>(); + _interceptors = new List(); + } + + ICommonClientBuilder ICommonClientBuilder.ConfigureSettings(Action configure) + { + return ConfigureSettings(configure); + } + + ICommonClientBuilder ICommonClientBuilder.UseInterceptor(HttpInterceptor interceptor) + { + return UseInterceptor(interceptor); + } + + ICommonClientBuilder ICommonClientBuilder.UseHttpClient(HttpClient httpClient, bool disposeClient) + { + return UseHttpClient(httpClient, disposeClient); + } + + public DouyinMicroAppRoleApiClientBuilder ConfigureSettings(Action configure) + { + if (configure is null) throw new ArgumentNullException(nameof(configure)); + + _configures.Add(configure); + return this; + } + + public DouyinMicroAppRoleApiClientBuilder UseInterceptor(HttpInterceptor interceptor) + { + if (interceptor is null) throw new ArgumentNullException(nameof(interceptor)); + + _interceptors.Add(interceptor); + return this; + } + + public DouyinMicroAppRoleApiClientBuilder UseHttpClient(HttpClient httpClient, bool disposeClient = true) + { + if (httpClient is null) throw new ArgumentNullException(nameof(httpClient)); + + _httpClient = httpClient; + _disposeClient = disposeClient; + return this; + } + + public DouyinMicroAppRoleApiClient Build() + { + DouyinMicroAppRoleApiClient client = _disposeClient.HasValue + ? new DouyinMicroAppRoleApiClient(_options, _httpClient, _disposeClient.Value) + : new DouyinMicroAppRoleApiClient(_options, _httpClient); + + foreach (Action configure in _configures) + { + client.Configure(configure); + } + + foreach (HttpInterceptor interceptor in _interceptors) + { + client.Interceptors.Add(interceptor); + } + + return client; + } + } + + partial class DouyinMicroAppRoleApiClientBuilder + { + public static DouyinMicroAppRoleApiClientBuilder Create(DouyinMicroAppRoleApiClientOptions options) + { + if (options is null) throw new ArgumentNullException(nameof(options)); + + return new DouyinMicroAppRoleApiClientBuilder(options); + } + } +}