Skip to content

Commit b65cdd8

Browse files
committed
Added functionality to get custom post types
1 parent e8345aa commit b65cdd8

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>com.afrozaar.wordpress</groupId>
55
<artifactId>wp-api-v2-client-java</artifactId>
6-
<version>4.8.4-SNAPSHOT</version>
6+
<version>4.8.5-SNAPSHOT</version>
77

88
<packaging>jar</packaging>
99

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static com.afrozaar.wordpress.wpapi.v2.util.FieldExtractor.extractField;
44
import static com.afrozaar.wordpress.wpapi.v2.util.Tuples.tuple;
5-
65
import static java.lang.String.format;
76
import static java.net.URLDecoder.decode;
87
import static java.util.Objects.isNull;
@@ -71,7 +70,6 @@
7170
import com.fasterxml.jackson.databind.DeserializationFeature;
7271
import com.fasterxml.jackson.databind.JsonMappingException;
7372
import com.fasterxml.jackson.databind.ObjectMapper;
74-
7573
import org.apache.commons.beanutils.BeanUtils;
7674
import org.assertj.core.util.VisibleForTesting;
7775
import org.slf4j.Logger;
@@ -188,15 +186,24 @@ public Post createPost(Post post, PostStatus status) throws PostCreateException
188186
return createPost(fieldsFrom(post), status);
189187
}
190188

189+
@Override
190+
public Post getCustomPost(Long id, String postTypeName) throws PostNotFoundException {
191+
return getPost(id, postTypeName, Contexts.VIEW);
192+
}
193+
191194
@Override
192195
public Post getPost(Long id) throws PostNotFoundException {
193196
return getPost(id, Contexts.VIEW);
194197
}
195198

196199
@Override
197200
public Post getPost(Long id, String context) throws PostNotFoundException {
201+
return getPost(id, Request.POST, context);
202+
}
203+
204+
public Post getPost(Long id, String postTypeName, String context) throws PostNotFoundException {
198205
try {
199-
return doExchange1(Request.POST, HttpMethod.GET, Post.class, forExpand(id), ImmutableMap.of(CONTEXT_, context), null).getBody();
206+
return doExchange1(postTypeName, HttpMethod.GET, Post.class, forExpand(id), ImmutableMap.of(CONTEXT_, context), null).getBody();
200207
} catch (HttpClientErrorException e) {
201208
if (e.getStatusCode().is4xxClientError() && e.getStatusCode().value() == 404) {
202209
throw new PostNotFoundException(e);

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
@@ -33,6 +33,8 @@ public interface Posts {
3333

3434
Post createPost(Post post, PostStatus status) throws PostCreateException;
3535

36+
Post getCustomPost(Long id, String postTypeName) throws PostNotFoundException;
37+
3638
Post getPost(Long id) throws PostNotFoundException;
3739
Post getPost(Long id, String context) throws PostNotFoundException;
3840

0 commit comments

Comments
 (0)