Skip to content

Commit

Permalink
vknet#1500 Implement calls.forceFinish method
Browse files Browse the repository at this point in the history
  • Loading branch information
smtyper committed Nov 16, 2024
1 parent dc69c40 commit fd95439
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 0 deletions.
26 changes: 26 additions & 0 deletions VkNet.Tests/Categories/Calls/CallsCategoryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using FluentAssertions;
using VkNet.Tests.Infrastructure;
using Xunit;

namespace VkNet.Tests.Categories.Calls;

public class CallsCategoryTest : CategoryBaseTest
{
protected override string Folder => "Calls";

[Fact]
public void ForceFinish()
{
Url = "https://api.vk.com/method/calls.forceFinish";

ReadCategoryJsonPath(nameof(ForceFinish));

var result = Api.Calls.ForceFinish(new()
{
CallId = "10c5386e-10cb-43c6-999a-d01a37ee71e0"
});

result.Should()
.BeTrue();
}
}
3 changes: 3 additions & 0 deletions VkNet.Tests/TestData/Categories/Calls/ForceFinish.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"response": 1
}
23 changes: 23 additions & 0 deletions VkNet/Abstractions/Category/Async/ICallCategoryAsync.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Threading;
using System.Threading.Tasks;
using VkNet.Model;

namespace VkNet.Abstractions;

/// <summary>
/// Методы для работы со звонками
/// </summary>
public interface ICallsCategoryAsync
{
/// <summary>
/// Принудительно завершить звонок
/// </summary>
/// <param name="params">Параметры запроса</param>
/// <param name="token">Токен отмены операции</param>
/// <returns>После успешного выполнения возвращает <c> true </c>.</returns>
/// <remarks>
/// Страница документации ВКонтакте https://dev.vk.com/ru/method/calls.forceFinish
/// </remarks>
Task<bool> ForceFinishAsync(CallsForceFinishParams @params,
CancellationToken token = default);
}
12 changes: 12 additions & 0 deletions VkNet/Abstractions/Category/ICallsCategory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using VkNet.Model;

namespace VkNet.Abstractions;

/// <summary>
/// Методы для работы со звонками
/// </summary>
public interface ICallsCategory : ICallsCategoryAsync
{
/// <inheritdoc cref="ICallsCategoryAsync.ForceFinishAsync"/>
bool ForceFinish(CallsForceFinishParams @params);
}
5 changes: 5 additions & 0 deletions VkNet/Abstractions/Core/IVkApiCategories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,9 @@ public interface IVkApiCategories
/// ShortVideo
/// </summary>
IShortVideoCategory ShortVideo { get; }

/// <summary>
/// Calls
/// </summary>
ICallsCategory Calls { get; }
}
16 changes: 16 additions & 0 deletions VkNet/Categories/Async/CallsCategoryAsync.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Threading;
using System.Threading.Tasks;
using VkNet.Abstractions;
using VkNet.Model;
using VkNet.Utils;

namespace VkNet.Categories;

/// <inheritdoc cref="ICallsCategory" />
public partial class CallsCategory
{
/// <inheritdoc />
public Task<bool> ForceFinishAsync(CallsForceFinishParams @params, CancellationToken token = default) =>
TypeHelper.TryInvokeMethodAsync(() =>
ForceFinish(@params), token);
}
32 changes: 32 additions & 0 deletions VkNet/Categories/CallsCategory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using VkNet.Abstractions;
using VkNet.Exception;
using VkNet.Model;

namespace VkNet.Categories;

/// <inheritdoc cref="ICallsCategory" />
public partial class CallsCategory : ICallsCategory
{
private readonly IVkApiInvoke _vk;

/// <summary>
/// Инициализирует новый экземпляр класса <see cref="CallsCategory" />
/// </summary>
public CallsCategory(IVkApiInvoke vk) => _vk = vk;

/// <inheritdoc />
public bool ForceFinish(CallsForceFinishParams @params)
{
if (@params.CallId.Length is not 36)
{
throw new VkApiException(message: "Параметр call_id обязательный. Макс. длина = 36 Мин. длина = 36");
}

return _vk.Call<bool>("calls.forceFinish", new()
{
{
"call_id", @params.CallId
}
});
}
}
16 changes: 16 additions & 0 deletions VkNet/Model/RequestParams/Calls/CallsForceFinishParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace VkNet.Model;

/// <summary>
/// Список параметров для метода calls.forceFinish
/// </summary>
[Serializable]
public class CallsForceFinishParams
{
/// <summary>
/// Идентификатор звонка
/// </summary>
/// <remarks>Обязательный параметр Макс. длина = 36 Мин. длина = 36</remarks>
public string CallId { get; set; }
}
4 changes: 4 additions & 0 deletions VkNet/VkApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,9 @@ public int MaxCaptchaRecognitionCount
/// <inheritdoc />
public IShortVideoCategory ShortVideo { get; set; }

/// <inheritdoc />
public ICallsCategory Calls { get; set; }

#endregion

#region private
Expand Down Expand Up @@ -1084,6 +1087,7 @@ private void Initialization(IServiceProvider serviceProvider)
DownloadedGames = new DownloadedGamesCategory(this);
Asr = new AsrCategory(this);
ShortVideo = new ShortVideoCategory(this);
Calls = new CallsCategory(this);

RequestsPerSecond = 3;

Expand Down

0 comments on commit fd95439

Please sign in to comment.