Merge remote-tracking branch 'origin/master'
Change-Id: I9015257bce122fc37c8537ae57c23b55919741f5
This commit is contained in:
commit
fcd79fb935
@ -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)文档描述。
|
||||
|
||||
## 获取文章
|
||||
|
2
pom.xml
2
pom.xml
@ -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>
|
||||
|
@ -1,9 +1,17 @@
|
||||
package org.chobit.wp.enums;
|
||||
|
||||
/**
|
||||
* @author robin
|
||||
*/
|
||||
public enum PostTaxonomy {
|
||||
|
||||
|
||||
/**
|
||||
* 文章分类
|
||||
*/
|
||||
CATEGORY("category"),
|
||||
/**
|
||||
* 文章标签
|
||||
*/
|
||||
TAG("post_tag"),
|
||||
;
|
||||
public final String taxonomy;
|
||||
|
@ -1,5 +1,9 @@
|
||||
package org.chobit.wp.model.interval;
|
||||
|
||||
|
||||
/**
|
||||
* @author robin
|
||||
*/
|
||||
public class Enclosure {
|
||||
|
||||
private String url;
|
||||
|
@ -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")
|
||||
|
@ -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() {
|
||||
|
@ -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 {
|
||||
|
@ -3,6 +3,9 @@ package org.chobit.wp.model.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* @author robin
|
||||
*/
|
||||
public class Author {
|
||||
|
||||
@JsonProperty("user_id")
|
||||
|
@ -5,6 +5,9 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author robin
|
||||
*/
|
||||
public class MediaItem {
|
||||
|
||||
@JsonProperty("attachment_id")
|
||||
|
@ -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")
|
||||
|
@ -3,6 +3,9 @@ package org.chobit.wp.model.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* @author robin
|
||||
*/
|
||||
public class Term {
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user