Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bindings for ISteamRemoteStorage/GetCollectionDetails endpoint. #107

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/SteamWebAPI2/Interfaces/ISteamRemoteStorage.cs
Original file line number Diff line number Diff line change
@@ -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<ISteamWebResponse<IReadOnlyCollection<CollectionDetail>>> GetCollectionDetails(ulong collectionId);

Task<ISteamWebResponse<IReadOnlyCollection<CollectionDetail>>> GetCollectionDetails(IList<ulong> collectionId);

Task<ISteamWebResponse<IReadOnlyCollection<PublishedFileDetailsModel>>> GetPublishedFileDetailsAsync(uint itemCount, IList<ulong> publishedFileIds);

Task<ISteamWebResponse<IReadOnlyCollection<PublishedFileDetailsModel>>> GetPublishedFileDetailsAsync(IList<ulong> publishedFileIds);
Expand Down
45 changes: 45 additions & 0 deletions src/SteamWebAPI2/Interfaces/SteamRemoteStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,51 @@ public SteamRemoteStorage(IMapper mapper, ISteamWebRequest steamWebRequest, ISte
: steamWebInterface;
}

/// <summary>
/// Retrieves the list of items in the provided collection.
/// </summary>
/// <param name="collectionId">The collection's ID.</param>
/// <returns>A collection of the details of each collection or <c>null</c> if the request failed.</returns>
public async Task<ISteamWebResponse<IReadOnlyCollection<CollectionDetail>>> GetCollectionDetails(ulong collectionId) => await GetCollectionDetails(new List<ulong> { collectionId });

/// <summary>
/// Retrieves the list of items in the provided collections.
/// </summary>
/// <param name="collectionIds">The list of IDs of collections for which to retrieve details.</param>
/// <returns>A collection of the details of each collection or <c>null</c> if the request failed.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="collectionIds"/> is null.</exception>
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="collectionIds"/> is empty.</exception>
public async Task<ISteamWebResponse<IReadOnlyCollection<CollectionDetail>>> GetCollectionDetails(IList<ulong> collectionIds)
{
if (collectionIds == null)
throw new ArgumentNullException(nameof(collectionIds));

if (!collectionIds.Any())
throw new ArgumentOutOfRangeException(nameof(collectionIds), $"{nameof(collectionIds)} is empty.");

IList<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();

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<CollectionDetailsResponseContainer>("GetCollectionDetails", 1, parameters);

var steamWebResponseModel = mapper.Map<
ISteamWebResponse<CollectionDetailsResponseContainer>,
ISteamWebResponse<IReadOnlyCollection<CollectionDetail>>>(steamWebResponse);

return steamWebResponseModel;
}
catch (HttpRequestException)
{
return null;
}
}

/// <summary>
/// Retrieves information about published files such as workshop items and screenshots.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/SteamWebAPI2/Mappings/SteamRemoteStorageProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public SteamRemoteStorageProfile()
CreateMap<UGCFileDetailsResultContainer, UGCFileDetailsModel>().ConvertUsing((src, dest, context) =>
context.Mapper.Map<UGCFileDetails, UGCFileDetailsModel>(src.Result)
);
CreateMap<CollectionDetailsResponseContainer, IReadOnlyCollection<CollectionDetail>>().ConvertUsing((src, dest, context) =>
context.Mapper.Map<IReadOnlyCollection<CollectionDetail>>(src.Response.CollectionDetails));
}
}
}
1 change: 1 addition & 0 deletions src/SteamWebAPI2/Mappings/SteamWebResponseProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public SteamWebResponseProfile()
CreateSteamWebResponseMap<PublishedFileDetailsResultContainer, IReadOnlyCollection<PublishedFileDetailsModel>>();
CreateSteamWebResponseMap<PublishedFileDetailsResultContainer, PublishedFileDetailsModel>();
CreateSteamWebResponseMap<UGCFileDetailsResultContainer, UGCFileDetailsModel>();
CreateSteamWebResponseMap<CollectionDetailsResponseContainer, IReadOnlyCollection<CollectionDetail>>();
CreateSteamWebResponseMap<PlayerSummaryResultContainer, PlayerSummaryModel>();
CreateSteamWebResponseMap<PlayerSummaryResultContainer, IReadOnlyCollection<PlayerSummaryModel>>();
CreateSteamWebResponseMap<FriendsListResultContainer, IReadOnlyCollection<FriendModel>>();
Expand Down
47 changes: 47 additions & 0 deletions src/SteamWebAPI2/Models/CollectionDetailsResponseContainer.cs
Original file line number Diff line number Diff line change
@@ -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<CollectionDetail> CollectionDetails { get; set; }
}

public class CollectionDetail
{
[JsonProperty("publishedfileid")]
public string PublishedFileId { get; set; }

[JsonProperty("result")]
public uint Result { get; set; }

[JsonProperty("children")]
public IList<CollectionDetailItem> 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; }
}
}