|
|
|
@ -32,9 +32,8 @@ import static me.goudham.APIUtils.paginationData;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns API information to {@link MyWaifuClient}
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public class APIWrapper {
|
|
|
|
|
class APIWrapper {
|
|
|
|
|
private final String version = "1.0";
|
|
|
|
|
private static final String host = "https://mywaifulist.moe/api/v1/";
|
|
|
|
|
private String apiKey;
|
|
|
|
@ -50,7 +49,6 @@ public class APIWrapper {
|
|
|
|
|
*
|
|
|
|
|
* @param apiKey API Key to authorise API request
|
|
|
|
|
* @param httpClient The underlying {@link HttpClient} to use for HttpRequests
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
APIWrapper(String apiKey, HttpClient httpClient) {
|
|
|
|
|
this.apiKey = apiKey;
|
|
|
|
@ -63,7 +61,6 @@ public class APIWrapper {
|
|
|
|
|
*
|
|
|
|
|
* @param param The end of the endpoint appended onto the host
|
|
|
|
|
* @return {@link HttpRequest.Builder}
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
private HttpRequest.Builder getBaseRequest(String param) {
|
|
|
|
|
return HttpRequest.newBuilder()
|
|
|
|
@ -78,7 +75,6 @@ public class APIWrapper {
|
|
|
|
|
* @param param The end of the endpoint appended onto the host
|
|
|
|
|
* @return {@link Result}
|
|
|
|
|
* @throws APIResponseException If {@link #sendRequest(HttpRequest)} cannot retrieve the proper data from the API
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Result sendGetRequest(String param) throws APIResponseException {
|
|
|
|
|
HttpRequest request = getBaseRequest(param).GET().build();
|
|
|
|
@ -93,7 +89,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Result}
|
|
|
|
|
* @throws APIResponseException If {@link #sendRequest(HttpRequest)} cannot retrieve the proper data from the API
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper#getObjectAsString(Object)} cannot properly serialize object
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
private Result sendPostRequest(String param, Map<String, String> headers) throws APIResponseException, APIMapperException {
|
|
|
|
|
HttpRequest request = getBaseRequest(param)
|
|
|
|
@ -110,7 +105,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Result}
|
|
|
|
|
* @throws APIResponseException If the {@link CompletableFuture Response}
|
|
|
|
|
* cannot be decoded or the thread was interrupted while waiting to receive the data
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
private Result sendRequest(HttpRequest httpRequest) throws APIResponseException {
|
|
|
|
|
CompletableFuture<Result> futureResult = CompletableFuture.supplyAsync(() -> {
|
|
|
|
@ -136,7 +130,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link Waifu}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<Waifu> getWaifu(String waifuId) throws APIResponseException, APIMapperException {
|
|
|
|
|
Result waifuResult = sendGetRequest("waifu/" + waifuId);
|
|
|
|
@ -151,7 +144,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link WaifuImage}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<PaginationData<WaifuImage>> getWaifuImages(String waifuId, String pageNum) throws APIResponseException, APIMapperException {
|
|
|
|
|
Result waifuImagesResult = sendGetRequest("waifu/" + waifuId + "/images?page=" + pageNum);
|
|
|
|
@ -165,7 +157,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link PaginationData} with {@link FilteredWaifu}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<PaginationData<FilteredWaifu>> getWaifusByPage(String pageNum) throws APIResponseException, APIMapperException {
|
|
|
|
|
Result waifusByPageResult = sendGetRequest("waifu?page=" + pageNum);
|
|
|
|
@ -178,7 +169,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link FilteredWaifu}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<FilteredWaifu> getDailyWaifu() throws APIResponseException, APIMapperException {
|
|
|
|
|
Result dailyWaifuResult = sendGetRequest("meta/daily");
|
|
|
|
@ -191,7 +181,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link FilteredWaifu}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<FilteredWaifu> getRandomWaifu() throws APIResponseException, APIMapperException {
|
|
|
|
|
Result randomWaifuResult = sendGetRequest("meta/random");
|
|
|
|
@ -204,7 +193,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link List} with {@link FilteredSeries}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<List<FilteredSeries>> getSeasonalAnime() throws APIResponseException, APIMapperException {
|
|
|
|
|
Result seasonalAnimeResult = sendGetRequest("airing");
|
|
|
|
@ -217,7 +205,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link List} with {@link FilteredWaifu}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<List<FilteredWaifu>> getBestWaifus() throws APIResponseException, APIMapperException {
|
|
|
|
|
Result waifuResults = sendGetRequest("airing/best");
|
|
|
|
@ -231,7 +218,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link List} with {@link FilteredWaifu}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<List<FilteredWaifu>> getPopularWaifus() throws APIResponseException, APIMapperException {
|
|
|
|
|
Result waifuResults = sendGetRequest("airing/popular");
|
|
|
|
@ -244,7 +230,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link List} with {@link FilteredWaifu}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<List<FilteredWaifu>> getTrashWaifus() throws APIResponseException, APIMapperException {
|
|
|
|
|
Result waifuResults = sendGetRequest("airing/trash");
|
|
|
|
@ -258,7 +243,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link Series}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<Series> getSeries(String seriesId) throws APIResponseException, APIMapperException {
|
|
|
|
|
Result seriesResult = sendGetRequest("series/" + seriesId);
|
|
|
|
@ -272,7 +256,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link PaginationData} with {@link FilteredSeries}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<PaginationData<FilteredSeries>> getSeriesByPage(String pageNum) throws APIResponseException, APIMapperException {
|
|
|
|
|
Result seriesPageResult = sendGetRequest("series?page=" + pageNum);
|
|
|
|
@ -287,7 +270,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link List} with {@link FilteredSeries}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<List<FilteredSeries>> getAllSeries(Season season, Integer year) throws APIResponseException, APIMapperException {
|
|
|
|
|
Result allSeriesResult = sendGetRequest("airing/" + season.getSeason() + "/" + year);
|
|
|
|
@ -301,7 +283,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link List} with {@link FilteredWaifu}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<List<FilteredWaifu>> getSeriesWaifus(String seriesId) throws APIResponseException, APIMapperException {
|
|
|
|
|
Result allWaifusFromSeriesResults = sendGetRequest("series/" + seriesId + "/waifus");
|
|
|
|
@ -315,7 +296,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link User}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<User> getUserProfile(String userId) throws APIResponseException, APIMapperException {
|
|
|
|
|
Result userProfileResult = sendGetRequest("user/" + userId);
|
|
|
|
@ -331,7 +311,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link PaginationData} with {@link FilteredWaifu}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<PaginationData<FilteredWaifu>> getUserWaifus(String userId, String listType, String pageNum) throws APIResponseException, APIMapperException {
|
|
|
|
|
Result userWaifusResult = sendGetRequest("user/" + userId + "/" + listType + "?page=" + pageNum);
|
|
|
|
@ -345,7 +324,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link List} with {@link UserList}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<List<UserList>> getUserLists(String userId) throws APIResponseException, APIMapperException {
|
|
|
|
|
Result userProfileResult = sendGetRequest("user/" + userId + "/lists");
|
|
|
|
@ -360,7 +338,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link UserList}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<UserList> getUserList(String userId, String listId) throws APIResponseException, APIMapperException {
|
|
|
|
|
Result userProfileResult = sendGetRequest("user/" + userId + "/lists/" + listId);
|
|
|
|
@ -374,7 +351,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link List} with {@link FilteredWaifu}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<List<FilteredWaifu>> betaSearch(String searchString) throws APIMapperException, APIResponseException {
|
|
|
|
|
Result betaSearchResult = sendPostRequest("search/beta", Map.of("term", searchString));
|
|
|
|
@ -388,7 +364,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link List} with {@link FilteredWaifu}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<List<FilteredWaifu>> searchWaifus(String waifuName) throws APIMapperException, APIResponseException {
|
|
|
|
|
Result searchWaifusResult = sendPostRequest("search/waifus", Map.of("term", waifuName));
|
|
|
|
@ -402,7 +377,6 @@ public class APIWrapper {
|
|
|
|
|
* @return {@link Response} of {@link List} with {@link FilteredSeries}
|
|
|
|
|
* @throws APIResponseException If {@link APIWrapper} could not return information properly
|
|
|
|
|
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
Response<List<FilteredSeries>> searchSeries(String seriesName) throws APIMapperException, APIResponseException {
|
|
|
|
|
Result searchSeriesResult = sendPostRequest("search/series", Map.of("term", seriesName));
|
|
|
|
|