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); 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>(); diff --git a/src/SteamWebAPI2/Models/CollectionDetailsResponseContainer.cs b/src/SteamWebAPI2/Models/CollectionDetailsResponseContainer.cs new file mode 100644 index 0000000..bbb512a --- /dev/null +++ b/src/SteamWebAPI2/Models/CollectionDetailsResponseContainer.cs @@ -0,0 +1,47 @@ +using Newtonsoft.Json; +using System.Collections.Generic; + +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; } + } +}