Example #1
0
        /// <summary>
        /// Returns all server in a list.
        /// </summary>
        /// <param name="page">optional parameter to get a specific page. default is page 1.</param>
        /// <returns>a list with the server-objects.</returns>
        public static async Task <List <Server> > GetAsync(int page = 1)
        {
            if ((_maxPages > 0 && (page <= 0 || page > _maxPages)))
            {
                throw new InvalidPageException("invalid page number (" + page + "). valid values between 1 and " + _maxPages + "");
            }

            List <Server> serverList = new List <Server>();

            string url = string.Format("/servers");

            if (page > 1)
            {
                url += "?page=" + page.ToString();
            }

            string responseContent = await ApiCore.SendRequest(url);

            Objects.Server.Get.Response response = JsonConvert.DeserializeObject <Objects.Server.Get.Response>(responseContent);

            // load meta
            SaveResponseMetaData(response);

            foreach (Objects.Server.Universal.Server responseServer in response.servers)
            {
                Server server = GetServerFromResponseData(responseServer);

                serverList.Add(server);
            }

            return(serverList);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response"></param>
        private static void SaveResponseMetaData(Objects.Server.Get.Response response)
        {
            CurrentPage = response.meta.pagination.page;
            float pagesDValue = ((float)response.meta.pagination.total_entries / (float)response.meta.pagination.per_page);

            MaxPages = (int)Math.Ceiling(pagesDValue);
        }
        /// <summary>
        /// Returns all server filtered by the given filter-value.
        /// </summary>
        /// <param name="filter">Can be used to filter servers by their name. The response will only contain the server matching the specified name.</param>
        /// <param name="page"></param>
        /// <returns>Returns a list with the server-objects.</returns>
        public static async Task <List <Server> > GetAsync(string filter, int page = 1, string token = null)
        {
            if ((_maxPages > 0 && (page <= 0 || page > _maxPages)))
            {
                throw new InvalidPageException("invalid page number (" + page + "). valid values between 1 and " + _maxPages + "");
            }

            if (string.IsNullOrEmpty(filter) || string.IsNullOrWhiteSpace(filter))
            {
                return(await GetAsync());
            }

            List <Server> serverList = new List <Server>();

            string url = string.Format("/servers?name={0}", filter);

            if (page > 1)
            {
                url += "&page=" + page.ToString();
            }

            string responseContent = await ApiCore.SendRequest(url, token);

            Objects.Server.Get.Response response = JsonConvert.DeserializeObject <Objects.Server.Get.Response>(responseContent);

            // load meta
            SaveResponseMetaData(response);

            foreach (Objects.Server.Universal.Server responseServer in response.servers)
            {
                Server server = GetServerFromResponseData(responseServer);

                serverList.Add(server);
            }

            return(serverList);
        }