public async Task <IServiceResult <GameDetails, ApiErrorModel> > GetGameDetailsAsync(long appId) { try { var request = (HttpWebRequest)WebRequest.Create(string.Format("https://store.steampowered.com/api/appdetails?appids={0}", appId)); var response = (HttpWebResponse)await request.GetResponseAsync(); var reader = new StreamReader(response.GetResponseStream()); string jsonResponse = reader.ReadToEnd(); var gameDetails = JObject.Parse(jsonResponse).SelectToken(appId.ToString())?.SelectToken("data")?.ToObject <GameDetails>(); return(ServiceResultFactory.Ok <GameDetails, ApiErrorModel>(gameDetails)); } catch (Exception ex) { var em = new ApiErrorModel() { Errors = new List <string>() { ex.Message.Contains("429") ? "Rate limited" : ex.ToString() }, Type = ApiErrorModel.TYPE_SERVER_ERROR }; return(ServiceResultFactory.Error <GameDetails, ApiErrorModel>(em)); } }
public async Task <IServiceResult <string, ApiErrorModel> > GetSteamIdFromProfileUrlAsync(string url) { string steamId = string.Empty; try { steamId = await _steamService.Get64BitSteamIdAsync(url); _logger.Log(LogLevel.Debug, new EventId((int)LogEventId.General), $"SteamID for {url}: {steamId}"); } catch (Exception ex) { //Type of error that is expected and should be relayed back to the client as a toast message _logger.Log(LogLevel.Error, new EventId((int)LogEventId.General), $"Failed to find Steam Id for {url}"); _logger.Log(LogLevel.Error, new EventId((int)LogEventId.General), ex.ToString()); var em = new ApiErrorModel() { Errors = new List <string>() { $"No Steam profile found for {url}" }, Type = ApiErrorModel.TYPE_TOAST_ERROR }; return(ServiceResultFactory.Error <string, ApiErrorModel>(em)); } return(ServiceResultFactory.Ok <string, ApiErrorModel>(steamId)); }
public async Task <IServiceResult <List <Player>, ApiErrorModel> > GetPlayersAsync(params string[] steamIds) { var profileResponse = await GetResponseAsync <PlayerRootResponse>( _config.ApiSteamUserController, _config.ApiSteamPlayerSummariesAction, "v0002", $"steamids={string.Join(',', steamIds)}"); return(ServiceResultFactory.Ok <List <Player>, ApiErrorModel>(profileResponse?.Response?.Players ?? new List <Player>())); }
public async Task <IServiceResult <List <GameDetails>, ApiErrorModel> > GetGamesForSteamIdAsync(string steamId64) { var games = await _steamService.GetGamesFromProfileAsync(steamId64); //Example of an error that is unexpected and should not be displayed in the browser if (games == null) { var em = new ApiErrorModel() { Errors = new List <string>() { $"Failed to find games for Steam Id: {steamId64}" }, Type = ApiErrorModel.TYPE_SILENT_ERROR }; return(ServiceResultFactory.Error <List <GameDetails>, ApiErrorModel>(em)); } //Type of error that is expected and should be relayed back to the client as a toast message if (games.Count == 0) { var em = new ApiErrorModel() { Errors = new List <string>() { $"No games found for Steam Id: {steamId64}" }, Type = ApiErrorModel.TYPE_TOAST_ERROR }; return(ServiceResultFactory.Error <List <GameDetails>, ApiErrorModel>(em)); } var returnValues = await _gameSearchService.GetAsync(games.Select(g => g.AppId).ToArray()); return(ServiceResultFactory.Ok <List <GameDetails>, ApiErrorModel>(returnValues)); }
public async Task <IServiceResult <GameDetails, ApiErrorModel> > GetGameDetailsAsync(long appId) { var gameDetails = await _steamService.GetGameDetailsAsync(appId); if (gameDetails.HasError) { return(gameDetails); } if (gameDetails.Value == null) { return(ServiceResultFactory.Error <GameDetails, ApiErrorModel>(new ApiErrorModel() { Errors = new List <string>() { $"Failed to find game for app id: {appId}" }, Type = ApiErrorModel.TYPE_SILENT_ERROR })); } return(ServiceResultFactory.Ok <GameDetails, ApiErrorModel>(gameDetails.Value)); }