public static async Task <PubgPlayer> GetPlayerFromName(string playerName, PubgRegion region) { if (cachedPlayers.ContainsKey(playerName) && DateTime.Now - cachedPlayers[playerName].Item2 < cacheTimeout) { System.Console.WriteLine("Cache hit for player {0}", playerName); return(cachedPlayers[playerName].Item1); } var playerFilter = new GetPubgPlayersRequest() { PlayerNames = new string[] { playerName } }; var pubgPlayers = await _playerService.GetPlayersAsync(region, playerFilter); using (var pubgPlayersEnumerator = pubgPlayers.GetEnumerator()) { if (pubgPlayersEnumerator.MoveNext()) { var pubgPlayer = pubgPlayersEnumerator.Current; cachedPlayers[playerName] = new Tuple <PubgPlayer, DateTime>(pubgPlayer, DateTime.Now); return(pubgPlayer); } } return(null); }
private async Task GetPlayerData() { var playerRequest = new GetPubgPlayersRequest { PlayerNames = new[] { UserName } }; var playerData = await _playerService.GetPlayersAsync(GetPubgRegion(), playerRequest); var player = playerData.First(); }
public void GetPlayers_Throws_Exception_When_NotFound() { var playerService = new PubgPlayerService(Storage.ApiKey); var filter = new GetPubgPlayersRequest { PlayerNames = new string[] { "NonExistantPlayerHopefully" } }; Assert.Throws <PubgNotFoundException>(() => playerService.GetPlayers(PubgRegion.PCEurope, filter)); }
public async Task <PubgPlayer> GetPlayerByNameAsync(string playerName, PubgRegion region = PubgRegion.PCNorthAmerica) { PubgPlayerService playerService = new PubgPlayerService(); var request = new GetPubgPlayersRequest { PlayerNames = new string[] { playerName } }; var response = await playerService.GetPlayersAsync(region, request); return(response.First()); }
public async Task <RequestResult <PubgPlayer> > Handle(GetRecentMatchesForPlayer request, CancellationToken cancellationToken) { var pubgPlayerService = new PubgPlayerService(); var playersRequest = new GetPubgPlayersRequest() { PlayerNames = new string[] { "S_T_A_R" } }; var players = pubgPlayerService.GetPlayers(PubgPlatform.Steam, playersRequest); return(players .FirstOrDefault()? .AsSuccessResult()); }
public void Can_Get_Players_ById() { var playerService = new PubgPlayerService(Storage.ApiKey); var playerIds = Storage.GetMatch(PubgRegion.PCEurope).Rosters.SelectMany(r => r.Participants).Select(p => p.Stats.PlayerId).Take(5).ToArray(); var filter = new GetPubgPlayersRequest { PlayerIds = playerIds }; var players = playerService.GetPlayers(PubgRegion.PCEurope, filter); Assert.NotEmpty(players); Assert.All(players.Select(p => p.Id), id => playerIds.Contains(id)); }
public void Can_Get_Players_ByName() { var playerService = new PubgPlayerService(Storage.ApiKey); var playerNames = Storage.GetMatch(PubgPlatform.Steam).Rosters.SelectMany(r => r.Participants).Select(p => p.Stats.Name).Take(5).ToArray(); var filter = new GetPubgPlayersRequest { PlayerNames = playerNames }; var players = playerService.GetPlayers(PubgPlatform.Steam, filter); Assert.NotEmpty(players); Assert.All(players.Select(p => p.Name), name => playerNames.Contains(name)); }