Merge remote-tracking branch 'origin/master'

Change-Id: I9015257bce122fc37c8537ae57c23b55919741f5
This commit is contained in:
rui.zhang 2018-12-28 12:24:00 +08:00
commit fcd79fb935
12 changed files with 42 additions and 5 deletions

View File

@ -96,7 +96,7 @@ getAuthors()方法返回的是用户相关的信息:
PostRequest post = new PostRequest();
post.setPostTitle("测试Title");
post.setPostContent("这是一段测试文章内容");
post.setCategories("测试");
post.setCategories("分类1","分类2");
post.setTags("a", "b", "c");
post.setPostName("test-post-name");
int postId = wp.newPost(post);
@ -105,6 +105,10 @@ getAuthors()方法返回的是用户相关的信息:
这里需要注意postName和postTitle。postTitle指的是文章标题postName指的则是文章别名主要在文章的url路径中使用。通常建议将postName设置为英文字符。
setCategories设置的是文章分类如设置的分类在博客中不存在将会按提交的分类名称创建新的分类。
setTags设置的是文章标签同样的如标签在博客中不存在将会创建新的标签。
更多发布文章的参数可以参考[XML-RPC WordPress API/Posts - newPost](https://codex.wordpress.org/XML-RPC_WordPress_API/Posts#wp.newPost)文档描述。
## 获取文章

View File

@ -12,7 +12,7 @@
<groupId>org.chobit.wp</groupId>
<artifactId>wordpress-client</artifactId>
<version>0.1.1</version>
<version>0.1.2</version>
<packaging>jar</packaging>
<name>WordPress-Client</name>

View File

@ -1,9 +1,17 @@
package org.chobit.wp.enums;
/**
* @author robin
*/
public enum PostTaxonomy {
/**
* 文章分类
*/
CATEGORY("category"),
/**
* 文章标签
*/
TAG("post_tag"),
;
public final String taxonomy;

View File

@ -1,5 +1,9 @@
package org.chobit.wp.model.interval;
/**
* @author robin
*/
public class Enclosure {
private String url;

View File

@ -3,6 +3,9 @@ package org.chobit.wp.model.request;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* @author robin
*/
public class PostFilter extends Request {
@JsonProperty("post_type")

View File

@ -13,6 +13,9 @@ import java.util.Map;
import static org.chobit.wp.enums.PostTaxonomy.CATEGORY;
import static org.chobit.wp.enums.PostTaxonomy.TAG;
/**
* @author robin
*/
public class PostRequest extends Request {
public PostRequest() {

View File

@ -9,6 +9,9 @@ import java.util.Map;
import static org.chobit.wp.tools.JsonKit.fromJson;
import static org.chobit.wp.tools.JsonKit.toJson;
/**
* @author robin
*/
public abstract class Request {
public Map<String, Object> toMap() throws IOException {

View File

@ -3,6 +3,9 @@ package org.chobit.wp.model.response;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* @author robin
*/
public class Author {
@JsonProperty("user_id")

View File

@ -5,6 +5,9 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Date;
/**
* @author robin
*/
public class MediaItem {
@JsonProperty("attachment_id")

View File

@ -6,6 +6,9 @@ import org.chobit.wp.model.interval.Enclosure;
import java.util.Date;
import java.util.List;
/**
* @author robin
*/
public class Post {
@JsonProperty("post_id")

View File

@ -3,6 +3,9 @@ package org.chobit.wp.model.response;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* @author robin
*/
public class Term {

View File

@ -73,8 +73,8 @@ public class WordPressTest {
PostRequest post = new PostRequest();
post.setPostTitle("测试PostName");
post.setPostContent("这是一段测试文章内容");
post.addCategories("测试");
post.addTags("a", "b", "c");
post.setCategories("分类");
post.setTags("a", "b", "c");
post.setPostName("test-post-name");
int postId = wp.newPost(post);
System.out.println(postId);