示例#1
0
        /// <summary>
        /// Requests a collection of rants sorted and selected by the arguments from the rest-api.
        /// </summary>
        /// <param name="sort">Sorting of the rant collection.</param>
        /// <param name="limit">Maximal rants to return.</param>
        /// <param name="skip">Number of rants to skip.</param>
        /// <inheritdoc />
        public async Task <IReadOnlyCollection <Rant> > GetRantsAsync(RantSort sort = RantSort.Algo, RantRange range = RantRange.Day, int limit = 50, int skip = 0, ValuesCollection settings = null)
        {
            var sortText = sort.ToString().ToLower();

            var paramz = new Parameters()
            {
                { "sort", sortText },
                { "limit", limit.ToString() },
                { "skip", skip.ToString() },
            };

            if (sort == RantSort.Top)
            {
                paramz.Add("range", range.ToString().ToLower());
            }

            string url = owner.MakeUrl("/api/devrant/rants", paramz);


            var response = await client.GetAsync(url);

            var responseText = await response.Content.ReadAsStringAsync();

            List <Rant> rants = new List <Rant>();

            JObject tmp = JObject.Parse(responseText);

            foreach (JObject obj in tmp["rants"].Children())
            {
                var r = ContentObject.Parse <Rant>(obj);
                rants.Add(r);
            }

            if (settings != null)
            {
                var num = tmp[ValuesCollection.NumNotifs];
                if (tmp[ValuesCollection.NumNotifs] != null)
                {
                    var notifs = Convert.ToInt32(num.ToString());
                    settings[ValuesCollection.NumNotifs] = notifs;
                }

                if (tmp[ValuesCollection.Set] != null)
                {
                    settings[ValuesCollection.Set] = tmp[ValuesCollection.Set];
                }
            }

            return(rants);
        }
示例#2
0
        /// <summary>
        /// Requests a collection of stories sorted and selected by the arguments from the rest-api.
        /// </summary>
        /// <inheritdoc />
        public async Task <IReadOnlyCollection <Rant> > GetStoriesAsync(RantSort sort = RantSort.Top, RantRange range = RantRange.Day, int limit = 50, int skip = 0)
        {
            var sortText  = sort.ToString().ToLower();
            var rangeText = range.ToString().ToLower();

            string url = owner.MakeUrl("/api/devrant/story-rants", new Parameters()
            {
                { "range", rangeText },
                { "sort", sortText },
                { "limit", limit.ToString() },
                { "skip", skip.ToString() },
            });

            var response = await client.GetAsync(url);

            var responseText = await response.Content.ReadAsStringAsync();

            JObject tmp = JObject.Parse(responseText);

            if (owner.CheckSuccess(tmp))
            {
                List <Rant> rants = new List <Rant>();

                foreach (JObject obj in tmp["rants"].Children())
                {
                    var r = ContentObject.Parse <Rant>(obj);
                    rants.Add(r);
                }

                return(rants);
            }
            else
            {
                return(null);
            }
        }