forked from mochi-neko/youtube-live-streaming-client-unity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLiveChatMessagesAPITest.cs
55 lines (48 loc) · 1.91 KB
/
LiveChatMessagesAPITest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.IO;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Mochineko.Relent.UncertainResult;
using Newtonsoft.Json;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
namespace Mochineko.YouTubeLiveStreamingClient.Tests
{
[TestFixture]
internal sealed class LiveChatMessagesAPITest
{
[TestCase("tcRvI1rSokk")]
[RequiresPlayMode(false)]
public async Task GetLiveStreamingDetailsAsyncTest(string videoID)
{
var apiKeyPath = Path.Combine(
Application.dataPath,
"Mochineko/YouTubeLiveStreamingClient.Tests/YouTubeAPIKey.txt");
var httpClient = new HttpClient();
var apiKey = await File.ReadAllTextAsync(apiKeyPath, CancellationToken.None);
var result = await VideosAPI.GetVideoInformationAsync(
httpClient,
apiKey,
videoID,
CancellationToken.None);
var liveChatID = result.Unwrap().Items[0].LiveStreamingDetails.ActiveLiveChatId;
var liveChatMessagesResult = await LiveChatMessagesAPI.GetLiveChatMessagesAsync(
httpClient,
apiKey,
liveChatID,
CancellationToken.None);
if (liveChatMessagesResult.Failure)
{
Debug.LogError(
$"Failed get live chat messages from live chat ID:{liveChatID} because -> {liveChatMessagesResult.ExtractMessage()}.");
Assert.Fail();
}
var liveChatMessages = liveChatMessagesResult.Unwrap().Items;
foreach (var message in liveChatMessages)
{
Debug.Log($"{message.Snippet.Type}:{message.AuthorDetails.DisplayName} -> {message.Snippet.DisplayMessage} at {message.Snippet.PublishedAt}.");
}
}
}
}