From d9355ceab0c21128a1c0c45ff7472dca8dab12fe Mon Sep 17 00:00:00 2001 From: JustArchi Date: Wed, 3 Jun 2020 16:52:08 +0200 Subject: [PATCH] Unify NumberResponse as EResultResponse Since it uses a number, very likely it is indeed EResult under the hood, and not just a boolean written as 0 and 1. --- ArchiSteamFarm/ArchiWebHandler.cs | 20 +++++++++++++----- ArchiSteamFarm/Json/Steam.cs | 34 +------------------------------ 2 files changed, 16 insertions(+), 38 deletions(-) diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 040600579..96e92c7fa 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -153,7 +153,7 @@ namespace ArchiSteamFarm { throw new HttpRequestException(string.Format(Strings.ErrorObjectIsNull, nameof(response))); } - if (!response.Success) { + if (response.Result != EResult.OK) { throw new HttpRequestException(!string.IsNullOrEmpty(response.Error) ? string.Format(Strings.WarningFailedWithError, response.Error) : Strings.WarningFailed); } @@ -1232,9 +1232,19 @@ namespace ArchiSteamFarm { { "giftcardid", giftCardID.ToString() } }; - Steam.NumberResponse result = await UrlPostToJsonObjectWithSession(SteamStoreURL, request, data).ConfigureAwait(false); + Steam.EResultResponse response = await UrlPostToJsonObjectWithSession(SteamStoreURL, request, data).ConfigureAwait(false); - return result?.Success == true; + if (response == null) { + return false; + } + + if (response.Result != EResult.OK) { + Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed); + + return false; + } + + return true; } internal async Task<(bool Success, bool RequiresMobileConfirmation)> AcceptTradeOffer(ulong tradeID) { @@ -1301,13 +1311,13 @@ namespace ArchiSteamFarm { { "Privacy", JsonConvert.SerializeObject(userPrivacy.Settings) } }; - Steam.NumberResponse response = await UrlPostToJsonObjectWithSession(SteamCommunityURL, request, data).ConfigureAwait(false); + Steam.EResultResponse response = await UrlPostToJsonObjectWithSession(SteamCommunityURL, request, data).ConfigureAwait(false); if (response == null) { return false; } - if (!response.Success) { + if (response.Result != EResult.OK) { Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed); return false; diff --git a/ArchiSteamFarm/Json/Steam.cs b/ArchiSteamFarm/Json/Steam.cs index 9a3236432..405b28f4f 100644 --- a/ArchiSteamFarm/Json/Steam.cs +++ b/ArchiSteamFarm/Json/Steam.cs @@ -400,38 +400,6 @@ namespace ArchiSteamFarm.Json { protected EResultResponse() { } } - [SuppressMessage("ReSharper", "ClassCannotBeInstantiated")] - public class NumberResponse { - [JsonIgnore] - [PublicAPI] - public bool Success { get; private set; } - -#pragma warning disable IDE0051 - [JsonProperty(PropertyName = "success", Required = Required.Always)] - private byte SuccessNumber { - set { - switch (value) { - case 0: - Success = false; - - break; - case 1: - Success = true; - - break; - default: - ASF.ArchiLogger.LogGenericError(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(value), value)); - - return; - } - } - } -#pragma warning restore IDE0051 - - [JsonConstructor] - protected NumberResponse() { } - } - // REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_TradeOffer public sealed class TradeOffer { [PublicAPI] @@ -476,7 +444,7 @@ namespace ArchiSteamFarm.Json { } [SuppressMessage("ReSharper", "ClassCannotBeInstantiated")] - internal sealed class InventoryResponse : NumberResponse { + internal sealed class InventoryResponse : EResultResponse { [JsonProperty(PropertyName = "assets", Required = Required.DisallowNull)] internal readonly ImmutableHashSet Assets;