From ed94ac42ba7d2853ac68e3a6d695b3af55f84adc Mon Sep 17 00:00:00 2001 From: Oliver <8377772+oliver4888@users.noreply.github.com> Date: Mon, 5 Oct 2020 21:35:05 +0100 Subject: [PATCH 1/3] Add GetCollectionDetails. --- .../CollectionDetailsResponseContainer.cs | 30 +++++++++++++ .../Interfaces/SteamRemoteStorage.cs | 45 +++++++++++++++++++ .../Mappings/SteamRemoteStorageProfile.cs | 2 + .../Mappings/SteamWebResponseProfile.cs | 1 + 4 files changed, 78 insertions(+) create mode 100644 src/Steam.Models/CollectionDetailsResponseContainer.cs diff --git a/src/Steam.Models/CollectionDetailsResponseContainer.cs b/src/Steam.Models/CollectionDetailsResponseContainer.cs new file mode 100644 index 0000000..c5b5990 --- /dev/null +++ b/src/Steam.Models/CollectionDetailsResponseContainer.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; + +namespace Steam.Models +{ + public class CollectionDetailsResponseContainer + { + public CollectionDetailsResponse Response { get; set; } + } + + public class CollectionDetailsResponse + { + public uint Result { get; set; } + public uint ResultCount { get; set; } + public IList CollectionDetails { get; set; } + } + + public class CollectionDetail + { + public string PublishedFileId { get; set; } + public uint Result { get; set; } + public IList Children { get; set; } + } + + public class CollectionDetailItem + { + public string PublishedFileId { get; set; } + public uint SortOrder { get; set; } + public uint FileType { get; set; } + } +} diff --git a/src/SteamWebAPI2/Interfaces/SteamRemoteStorage.cs b/src/SteamWebAPI2/Interfaces/SteamRemoteStorage.cs index 5ada500..7d76226 100644 --- a/src/SteamWebAPI2/Interfaces/SteamRemoteStorage.cs +++ b/src/SteamWebAPI2/Interfaces/SteamRemoteStorage.cs @@ -29,6 +29,51 @@ public SteamRemoteStorage(IMapper mapper, ISteamWebRequest steamWebRequest, ISte : steamWebInterface; } + /// + /// Retrieves the list of items in the provided collection. + /// + /// The collection's ID. + /// A collection of the details of each collection or null if the request failed. + public async Task>> GetCollectionDetails(ulong collectionId) => await GetCollectionDetails(new List { collectionId }); + + /// + /// Retrieves the list of items in the provided collections. + /// + /// The list of IDs of collections for which to retrieve details. + /// A collection of the details of each collection or null if the request failed. + /// Thrown when is null. + /// Thrown when is empty. + public async Task>> GetCollectionDetails(IList collectionIds) + { + if (collectionIds == null) + throw new ArgumentNullException(nameof(collectionIds)); + + if (!collectionIds.Any()) + throw new ArgumentOutOfRangeException(nameof(collectionIds), $"{nameof(collectionIds)} is empty."); + + IList parameters = new List(); + + parameters.AddIfHasValue(collectionIds.Count, "collectioncount"); + + for (int i = 0; i < collectionIds.Count; ++i) + parameters.AddIfHasValue(collectionIds[i], $"publishedfileids[{i}]"); + + try + { + var steamWebResponse = await steamWebInterface.PostAsync("GetCollectionDetails", 1, parameters); + + var steamWebResponseModel = mapper.Map< + ISteamWebResponse, + ISteamWebResponse>>(steamWebResponse); + + return steamWebResponseModel; + } + catch (HttpRequestException) + { + return null; + } + } + /// /// Retrieves information about published files such as workshop items and screenshots. /// diff --git a/src/SteamWebAPI2/Mappings/SteamRemoteStorageProfile.cs b/src/SteamWebAPI2/Mappings/SteamRemoteStorageProfile.cs index cd7dd7f..5976337 100644 --- a/src/SteamWebAPI2/Mappings/SteamRemoteStorageProfile.cs +++ b/src/SteamWebAPI2/Mappings/SteamRemoteStorageProfile.cs @@ -36,6 +36,8 @@ public SteamRemoteStorageProfile() CreateMap().ConvertUsing((src, dest, context) => context.Mapper.Map(src.Result) ); + CreateMap>().ConvertUsing((src, dest, context) => + context.Mapper.Map>(src.Response.CollectionDetails)); } } } \ No newline at end of file diff --git a/src/SteamWebAPI2/Mappings/SteamWebResponseProfile.cs b/src/SteamWebAPI2/Mappings/SteamWebResponseProfile.cs index ae9ef74..7b2f11f 100644 --- a/src/SteamWebAPI2/Mappings/SteamWebResponseProfile.cs +++ b/src/SteamWebAPI2/Mappings/SteamWebResponseProfile.cs @@ -62,6 +62,7 @@ public SteamWebResponseProfile() CreateSteamWebResponseMap>(); CreateSteamWebResponseMap(); CreateSteamWebResponseMap(); + CreateSteamWebResponseMap>(); CreateSteamWebResponseMap(); CreateSteamWebResponseMap>(); CreateSteamWebResponseMap>(); From 37fc0898290f3b68f67238c26e4b8ca7045a65d7 Mon Sep 17 00:00:00 2001 From: Oliver <8377772+oliver4888@users.noreply.github.com> Date: Mon, 5 Oct 2020 22:01:53 +0100 Subject: [PATCH 2/3] Move CollectionDetailsResponseContainer and add JsonProperty attributes. --- .../CollectionDetailsResponseContainer.cs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) rename src/{Steam.Models => SteamWebAPI2/Models}/CollectionDetailsResponseContainer.cs (61%) diff --git a/src/Steam.Models/CollectionDetailsResponseContainer.cs b/src/SteamWebAPI2/Models/CollectionDetailsResponseContainer.cs similarity index 61% rename from src/Steam.Models/CollectionDetailsResponseContainer.cs rename to src/SteamWebAPI2/Models/CollectionDetailsResponseContainer.cs index c5b5990..bbb512a 100644 --- a/src/Steam.Models/CollectionDetailsResponseContainer.cs +++ b/src/SteamWebAPI2/Models/CollectionDetailsResponseContainer.cs @@ -1,30 +1,47 @@ -using System.Collections.Generic; +using Newtonsoft.Json; +using System.Collections.Generic; -namespace Steam.Models +namespace SteamWebAPI2.Models { public class CollectionDetailsResponseContainer { + [JsonProperty("response")] public CollectionDetailsResponse Response { get; set; } } public class CollectionDetailsResponse { + [JsonProperty("result")] public uint Result { get; set; } + + [JsonProperty("resultcount")] public uint ResultCount { get; set; } + + [JsonProperty("collectiondetails")] public IList CollectionDetails { get; set; } } public class CollectionDetail { + [JsonProperty("publishedfileid")] public string PublishedFileId { get; set; } + + [JsonProperty("result")] public uint Result { get; set; } + + [JsonProperty("children")] public IList Children { get; set; } } public class CollectionDetailItem { + [JsonProperty("publishedfileid")] public string PublishedFileId { get; set; } + + [JsonProperty("sortorder")] public uint SortOrder { get; set; } + + [JsonProperty("filetype")] public uint FileType { get; set; } } } From ea9d647ccae51cace76f2794e6a3ed7d597c5644 Mon Sep 17 00:00:00 2001 From: Oliver <8377772+oliver4888@users.noreply.github.com> Date: Mon, 5 Oct 2020 22:35:05 +0100 Subject: [PATCH 3/3] Add collection methods to ISteamRemoteStorage. --- src/SteamWebAPI2/Interfaces/ISteamRemoteStorage.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/SteamWebAPI2/Interfaces/ISteamRemoteStorage.cs b/src/SteamWebAPI2/Interfaces/ISteamRemoteStorage.cs index f951876..96f105b 100644 --- a/src/SteamWebAPI2/Interfaces/ISteamRemoteStorage.cs +++ b/src/SteamWebAPI2/Interfaces/ISteamRemoteStorage.cs @@ -1,13 +1,17 @@ using Steam.Models; +using SteamWebAPI2.Models; using SteamWebAPI2.Utilities; using System.Threading.Tasks; +using System.Collections.Generic; namespace SteamWebAPI2.Interfaces { - using System.Collections.Generic; - public interface ISteamRemoteStorage { + Task>> GetCollectionDetails(ulong collectionId); + + Task>> GetCollectionDetails(IList collectionId); + Task>> GetPublishedFileDetailsAsync(uint itemCount, IList publishedFileIds); Task>> GetPublishedFileDetailsAsync(IList publishedFileIds);