Skip to content

Commit

Permalink
Merge pull request #6 from DineshSolanki/feature/collection
Browse files Browse the repository at this point in the history
collections endpoints
  • Loading branch information
DineshSolanki authored Sep 12, 2024
2 parents 26202e4 + 828dceb commit a42f30d
Show file tree
Hide file tree
Showing 7 changed files with 394 additions and 11 deletions.
200 changes: 200 additions & 0 deletions DeviantArt.Net/Api/CollectionClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
using DeviantArt.Net.Models.Deviation;
using DeviantArt.Net.Models.User;
using DeviantArt.Net.Modules;

namespace DeviantArt.Net.Api;

public partial class Client
{
/// <summary>
/// Fetches the contents of a collection folder.
/// </summary>
/// <param name="folderId">The ID of the collection folder.</param>
/// <param name="offset">The offset for pagination.</param>
/// <param name="limit">The maximum number of deviations to retrieve.</param>
/// <param name="withSession">Whether to include session information.</param>
/// <param name="matureContent">Whether to include mature content.</param>
/// <returns>A paginated list of deviations.</returns>
public async Task<PaginatedBase<Deviation>> GetCollectionAsync(Guid folderId, int? offset = null, int? limit = null, bool? withSession = null, bool? matureContent = null)
{
return await _api.GetCollection(folderId, offset, limit, withSession, matureContent);
}

/// <summary>
/// Creates a new collection folder.
/// </summary>
/// <param name="collectionName">The name of the new collection folder.</param>
/// <returns>The created folder.</returns>
public async Task<Folder> CreateCollectionAsync(string collectionName)
{
return await _api.CreateCollection(new Dictionary<string, object> {{"folder", collectionName}});
}

/// <summary>
/// Fetches deviations from all collection folders.
/// </summary>
/// <param name="username">The username of the user whose collections are to be retrieved. If null, retrieves the authenticated user's collections.</param>
/// <param name="offset">The offset for pagination.</param>
/// <param name="limit">The maximum number of deviations to retrieve.</param>
/// <param name="withSession">Whether to include session information.</param>
/// <param name="matureContent">Whether to include mature content.</param>
/// <returns>A paginated list of deviations.</returns>
public async Task<PaginatedBase<Deviation>> GetFromAllCollectionsAsync(string? username = null, int? offset = null, int? limit = null, bool? withSession = null, bool? matureContent = null)
{
return await _api.GetFromAllCollections(username, offset, limit, withSession, matureContent);
}

/// <summary>
/// Fetches all collection folders.
/// </summary>
/// <param name="username">The username of the user whose collection folders are to be retrieved. If null, retrieves the authenticated user's collection folders.</param>
/// <param name="calculateSize">Whether to calculate the size of each folder.</param>
/// <param name="extPreload">Whether to preload extended information.</param>
/// <param name="filterEmptyFolder">Filter to exclude empty folders.</param>
/// <param name="offset">The offset for pagination.</param>
/// <param name="limit">The maximum number of folders to retrieve.</param>
/// <param name="withSession">Whether to include session information.</param>
/// <param name="matureContent">Whether to include mature content.</param>
/// <returns>A paginated list of collection folders.</returns>
public async Task<PaginatedBase<CollectionFolder>> GetAllCollectionsAsync(string? username = null, bool? calculateSize = null, bool? extPreload = null, bool? filterEmptyFolder = null, int? offset = null, int? limit = null, bool? withSession = null, bool? matureContent = null)
{
return await _api.GetAllCollections(username, calculateSize, extPreload, filterEmptyFolder, offset, limit, withSession, matureContent);
}

/// <summary>
/// Adds deviations to favorites, optionally into a collection folder.
/// </summary>
/// <param name="deviationId">The ID of the deviation to add to favorites.</param>
/// <param name="collectionIds">The list of collection folder IDs to add the deviation to. If null, adds to the Featured collection.</param>
/// <returns>A simple response indicating the result of the operation.</returns>
public async Task<SimpleResponseBase> AddDeviationsToFavouritesAsync(Guid deviationId, List<Guid>? collectionIds = null)
{
var request = new Dictionary<string, object> {{"deviationid", deviationId}};
request.AddIfNotNull("folderid", collectionIds);
return await _api.AddDeviationsToFavourites(request);
}

/// <summary>
/// Copies a list of deviations to a collection.
/// </summary>
/// <param name="copyDeviationsRequest">The request containing the target folder ID and the list of deviation IDs to copy.</param>
/// <returns>A simple response indicating the result of the operation.</returns>
public async Task<SimpleResponseBase> CopyDeviationsToCollectionAsync(CopyDeviationsRequest copyDeviationsRequest)
{
var requestDictionary = new Dictionary<string, object>
{
{ "target_folderid", copyDeviationsRequest.TargetFolderId },
};
requestDictionary.AddEnumerable("deviationids", copyDeviationsRequest.DeviationIds);
return await _api.CopyDeviationsToCollection(requestDictionary);
}

/// <summary>
/// Moves a list of deviations to a collection.
/// </summary>
/// <param name="moveDeviationsRequest">The request containing the target folder ID, source folder ID, and the list of deviation IDs to move.</param>
/// <returns>A simple response indicating the result of the operation.</returns>
public async Task<SimpleResponseBase> MoveDeviationsToCollectionAsync(MoveDeviationsRequest moveDeviationsRequest)
{
var requestDictionary = new Dictionary<string, object>
{
{ "target_folderid", moveDeviationsRequest.TargetFolderId },
{ "source_folderid", moveDeviationsRequest.SourceFolderId }
};
requestDictionary.AddEnumerable("deviationids", moveDeviationsRequest.DeviationIds);
return await _api.MoveDeviationsToCollection(requestDictionary);
}

/// <summary>
/// Removes a collection folder.
/// </summary>
/// <param name="folderId">The ID of the collection folder to remove.</param>
/// <returns>A simple response indicating the result of the operation.</returns>
public async Task<SimpleResponseBase> RemoveCollectionAsync(Guid folderId)
{
return await _api.RemoveCollection(folderId);
}

/// <summary>
/// Removes a list of deviations from a collection.
/// </summary>
/// <param name="folderId">The ID of the collection folder.</param>
/// <param name="deviationIds">The list of deviation IDs to remove.</param>
/// <returns>A simple response indicating the result of the operation.</returns>
public async Task<SimpleResponseBase> RemoveDeviationsFromCollectionAsync(Guid folderId, List<Guid> deviationIds)
{
var requestDictionary = new Dictionary<string, object>
{
{ " folderid ", folderId }
};
requestDictionary.AddEnumerable("deviationids", deviationIds);
return await _api.RemoveDeviationsFromCollection(requestDictionary);
}

/// <summary>
/// Updates a collection folder.
/// </summary>
/// <param name="folderId">The ID of the collection folder to update.</param>
/// <param name="name">The new name of the collection folder.</param>
/// <param name="description">The new description of the collection folder.</param>
/// <param name="coverDeviationId">The ID of the cover deviation.</param>
/// <returns>A simple response indicating the result of the operation.</returns>
public async Task<SimpleResponseBase> UpdateCollectionAsync(Guid folderId, string? name, string? description = null, Guid? coverDeviationId = null)
{
var request = new Dictionary<string, object>
{
{ "folderid", folderId },
};
request.AddIfNotNull("name", name);
request.AddIfNotNull("description", description);
request.AddIfNotNull("cover_deviationid", coverDeviationId);
return await _api.UpdateCollection(request);
}

/// <summary>
/// Updates the order of deviations in a collection folder.
/// </summary>
/// <param name="folderId">The ID of the collection folder.</param>
/// <param name="deviationId">The ID of the deviation to reorder.</param>
/// <param name="position">The new position of the deviation.</param>
/// <returns>A simple response indicating the result of the operation.</returns>
public async Task<SimpleResponseBase> UpdateDeviationOrderCollectionAsync(Guid folderId, Guid deviationId, int position)
{
var request = new Dictionary<string, object>
{
{ "folderid", folderId }
};
request.AddIfNotNull("deviationid", deviationId);
request.AddIfNotNull("position", position);
return await _api.UpdateDeviationOrderCollection(request);
}

/// <summary>
/// Rearranges the position of collection folders.
/// </summary>
/// <param name="folderId">The ID of the collection folder.</param>
/// <param name="position">The new position of the collection folder.</param>
/// <returns>A simple response indicating the result of the operation.</returns>
public async Task<SimpleResponseBase> UpdateCollectionOrderAsync(Guid folderId, int position)
{
var request = new Dictionary<string, object>
{
{ "folderid", folderId },
{ "position", position }
};
return await _api.UpdateOrderCollection(request);
}

/// <summary>
/// Removes a list of deviations from favorites.
/// </summary>
/// <param name="deviationId">The ID of the deviation to remove from favorites.</param>
/// <param name="folderId">Optional UUID remove from a single collection folder</param>
/// <returns>A simple response indicating the result of the operation.</returns>
public async Task<SimpleResponseBase> RemoveDeviationsFromFavouritesAsync(Guid deviationId, List<Guid>? folderId = null)
{
var request = new Dictionary<string, object> {{"deviationid", deviationId}};
request.AddIfNotNull("folderid", folderId);
return await _api.RemoveDeviationsFromFavourites(request);
}
}
14 changes: 7 additions & 7 deletions DeviantArt.Net/Api/GalleryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public partial class Client
/// <param name="withSession">Whether to include session information.</param>
/// <returns>A paginated list of gallery folders.</returns>
public async Task<PaginatedBase<GalleryFolder>> GetGalleryFoldersAsync(string? username = null,
bool? calculateSize = null, bool? extPreload = null, string? filterEmptyFolder = null, int? offset = null, int? limit = null,
bool? calculateSize = null, bool? extPreload = null, bool? filterEmptyFolder = null, int? offset = null, int? limit = null,
bool? withSession = null)
{
return await _api.GetGalleryFoldersAsync(username, calculateSize, extPreload, filterEmptyFolder, offset, limit, withSession);
Expand Down Expand Up @@ -66,12 +66,12 @@ public async Task<PaginatedBase<Deviation>> GetAllGalleryFoldersAsync(string? us
/// <returns>A simple response indicating the result of the operation.</returns>
public async Task<SimpleResponseBase> CopyDeviationsAsync(CopyDeviationsRequest request)
{
var requeDictionary = new Dictionary<string, object>
var requestDictionary = new Dictionary<string, object>
{
{ "target_folderid", request.TargetFolderId },
};
requeDictionary.AddEnumerable("deviationids", request.DeviationIds);
return await _api.CopyDeviationsAsync(requeDictionary);
requestDictionary.AddEnumerable("deviationids", request.DeviationIds);
return await _api.CopyDeviationsAsync(requestDictionary);
}

/// <summary>
Expand All @@ -81,13 +81,13 @@ public async Task<SimpleResponseBase> CopyDeviationsAsync(CopyDeviationsRequest
/// <returns>A simple response indicating the result of the operation.</returns>
public async Task<SimpleResponseBase> MoveDeviationsAsync(MoveDeviationsRequest request)
{
var requeDictionary = new Dictionary<string, object>
var requestDictionary = new Dictionary<string, object>
{
{ "target_folderid", request.TargetFolderId },
{ "source_folderid", request.SourceFolderId }
};
requeDictionary.AddEnumerable("deviationids", request.DeviationIds);
return await _api.MoveDeviationsAsync(requeDictionary);
requestDictionary.AddEnumerable("deviationids", request.DeviationIds);
return await _api.MoveDeviationsAsync(requestDictionary);
}

/// <summary>
Expand Down
61 changes: 61 additions & 0 deletions DeviantArt.Net/Api/ICollectionApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using DeviantArt.Net.Models.Deviation;
using DeviantArt.Net.Models.User;

namespace DeviantArt.Net.Api;

internal partial interface IDeviantArtApi
{
[Get("/api/v1/oauth2/collections/{folderId}")]
Task<PaginatedBase<Deviation>> GetCollection(Guid folderId,
[AliasAs("offset")] int? offset = null,
[AliasAs("limit")] int? limit = null,
[AliasAs("with_session")] bool? withSession = null,
[AliasAs("mature_content")] bool? matureContent = null);

[Post("/api/v1/oauth2/collections/folders/create")]
Task<Folder> CreateCollection([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, object> data);

[Get("/api/v1/oauth2/collections/all")]
Task<PaginatedBase<Deviation>> GetFromAllCollections([AliasAs("username")]string? username,
[AliasAs("offset")] int? offset = null,
[AliasAs("limit")] int? limit = null,
[AliasAs("with_session")] bool? withSession = null,
[AliasAs("mature_content")] bool? matureContent = null);

[Get("/api/v1/oauth2/collections/folders")]
Task<PaginatedBase<CollectionFolder>> GetAllCollections([AliasAs("username")]string? username,
[AliasAs("calculate_size")] bool? calculateSize,
[AliasAs("ext_preload")] bool? extPreload,
[AliasAs("filter_empty_folder")] bool? filterEmptyFolder,
[AliasAs("offset")] int? offset = null,
[AliasAs("limit")] int? limit = null,
[AliasAs("with_session")] bool? withSession = null,
[AliasAs("mature_content")] bool? matureContent = null);

[Post("/api/v1/oauth2/collections/fave")]
Task<SimpleResponseBase> AddDeviationsToFavourites([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, object> request);

[Post("/api/v1/oauth2/collections/folders/copy_deviations")]
Task<SimpleResponseBase> CopyDeviationsToCollection([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, object> request);

[Post("/api/v1/oauth2/collections/folders/move_deviations")]
Task<SimpleResponseBase> MoveDeviationsToCollection([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, object> request);

[Get("/api/v1/oauth2/collections/folders/remove/{folderId}")]
Task<SimpleResponseBase> RemoveCollection(Guid folderId);

[Post("/api/v1/oauth2/collections/folders/remove_deviations")]
Task<SimpleResponseBase> RemoveDeviationsFromCollection([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, object> request);

[Post("/api/v1/oauth2/collections/folders/update")]
Task<SimpleResponseBase> UpdateCollection([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, object> request);

[Post("/api/v1/oauth2/collections/folders/update_deviation_order")]
Task<SimpleResponseBase> UpdateDeviationOrderCollection([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, object> request);

[Post("/api/v1/oauth2/collections/folders/update_order")]
Task<SimpleResponseBase> UpdateOrderCollection([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, object> request);

[Post("/api/v1/oauth2/collections/unfave")]
Task<SimpleResponseBase> RemoveDeviationsFromFavourites([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, object> request);
}
2 changes: 1 addition & 1 deletion DeviantArt.Net/Api/IGalleryApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal partial interface IDeviantArtApi
Task<PaginatedBase<GalleryFolder>> GetGalleryFoldersAsync([Query] string? username,
[AliasAs("calculate_size")] bool? calculateSize,
[AliasAs("ext_preload")] bool? extPreload,
[AliasAs("filter_empty_folder")] string? filterEmptyFolder,
[AliasAs("filter_empty_folder")] bool? filterEmptyFolder,
[Query] int? offset,
[Query] int? limit,
[AliasAs("with_session")] bool? withSession);
Expand Down
4 changes: 2 additions & 2 deletions DeviantArt.Net/Models/Scope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public enum Scope
[Description("gallery")] [EnumMember(Value = "gallery")]
Gallery,

/*
Collection,*/
[Description("collection")] [EnumMember(Value = "collection")]
Collection
}
Loading

0 comments on commit a42f30d

Please sign in to comment.