Beispiel #1
0
        /// <summary>
        /// Get leaderboard data relative to a username.
        /// </summary>
        /// <param name="platform">Platform to get leaderboards for</param>
        ///	<param name="time">Length of time to return leaderboard data for</param>
        /// <param name="mode">Gamemode to get leaderboard data for</param>
        /// <param name="username">User to find on leaderboards</param>
        /// <param name="order">Order of the results. Only applies to Gamemode.Career.</param>
        /// <returns>Leaderboard data</returns>
        public static Leaderboards.Data GetLeaderboards(Platform platform, Time time, Gamemode mode, string username, Sort order = Sort.Kills)
        {
            using (var client = new HttpClient())
            {
                var url = $"{Utilities.IW_LEADERBOARDS_URL}platform/{platform.GetDescription()}/time/{time.GetDescription()}/type/core/mode/{mode.GetDescription()}/gamer/{username}/";

                //Since sorting only applies to career
                if (mode == Gamemode.Career)
                {
                    url += $"?sort={order.ToString().ToLower()}";
                }

                var response = client.GetAsync(url).Result;

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    throw new Exception($"Bad response {response.StatusCode}");
                }

                var responseData = response.Content.ReadAsStringAsync().Result;

                if (Utilities.ValidResponse(responseData))
                {
                    return(JsonConvert.DeserializeObject <Leaderboards>(responseData).data);
                }

                dynamic data = JsonConvert.DeserializeObject(responseData);

                throw new CODException(data.data.message.ToString());
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get leaderboard data based on page number.
        /// </summary>
        /// <param name="platform">Platform to get leaderboards for</param>
        /// <param name="time">Length of time to return leaderboard data for</param>
        /// <param name="mode">Gamemode to get leaderboard data for</param>
        /// <param name="page">Page to fetch</param>
        /// <returns>Leaderboard data</returns>
        public static Leaderboards.Data GetLeaderboards(Platform platform, Time time, Gamemode mode, int page = 1)
        {
            using (var client = new HttpClient())
            {
                var response = client.GetAsync($"{Utilities.WWII_LEADERBOARDS_URL}platform/{platform.GetDescription()}/time/{time.GetDescription()}/type/core/mode/{mode.GetDescription()}/page/{page}/").Result;

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    throw new Exception($"Bad response {response.StatusCode}");
                }

                var responseData = response.Content.ReadAsStringAsync().Result;

                if (Utilities.ValidResponse(responseData))
                {
                    return(JsonConvert.DeserializeObject <Leaderboards>(responseData).data);
                }

                dynamic data = JsonConvert.DeserializeObject(responseData);

                throw new CODException(data.data.message.ToString());
            }
        }
Beispiel #3
0
        /// <summary>
        /// Get leaderboard data relative to a username.
        /// </summary>
        /// <param name="platform">Platform to get leaderboards for</param>
        ///	<param name="time">Length of time to return leaderboard data for</param>
        /// <param name="type">Type of mode to search for</param>
        /// <param name="mode">Gamemode to get leaderboard data for</param>
        /// <param name="username">User to find on leaderboards</param>
        /// <returns>Leaderboard data</returns>
        public static Leaderboards.Data GetLeaderboards(Platform platform, Time time, Type type, Gamemode mode, string username)
        {
            using (var client = new HttpClient())
            {
                //Business logic
                if (type == Type.Arena && !IsValidArenaMode(mode))
                {
                    throw new CODException($"Mode {mode.ToString()} is not a valid Arena mode.");
                }
                if (type == Type.Hardcore && !IsValidHardcoreMode(mode))
                {
                    throw new CODException($"Mode {mode.ToString()} is not a valid Hardcore mode.");
                }

                var response = client.GetAsync($"{Utilities.BO3_LEADERBOARDS_URL}platform/{platform.GetDescription()}/time/{time.GetDescription()}/type/{type.GetDescription()}/mode/{mode.GetDescription()}/gamer/{username}/").Result;

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    throw new Exception($"Bad response {response.StatusCode}");
                }

                var responseData = response.Content.ReadAsStringAsync().Result;

                if (Utilities.ValidResponse(responseData))
                {
                    return(JsonConvert.DeserializeObject <Leaderboards>(responseData).data);
                }

                dynamic data = JsonConvert.DeserializeObject(responseData);

                throw new CODException(data.data.message.ToString());
            }
        }