Skip to content

Commit

Permalink
Add fields for method "market.get" (#1580)
Browse files Browse the repository at this point in the history
## List of changes
- added support for new fields of method
*[market.get](https://dev.vk.com/ru/method/market.get)* - date_from,
date_to, need_variants, with_disabled
- added model *MarketGetParams* for wrap arguments for method
*market.get*
- added unit test and test data for thid method

[Source of args](https://dev.vk.com/ru/method/market.get)

Bound with issue #1222

---------

Co-authored-by: inyutin-maxim <[email protected]>
  • Loading branch information
Rahovski and inyutin-maxim authored Aug 28, 2023
1 parent cde6328 commit 2796c74
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 0 deletions.
73 changes: 73 additions & 0 deletions VkNet.Tests/Categories/Market/MarketGetTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using FluentAssertions;
using System.Reflection;
using VkNet.Tests.Infrastructure;
using Xunit;

namespace VkNet.Tests.Categories.Market
{
public class MarketGetTest : CategoryBaseTest
{
protected override string Folder => "Market";

[Fact]
public void MarketGet()
{
Url = "https://api.vk.com/method/market.get";

ReadCategoryJsonPath(nameof(Api.Markets.Get));

var result = Api.Markets.Get(new()
{
OwnerId = -85689507,
Count = 2,
Offset = 0,
DateFrom = "10.08.2022",
DateTo = "10.06.2023"
});

result.Should().
NotBeNull();

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

result[0].Title.
Should().
Be("Жетон Bronze");

result[0].Price.
Amount.
Should().
Be(89000);

result[0].Category.
Name.
Should().
Be("Кошельки, ключницы и брелки");

result[0].Category.
Section.
Name.
Should().
Be("Гардероб");

result[1].Title.
Should().
Be("Жетон Black");

result[1].Price.
Amount.
Should().
Be(89000);

result[1].Description.
Should().
Be("Брендированный жетон в расцветке Black");

result[1].OwnerId.
Should().
Be(-85689507);
}
}
}
73 changes: 73 additions & 0 deletions VkNet.Tests/TestData/Categories/Market/Get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"response": {
"count": 18,
"items": [
{
"availability": 0,
"category": {
"id": 40105,
"name": "Кошельки, ключницы и брелки",
"section": {
"id": 10000,
"name": "Гардероб"
}
},
"description": "Брендированный жетон в расцветке Bronze",
"id": 6148970,
"owner_id": -85689507,
"price": {
"amount": "89000",
"currency": {
"id": 643,
"name": "RUB",
"title": ""
},
"text": "890 ₽"
},
"title": "Жетон Bronze",
"is_owner": false,
"is_adult": false,
"thumb_photo": "https://sun6-23.userapi.com/impg/ylLImplvcmF0omQmzaenCERHGvW4DKGPb26kEw/45ids_vcpKY.jpg?crop=0,0.125,1,0.75&size=400x0&quality=95&sign=63cdf689f65863d29bd1b59d22a28d8a&c_uniq_tag=2b7ctR3uLfKgLuyMMK2DLEpDeUzLLnavkx6vHEvV3BM",
"cart_quantity": 0,
"item_rating": {
"rating": 0,
"reviews_count": 0,
"reviews_count_text": "Нет отзывов"
}
},
{
"availability": 0,
"category": {
"id": 40105,
"name": "Кошельки, ключницы и брелки",
"section": {
"id": 10000,
"name": "Гардероб"
}
},
"description": "Брендированный жетон в расцветке Black",
"id": 6148964,
"owner_id": -85689507,
"price": {
"amount": "89000",
"currency": {
"id": 643,
"name": "RUB",
"title": ""
},
"text": "890 ₽"
},
"title": "Жетон Black",
"is_owner": false,
"is_adult": false,
"thumb_photo": "https://sun6-22.userapi.com/impg/Io4mIHuLZ0C_fdUcDk8YKOBz0yXu2ZjwmldSoQ/qPnb13rLpr4.jpg?crop=0,0.125,1,0.75&size=400x0&quality=95&sign=2a92edc192a4cc5d36648741934d6656&c_uniq_tag=XDmXPyLGFJFhdhuEz1CqYHRRsJlHFVBxYaCxl8n9icU",
"cart_quantity": 0,
"item_rating": {
"rating": 0,
"reviews_count": 0,
"reviews_count_text": "Нет отзывов"
}
}
]
}
}
16 changes: 16 additions & 0 deletions VkNet/Abstractions/Category/Async/IMarketsCategoryAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ namespace VkNet.Abstractions;
/// </summary>
public interface IMarketsCategoryAsync
{
/// <summary>
/// Метод возвращает список товаров в сообществе.
/// </summary>
/// <param name="params">Модель параметров запроса market.get</param>
/// <param name="token">Токен отмены операции</param>
/// <returns>
/// После успешного выполнения возвращает список объектов item с дополнительным
/// полем comments, содержащим число
/// комментариев у товара.
/// </returns>
/// <remarks>
/// Страница документации ВКонтакте http://vk.com/dev/market.get
/// </remarks>
Task<VkCollection<Market>> GetAsync(MarketGetParams @params,
CancellationToken token = default);

/// <summary>
/// Метод возвращает список товаров в сообществе.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions VkNet/Abstractions/Category/IMarketsCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ namespace VkNet.Abstractions;
/// <inheritdoc cref="IMarketsCategoryAsync"/>
public interface IMarketsCategory : IMarketsCategoryAsync
{
/// <inheritdoc cref="IMarketsCategoryAsync.GetAsync"/>
VkCollection<Market> Get(MarketGetParams @params);

/// <inheritdoc cref="IMarketsCategoryAsync.GetAsync"/>
VkCollection<Market> Get(long ownerId, long? albumId = null, int? count = null, int? offset = null, bool extended = false);

Expand Down
7 changes: 7 additions & 0 deletions VkNet/Categories/Async/MarketsCategoryAsync.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -9,6 +10,12 @@ namespace VkNet.Categories;

public partial class MarketsCategory
{
/// <inheritdoc />
public Task<VkCollection<Market>> GetAsync(MarketGetParams @params,
CancellationToken token = default) =>
TypeHelper.TryInvokeMethodAsync(() =>
Get(@params), token);

/// <inheritdoc />
public Task<VkCollection<Market>> GetAsync(long ownerId,
long? albumId = null,
Expand Down
37 changes: 37 additions & 0 deletions VkNet/Categories/MarketsCategory.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using VkNet.Abstractions;
using VkNet.Enums;
Expand All @@ -21,6 +22,42 @@ public partial class MarketsCategory : IMarketsCategory
public MarketsCategory(IVkApiInvoke vk) => _vk = vk;

/// <inheritdoc />

public VkCollection<Market> Get(MarketGetParams @params) => _vk.Call<VkCollection<Market>>("market.get",
new()
{
{
"owner_id", @params.OwnerId
},
{
"album_id", @params.AlbumId
},
{
"count", @params.Count
},
{
"offset", @params.Offset
},
{
"extended", @params.Extended
},
{
"date_from", @params.DateFrom
},
{
"date_to", @params.DateTo
},
{
"need_variants", @params.NeedVariants
},
{
"with_disabled", @params.WithDisabled
}
});


/// <inheritdoc />
[Obsolete("This method is deprecated. Use Get(MarketGetParams @params) instead", false)]
public VkCollection<Market> Get(long ownerId, long? albumId = null, int? count = null, int? offset = null, bool extended = false)
{
var parameters = new VkParameters
Expand Down
62 changes: 62 additions & 0 deletions VkNet/Model/RequestParams/Market/MarketGetParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using HtmlAgilityPack;
using System;

namespace VkNet.Model
{
/// <summary>
/// Параметры для запроса market.get
/// </summary>
[Serializable]
public class MarketGetParams
{
/// <summary>
/// Идентификатор сообщества, которому принадлежат товары.
/// </summary>
public long? OwnerId { get; set; }

/// <summary>
/// Идентификатор подборки, товары из которой нужно вернуть.
/// </summary>
public long? AlbumId { get; set; }

/// <summary>
/// Количество возвращаемых товаров.
/// </summary>
public long? Count { get; set; }

/// <summary>
/// Смещение относительно первого найденного товара для выборки определенного
/// подмножества.
/// </summary>
public long? Offset { get; set; }


/// <summary>
/// 1 - чтобы вернуть доп.поля likes, can_comment, can_repost, photos, views_count.
/// По умолчанию 0
/// </summary>
public bool? Extended { get; set; }

/// <summary>
/// Параметр для сортировки выгрузки товаров, загруженных с определенной даты
/// DateFrom - строка вида dd.MM.yyyy или dd.MM(год текущий по умолчанию)
/// </summary>
public string DateFrom { get; set; }

/// <summary>
/// Параметр для сортировки выгрузки товаров, загруженных до определенной даты
/// DateTo - строка вида dd.MM.yyyy или dd.MM(год текущий по умолчанию)
/// </summary>
public string DateTo { get; set; }

/// <summary>
/// Флаг для получения вариантов одного товара,если они существуют
/// </summary>
public bool? NeedVariants { get; set; }

/// <summary>
/// Флаг для получения выведденых товаров с продажи
/// </summary>
public bool? WithDisabled { get; set; }
};
}

0 comments on commit 2796c74

Please sign in to comment.