Skip to content

Commit 2c110d3

Browse files
committed
Merged devlop into master and stabilized - paginated getPostMedias call
2 parents 76721f5 + b1d43de commit 2c110d3

3 files changed

Lines changed: 11 additions & 15 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.9.0</version>
6+
<version>4.10.0</version>
77

88
<packaging>jar</packaging>
99

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -268,24 +268,19 @@ public Post setPostFeaturedMedia(Long postId, Media media) {
268268

269269
@Override
270270
public List<Media> getPostMedias(Long postId) {
271-
Media[] medias = CustomRenderableParser.parse(
272-
doExchange1(
273-
Request.MEDIAS, HttpMethod.GET, String.class, forExpand(),
274-
ImmutableMap.of("parent", postId, CONTEXT_, Contexts.EDIT), null
275-
).getBody(),
276-
Media[].class);
277-
return Arrays.asList(medias);
271+
return getPostMedias(postId, Contexts.EDIT);
278272
}
279273

280274
@Override
281275
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);
276+
List<Media> collected = new ArrayList<>();
277+
PagedResponse<Media> pagedResponse = this.getPagedResponse(Request.POST_MEDIAS, Media.class, String.valueOf(postId), context);
278+
collected.addAll(pagedResponse.getList());
279+
while (pagedResponse.hasNext()) {
280+
pagedResponse = this.traverse(pagedResponse, PagedResponse.NEXT);
281+
collected.addAll(pagedResponse.getList());
282+
}
283+
return collected;
289284
}
290285

291286
@Override

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
@@ -31,6 +31,7 @@ public abstract class Request {
3131
public static final String TAXONOMY = "/taxonomies/{slug}";
3232
public static final String TERMS = "/terms/{taxonomySlug}";
3333
public static final String TERM = "/terms/{taxonomySlug}/{termId}";
34+
public static final String POST_MEDIAS = "/media?parent={postId}?context={context}";
3435
public static final String MEDIAS = "/media";
3536
public static final String MEDIA = "/media/{mediaId}";
3637
public static final String PAGES = "/pages";

0 commit comments

Comments
 (0)