Skip to content
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
10 changes: 9 additions & 1 deletion src/Nullinside.Api.Common/Twitch/ITwitchApiProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,17 @@ public interface ITwitchApiProxy {
/// Gets the twitch id and username of the owner of the <see cref="OAuth" />.
/// </summary>
/// <param name="token">The cancellation token.</param>
/// <returns>The twitch username if successful, null otherwise.</returns>
/// <returns>The twitch user information if successful, null otherwise.</returns>
Task<(string? id, string? username)> GetUser(CancellationToken token = new());

/// <summary>
/// Gets the twitch id and username of the username provided.
/// </summary>
/// <param name="username">The username to look up.</param>
/// <param name="token">The cancellation token.</param>
/// <returns>The twitch information if successful, null otherwise.</returns>
Task<(string? id, string? username)> GetUser(string username, CancellationToken token = new());

/// <summary>
/// Gets the email address of the owner of the <see cref="OAuth" />.
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions src/Nullinside.Api.Common/Twitch/TwitchApiProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ public TwitchApiProxy(string token, string refreshToken, DateTime tokenExpires,
}, Retries, token);
}

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

/// <inheritdoc />
public virtual async Task<string?> GetUserEmail(CancellationToken token = new()) {
return await Retry.Execute(async () => {
Expand Down