Simplecast.Client 1.0.0
dotnet add package Simplecast.Client --version 1.0.0
NuGet\Install-Package Simplecast.Client -Version 1.0.0
<PackageReference Include="Simplecast.Client" Version="1.0.0" />
paket add Simplecast.Client --version 1.0.0
#r "nuget: Simplecast.Client, 1.0.0"
// Install Simplecast.Client as a Cake Addin #addin nuget:?package=Simplecast.Client&version=1.0.0 // Install Simplecast.Client as a Cake Tool #tool nuget:?package=Simplecast.Client&version=1.0.0
Simplecast 客户端库 .NET
Simplecast .NET 客户端库是一个针对 .NET Standard 2.0 和 .NET 4.6.1 的客户端库,它提供了一个轻松与 Simplecast API(https://api.simplecast.com/)交互的方法。
所有请求都必须使用您的 API 密钥进行身份验证,该密钥可在您的 Simplecast 账户设置中找到。您可以选择以下三种方式之一进行身份验证:使用 HTTP Basic Auth,将其作为请求参数传递或设置 HTTP 标头。您的 API 密钥可在您的 Simplecast 账户设置 中找到。
用法
Simplecast.Client 可以与任何 DI 库一起使用,或者可以独立使用。
独立初始化
如果您不想使用任何 DI 框架,您必须如下实例化 SimplecastClientStandalone
。
ApiOptions apiOptions = new ApiOptions("<your token>", "https://api.simplecast.com/v1/");
var apiClientContext = SimplecastClientStandalone.Create(apiOptions);
IEpisodeClient episodeClient = apiClientContext.EpisodeClient;
IPlayerEmbedClient playerEmbedClient = apiClientContext.PlayerEmbedClient;
IPodcastClient podcastClient = apiClientContext.PodcastClient;
IStatisticClient statisticClient = apiClientContext.StatisticClient;
apiClientContext
包含所有必要的客户端。
Microsoft.Extensions.DependencyInjection 初始化
首先,您需要按照如下方式安装 Microsoft.Extensions.DependencyInjection
和 Microsoft.Extensions.Http
NuGet 包
dotnet add package Microsoft.Extensions.DependencyInjection
dotnet add package Microsoft.Extensions.Http
通过安装 Microsoft.Extensions.Http
,您将能够使用 HttpClientFactory
。用 ASP.NET Team 的话说,它是一个“具有特定观点的 HttpClient 实例创建工厂”,是随着 ASP.NET Core 2.1 版本一起推出的新功能。
如果您不想使用 HttpClientFactory
,您必须自己将 HttpClient
注册到容器中。
按照如下方式将必要的依赖项注册到 ServiceCollection
中
var apiOptions = new ApiOptions("<your token>", "https://api.simplecast.com/v1/");
var services = new ServiceCollection();
services.AddSingleton(apiOptions);
services.AddHttpClient<IRestApiClient, RestApiClient>();
services.AddTransient<IPodcastClient, PodcastClient>();
services.AddTransient<IEpisodeClient, EpisodeClient>();
services.AddTransient<IPlayerEmbedClient, PlayerEmbedClient>();
services.AddTransient<IStatisticClient, StatisticClient>();
ServiceProvider buildServiceProvider = services.BuildServiceProvider();
var podcastClient = buildServiceProvider.GetRequiredService<IPodcastClient>();
var episodeClient = buildServiceProvider.GetRequiredService<IEpisodeClient>();
var playerEmbedClient = buildServiceProvider.GetRequiredService<IPlayerEmbedClient>();
var statisticClient = buildServiceProvider.GetRequiredService<IStatisticClient>();
调用端点
调用端点有两种方式。唯一的区别是返回类型。以 ResponseAsync 结尾的方法返回包含模型本身、HTTP 状态码、错误信息和响应头的 ApiResponse<TModel>
。
ApiResponse<List<Episode>> episodesResponse = await episodeClient.GetEpisodesResponseAsync(podcastId);
if(episodesResponse.Error)
{
HttpStatusCode statusCode = episodesResponse.HttpStatusCode;
string errorMessage = episodesResponse.Message;
IDictionary<string, string> headers = episodesResponse.Headers;
string urlPath = episodesResponse.UrlPath;
// Handle http error
}
List<Episode> episodes = episodesResponse.Model;
以 Async 结尾的方法不返回额外的 HTTP 响应信息,只返回模型本身。但在 HTTP 错误的情况下,您需要处理异常。
List<Episode> episodes = await episodeClient.GetEpisodesAsync(podcastId);
产品 | 版本 兼容和额外的目标框架版本。 |
---|---|
.NET | net5.0 已计算。 net5.0-windows 已计算。 net6.0 已计算。 net6.0-android 已计算。 net6.0-ios 已计算。 net6.0-maccatalyst 已计算。 net6.0-macos 已计算。 net6.0-tvos 已计算。 net6.0-windows 已计算。 net7.0 已计算。 net7.0-android 已计算。 net7.0-ios 已计算。 net7.0-maccatalyst 已计算。 net7.0-macos 已计算。 net7.0-tvos 已计算。 net7.0-windows 已计算。 net8.0 已计算。 net8.0-android 已计算。 net8.0-browser 已计算。 net8.0-ios 已计算。 net8.0-maccatalyst 已计算。 net8.0-macos 已计算。 net8.0-tvos 已计算。 net8.0-windows 已计算。 |
.NET Core | netcoreapp2.0 已计算。 netcoreapp2.1 已计算。 netcoreapp2.2 已计算。 netcoreapp3.0 已计算。 netcoreapp3.1 已计算。 |
.NET 标准化 | netstandard2.0 兼容。 netstandard2.1 已计算。 |
.NET 框架 | net461 兼容。 net462 已计算。 net463 已计算。 net47 已计算。 net471 已计算。 net472 已计算。 net48 已计算。 net481 已计算。 |
MonoAndroid | monoandroid 已计算。 |
MonoMac | monomac 已计算。 |
MonoTouch | monotouch 已计算。 |
Tizen | tizen40 已计算。 tizen60 已计算。 |
Xamarin.iOS | xamarinios 已计算。 |
Xamarin.Mac | xamarinmac 已计算。 |
Xamarin.TVOS | xamarintvos 已计算。 |
Xamarin.WatchOS | xamarinwatchos 已计算。 |
-
.NETFramework 4.6.1
- Newtonsoft.Json (>= 11.0.2)
- System.Net.Http (>= 4.3.3)
-
.NETStandard 2.0
- Newtonsoft.Json (>= 11.0.2)
- System.Net.Http (>= 4.3.3)
NuGet 包
此包不被任何 NuGet 包使用。
GitHub 仓库
此包不被任何流行的 GitHub 仓库使用。
版本 | 下载 | 最后更新时间 |
---|---|---|
1.0.0 | 777 | 10/11/2018 |