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); }
/// <summary> /// Retrieves Pubgplayer data form Pubg corp database /// </summary> /// public static async Task <PubgPlayer> GetPubgPlayer(string id = null, string name = null) { PubgPlayer player = null; try { var playerService = new PubgPlayerService(); if (id != null) { player = await playerService.GetPlayerAsync(PubgPlatform.Steam, id, Config.PubgToken); } else if (name != null) { var result = await playerService.GetPlayersAsync(PubgPlatform.Steam, new GetPubgPlayersRequest { ApiKey = Config.PubgToken, PlayerNames = new string[] { name } }); player = result.FirstOrDefault(); } } catch (Exception ss) { } return(player); }
private async Task GetPlayerData() { var playerRequest = new GetPubgPlayersRequest { PlayerNames = new[] { UserName } }; var playerData = await _playerService.GetPlayersAsync(GetPubgRegion(), playerRequest); var player = playerData.First(); }
private static async Task <PubgPlayer> GetPlayerFromApiAsync(string username, PubgPlatform platform) { PubgPlayerService service = new PubgPlayerService(); List <PubgPlayer> players = (await service.GetPlayersAsync(platform, new GetPubgPlayersRequest { PlayerNames = new[] { username } })).ToList(); return(players.FirstOrDefault()); }
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()); }