-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new ASF API endpoint for inventory summary, add inventory command
Wow, new features in ASF?!
- Loading branch information
Showing
10 changed files
with
336 additions
and
8 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
ArchiSteamFarm/Helpers/Json/BooleanNormalizationConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// ---------------------------------------------------------------------------------------------- | ||
// _ _ _ ____ _ _____ | ||
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ | ||
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ | ||
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | | ||
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| | ||
// ---------------------------------------------------------------------------------------------- | ||
// | | ||
// Copyright 2015-2025 Łukasz "JustArchi" Domeradzki | ||
// Contact: [email protected] | ||
// | | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using JetBrains.Annotations; | ||
|
||
namespace ArchiSteamFarm.Helpers.Json; | ||
|
||
[PublicAPI] | ||
public sealed class BooleanNormalizationConverter : JsonConverter<bool> { | ||
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => | ||
reader.TokenType switch { | ||
JsonTokenType.True => true, | ||
JsonTokenType.False => false, | ||
JsonTokenType.Number => reader.GetByte() == 1, | ||
JsonTokenType.String => reader.GetString() == "1", | ||
_ => throw new JsonException() | ||
}; | ||
|
||
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options) { | ||
ArgumentNullException.ThrowIfNull(writer); | ||
|
||
writer.WriteBooleanValue(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// ---------------------------------------------------------------------------------------------- | ||
// _ _ _ ____ _ _____ | ||
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ | ||
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ | ||
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | | ||
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| | ||
// ---------------------------------------------------------------------------------------------- | ||
// | | ||
// Copyright 2015-2025 Łukasz "JustArchi" Domeradzki | ||
// Contact: [email protected] | ||
// | | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Collections.Immutable; | ||
using System.Text.Json.Serialization; | ||
using ArchiSteamFarm.Helpers.Json; | ||
|
||
namespace ArchiSteamFarm.Steam.Data; | ||
|
||
public sealed class InventoryAppData { | ||
[JsonInclude] | ||
[JsonPropertyName("appid")] | ||
[JsonRequired] | ||
public uint AppID { get; private init; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("asset_count")] | ||
[JsonRequired] | ||
public uint AssetsCount { get; private init; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("rgContexts")] | ||
[JsonRequired] | ||
public ImmutableDictionary<ulong, InventoryContextData> Contexts { get; private init; } = ImmutableDictionary<ulong, InventoryContextData>.Empty; | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("icon")] | ||
[JsonRequired] | ||
public Uri Icon { get; private init; } = null!; | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("inventory_logo")] | ||
public Uri? InventoryLogo { get; private init; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("link")] | ||
[JsonRequired] | ||
public Uri Link { get; private init; } = null!; | ||
|
||
// This seems to be rendered as number always, but who knows, better treat it like other brain damages in this response | ||
[JsonConverter(typeof(BooleanNormalizationConverter))] | ||
[JsonInclude] | ||
[JsonPropertyName("load_failed")] | ||
[JsonRequired] | ||
public bool LoadFailed { get; private init; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("name")] | ||
[JsonRequired] | ||
public string Name { get; private init; } = ""; | ||
|
||
// Steam renders this sometimes as a number, sometimes as a boolean, because fuck you, that's why | ||
[JsonConverter(typeof(BooleanNormalizationConverter))] | ||
[JsonInclude] | ||
[JsonPropertyName("owner_only")] | ||
[JsonRequired] | ||
public bool OwnerOnly { get; private init; } | ||
|
||
// Steam renders this sometimes as a string, sometimes as a boolean, because fuck you, that's why | ||
[JsonConverter(typeof(BooleanNormalizationConverter))] | ||
[JsonInclude] | ||
[JsonPropertyName("store_vetted")] | ||
[JsonRequired] | ||
public bool StoreVetted { get; private init; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("trade_permissions")] | ||
[JsonRequired] | ||
public string TradePermissions { get; private init; } = ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// ---------------------------------------------------------------------------------------------- | ||
// _ _ _ ____ _ _____ | ||
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ | ||
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ | ||
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | | ||
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| | ||
// ---------------------------------------------------------------------------------------------- | ||
// | | ||
// Copyright 2015-2025 Łukasz "JustArchi" Domeradzki | ||
// Contact: [email protected] | ||
// | | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System.Text.Json.Serialization; | ||
|
||
namespace ArchiSteamFarm.Steam.Data; | ||
|
||
public sealed class InventoryContextData { | ||
[JsonInclude] | ||
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString)] | ||
[JsonPropertyName("id")] | ||
[JsonRequired] | ||
public ulong ID { get; private init; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("name")] | ||
[JsonRequired] | ||
public string Name { get; private init; } = ""; | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("asset_count")] | ||
[JsonRequired] | ||
public uint AssetsCount { get; private init; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.