public async Task <DsqApiResponse <List <DsqPost> > > ThreadsListPostsAsync( string thread, string cursor = "", DsqLimit?limit = null, DsqIncludePost include = DsqIncludePost.Approved | DsqIncludePost.Unapproved | DsqIncludePost.Highlighted, DsqSortOrder order = DsqSortOrder.Newest, string forum = "", PostAttachments attach = PostAttachments.None, string query = "" ) { var arguments = new List <KeyValuePair <string, string> >() { { new KeyValuePair <string, string>("thread", thread) }, { new KeyValuePair <string, string>("limit", (limit ?? new DsqLimit(25)).ToString()) }, { new KeyValuePair <string, string>("order", order.ToArgument()) }, { new KeyValuePair <string, string>("cursor", cursor) }, }; foreach (var a in attach.GetFlags().Where(f => f.ToArgument() != "")) { if (attach.HasFlag(a)) { arguments.Add(new KeyValuePair <string, string>("attach", a.ToArgument())); } } foreach (var f in include.GetFlags()) { if (include.HasFlag(f)) { arguments.Add(new KeyValuePair <string, string>("include", f.ToArgument())); } } if (!String.IsNullOrWhiteSpace(forum)) { arguments.Add(new KeyValuePair <string, string>("forum", forum)); } if (!String.IsNullOrWhiteSpace(query)) { arguments.Add(new KeyValuePair <string, string>("query", query)); } return(await _factory.GetApiDataAsync <DsqApiResponse <List <DsqPost> > >(resource : "threads", endpoint : "listPosts", arguments : arguments)); }
public async Task <DsqApiResponse <List <DsqPost> > > PostsListChildrenAsync( string parentPost, string forum, DsqSortOrder order = DsqSortOrder.Oldest, DsqLimit?limit = null, bool includeForum = false, bool includeThread = false, DsqIncludePost include = DsqIncludePost.Approved | DsqIncludePost.Highlighted, PostAttachments attach = PostAttachments.None ) { var arguments = new List <KeyValuePair <string, string> >() { { new KeyValuePair <string, string>("parent_post", parentPost) }, { new KeyValuePair <string, string>("forum", forum) }, { new KeyValuePair <string, string>("limit", limit.ToString()) }, { new KeyValuePair <string, string>("order", order.ToArgument()) }, }; if (includeForum) { arguments.Add(new KeyValuePair <string, string>("related", "forum")); } if (includeThread) { arguments.Add(new KeyValuePair <string, string>("related", "thread")); } foreach (var a in attach.GetFlags().Where(f => f.ToArgument() != "")) { if (attach.HasFlag(a)) { arguments.Add(new KeyValuePair <string, string>("attach", a.ToArgument())); } } return(await _factory.GetApiDataAsync <DsqApiResponse <List <DsqPost> > >("posts", "list", arguments)); }
/// <summary> /// Wraps the returning posts into Post objects. Uses JSON.net for deserialization /// </summary> /// <param name="site">the site url. insert without http:// prefix</param> /// <param name="type">the type of posts that shall be returned (post or page)</param> /// <param name="status">the status of posts that shall be returned</param> /// <param name="number">the number of posts that shall be returned</param> /// <param name="offset">the 0-indexed offset for the request. Default value goes to 0. Use this parameter for pagination.</param> /// <returns>List of all posts that matching the query</returns> public async Task <PostsList> GetPostList(string site, PostType type, PostStatus status, int?number = null, int?offset = null) { PostsList post_list = new PostsList(); var response = await getPosts(site, type, status, number, offset); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var responseString = await response.Content.ReadAsStringAsync(); post_list = JsonConvert.DeserializeObject <PostsList>(responseString); if (post_list.posts_total_count != 0) { foreach (var item in post_list.posts_list) { //getting categories as string but handled as object to keep deserializing of posts possible if (item.categories != null) { var cat_object = item.categories; item.categories = PostCategories.GetString(cat_object); } //getting tags as string but handled as object to keep deserializing of posts possible if (item.tags != null) { var tags_object = item.tags; item.tags = PostTags.GetString(tags_object); } //getting attachments as List but handled as object to keep deserializing of posts possible if (item.attachments != null) { var attachments_obj = item.attachments; item.attachments = PostAttachments.GetList(attachments_obj); } //getting metadata as List but handled as object to keep deserializing of posts possible if (item.metadata != null) { var metadata_obj = item.metadata; item.metadata = PostMetaData.GetList(metadata_obj); } } } else { Debug.WriteLine("WARNING: GetPostList returned 0 results. Wrong parameters?"); } } else if (response.StatusCode != System.Net.HttpStatusCode.OK) { var responseString = await response.Content.ReadAsStringAsync(); var Error = JsonConvert.DeserializeObject <apiError>(responseString); Debug.WriteLine(string.Format("ERROR on GetPostList: The site returned: {0}. JetPack not installed on WordPress or JetPack JSON API not active?", Error.message)); } return(post_list); }