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

1500 api calls #1622

Merged
merged 2 commits into from
Nov 16, 2024
Merged
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
45 changes: 45 additions & 0 deletions VkNet.Tests/Categories/Calls/CallsCategoryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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();
}

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

ReadCategoryJsonPath(nameof(Start));

var result = Api.Calls.Start(new());

result.JoinLink.Should()
.Be("https://vk.com/call/join/7BIRLBXzMD74J_JGR3G5wNZbZCkAT_ZtNFzJbHhIkMk");

result.OkJoinLink.Should()
.Be("7BIRLBXzMD74J_JGR3G5wNZbZCkAT_ZtNFzJbHhIkMk");

result.CallId.Should()
.Be("10c5386e-10cb-43c6-999a-d01a37ee71e0");
}
}
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
}
7 changes: 7 additions & 0 deletions VkNet.Tests/TestData/Categories/Calls/Start.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"response": {
"join_link": "https://vk.com/call/join/7BIRLBXzMD74J_JGR3G5wNZbZCkAT_ZtNFzJbHhIkMk",
"ok_join_link": "7BIRLBXzMD74J_JGR3G5wNZbZCkAT_ZtNFzJbHhIkMk",
"call_id": "10c5386e-10cb-43c6-999a-d01a37ee71e0"
}
}
35 changes: 35 additions & 0 deletions VkNet/Abstractions/Category/Async/ICallCategoryAsync.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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);

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

namespace VkNet.Abstractions;

/// <summary>
/// Методы для работы со звонками
/// </summary>
public interface ICallsCategory : ICallsCategoryAsync
{
/// <inheritdoc cref="ICallsCategoryAsync.ForceFinishAsync"/>
bool ForceFinish(CallsForceFinishParams @params);

/// <inheritdoc cref="ICallsCategoryAsync.StartAsync"/>
CallStartResult Start(CallsStartParams @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; }
}
21 changes: 21 additions & 0 deletions VkNet/Categories/Async/CallsCategoryAsync.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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);

/// <inheritdoc />
public Task<CallStartResult> StartAsync(CallsStartParams @params, CancellationToken token = default) =>
TypeHelper.TryInvokeMethodAsync(() =>
Start(@params), token);
}
41 changes: 41 additions & 0 deletions VkNet/Categories/CallsCategory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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
}
});
}

/// <inheritdoc />
public CallStartResult Start(CallsStartParams @params) =>
_vk.Call<CallStartResult>("calls.start", new()
{
{
"group_id", @params.GroupId
}
});
}
29 changes: 29 additions & 0 deletions VkNet/Model/CallStartResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using Newtonsoft.Json;

namespace VkNet.Model;

/// <summary>
/// Результат создания нового звонка
/// </summary>
[Serializable]
public class CallStartResult
{
/// <summary>
/// Ссылка на звонок
/// </summary>
[JsonProperty("join_link")]
public string JoinLink { get; set; }

/// <summary>
/// Ссылка на звонок (Ok)
/// </summary>
[JsonProperty("ok_join_link")]
public string OkJoinLink { get; set; }

/// <summary>
/// Идентификатор созданного звонка
/// </summary>
[JsonProperty("call_id")]
public string CallId { get; set; }
}
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; }
}
14 changes: 14 additions & 0 deletions VkNet/Model/RequestParams/Calls/CallsStartParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace VkNet.Model;
/// <summary>
/// Список параметров для метода calls.start
/// </summary>
[Serializable]
public class CallsStartParams
{
/// <summary>
/// Идентификатор сообщества
/// </summary>
public int? GroupId { 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
Loading