Created
August 30, 2010 02:46
-
-
Save fpotter/556944 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: src/net/bican/wordpress/Comment.java | |
=================================================================== | |
--- src/net/bican/wordpress/Comment.java (revision 0) | |
+++ src/net/bican/wordpress/Comment.java (revision 0) | |
@@ -0,0 +1,231 @@ | |
+package net.bican.wordpress; | |
+ | |
+import java.util.Date; | |
+ | |
+/** | |
+ * A WordPress Comment object | |
+ * | |
+ * @author Fred Potter <fpoptter@gmail.com> | |
+ * | |
+ */ | |
+public class Comment extends XmlRpcMapped implements StringHeader { | |
+ | |
+ Date date_created_gmt; | |
+ Integer user_id; | |
+ Integer comment_id; | |
+ Integer parent; | |
+ String status; | |
+ String content; | |
+ String link; | |
+ Integer post_id; | |
+ String post_title; | |
+ String author; | |
+ String author_url; | |
+ String author_email; | |
+ String author_ip; | |
+ | |
+ /** | |
+ * @return the date_created_gmt | |
+ */ | |
+ public Date getDate_created_gmt() { | |
+ return date_created_gmt; | |
+ } | |
+ | |
+ /** | |
+ * @param dateCreatedGmt the date_created_gmt to set | |
+ */ | |
+ public void setDate_created_gmt(Date dateCreatedGmt) { | |
+ date_created_gmt = dateCreatedGmt; | |
+ } | |
+ | |
+ /** | |
+ * @return the user_id | |
+ */ | |
+ public Integer getUser_id() { | |
+ return user_id; | |
+ } | |
+ | |
+ /** | |
+ * @param userId the user_id to set | |
+ */ | |
+ public void setUser_id(Integer userId) { | |
+ user_id = userId; | |
+ } | |
+ | |
+ /** | |
+ * @return the comment_id | |
+ */ | |
+ public Integer getComment_id() { | |
+ return comment_id; | |
+ } | |
+ | |
+ /** | |
+ * @param commentId the comment_id to set | |
+ */ | |
+ public void setComment_id(Integer commentId) { | |
+ comment_id = commentId; | |
+ } | |
+ | |
+ /** | |
+ * @return the parent | |
+ */ | |
+ public Integer getParent() { | |
+ return parent; | |
+ } | |
+ | |
+ /** | |
+ * @param parent the parent to set | |
+ */ | |
+ public void setParent(Integer parent) { | |
+ this.parent = parent; | |
+ } | |
+ | |
+ /** | |
+ * @return the status | |
+ */ | |
+ public String getStatus() { | |
+ return status; | |
+ } | |
+ | |
+ /** | |
+ * @param status the status to set | |
+ */ | |
+ public void setStatus(String status) { | |
+ this.status = status; | |
+ } | |
+ | |
+ /** | |
+ * @return the content | |
+ */ | |
+ public String getContent() { | |
+ return content; | |
+ } | |
+ | |
+ /** | |
+ * @param content the content to set | |
+ */ | |
+ public void setContent(String content) { | |
+ this.content = content; | |
+ } | |
+ | |
+ /** | |
+ * @return the link | |
+ */ | |
+ public String getLink() { | |
+ return link; | |
+ } | |
+ | |
+ /** | |
+ * @param link the link to set | |
+ */ | |
+ public void setLink(String link) { | |
+ this.link = link; | |
+ } | |
+ | |
+ /** | |
+ * @return the post_id | |
+ */ | |
+ public Integer getPost_id() { | |
+ return post_id; | |
+ } | |
+ | |
+ /** | |
+ * @param postId the post_id to set | |
+ */ | |
+ public void setPost_id(Integer postId) { | |
+ post_id = postId; | |
+ } | |
+ | |
+ /** | |
+ * @return the post_title | |
+ */ | |
+ public String getPost_title() { | |
+ return post_title; | |
+ } | |
+ | |
+ /** | |
+ * @param postTitle the post_title to set | |
+ */ | |
+ public void setPost_title(String postTitle) { | |
+ post_title = postTitle; | |
+ } | |
+ | |
+ /** | |
+ * @return the author | |
+ */ | |
+ public String getAuthor() { | |
+ return author; | |
+ } | |
+ | |
+ /** | |
+ * @param author the author to set | |
+ */ | |
+ public void setAuthor(String author) { | |
+ this.author = author; | |
+ } | |
+ | |
+ /** | |
+ * @return the author_url | |
+ */ | |
+ public String getAuthor_url() { | |
+ return author_url; | |
+ } | |
+ | |
+ /** | |
+ * @param authorUrl the author_url to set | |
+ */ | |
+ public void setAuthor_url(String authorUrl) { | |
+ author_url = authorUrl; | |
+ } | |
+ | |
+ /** | |
+ * @return the author_email | |
+ */ | |
+ public String getAuthor_email() { | |
+ return author_email; | |
+ } | |
+ | |
+ /** | |
+ * @param authorEmail the author_email to set | |
+ */ | |
+ public void setAuthor_email(String authorEmail) { | |
+ author_email = authorEmail; | |
+ } | |
+ | |
+ /** | |
+ * @return the author_ip | |
+ */ | |
+ public String getAuthor_ip() { | |
+ return author_ip; | |
+ } | |
+ | |
+ /** | |
+ * @param authorIp the author_ip to set | |
+ */ | |
+ public void setAuthor_ip(String authorIp) { | |
+ author_ip = authorIp; | |
+ } | |
+ | |
+ /** | |
+ * (non-Javadoc) | |
+ * | |
+ * @see net.bican.wordpress.StringHeader#getStringHeader() | |
+ */ | |
+ public String getStringHeader() { | |
+ final String TAB = ":"; | |
+ return | |
+ "Date Created GMT" + TAB + | |
+ "User Id" + TAB + | |
+ "Comment Id" + TAB + | |
+ "Parent" + TAB + | |
+ "Status" + TAB + | |
+ "Content" + TAB + | |
+ "Link" + TAB + | |
+ "Post Id" + TAB + | |
+ "Post Title" + TAB + | |
+ "Author" + TAB + | |
+ "Author URL " + TAB + | |
+ "Author Email" + TAB + | |
+ "Author IP"; | |
+ } | |
+} | |
Index: src/net/bican/wordpress/CommentCount.java | |
=================================================================== | |
--- src/net/bican/wordpress/CommentCount.java (revision 0) | |
+++ src/net/bican/wordpress/CommentCount.java (revision 0) | |
@@ -0,0 +1,84 @@ | |
+package net.bican.wordpress; | |
+ | |
+/** | |
+ * Comment Count object for a blog post. | |
+ * | |
+ * @author Fred Potter <fpoptter@gmail.com> | |
+ * | |
+ */ | |
+public class CommentCount extends XmlRpcMapped implements StringHeader { | |
+ | |
+ Integer approved; | |
+ Integer awaiting_moderation; | |
+ Integer spam; | |
+ Integer total_comments; | |
+ | |
+ /** | |
+ * @return Number of approved comments. | |
+ */ | |
+ public Integer getApproved() { | |
+ return approved; | |
+ } | |
+ | |
+ /** | |
+ * @param approved Sets number of approved comments. | |
+ */ | |
+ public void setApproved(Integer approved) { | |
+ this.approved = approved; | |
+ } | |
+ | |
+ /** | |
+ * @return Number of comments awaiting moderation | |
+ */ | |
+ public Integer getAwaiting_moderation() { | |
+ return awaiting_moderation; | |
+ } | |
+ | |
+ /** | |
+ * @param awaitingModeration Number of comments awaiting moderation. | |
+ */ | |
+ public void setAwaiting_moderation(Integer awaitingModeration) { | |
+ awaiting_moderation = awaitingModeration; | |
+ } | |
+ | |
+ /** | |
+ * @return Number of comments marked as spam. | |
+ */ | |
+ public Integer getSpam() { | |
+ return spam; | |
+ } | |
+ | |
+ /** | |
+ * @param spam Number of comments that are spam | |
+ */ | |
+ public void setSpam(Integer spam) { | |
+ this.spam = spam; | |
+ } | |
+ | |
+ /** | |
+ * @return Total number of comments | |
+ */ | |
+ public Integer getTotal_comments() { | |
+ return total_comments; | |
+ } | |
+ | |
+ /** | |
+ * @param totalComments Total number of comments. | |
+ */ | |
+ public void setTotal_comments(Integer totalComments) { | |
+ total_comments = totalComments; | |
+ } | |
+ | |
+ /** | |
+ * (non-Javadoc) | |
+ * | |
+ * @see net.bican.wordpress.StringHeader#getStringHeader() | |
+ */ | |
+ public String getStringHeader() { | |
+ final String TAB = ":"; | |
+ return "Approved" + TAB + "Awaiting Moderation" + TAB + "Spam" + TAB | |
+ + "Total Comments"; | |
+ } | |
+ | |
+ | |
+} | |
Index: src/net/bican/wordpress/Wordpress.java | |
=================================================================== | |
--- src/net/bican/wordpress/Wordpress.java (revision 64) | |
+++ src/net/bican/wordpress/Wordpress.java (working copy) | |
@@ -696,6 +696,96 @@ | |
} | |
return result; | |
} | |
+ | |
+ /** | |
+ * @param post_ID Blog Post ID | |
+ * @return Number of comments (approved, spam, otherwise) | |
+ * @throws XmlRpcFault Generic exception for xml-rpc operations | |
+ */ | |
+ public CommentCount getCommentsCount(int post_ID) throws XmlRpcFault { | |
+ XmlRpcStruct struct = this.wp.getCommentCount(0, this.username, this.password, post_ID); | |
+ CommentCount cc = new CommentCount(); | |
+ cc.fromXmlRpcStruct(struct); | |
+ return cc; | |
+ } | |
+ | |
+ /** | |
+ * | |
+ * @param status One of "approve", "hold", or "spam". Or, null to show all. | |
+ * @param post_id Filter comments by post_id, or null to not filter. | |
+ * @param number The number of comments to return, or null for the default (of 10) | |
+ * @param offset The offset into the set of comments to return, or null for 0 | |
+ * @return A list of Comment objects | |
+ * @throws XmlRpcFault Generic exception for xml-rpc operations | |
+ */ | |
+ @SuppressWarnings("unchecked") | |
+ public List<Comment> getComments(String status, Integer post_id, Integer number, Integer offset) throws XmlRpcFault { | |
+ | |
+ XmlRpcStruct filter = new XmlRpcStruct(); | |
+ | |
+ if (status != null) { | |
+ filter.put("status", status); | |
+ } | |
+ | |
+ if (post_id != null) { | |
+ filter.put("post_id", post_id); | |
+ } | |
+ | |
+ if (number != null) { | |
+ filter.put("number", number); | |
+ } | |
+ | |
+ if (offset != null) { | |
+ filter.put("offset", offset); | |
+ } | |
+ | |
+ XmlRpcArray r = this.wp.getComments(0, this.username, this.password, filter); | |
+ return fillFromXmlRpcArray(r, Comment.class); | |
+ } | |
+ | |
+ /** | |
+ * @param comment_id comment_id to fetch | |
+ * @return A Comment object | |
+ * @throws XmlRpcFault Generic exception for xml-rpc operations | |
+ */ | |
+ public Comment getComment(Integer comment_id) throws XmlRpcFault { | |
+ XmlRpcStruct struct = this.wp.getComment(0, this.username, this.password, comment_id); | |
+ | |
+ Comment comment = new Comment(); | |
+ comment.fromXmlRpcStruct(struct); | |
+ | |
+ return comment; | |
+ } | |
+ | |
+ /** | |
+ * @param post_id Post to attach the comment to. | |
+ * @param comment_parent Id of the parent comment (for threading) | |
+ * @param content Content of comment | |
+ * @param author Author's name | |
+ * @param author_url Author's URL (can be empty) | |
+ * @param author_email Author's Email Address | |
+ * @return the id for the newly created comment. | |
+ * @throws XmlRpcFault Generic exception for xml-rpc operations | |
+ */ | |
+ @SuppressWarnings("unchecked") | |
+ public Integer newComment(Integer post_id, Integer comment_parent, String content, | |
+ String author, String author_url, String author_email) throws XmlRpcFault { | |
+ | |
+ XmlRpcStruct comment = new XmlRpcStruct(); | |
+ | |
+ if (comment_parent != null) { | |
+ comment.put("comment_parent", comment_parent); | |
+ } | |
+ | |
+ comment.put("content", content); | |
+ comment.put("author", author); | |
+ comment.put("author_url", author_url); | |
+ comment.put("author_email", author_email); | |
+ | |
+ Integer comment_id = this.wp.newComment(0, this.username, this.password, post_id, comment); | |
+ | |
+ return comment_id; | |
+ } | |
} | |
interface WordpressBridge { | |
@@ -816,4 +906,17 @@ | |
XmlRpcStruct getPageStatusList(Integer blogid, String username, | |
String password) throws XmlRpcFault; | |
+ | |
+ XmlRpcStruct getCommentCount(Integer blogid, String username, | |
+ String password, Integer post_ID) throws XmlRpcFault; | |
+ | |
+ XmlRpcArray getComments(Integer blogid, String username, | |
+ String password, XmlRpcStruct filter) throws XmlRpcFault; | |
+ | |
+ XmlRpcStruct getComment(Integer blogid, String username, String password, | |
+ Integer comment_id) throws XmlRpcFault; | |
+ | |
+ Integer newComment(Integer blogid, String username, String password, | |
+ Integer post_id, XmlRpcStruct comment) throws XmlRpcFault; | |
+ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment