Example #1
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())
            }));
        }
Example #2
0
        public virtual IEnumerable <PubgPlayer> GetPlayers(PubgPlatform platform, GetPubgPlayersRequest filter)
        {
            var url    = RequestBuilder.BuildRequestUrl(Api.Players.PlayersEndpoint(platform), 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 PubgMatchSample GetMatchSamples(PubgPlatform platform, GetSamplesRequest request)
        {
            var url    = RequestBuilder.BuildRequestUrl(Api.Samples.SamplesEndpoint(platform), 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());
        }
Example #4
0
        public virtual PubgPlayer GetPlayer(PubgRegion region, string playerId, string apiKey = null)
        {
            var url = string.Format(Api.Players.PlayersEndpoint + "/{1}", region.Serialize(), playerId);

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

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

            return(JsonConvert.DeserializeObject <PubgPlayer>(playerJson, new JsonApiSerializerSettings()));
        }
        public virtual PubgTournament GetTournament(string tournamentId, string apiKey = null)
        {
            var url = Api.Tournaments.TournamentsEndpoint(tournamentId);

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

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

            return(JsonConvert.DeserializeObject <PubgTournament>(matchJson, new JsonApiSerializerSettings()));
        }
Example #6
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()));
        }
Example #7
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());
        }
Example #8
0
        /// <summary>
        ///   Gets the players season stats and matches for the specified platform
        /// </summary>
        /// <param name="platform">The platform on which the season took place</param>
        /// <param name="playerId">The ID of the player you wish to retrieve the season stats for</param>
        /// <param name="seasonId">The ID of the season you wish to recieve stats and matches for</param>
        /// <param name="apiKey">Your API key (optional)</param>
        /// <returns>Stats and matches for a given player during a given season</returns>
        /// <exception cref="Pubg.Net.Exceptions.PubgException">Exception thrown on the API side, details included on object</exception>
        /// <exception cref="Pubg.Net.Exceptions.PubgNotFoundException">The api is unable to find the specified player</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 PubgPlayerSeason GetPlayerSeason(PubgPlatform platform, string playerId, string seasonId, string apiKey = null)
        {
            var url = Api.Players.PlayerSeasonsEndpoint(platform, playerId, seasonId);

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

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

            return(JsonConvert.DeserializeObject <PubgPlayerSeason>(seasonJson, new JsonApiSerializerSettings()));
        }
Example #9
0
        /// <summary>
        ///  Get a list of seasons for the specified platform on the PC (default: Steam)
        /// </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> GetSeasonsPC(PubgPlatform platform = PubgPlatform.Steam, string apiKey = null)
        {
            var url = Api.Seasons.SeasonsPCEndpoint(platform);

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

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

            return(JsonConvert.DeserializeObject <IEnumerable <PubgSeason> >(seasonJson, new JsonApiSerializerSettings()));
        }
Example #10
0
        public virtual PubgLeaderboard GetGameModeLeaderboard(PubgPlatform platform, PubgGameMode gameMode, string apiKey = null)
        {
            var url = Api.Leaderboard.LeaderboardEndpoint(platform, gameMode);

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

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

            return(JsonConvert.DeserializeObject <PubgLeaderboard>(leaderboardJson, new JsonApiSerializerSettings()));
        }
Example #11
0
        public virtual PubgStatEntity GetPlayerLifetimeStats(PubgPlatform platform, string playerId, string apiKey = null)
        {
            var url = Api.Players.PlayerSeasonsEndpoint(platform, playerId, LIFETIME_SEASON_NAME);

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

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

            return(JsonConvert.DeserializeObject <PubgStatEntity>(seasonJson, new JsonApiSerializerSettings()));
        }
Example #12
0
        public virtual PubgStatus GetStatus(string apiKey = null)
        {
            var url = Api.Status.StatusEndpoint();

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

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

            return(JsonConvert.DeserializeObject <PubgStatus>(objectJson, new JsonApiSerializerSettings()));
        }
        public void HttpRequestor_Requests_CorrectMediaType()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Fallback.Throw(new InvalidOperationException("No gzip header was found"));

            mockHttp.Expect(HttpMethod.Get, "*").WithHeaders("Accept", "application/vnd.api+json").Respond("application/json", "test string");

            MockHttpClient(mockHttp);

            var result = HttpRequestor.GetString("http://www.random.url", "token");
        }
        public void HttpRequestor_Attaches_ApiKey_To_Request()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Fallback.Throw(new InvalidOperationException("No token attached to request"));

            var apiToken = "token";

            mockHttp.Expect(HttpMethod.Get, "*").WithHeaders("Authorization", $"Bearer {apiToken}").Respond("application/json", "test string");

            MockHttpClient(mockHttp);

            var result = HttpRequestor.GetString("http://www.random.url", apiToken);
        }
        public void HttpRequestor_Throws_CorrectErrorForHttpStatus(HttpStatusCode statusCode, Type errorType)
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp
            .When("*")
            .Respond(statusCode, new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("X-RateLimit-Reset", "1000")
            }, new StringContent("{\"errors\" : []}"));

            MockHttpClient(mockHttp);

            Assert.Throws(errorType, () => HttpRequestor.GetString("http://random.url"));
        }
        public void PubgErrors_Have_ApiErrors_MappedCorrectly()
        {
            var mockHttp   = new MockHttpMessageHandler();
            var errors     = new Fixture().CreateMany <PubgError>();
            var errorsJson = JsonConvert.SerializeObject(errors);

            mockHttp
            .When("*")
            .Respond(HttpStatusCode.BadRequest, "application/json", $"{{ \"errors\": {errorsJson} }}");

            MockHttpClient(mockHttp);

            try
            {
                HttpRequestor.GetString("http://random.url");
            }
            catch (PubgException ex)
            {
                ex.Errors.Count().Should().Equals(errors.Count());
                Assert.All(ex.Errors, err => errors.Contains(err));
            }
        }
        public void PubgErrors_Have_Correct_HttpStatus(HttpStatusCode statusCode)
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp
            .When("*")
            .Respond(statusCode, new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("X-RateLimit-Reset", "1000")
            }, new StringContent("{\"errors\" : []}"));

            MockHttpClient(mockHttp);

            try
            {
                HttpRequestor.GetString("http://random.url");
            }
            catch (PubgException ex)
            {
                ex.HttpStatusCode.Should().Equals(statusCode);
            }
        }
        public virtual IEnumerable <PubgTelemetryEvent> GetTelemetry(PubgRegion region, string url)
        {
            var collectionJson = HttpRequestor.GetString(url);

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