Skip to content

Commit

Permalink
vknet#1500 Implement calls.start method
Browse files Browse the repository at this point in the history
  • Loading branch information
smtyper committed Nov 16, 2024
1 parent fd95439 commit cf17edf
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 0 deletions.
19 changes: 19 additions & 0 deletions VkNet.Tests/Categories/Calls/CallsCategoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,23 @@ public void ForceFinish()
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");
}
}
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"
}
}
12 changes: 12 additions & 0 deletions VkNet/Abstractions/Category/Async/ICallCategoryAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,16 @@ public interface ICallsCategoryAsync
/// </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);
}
3 changes: 3 additions & 0 deletions VkNet/Abstractions/Category/ICallsCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ 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/Categories/Async/CallsCategoryAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ public partial class CallsCategory
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);
}
9 changes: 9 additions & 0 deletions VkNet/Categories/CallsCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ public bool ForceFinish(CallsForceFinishParams @params)
}
});
}

/// <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; }
}
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; }
}

0 comments on commit cf17edf

Please sign in to comment.