Beispiel #1
0
        internal virtual async Task <FortniteResponse <T> > ExecuteAsync <T>(
            RestRequest request,
            bool withAuth           = false,
            CancellationToken token = default,
            bool withData           = true,
            string accessToken      = null,
            bool requiresLogin      = true)
        {
            if (requiresLogin)
            {
                var isLoggedIn = await Client.VerifyTokenAsync()
                                 .ConfigureAwait(false);

                if (!isLoggedIn)
                {
                    throw new FortniteException("You need to be logged in to use this!");
                }
            }

            if (withAuth)
            {
                request.AddHeader("Authorization", $"bearer {accessToken ?? Client.CurrentLogin.AccessToken}");
            }

            var response = await RestClient.ExecuteAsync(request, token)
                           .ConfigureAwait(false);

            var content          = response.Content;
            var fortniteResponse = new FortniteResponse <T>
            {
                HttpStatusCode = response.StatusCode
            };

            if (response.IsSuccessful && withData)
            {
                fortniteResponse.Data =
                    JsonConvert.DeserializeObject <T>(content, NewtonsoftSerializer.SerializerSettings);
            }

            if (!response.IsSuccessful)
            {
                fortniteResponse.Error =
                    JsonConvert.DeserializeObject <EpicError>(content, NewtonsoftSerializer.SerializerSettings);
            }

            return(fortniteResponse);
        }
Beispiel #2
0
        public static FortniteStatsResponse ConvertFromApiResponse(this FortniteResponse fortniteResponse)
        {
            var fortniteStatsResponse = new FortniteStatsResponse();

            fortniteStatsResponse.DuoTop1     = Int32.Parse(fortniteResponse.Stats.p10.Top1.Value);
            fortniteStatsResponse.DuoTop5     = Int32.Parse(fortniteResponse.LifeTimeStats.FirstOrDefault(i => i.Key == "Top 5s")?.Value);
            fortniteStatsResponse.DuoTop12    = Int32.Parse(fortniteResponse.LifeTimeStats.FirstOrDefault(i => i.Key == "Top 12s")?.Value);
            fortniteStatsResponse.SoloTop1    = Int32.Parse(fortniteResponse.Stats.p2.Top1.Value);
            fortniteStatsResponse.SoloTop25   = Int32.Parse(fortniteResponse.LifeTimeStats.FirstOrDefault(i => i.Key == "Top 25s")?.Value);
            fortniteStatsResponse.SquadTop1   = Int32.Parse(fortniteResponse.Stats.p9.Top1.Value);
            fortniteStatsResponse.SquadTop3   = Int32.Parse(fortniteResponse.LifeTimeStats.FirstOrDefault(i => i.Key == "Top 3s")?.Value);
            fortniteStatsResponse.SquadTop6   = Int32.Parse(fortniteResponse.LifeTimeStats.FirstOrDefault(i => i.Key == "Top 6s")?.Value);
            fortniteStatsResponse.Kills       = Int32.Parse(fortniteResponse.LifeTimeStats.FirstOrDefault(i => i.Key == "Kills")?.Value);
            fortniteStatsResponse.Kd          = float.Parse(fortniteResponse.LifeTimeStats.FirstOrDefault(i => i.Key == @"K/d")?.Value, CultureInfo.InvariantCulture.NumberFormat);
            fortniteStatsResponse.Matches     = Int32.Parse(fortniteResponse.LifeTimeStats.FirstOrDefault(i => i.Key == "Matches Played")?.Value);
            fortniteStatsResponse.WinsPercent = Int32.Parse(fortniteResponse.LifeTimeStats.FirstOrDefault(i => i.Key == @"Win%")?.Value.Split('%')[0]);
            fortniteStatsResponse.Wins        = Int32.Parse(fortniteResponse.LifeTimeStats.FirstOrDefault(i => i.Key == "Wins")?.Value);
            return(fortniteStatsResponse);
        }