Very important CatAPI fixes

This commit is contained in:
JustArchi
2022-06-24 23:19:31 +02:00
parent 053cb5fc03
commit d338477e5c
4 changed files with 44 additions and 26 deletions

View File

@@ -34,32 +34,13 @@ namespace ArchiSteamFarm.CustomPlugins.ExamplePlugin;
internal static class CatAPI {
private const string URL = "https://aws.random.cat";
internal static async Task<string?> GetRandomCatURL(WebBrowser webBrowser) {
internal static async Task<Uri?> GetRandomCatURL(WebBrowser webBrowser) {
ArgumentNullException.ThrowIfNull(webBrowser);
Uri request = new($"{URL}/meow");
ObjectResponse<MeowResponse>? response = await webBrowser.UrlGetToJsonObject<MeowResponse>(request).ConfigureAwait(false);
if (response?.Content == null) {
return null;
}
if (string.IsNullOrEmpty(response.Content.Link)) {
throw new InvalidOperationException(nameof(response.Content.Link));
}
return Uri.EscapeDataString(response.Content.Link);
return response?.Content?.URL;
}
#pragma warning disable CA1812 // False positive, the class is used during json deserialization
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
private sealed class MeowResponse {
[JsonProperty("file", Required = Required.Always)]
internal readonly string Link = "";
[JsonConstructor]
private MeowResponse() { }
}
#pragma warning restore CA1812 // False positive, the class is used during json deserialization
}