@@ -277,6 +277,17 @@ Request.MEDIAS, HttpMethod.GET, String.class, forExpand(),
277277 return Arrays .asList (medias );
278278 }
279279
280+ @ Override
281+ public List <Media > getPostMedias (Long postId , @ Nullable String context ) {
282+ Media [] medias = CustomRenderableParser .parse (
283+ doExchange1 (
284+ Request .MEDIAS , HttpMethod .GET , String .class , forExpand (),
285+ ImmutableMap .of ("parent" , postId , CONTEXT_ , context ), null
286+ ).getBody (),
287+ Media [].class );
288+ return Arrays .asList (medias );
289+ }
290+
280291 @ Override
281292 public List <Media > getMedia () {
282293 List <Media > collected = new ArrayList <>();
@@ -441,6 +452,23 @@ public boolean deletePostMeta(Long postId, Long metaId, Boolean force) {
441452 }
442453 }
443454
455+ @ Override
456+ public boolean deleteCustomPostMeta (Long postId , Long metaId , Boolean force , String customPostTypeName ) {
457+ if (supportsMetaDeleteViaPostMethod .apply (postId , metaId )) {
458+ // deleting meta via meta POST is available, so use that to delete.
459+ final ResponseEntity <Map > result = doExchange1 (Request .CUSTOM_META_POST_DELETE , HttpMethod .POST , Map .class , forExpand (customPostTypeName , postId , metaId ),
460+ isNull (force ) ? null : ImmutableMap .of (FORCE , force ), null );
461+ return result .getStatusCode ().is2xxSuccessful () && "Deleted meta" .equals (result .getBody ().get ("message" ));
462+ } else {
463+ // attempt normal delete
464+ final ResponseEntity <Map > exchange = doExchange1 (Request .CUSTOM_POST_META , HttpMethod .DELETE , Map .class , forExpand (customPostTypeName , postId , metaId ),
465+ isNull (force ) ? null : ImmutableMap .of (FORCE , force ), null );
466+ Preconditions .checkArgument (exchange .getStatusCode ().is2xxSuccessful (), format ("Expected success on post meta delete request: /posts/%s/meta/%s" , postId , metaId ));
467+
468+ return exchange .getStatusCode ().is2xxSuccessful ();
469+ }
470+ }
471+
444472 @ SuppressWarnings ("unchecked" )
445473 @ Override
446474 public List <Taxonomy > getTaxonomies () {
@@ -646,7 +674,8 @@ public List<Term> getCategories() {
646674 return getAllTermsForEndpoint (Request .CATEGORIES );
647675 }
648676
649- private List <Term > getAllTermsForEndpoint (final String endpoint , String ... expandParams ) {
677+ @ Override
678+ public List <Term > getAllTermsForEndpoint (final String endpoint , String ... expandParams ) {
650679 List <Term > collected = new ArrayList <>();
651680 PagedResponse <Term > pagedResponse = this .getPagedResponse (endpoint , Term .class , expandParams );
652681 collected .addAll (pagedResponse .getList ());
@@ -962,10 +991,12 @@ protected Map<String, Object> fieldsFrom(Post post) {
962991 }
963992
964993 private <T , B > ResponseEntity <T > doExchange0 (HttpMethod method , URI uri , Class <T > typeRef , B body , @ Nullable MediaType mediaType ) {
965- final Tuple2 <String , String > authTuple = AuthUtil .authTuple (username , password );
966994 final RequestEntity .BodyBuilder builder = RequestEntity .method (method , uri )
967- .header (authTuple .v1 , authTuple .v2 )
968995 .header (userAgentTuple .v1 , userAgentTuple .v2 );
996+ if (username != null && password != null ) {
997+ final Tuple2 <String , String > authTuple = AuthUtil .authTuple (username , password );
998+ builder .header (authTuple .v1 , authTuple .v2 );
999+ }
9691000
9701001 ofNullable (mediaType ).ifPresent (builder ::contentType );
9711002
0 commit comments