private async Task <User> FetchUserInfoAsync(string userId) { var url = SteamUtils.GetUserInfoUrl(_secrets.Value.SteamApiKey, userId); var jsonObj = await _remoteApiService.GetJsonObjectAsync(url, SteamUtils.ApiName); var token = jsonObj["response"]["players"].First; var user = token.ToObject <User>(); if (user.CommunityVisibilityState == 3) { try { user.Friends = await FetchFriendsAsync(userId); } catch (ApiUnavailableException) { var key = SiteUtils.CacheKeys.UserInfo; _cache.Remove(key); throw; } } user.LatestUpdate = DateTime.Now; return(user); }
public async Task <GameInfo> GetGameAsync(ISet <string> userIds, int gameId) { var url = SteamUtils.GetGameUrl(gameId); var jsonObj = await _remoteApiService.GetJsonObjectAsync(url, SteamUtils.ApiName); var game = jsonObj[gameId.ToString()]["data"]?.ToObject <GameInfo>() ?? throw new GameNotFoundException($"Game {gameId} could not be found.", gameId); game.UserInfo = await GetUserInfoAsync(userIds, gameId); return(game); }