From 9163b57c3e0e1d0aa52038b1545afa07e791b1f5 Mon Sep 17 00:00:00 2001 From: Rudokhvist Date: Wed, 20 Sep 2023 13:40:41 +0300 Subject: [PATCH] Switch to different cat api in example plugin (#3006) * switch to different cat api * damn forgot json constructor * check for empty array in responce * revert meowresponse.cs * use firstordefault() --- ArchiSteamFarm.CustomPlugins.ExamplePlugin/CatAPI.cs | 10 ++++++---- .../MeowResponse.cs | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ArchiSteamFarm.CustomPlugins.ExamplePlugin/CatAPI.cs b/ArchiSteamFarm.CustomPlugins.ExamplePlugin/CatAPI.cs index 37a02fd02..9ad415cc4 100644 --- a/ArchiSteamFarm.CustomPlugins.ExamplePlugin/CatAPI.cs +++ b/ArchiSteamFarm.CustomPlugins.ExamplePlugin/CatAPI.cs @@ -20,6 +20,8 @@ // limitations under the License. using System; +using System.Collections.Immutable; +using System.Linq; using System.Threading.Tasks; using ArchiSteamFarm.Web; using ArchiSteamFarm.Web.Responses; @@ -30,15 +32,15 @@ namespace ArchiSteamFarm.CustomPlugins.ExamplePlugin; // You've always wanted from your ASF to post cats, right? Now is your chance! // P.S. The code is almost 1:1 copy from the one I use in ArchiBot, you can thank me later internal static class CatAPI { - private const string URL = "https://aws.random.cat"; + private const string URL = "https://api.thecatapi.com"; internal static async Task GetRandomCatURL(WebBrowser webBrowser) { ArgumentNullException.ThrowIfNull(webBrowser); - Uri request = new($"{URL}/meow"); + Uri request = new($"{URL}/v1/images/search"); - ObjectResponse? response = await webBrowser.UrlGetToJsonObject(request).ConfigureAwait(false); + ObjectResponse>? response = await webBrowser.UrlGetToJsonObject>(request).ConfigureAwait(false); - return response?.Content?.URL; + return response?.Content?.FirstOrDefault()?.URL; } } diff --git a/ArchiSteamFarm.CustomPlugins.ExamplePlugin/MeowResponse.cs b/ArchiSteamFarm.CustomPlugins.ExamplePlugin/MeowResponse.cs index 6ccaf7bcc..c143df357 100644 --- a/ArchiSteamFarm.CustomPlugins.ExamplePlugin/MeowResponse.cs +++ b/ArchiSteamFarm.CustomPlugins.ExamplePlugin/MeowResponse.cs @@ -28,7 +28,7 @@ namespace ArchiSteamFarm.CustomPlugins.ExamplePlugin; #pragma warning disable CA1812 // False positive, the class is used during json deserialization [SuppressMessage("ReSharper", "ClassCannotBeInstantiated")] internal sealed class MeowResponse { - [JsonProperty("file", Required = Required.Always)] + [JsonProperty("url", Required = Required.Always)] internal readonly Uri URL = null!; [JsonConstructor]