From ff0f82a8d4ac8865e2f686306a11dbe8742791e3 Mon Sep 17 00:00:00 2001 From: Hammy Date: Sun, 13 Jun 2021 02:00:09 +0100 Subject: [PATCH] Add support for getting User Waifus This includes waifus that have been created, liked or trashed --- src/main/java/me/goudham/APIWrapper.java | 5 +++++ src/main/java/me/goudham/MyWaifuClient.java | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/me/goudham/APIWrapper.java b/src/main/java/me/goudham/APIWrapper.java index 95aff97..12700e8 100644 --- a/src/main/java/me/goudham/APIWrapper.java +++ b/src/main/java/me/goudham/APIWrapper.java @@ -156,6 +156,11 @@ public class APIWrapper { return apiMapper.deserialize(userProfileResult, User.class); } + Response> getUserWaifus(String userId, String listType, String pageNum) throws APIResponseException, APIMapperException { + Result userWaifusResult = sendRequest("user/" + userId + "/" + listType + "?page=" + pageNum); + return apiMapper.deserializeToPaginationData(userWaifusResult, paginationData(FilteredWaifu.class)); + } + Response> getUserLists(String userId) throws APIResponseException, APIMapperException { Result userProfileResult = sendRequest("user/" + userId + "/lists"); return apiMapper.deserializeToList(userProfileResult, listOf(UserList.class)); diff --git a/src/main/java/me/goudham/MyWaifuClient.java b/src/main/java/me/goudham/MyWaifuClient.java index 67bc5cb..02406ed 100644 --- a/src/main/java/me/goudham/MyWaifuClient.java +++ b/src/main/java/me/goudham/MyWaifuClient.java @@ -11,6 +11,7 @@ import me.goudham.domain.waifu.WaifuImage; import me.goudham.exception.APIMapperException; import me.goudham.exception.APIResponseException; import me.goudham.util.Season; +import me.goudham.util.WaifuListType; import org.jetbrains.annotations.NotNull; import javax.net.ssl.SSLParameters; @@ -86,6 +87,15 @@ public class MyWaifuClient { return APIWrapper.getWaifu(String.valueOf(id)); } + /** + * Retrieves paginated images from the gallery, in sets of 10 + * + * @param id The id of the {@link Waifu} + * @param pageNum The page number of the gallery + * @return {@link Response} + * @throws APIResponseException If {@link APIWrapper} could not return information properly + * @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model + */ public Response> getWaifuImages(@NotNull Integer id, @NotNull Integer pageNum) throws APIResponseException, APIMapperException { return APIWrapper.getWaifuImages(String.valueOf(id), String.valueOf(pageNum)); } @@ -142,6 +152,9 @@ public class MyWaifuClient { return APIWrapper.getUserProfile(String.valueOf(id)); } + public Response> getUserWaifus(@NotNull Integer id, @NotNull WaifuListType waifuListType, @NotNull Integer pageNum) throws APIMapperException, APIResponseException { + return APIWrapper.getUserWaifus(String.valueOf(id), waifuListType.getListType(), String.valueOf(pageNum)); + } public Response> getUserLists(@NotNull Integer id) throws APIMapperException, APIResponseException { return APIWrapper.getUserLists(String.valueOf(id)); }