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()
This commit is contained in:
Rudokhvist
2023-09-20 13:40:41 +03:00
committed by GitHub
parent 69aaca3bad
commit 9163b57c3e
2 changed files with 7 additions and 5 deletions

View File

@@ -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<Uri?> GetRandomCatURL(WebBrowser webBrowser) {
ArgumentNullException.ThrowIfNull(webBrowser);
Uri request = new($"{URL}/meow");
Uri request = new($"{URL}/v1/images/search");
ObjectResponse<MeowResponse>? response = await webBrowser.UrlGetToJsonObject<MeowResponse>(request).ConfigureAwait(false);
ObjectResponse<ImmutableList<MeowResponse>>? response = await webBrowser.UrlGetToJsonObject<ImmutableList<MeowResponse>>(request).ConfigureAwait(false);
return response?.Content?.URL;
return response?.Content?.FirstOrDefault()?.URL;
}
}

View File

@@ -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]