internal Player Parse(RawPlayerStats stats, Platform platform, string profileUrl) { Player player = new Player(); player.Username = stats.Name; player.Platform = platform; player.ProfileUrl = new Uri(profileUrl); player.Prestige = Convert.ToUInt16(stats.Prestige ?? 0); player.PrestigeImage = stats.PrestigeIcon; player.PlayerLevel = Convert.ToUInt16(stats.Level ?? 0); player.PlayerLevelImage = stats.LevelIcon; player.CompetitiveRank = Convert.ToUInt16(stats.Rating ?? 0); player.CompetitiveRankImageUrl = stats.RatingIcon; player.EndorsementLevel = Convert.ToUInt16(stats.Endorsement ?? 0); player.EndorsementImage = stats.EndorsementIcon; player.IsProfilePrivate = stats.Private; player.GamesWon = stats.GamesWon ?? 0; player.ProfilePortraitUrl = stats.Icon; player.CasualStats = ParseCasualStats(stats); player.CompetitiveStats = ParseCompetitiveStats(stats); player.PlayerLevel = (ushort)((player.Prestige * 100) + player.PlayerLevel); return(player); }
public async Task <Player> GetPlayerStatsAsync(Platform platform, string userName) { RawPlayerStats stats; string url; using (var client = new HttpClient() { BaseAddress = new Uri("https://ovrstat.com/stats/") }) { var path = ""; switch (platform) { case Platform.Psn: if (!userName.IsValidPsnId()) { return(null); } path = $"psn/{userName}"; break; case Platform.Xbl: if (!userName.IsValidXblId()) { return(null); } path = $"xbl/{userName}"; break; case Platform.Pc: default: if (!userName.IsValidBattletag()) { return(null); } path = $"pc/us/{ userName.BattletagToUrlFriendlyString() }"; break; } using (var request = await client.GetAsync(path)) { if (!request.IsSuccessStatusCode) { return(null); } var rsltContent = await request.Content.ReadAsStringAsync(); if (rsltContent.Contains("Player Not Found")) { return(null); } url = request.RequestMessage.RequestUri.ToString(); stats = RawPlayerStats.FromJson(rsltContent); } } return(_rawPlayerStatsParser.Parse(stats, platform, url)); }
internal static Stat ParseCompetitiveStats(RawPlayerStats stats) => ParseStat(stats.CompetitiveStats);
internal static Stat ParseCasualStats(RawPlayerStats stats) => ParseStat(stats.QuickPlayStats);