Skip to content

Commit

Permalink
Implement store.getFavoriteStickers method (vknet#1501)
Browse files Browse the repository at this point in the history
  • Loading branch information
smtyper committed Nov 16, 2024
1 parent b8060df commit 1bf56c7
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 0 deletions.
35 changes: 35 additions & 0 deletions VkNet.Tests/Categories/Store/StoreCategoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,39 @@ public void AddStickersToFavorite()
result.Should()
.BeTrue();
}

[Fact]
public void GetFavoriteStickers()
{
Url = "https://api.vk.com/method/store.getFavoriteStickers";

ReadCategoryJsonPath(nameof(GetFavoriteStickers));

var result = Api.Store.GetFavoriteStickers();

result.Count.Should()
.Be(2);

var first = result[0];

first.Id.Should()
.Be(126);

first.InnerType.Should()
.Be("base_sticker_new");

first.IsAllowed.Should()
.BeTrue();

var second = result[1];

second.Id.Should()
.Be(70);

second.InnerType.Should()
.Be("base_sticker_new");

second.IsAllowed.Should()
.BeFalse();
}
}
17 changes: 17 additions & 0 deletions VkNet.Tests/TestData/Categories/Store/GetFavoriteStickers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"response": {
"count": 2,
"items": [
{
"inner_type": "base_sticker_new",
"sticker_id": 126,
"is_allowed": true
},
{
"inner_type": "base_sticker_new",
"sticker_id": 70,
"is_allowed": false
}
]
}
}
10 changes: 10 additions & 0 deletions VkNet/Abstractions/Category/Async/IStoreCategoryAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,14 @@ public interface IStoreCategoryAsync
/// </remarks>
Task<bool> AddStickersToFavoriteAsync(StoreAddStickerToFavoriteParams @params,
CancellationToken token = default);

/// <summary>
/// Возвращает список избранных стикеров.
/// </summary>
/// <param name="token">Токен отмены операции</param>
/// <returns>После успешного выполнения возвращает список объектов Sticker</returns>
/// <remarks>
/// Страница документации ВКонтакте https://dev.vk.com/ru/method/store.getFavoriteStickers
/// </remarks>
Task<VkCollection<Sticker>> GetFavoriteStickersAsync(CancellationToken token = default);
}
3 changes: 3 additions & 0 deletions VkNet/Abstractions/Category/IStoreCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ public interface IStoreCategory : IStoreCategoryAsync
{
/// <inheritdoc cref="IStoreCategoryAsync.AddStickersToFavoriteAsync"/>
bool AddStickersToFavorite(StoreAddStickerToFavoriteParams @params);

/// <inheritdoc cref="IStoreCategoryAsync.GetFavoriteStickersAsync"/>
VkCollection<Sticker> GetFavoriteStickers();
}
4 changes: 4 additions & 0 deletions VkNet/Categories/Async/StoreCategoryAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ public bool AddStickersToFavorite(StoreAddStickerToFavoriteParams @params) =>
"sticker_ids", @params.StickerIds
}
});

/// <inheritdoc />
public VkCollection<Sticker> GetFavoriteStickers() =>
_vk.Call<VkCollection<Sticker>>("store.getFavoriteStickers", new());
}
5 changes: 5 additions & 0 deletions VkNet/Categories/StoreCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public Task<bool> AddStickersToFavoriteAsync(StoreAddStickerToFavoriteParams @pa
CancellationToken token = default) =>
TypeHelper.TryInvokeMethodAsync(() =>
AddStickersToFavorite(@params), token);

/// <inheritdoc />
public Task<VkCollection<Sticker>> GetFavoriteStickersAsync(CancellationToken token = default) =>
TypeHelper.TryInvokeMethodAsync(
GetFavoriteStickers, token);
}
19 changes: 19 additions & 0 deletions VkNet/Model/Attachments/Sticker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,23 @@ private long? StickerId
get => Id;
set => Id = value;
}

/// <summary>
/// URL анимации стикера (для анимированных стикеров)
/// </summary>
[JsonProperty("animation_url")]
public bool AnimationUrl { get; set; }

/// <summary>
/// Тип, который описывает вариант формата ответа.
/// </summary>
/// <remarks>По умолчанию: "base_sticker_new"</remarks>
[JsonProperty("inner_type")]
public string InnerType { get; set; }

/// <summary>
/// Информация о том, доступен ли стикер
/// </summary>
[JsonProperty("is_allowed")]
public bool IsAllowed { get; set; }
}

0 comments on commit 1bf56c7

Please sign in to comment.