示例#1
0
        public virtual IPagedList <Comment> GetComments(IEnumerable <int> fromUserIds, CommentSort sortBy = CommentSort.Creation, SortDirection sortDirection = SortDirection.Descending, int?toUserId = null, int?page = null, int?pageSize = null, DateTime?fromDate = null, DateTime?toDate = null, int?min = null, int?max = null)
        {
            string[] urlParameters = null;
            if (toUserId.HasValue)
            {
                urlParameters = new string[] { fromUserIds.Vectorize(), "comments", toUserId.ToString() };
            }
            else
            {
                urlParameters = new string[] { fromUserIds.Vectorize(), "comments" };
            }

            var response = MakeRequest <CommentResponse>("users", urlParameters, new
            {
                key      = apiKey,
                page     = page ?? null,
                pagesize = pageSize ?? null,
                fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
                todate   = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null,
                sort     = sortBy.ToString().ToLower(),
                order    = GetSortDirection(sortDirection),
                min      = min ?? null,
                max      = max ?? null
            });

            return(new PagedList <Comment>(response.Comments, response));
        }
示例#2
0
 public virtual void GetCommentsByPost(IEnumerable <int> postIds, Action <IPagedList <Comment> > onSuccess, Action <ApiException> onError, CommentSort sortBy = CommentSort.Creation, SortDirection sortDirection = SortDirection.Descending, int?page = null, int?pageSize = null, DateTime?fromDate = null, DateTime?toDate = null)
 {
     MakeRequest <CommentResponse>("posts", new string[] { postIds.Vectorize(), "comments" }, new
     {
         key      = apiKey,
         page     = page ?? null,
         pagesize = pageSize ?? null,
         fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
         todate   = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null,
         sort     = sortBy.ToString().ToLower(),
         order    = GetSortDirection(sortDirection),
     }, (items) => onSuccess(new PagedList <Comment>(items.Comments, items)), onError);
 }
示例#3
0
 public virtual void GetCommentsByPost(IEnumerable<int> postIds, Action<IPagedList<Comment>> onSuccess, Action<ApiException> onError = null, CommentSort sortBy = CommentSort.Creation, SortDirection sortDirection = SortDirection.Descending, int? page = null, int? pageSize = null, DateTime? fromDate = null, DateTime? toDate = null)
 {
     MakeRequest<CommentResponse>("posts", new string[] { postIds.Vectorize(), "comments" }, new
     {
         key = apiKey,
         page = page ?? null,
         pagesize = pageSize ?? null,
         fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
         todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null,
         sort = sortBy.ToString().ToLower(),
         order = GetSortDirection(sortDirection),
     }, (items) => onSuccess(new PagedList<Comment>(items.Comments, items)), onError);
 }
示例#4
0
 /// <summary>
 /// Gets all the comments in the site
 /// </summary>
 /// <param name="onSuccess"></param>
 /// <param name="onError"></param>
 /// <param name="sortBy">How the current sort should be ordered.</param>
 /// <param name="sortDirection"></param>
 /// <param name="page">The pagination offset for the current collection. Affected by the specified pagesize.</param>
 /// <param name="pageSize">The number of collection results to display during pagination. Should be between 0 and 100 inclusive.</param>
 /// <param name="fromDate"> Unix timestamp of the minimum creation date on a returned item.</param>
 /// <param name="toDate">Unix timestamp of the maximum creation date on a returned item.</param>
 /// <param name="min">Minimum of the range to include in the response according to the current sort.</param>
 /// <param name="max">Maximum of the range to include in the response according to the current sort.</param>
 /// <returns></returns>
 public virtual void GetComments(Action <IPagedList <Comment> > onSuccess, Action <ApiException> onError, CommentSort sortBy = CommentSort.Creation, SortDirection sortDirection = SortDirection.Descending, int?page = null, int?pageSize = null, DateTime?fromDate = null, DateTime?toDate = null, int?min = null, int?max = null)
 {
     MakeRequest <CommentResponse>("answers", null, new
     {
         key      = apiKey,
         page     = page ?? null,
         pagesize = pageSize ?? null,
         fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
         todate   = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null,
         sort     = sortBy.ToString().ToLower(),
         order    = GetSortDirection(sortDirection),
         min      = min ?? null,
         max      = max ?? null
     }, response => onSuccess(new PagedList <Comment>(response.Comments, response)), onError);
 }
示例#5
0
 public virtual void GetAnswerComments(IEnumerable<int> answerIds, Action<IPagedList<Comment>> onSuccess, Action<ApiException> onError = null, CommentSort sortBy = CommentSort.Creation, SortDirection sortDirection = SortDirection.Descending, int? page = null, int? pageSize = null, DateTime? fromDate = null, DateTime? toDate = null, int? min = null, int? max = null)
 {
     MakeRequest<CommentResponse>("answers", new string[] { answerIds.Vectorize(), "comments" }, new
     {
         key = apiKey,
         page = page ?? null,
         pagesize = pageSize ?? null,
         fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
         todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null,
         sort = sortBy.ToString().ToLower(),
         order = GetSortDirection(sortDirection),
         min = min ?? null,
         max = max ?? null
     }, response => onSuccess(new PagedList<Comment>(response.Comments, response)), onError);
 }
示例#6
0
        /// <summary>
        /// Gets all the comments in the site
        /// </summary>
        /// <param name="sortBy">How the current sort should be ordered.</param>
        /// <param name="sortDirection"></param>
        /// <param name="page">The pagination offset for the current collection. Affected by the specified pagesize.</param>
        /// <param name="pageSize">The number of collection results to display during pagination. Should be between 0 and 100 inclusive.</param>
        /// <param name="fromDate"> Unix timestamp of the minimum creation date on a returned item.</param>
        /// <param name="toDate">Unix timestamp of the maximum creation date on a returned item.</param>
        /// <param name="min">Minimum of the range to include in the response according to the current sort.</param>
        /// <param name="max">Maximum of the range to include in the response according to the current sort.</param>
        /// <returns></returns>
        public virtual IPagedList <Comment> GetComments(CommentSort sortBy = CommentSort.Creation, SortDirection sortDirection = SortDirection.Descending, int?page = null, int?pageSize = null, DateTime?fromDate = null, DateTime?toDate = null, int?min = null, int?max = null)
        {
            var response = MakeRequest <CommentResponse>("answers", null, new
            {
                key      = apiKey,
                page     = page ?? null,
                pagesize = pageSize ?? null,
                fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
                todate   = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null,
                sort     = sortBy.ToString().ToLower(),
                order    = GetSortDirection(sortDirection),
                min      = min ?? null,
                max      = max ?? null
            });

            return(new PagedList <Comment>(response.Comments, response));
        }
示例#7
0
        /// <summary>
        /// Returns a <see cref="List{T}"/> of <see cref="Thing"/> that contains <see cref="Comment"/> and <see cref="More"/>
        /// </summary>
        /// <param name="limit">Maximum number of comments to return. Returned list may be larger than this number though due to <see cref="More"/></param>
        /// <returns></returns>
        public async Task <List <Thing> > GetCommentsWithMoresAsync(int limit = 0, CommentSort sort = CommentSort.Best)
        {
            var url = string.Format(GetCommentsUrl, Id);

            //Only 'best' comment sorting isn't named the same
            if (sort == CommentSort.Best)
            {
                url = $"{url}?sort=confidence";
            }
            else
            {
                url = $"{url}?sort={sort.ToString().ToLower()}";
            }

            if (limit > 0)
            {
                url = $"{url}&limit={limit}";
            }

            var json = await WebAgent.Get(url).ConfigureAwait(false);

            var postJson = json.Last()["data"]["children"];

            var things = new List <Thing>();

            foreach (var comment in postJson)
            {
                Comment newComment = new Comment(WebAgent, comment, this);
                if (newComment.Kind != "more")
                {
                    things.Add(newComment);
                }
                else
                {
                    things.Add(new More(WebAgent, comment));
                }
            }

            return(things);
        }
示例#8
0
        public virtual void GetComments(IEnumerable <int> fromUserIds, Action <IPagedList <Comment> > onSuccess, Action <ApiException> onError, CommentSort sortBy = CommentSort.Creation, SortDirection sortDirection = SortDirection.Descending, int?toUserId = null, int?page = null, int?pageSize = null, DateTime?fromDate = null, DateTime?toDate = null)
        {
            string[] urlParameters = null;
            if (toUserId.HasValue)
            {
                urlParameters = new string[] { fromUserIds.Vectorize(), "comments", toUserId.ToString() };
            }
            else
            {
                urlParameters = new string[] { fromUserIds.Vectorize(), "comments" };
            }

            MakeRequest <CommentResponse>("users", urlParameters, new
            {
                key      = apiKey,
                page     = page ?? null,
                pagesize = pageSize ?? null,
                fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
                todate   = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null,
                sort     = sortBy.ToString().ToLower(),
                order    = GetSortDirection(sortDirection)
            }, (items) => onSuccess(new PagedList <Comment>(items.Comments, items)), onError);
        }
示例#9
0
        public virtual void GetComments(IEnumerable<int> fromUserIds, Action<IPagedList<Comment>> onSuccess, Action<ApiException> onError = null, CommentSort sortBy = CommentSort.Creation, SortDirection sortDirection = SortDirection.Descending, int? toUserId = null, int? page = null, int? pageSize = null, DateTime? fromDate = null, DateTime? toDate = null)
        {
            string[] urlParameters = null;
            if (toUserId.HasValue)
            {
                urlParameters = new string[] { fromUserIds.Vectorize(), "comments", toUserId.ToString() };
            }
            else
            {
                urlParameters = new string[] { fromUserIds.Vectorize(), "comments" };
            }

            MakeRequest<CommentResponse>("users", urlParameters, new
            {
                key = apiKey,
                page = page ?? null,
                pagesize = pageSize ?? null,
                fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
                todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null,
                sort = sortBy.ToString().ToLower(),
                order = GetSortDirection(sortDirection)
            }, (items) => onSuccess(new PagedList<Comment>(items.Comments, items)), onError);
        }