Beispiel #1
0
        public static PubgSeason GetSeason(PubgRegion region)
        {
            PubgSeason season = null;

            if (region.IsXbox())
            {
                season = StoredItems.OfType <PubgSeason>().FirstOrDefault(p => p.Id.ToLowerInvariant().Contains("xb"));
            }
            else if (region.IsPC())
            {
                season = StoredItems.OfType <PubgSeason>().FirstOrDefault(p => !p.Id.ToLowerInvariant().Contains("xb"));
            }

            if (season != null)
            {
                return(season);
            }

            var seasonService         = new PubgSeasonService(ApiKey);
            List <PubgSeason> seasons = new List <PubgSeason>();

            if (region.IsPC())
            {
                seasons = seasonService.GetSeasonsPC().ToList();
            }
            else if (region.IsXbox())
            {
                seasons = seasonService.GetSeasonsXbox(region).ToList();
            }

            seasons.ForEach(s => StoredItems.Add(s));

            return(seasons.LastOrDefault());
        }
Beispiel #2
0
        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);
        }
 //TODO: Refactor cache so we only store needed info, not entire match object
 public async Task <PubgMatch> GetMatchAsync(string matchId, PubgRegion region = PubgRegion.PCNorthAmerica)
 {
     return(await GetAsync <PubgMatch>(matchId + region, async (t) =>
     {
         return await pubgApi.GetMatchAsync(matchId, region);
     }));
 }
Beispiel #4
0
        public virtual IEnumerable <PubgTelemetryEvent> GetTelemetry(PubgRegion region, string url)
        {
            var collectionJson = HttpRequestor.GetString(url);

            return(JsonConvert.DeserializeObject <IEnumerable <PubgTelemetryEvent> >(collectionJson, new JsonSerializerSettings {
                ContractResolver = new TelemetryContractResolver(region.Serialize())
            }));
        }
 public async Task <IEnumerable <PubgSeason> > GetSeasonsAsync(PubgRegion region = PubgRegion.PCNorthAmerica)
 {
     return(await GetAsync <List <PubgSeason> >("seasons", async (t) =>
     {
         var retVal = await pubgApi.GetSeasonsAsync(region);
         return retVal.ToList();
     }));
 }
 public async Task <PubgPlayer> GetPlayerByNameAsync(string playerName, PubgRegion region = PubgRegion.PCNorthAmerica)
 {
     return(await GetAsync <PlayerCache>(playerName + region, async (t) =>
     {
         var retVal = await pubgApi.GetPlayerByNameAsync(playerName, region);
         return (PlayerCache)retVal;
     }));
 }
        public virtual IEnumerable <PubgPlayer> GetPlayers(PubgRegion region, GetPubgPlayersRequest filter)
        {
            var url    = RequestBuilder.BuildRequestUrl(string.Format(Api.Players.PlayersEndpoint, region.Serialize()), filter);
            var apiKey = string.IsNullOrEmpty(filter.ApiKey) ? ApiKey : filter.ApiKey;

            var collectionJson = HttpRequestor.GetString(url, apiKey);

            return(JsonConvert.DeserializeObject <IEnumerable <PubgPlayer> >(collectionJson, new JsonApiSerializerSettings()));
        }
        public virtual async Task <IEnumerable <PubgPlayer> > GetPlayersAsync(PubgRegion region, GetPubgPlayersRequest filter, CancellationToken cancellationToken = default(CancellationToken))
        {
            var url    = RequestBuilder.BuildRequestUrl(string.Format(Api.Players.PlayersEndpoint, region.Serialize()), filter);
            var apiKey = string.IsNullOrEmpty(filter.ApiKey) ? ApiKey : filter.ApiKey;

            var collectionJson = await HttpRequestor.GetStringAsync(url, cancellationToken, apiKey);

            return(JsonConvert.DeserializeObject <IEnumerable <PubgPlayer> >(collectionJson, new JsonApiSerializerSettings()));
        }
        public async Task <PubgMatchSample> GetMatchSamplesAsync(PubgRegion region, GetSamplesRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var url    = RequestBuilder.BuildRequestUrl(string.Format(Api.Samples.SamplesEndpoint, region.Serialize()), request);
            var apiKey = string.IsNullOrEmpty(request.ApiKey) ? ApiKey : request.ApiKey;

            var collectionJson = await HttpRequestor.GetStringAsync(url, cancellationToken, apiKey);

            return(JsonConvert.DeserializeObject <IEnumerable <PubgMatchSample> >(collectionJson, new JsonApiSerializerSettings()).FirstOrDefault());
        }
        public PubgMatchSample GetMatchSamples(PubgRegion region, GetSamplesRequest request)
        {
            var url    = RequestBuilder.BuildRequestUrl(string.Format(Api.Samples.SamplesEndpoint, region.Serialize()), request);
            var apiKey = string.IsNullOrEmpty(request.ApiKey) ? ApiKey : request.ApiKey;

            var collectionJson = HttpRequestor.GetString(url, apiKey);

            return(JsonConvert.DeserializeObject <IEnumerable <PubgMatchSample> >(collectionJson, new JsonApiSerializerSettings()).FirstOrDefault());
        }
Beispiel #11
0
        /// <summary>
        ///  Get a list of seasons for the specified region on Xbox
        /// </summary>
        /// <param name="platform">The platform you wish to get the seasons for</param>
        /// <param name="apiKey">Your api key (optional)</param>
        /// <returns>A list of seasons and their information</returns>
        /// <exception cref="Pubg.Net.Exceptions.PubgException">Exception thrown on the API side, details included on object</exception>
        /// <exception cref="Pubg.Net.Exceptions.PubgTooManyRequestsException">You have exceeded your rate limit</exception>
        /// <exception cref="Pubg.Net.Exceptions.PubgUnauthorizedException">Invalid API Key</exception>
        public async virtual Task <IEnumerable <PubgSeason> > GetSeasonsXboxAsync(PubgRegion region, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var url = Api.Seasons.SeasonsXboxEndpoint(region);

            apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

            var seasonJson = await HttpRequestor.GetStringAsync(url, cancellationToken, apiKey).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <IEnumerable <PubgSeason> >(seasonJson, new JsonApiSerializerSettings()));
        }
        public virtual async Task <PubgPlayer> GetPlayerAsync(PubgRegion region, string playerId, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var url = Api.Players.PlayersEndpoint(region, playerId);

            apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

            var playerJson = await HttpRequestor.GetStringAsync(url, cancellationToken, apiKey).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <PubgPlayer>(playerJson, new JsonApiSerializerSettings()));
        }
        public virtual PubgPlayer GetPlayer(PubgRegion region, string playerId, string apiKey = null)
        {
            var url = Api.Players.PlayersEndpoint(region, playerId);

            apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

            var playerJson = HttpRequestor.GetString(url, apiKey);

            return(JsonConvert.DeserializeObject <PubgPlayer>(playerJson, new JsonApiSerializerSettings()));
        }
Beispiel #14
0
        /// <summary>
        ///  Get a list of seasons for the specified region on Xbox
        /// </summary>
        /// <param name="platform">The platform you wish to get the seasons for</param>
        /// <param name="apiKey">Your api key (optional)</param>
        /// <returns>A list of seasons and their information</returns>
        /// <exception cref="Pubg.Net.Exceptions.PubgException">Exception thrown on the API side, details included on object</exception>
        /// <exception cref="Pubg.Net.Exceptions.PubgTooManyRequestsException">You have exceeded your rate limit</exception>
        /// <exception cref="Pubg.Net.Exceptions.PubgUnauthorizedException">Invalid API Key</exception>
        public virtual IEnumerable <PubgSeason> GetSeasonsXbox(PubgRegion region, string apiKey = null)
        {
            var url = Api.Seasons.SeasonsXboxEndpoint(region);

            apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

            var seasonJson = HttpRequestor.GetString(url, apiKey);

            return(JsonConvert.DeserializeObject <IEnumerable <PubgSeason> >(seasonJson, new JsonApiSerializerSettings()));
        }
Beispiel #15
0
        public async virtual Task <PubgPlayerSeason> GetPlayerSeasonAsync(PubgRegion region, string playerId, string seasonId, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var url = string.Format(Api.Players.PlayerSeasonsEndpoint, region.Serialize(), playerId, seasonId);

            apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

            var seasonJson = await HttpRequestor.GetStringAsync(url, cancellationToken, apiKey);

            return(JsonConvert.DeserializeObject <PubgPlayerSeason>(seasonJson, new JsonApiSerializerSettings()));
        }
Beispiel #16
0
        public virtual PubgMatch GetMatch(PubgRegion region, string matchId, string apiKey = null)
        {
            var url = string.Format(Api.Matches.MatchesEndpoint + "/{1}", region.Serialize(), matchId);

            apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

            var matchJson = HttpRequestor.GetString(url, apiKey);

            return(JsonConvert.DeserializeObject <IEnumerable <PubgMatch> >(matchJson, new JsonApiSerializerSettings()).FirstOrDefault());
        }
Beispiel #17
0
        public virtual PubgPlayerSeason GetPlayerSeason(PubgRegion region, string playerId, string seasonId, string apiKey = null)
        {
            var url = string.Format(Api.Players.PlayerSeasonsEndpoint, region.Serialize(), playerId, seasonId);

            apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

            var seasonJson = HttpRequestor.GetString(url, apiKey);

            return(JsonConvert.DeserializeObject <PubgPlayerSeason>(seasonJson, new JsonApiSerializerSettings()));
        }
Beispiel #18
0
        public async virtual Task <PubgMatch> GetMatchAsync(PubgRegion region, string matchId, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var url = string.Format(Api.Matches.MatchesEndpoint + "/{1}", region.Serialize(), matchId);

            apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey;

            var matchJson = await HttpRequestor.GetStringAsync(url, cancellationToken, apiKey);

            return(JsonConvert.DeserializeObject <IEnumerable <PubgMatch> >(matchJson, new JsonApiSerializerSettings()).FirstOrDefault());
        }
        public async Task <PlayerResponse> GetPlayer(PubgRegion region, string playerId)
        {
            var url  = new Uri(_baseUri, $"{region.Serialize()}/players/{playerId}");
            var data = await SendRequestAsync <PlayerResponse>(url, HttpMethod.Get, _defaultHeaders);

            if (!data.Success)
            {
                throw new Exception($"ERROR: Faild to get player - {data.ErrorCode} - {data.ErrorMessage}");
            }

            return(data.Data);
        }
Beispiel #20
0
        public async Task <IActionResult> GetSeasons(PubgRegion region)
        {
            try
            {
                var seasons = await pubgApi.GetSeasonsAsync(region);

                return(Ok(seasons));
            }
            catch (Exception e)
            {
                return(NotFound("Seasons Not Found For Region"));
            }
        }
Beispiel #21
0
        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());
        }
Beispiel #22
0
        public static PubgMatchSample GetSamples(PubgRegion region)
        {
            var samples = StoredItems.OfType<PubgMatchSample>().FirstOrDefault(p => p.ShardId == region.Serialize());

            if (samples != null)
                return samples;

            var sampleService = new PubgSamplesService(ApiKey);

            samples = sampleService.GetMatchSamples(region);

            StoredItems.Add(samples);

            return samples;
        }
Beispiel #23
0
        public static PubgSeason GetSeason(PubgRegion region)
        {
            var season = StoredItems.OfType <PubgSeason>().FirstOrDefault();

            if (season != null)
            {
                return(season);
            }

            var seasons = new PubgSeasonService(ApiKey).GetSeasons(region).ToList();

            seasons.ForEach(s => StoredItems.Add(s));

            return(seasons.FirstOrDefault());
        }
Beispiel #24
0
        public static PubgMatch GetMatch(PubgRegion region)
        {
            var match = StoredItems.OfType <PubgMatch>().FirstOrDefault(p => p.ShardId == region.Serialize());

            if (match != null)
            {
                return(match);
            }

            var samples = GetSamples(region);

            match = new PubgMatchService(ApiKey).GetMatch(region, samples.MatchIds.First());

            StoredItems.Add(match);

            return(match);
        }
        public async Task <FindPlayersResponse> FilterPlayersById(PubgRegion region, params string[] playerIds)
        {
            var playersUrl = new Uri(_baseUri, $"{region.Serialize()}/players");
            var url        = new UriBuilder(playersUrl);
            var query      = HttpUtility.ParseQueryString(url.Query);

            query["filter[playerIds]"] = string.Join(',', playerIds);
            url.Query = query.ToString();

            var data = await SendRequestAsync <FindPlayersResponse>(url.Uri, HttpMethod.Get, _defaultHeaders);

            if (!data.Success)
            {
                throw new Exception($"ERROR: Faild to find players - {data.ErrorCode} - {data.ErrorMessage}");
            }

            return(data.Data);
        }
Beispiel #26
0
        public async Task <IActionResult> GetPlayer(string playerName, PubgRegion region = PubgRegion.PCNorthAmerica)
        {
            if (String.IsNullOrEmpty(playerName))
            {
                return(NotFound());
            }

            try
            {
                var player = await pubgApi.GetPlayerByNameAsync(playerName, region);

                return(Ok(player));
            }
            catch (Exception e)
            {
                return(NotFound("Player Not Found"));
            }
        }
Beispiel #27
0
        public static PubgPlayer GetPlayer(PubgRegion region)
        {
            var player = StoredItems.OfType <PubgPlayer>().FirstOrDefault(p => p.ShardId == region.Serialize());

            if (player != null)
            {
                return(player);
            }

            var playerService = new PubgPlayerService(ApiKey);
            var playerNames   = GetMatch(region).Rosters.SelectMany(r => r.Participants).Select(p => p.Stats.Name).Take(5);
            var players       = playerService.GetPlayers(region, new GetPubgPlayersRequest {
                PlayerNames = playerNames.ToArray()
            });

            StoredItems.AddRange(players);

            return(players.FirstOrDefault());
        }
Beispiel #28
0
        public async Task <PlayerStats> FilterStats(string playerName, string seasonId,
                                                    PubgRegion region = PubgRegion.PCNorthAmerica)
        {
            //Wrapping in try catch in case player name or season id is incorrect
            try
            {
                PlayerStats playerStats = new PlayerStats();

                //Populate object properties
                this.playerName = playerName;
                this.seasonId   = seasonId;
                this.region     = region;

                //Get Player
                var player = await pubgApi.GetPlayerByNameAsync(playerName);

                playerId = player.Id;

                //Get Player Season

                var playerSeason = await pubgApi.GetPlayerSeasonAsync(playerId,
                                                                      seasonId, region);

                //Filter Matches
                var validMatches = await FilterMatches(LoadMatches(playerSeason));

                //Compute Stats
                if (validMatches > 0)
                {
                    return(BuildStats(playerSeason.GameModeStats,
                                      validMatches));
                }
            }
            catch (NullReferenceException e) {
            }


            return(null);
        }
Beispiel #29
0
        public static async Task <PubgPlayerSeason> GetPlayerSeason(PubgPlayer player, PubgRegion region, PubgSeason season)
        {
            var cacheKey = new PlayerSeasonKey(player.Id, region, season.Id);

            if (cachedPlayerSeasons.ContainsKey(cacheKey) && DateTime.Now - cachedPlayerSeasons[cacheKey].Item2 < cacheTimeout)
            {
                System.Console.WriteLine("Cache hit for player season {0}", player.Name);
                return(cachedPlayerSeasons[cacheKey].Item1);
            }

            var pubgPlayerSeason = await _playerService.GetPlayerSeasonAsync(region, player.Id, season.Id);

            cachedPlayerSeasons[cacheKey] = new Tuple <PubgPlayerSeason, DateTime>(pubgPlayerSeason, DateTime.Now);
            return(pubgPlayerSeason);
        }
        public virtual async Task <IEnumerable <PubgTelemetryEvent> > GetTelemetryAsync(PubgRegion region, string url, CancellationToken cancellationToken = default(CancellationToken))
        {
            var collectionJson = await HttpRequestor.GetStringAsync(url, cancellationToken);

            return(JsonConvert.DeserializeObject <IEnumerable <PubgTelemetryEvent> >(collectionJson));
        }