Skip to content

Commit e93b287

Browse files
committed
More support for custom post types
1 parent e40057a commit e93b287

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.afrozaar.wordpress</groupId>
66
<artifactId>wp-api-v2-client-java</artifactId>
7-
<version>4.18.0-SNAPSHOT</version>
7+
<version>4.19.0</version>
88

99
<packaging>jar</packaging>
1010

@@ -148,6 +148,11 @@
148148
</build>
149149

150150
<dependencies>
151+
<dependency>
152+
<groupId>javax.annotation</groupId>
153+
<artifactId>jsr250-api</artifactId>
154+
<version>1.0</version>
155+
</dependency>
151156
<dependency>
152157
<groupId>org.codehaus.jackson</groupId>
153158
<artifactId>jackson-mapper-asl</artifactId>

src/main/java/com/afrozaar/wordpress/wpapi/v2/Client.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ public Post createPost(Post post, PostStatus status) throws PostCreateException
158158
return createPost(fieldsFrom(post), status);
159159
}
160160

161+
@Override
162+
public Post deleteCustomPost(Long id, String customPostTypeName) {
163+
final ResponseEntity<Post> exchange = doExchange1(Request.CUSTOM_POST, HttpMethod.DELETE, Post.class,
164+
forExpand(customPostTypeName, id), null, null);// Deletion of a post returns the post's data before removing it.
165+
Preconditions.checkArgument(exchange.getStatusCode().is2xxSuccessful());
166+
return exchange.getBody();
167+
}
168+
161169
@Override
162170
public Post getCustomPost(Long id, String requestPath) throws PostNotFoundException {
163171
return getPost(id, requestPath, Contexts.VIEW);
@@ -265,8 +273,6 @@ public List<Media> getPostMedias(Long postId, @Nullable String context) {
265273

266274
@Override
267275
public List<Post> getCategoryPosts(Long categoryId) {
268-
// final ResponseEntity<Post[]> exchange = doExchange1(Request.CATEGORY_POSTS, HttpMethod.GET, Post[].class, forExpand(categoryId), null, null);
269-
// return Arrays.asList(exchange.getBody());
270276
List<Post> collected = new ArrayList<>();
271277
PagedResponse<Post> pagedResponse = this.getPagedResponse(Request.CATEGORY_POSTS, Post.class, String.valueOf(categoryId), context);
272278
collected.addAll(pagedResponse.getList());
@@ -275,7 +281,6 @@ public List<Post> getCategoryPosts(Long categoryId) {
275281
collected.addAll(pagedResponse.getList());
276282
}
277283
return collected;
278-
279284
}
280285

281286
@Override

src/main/java/com/afrozaar/wordpress/wpapi/v2/api/Posts.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public interface Posts {
3838

3939
Post getCustomPost(Long id, String postTypeName, String context) throws PostNotFoundException;
4040

41+
Post deleteCustomPost(Long id, String postTypeName);
42+
4143
Post getPost(Long id) throws PostNotFoundException;
4244
Post getPost(Long id, String context) throws PostNotFoundException;
4345

src/main/java/com/afrozaar/wordpress/wpapi/v2/request/Request.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
public abstract class Request {
1616
public static final String POSTS = "/posts";
1717
public static final String POST = "/posts/{id}";
18+
public static final String CUSTOM_POST = "/{postType}/{id}";
1819
public static final String POST_TERMS = "/posts/{postId}/{taxonomy}";
1920
public static final String POST_TERM = "/posts/{postId}/{taxonomy}/{termId}";
2021
public static final String POST_TAGS = "/tags?post={postId}";

0 commit comments

Comments
 (0)