From 23fb286db1dc36ab52c68994288a6e292fd211dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E2=96=88=E2=96=88=E2=96=88=E2=96=88=E2=96=88?= Date: Sat, 14 Jun 2025 20:07:25 -0400 Subject: [PATCH] feat: twitch api look up twitch users --- .../Twitch/ITwitchApiProxy.cs | 10 +++++++++- src/Nullinside.Api.Common/Twitch/TwitchApiProxy.cs | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Nullinside.Api.Common/Twitch/ITwitchApiProxy.cs b/src/Nullinside.Api.Common/Twitch/ITwitchApiProxy.cs index ab1fddb..1d49d3a 100644 --- a/src/Nullinside.Api.Common/Twitch/ITwitchApiProxy.cs +++ b/src/Nullinside.Api.Common/Twitch/ITwitchApiProxy.cs @@ -48,9 +48,17 @@ public interface ITwitchApiProxy { /// Gets the twitch id and username of the owner of the . /// /// The cancellation token. - /// The twitch username if successful, null otherwise. + /// The twitch user information if successful, null otherwise. Task<(string? id, string? username)> GetUser(CancellationToken token = new()); + /// + /// Gets the twitch id and username of the username provided. + /// + /// The username to look up. + /// The cancellation token. + /// The twitch information if successful, null otherwise. + Task<(string? id, string? username)> GetUser(string username, CancellationToken token = new()); + /// /// Gets the email address of the owner of the . /// diff --git a/src/Nullinside.Api.Common/Twitch/TwitchApiProxy.cs b/src/Nullinside.Api.Common/Twitch/TwitchApiProxy.cs index 25adbdc..f441760 100644 --- a/src/Nullinside.Api.Common/Twitch/TwitchApiProxy.cs +++ b/src/Nullinside.Api.Common/Twitch/TwitchApiProxy.cs @@ -150,6 +150,20 @@ public TwitchApiProxy(string token, string refreshToken, DateTime tokenExpires, }, Retries, token); } + /// + public virtual async Task<(string? id, string? username)> GetUser(string username, CancellationToken token = new()) { + return await Retry.Execute(async () => { + ITwitchAPI api = GetApi(); + GetUsersResponse? response = await api.Helix.Users.GetUsersAsync(logins: [username]); + if (null == response) { + return (null, null); + } + + User? user = response.Users.FirstOrDefault(); + return (user?.Id, user?.Login); + }, Retries, token); + } + /// public virtual async Task GetUserEmail(CancellationToken token = new()) { return await Retry.Execute(async () => {