This commit is contained in:
Archi
2023-11-14 20:58:02 +01:00
parent 0ae03c7cd5
commit 103c543eea
8 changed files with 153 additions and 126 deletions

View File

@@ -22,6 +22,7 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ArchiSteamFarm.Web;
using ArchiSteamFarm.Web.Responses;
@@ -34,12 +35,12 @@ namespace ArchiSteamFarm.CustomPlugins.ExamplePlugin;
internal static class CatAPI {
private const string URL = "https://api.thecatapi.com";
internal static async Task<Uri?> GetRandomCatURL(WebBrowser webBrowser) {
internal static async Task<Uri?> GetRandomCatURL(WebBrowser webBrowser, CancellationToken cancellationToken = default) {
ArgumentNullException.ThrowIfNull(webBrowser);
Uri request = new($"{URL}/v1/images/search");
ObjectResponse<ImmutableList<MeowResponse>>? response = await webBrowser.UrlGetToJsonObject<ImmutableList<MeowResponse>>(request).ConfigureAwait(false);
ObjectResponse<ImmutableList<MeowResponse>>? response = await webBrowser.UrlGetToJsonObject<ImmutableList<MeowResponse>>(request, cancellationToken: cancellationToken).ConfigureAwait(false);
return response?.Content?.FirstOrDefault()?.URL;
}