Skip to content

Commit b8942b7

Browse files
committed
Added endpoint for getting list of objects for custom get
1 parent a9b416d commit b8942b7

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

pom.xml

Lines changed: 1 addition & 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.15.2-SNAPSHOT</version>
7+
<version>4.15.3-SNAPSHOT</version>
88

99
<packaging>jar</packaging>
1010

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,18 @@ public Object getCustom(String customPath, String context, Class clazz) throws N
864864
}
865865
}
866866

867+
@Override
868+
public <T> List<T> getCustomObjects(String customPath, String context, Class clazz) throws NotFoundException {
869+
List<T> collected = new ArrayList<>();
870+
PagedResponse<T> response = this.getPagedResponse(customPath, clazz, context);
871+
collected.addAll(response.getList());
872+
while (response.hasNext()) {
873+
response = traverse(response, PagedResponse.NEXT);
874+
collected.addAll(response.getList());
875+
}
876+
return collected;
877+
}
878+
867879
@Override
868880
public void putCustom(String customPath) {
869881
doExchange1(customPath, HttpMethod.PUT, null, new Object[0], null, null).getBody();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.springframework.http.ResponseEntity;
77

88
import javax.annotation.Nullable;
9+
import java.util.List;
910
import java.util.Map;
1011

1112
/**
@@ -15,6 +16,8 @@ public interface CustomCalls {
1516

1617
Object getCustom(String customPath, String context, Class clazz) throws NotFoundException;
1718

19+
<T> List<T> getCustomObjects(String customPath, String context, Class clazz) throws NotFoundException;
20+
1821
void putCustom(String customPath);
1922

2023
<T, B> ResponseEntity<T> doCustomExchange(String context, HttpMethod method, Class<T> typeRef, Object[] buildAndExpand,

0 commit comments

Comments
 (0)