Exemplo n.º 1
0
        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, new JsonSerializerSettings {
                ContractResolver = new TelemetryContractResolver(region.Serialize())
            }));
        }
Exemplo n.º 2
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())
            }));
        }
Exemplo n.º 3
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());
        }
Exemplo n.º 4
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()));
        }
Exemplo n.º 5
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()));
        }
Exemplo n.º 6
0
        public virtual IEnumerable <PubgSeason> GetSeasons(PubgRegion region, string apiKey = null)
        {
            var url = string.Format(Api.Seasons.SeasonsEndpoint, region.Serialize());

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

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

            return(JsonConvert.DeserializeObject <IEnumerable <PubgSeason> >(seasonJson, new JsonApiSerializerSettings()));
        }
Exemplo n.º 7
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);
        }
        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);
        }
Exemplo n.º 10
0
 public static bool IsXbox(this PubgRegion region) => region.Serialize().ToLowerInvariant().Contains("xbox");
Exemplo n.º 11
0
        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()));
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
 internal static string PlayersEndpoint(PubgRegion region) => string.Format(ShardedBaseUrl + "/players", region.Serialize());
Exemplo n.º 14
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;
        }
Exemplo n.º 15
0
        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());
        }
Exemplo n.º 16
0
        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());
        }
Exemplo n.º 17
0
 internal static string MatchesEndpoint(PubgRegion region) => string.Format(ShardedBaseUrl + "/matches", region.Serialize());
Exemplo n.º 18
0
        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()));
        }
Exemplo n.º 19
0
 internal static string SeasonsEndpoint(PubgRegion region) => string.Format(ShardedBaseUrl + "/seasons", region.Serialize());
Exemplo n.º 20
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());
        }