Skip to content

Commit fdc4fbb

Browse files
Merge pull request #99 from nullinside-development-group/feat/twitch
feat: twitch api look up twitch users
2 parents b276e7a + 23fb286 commit fdc4fbb

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Nullinside.Api.Common/Twitch/ITwitchApiProxy.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,17 @@ public interface ITwitchApiProxy {
4848
/// Gets the twitch id and username of the owner of the <see cref="OAuth" />.
4949
/// </summary>
5050
/// <param name="token">The cancellation token.</param>
51-
/// <returns>The twitch username if successful, null otherwise.</returns>
51+
/// <returns>The twitch user information if successful, null otherwise.</returns>
5252
Task<(string? id, string? username)> GetUser(CancellationToken token = new());
5353

54+
/// <summary>
55+
/// Gets the twitch id and username of the username provided.
56+
/// </summary>
57+
/// <param name="username">The username to look up.</param>
58+
/// <param name="token">The cancellation token.</param>
59+
/// <returns>The twitch information if successful, null otherwise.</returns>
60+
Task<(string? id, string? username)> GetUser(string username, CancellationToken token = new());
61+
5462
/// <summary>
5563
/// Gets the email address of the owner of the <see cref="OAuth" />.
5664
/// </summary>

src/Nullinside.Api.Common/Twitch/TwitchApiProxy.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ public TwitchApiProxy(string token, string refreshToken, DateTime tokenExpires,
150150
}, Retries, token);
151151
}
152152

153+
/// <inheritdoc />
154+
public virtual async Task<(string? id, string? username)> GetUser(string username, CancellationToken token = new()) {
155+
return await Retry.Execute(async () => {
156+
ITwitchAPI api = GetApi();
157+
GetUsersResponse? response = await api.Helix.Users.GetUsersAsync(logins: [username]);
158+
if (null == response) {
159+
return (null, null);
160+
}
161+
162+
User? user = response.Users.FirstOrDefault();
163+
return (user?.Id, user?.Login);
164+
}, Retries, token);
165+
}
166+
153167
/// <inheritdoc />
154168
public virtual async Task<string?> GetUserEmail(CancellationToken token = new()) {
155169
return await Retry.Execute(async () => {

0 commit comments

Comments
 (0)