Skip to content

Commit 7a06c49

Browse files
committed
Added functionality to get custom post types
1 parent 59983cd commit 7a06c49

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,14 @@ public PostMeta getPostMeta(Long postId, Long metaId) {
348348
}
349349

350350
@Override
351-
public List<PostMeta> getCustomPostMetas(Long postId, String requestPath) {
352-
final ResponseEntity<PostMeta[]> exchange = doExchange1(Request.CUSTOM_POST_METAS, HttpMethod.GET, PostMeta[].class, forExpand(requestPath, postId), null, null);
351+
public List<PostMeta> getCustomPostMetas(Long postId, String customPostTypeName) {
352+
final ResponseEntity<PostMeta[]> exchange = doExchange1(Request.CUSTOM_POST_METAS, HttpMethod.GET, PostMeta[].class, forExpand(customPostTypeName, postId), null, null);
353353
return Arrays.asList(exchange.getBody());
354354
}
355355

356356
@Override
357-
public PostMeta getCustomPostMeta(Long postId, Long metaId, String requestPath) {
358-
final ResponseEntity<PostMeta> exchange = doExchange1(Request.CUSTOM_POST_META, HttpMethod.GET, PostMeta.class, forExpand(requestPath, postId, metaId), null, null);
357+
public PostMeta getCustomPostMeta(Long postId, Long metaId, String customPostTypeName) {
358+
final ResponseEntity<PostMeta> exchange = doExchange1(Request.CUSTOM_POST_META, HttpMethod.GET, PostMeta.class, forExpand(customPostTypeName, postId, metaId), null, null);
359359
return exchange.getBody();
360360
}
361361

@@ -366,17 +366,24 @@ public PostMeta updatePostMetaValue(Long postId, Long metaId, String value) {
366366

367367
@Override
368368
public PostMeta updatePostMeta(Long postId, Long metaId, String key, String value) {
369-
return updatePostMeta(postId, metaId, null, value, Request.META);
369+
ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
370+
BiConsumer<String, Object> biConsumer = (key1, value1) -> ofNullable(value1).ifPresent(v -> builder.put(key1, v));
371+
372+
biConsumer.accept(META_KEY, key);
373+
biConsumer.accept(META_VALUE, value);
374+
final ResponseEntity<PostMeta> exchange = doExchange1(Request.META, HttpMethod.POST, PostMeta.class, forExpand(postId, metaId), null, builder.build());
375+
376+
return exchange.getBody();
370377
}
371378

372379
@Override
373-
public PostMeta updatePostMeta(Long postId, Long metaId, String key, String value, String requestPath) {
380+
public PostMeta updateCustomPostMeta(Long postId, Long metaId, String key, String value, String customPostTypeName) {
374381
ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
375382
BiConsumer<String, Object> biConsumer = (key1, value1) -> ofNullable(value1).ifPresent(v -> builder.put(key1, v));
376383

377384
biConsumer.accept(META_KEY, key);
378385
biConsumer.accept(META_VALUE, value);
379-
final ResponseEntity<PostMeta> exchange = doExchange1(requestPath, HttpMethod.POST, PostMeta.class, forExpand(postId, metaId), null, builder.build());
386+
final ResponseEntity<PostMeta> exchange = doExchange1(Request.CUSTOM_POST_META, HttpMethod.POST, PostMeta.class, forExpand(customPostTypeName, postId, metaId), null, builder.build());
380387

381388
return exchange.getBody();
382389
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public interface PostMetas {
2323

2424
PostMeta updatePostMeta(Long postId, Long metaId, String key, String value);
2525

26-
PostMeta updatePostMeta(Long postId, Long metaId, String key, String value, String requestPath);
26+
PostMeta updateCustomPostMeta(Long postId, Long metaId, String key, String value, String customPostTypeName);
2727

2828
boolean deletePostMeta(Long postId, Long metaId);
2929

0 commit comments

Comments
 (0)