Remove public access from APIWrapper.java

pull/19/head
Hammy 3 years ago
parent 0f89db74da
commit 8bb61c1320

@ -32,388 +32,362 @@ import static me.goudham.APIUtils.paginationData;
/** /**
* Returns API information to {@link MyWaifuClient} * Returns API information to {@link MyWaifuClient}
*
*/ */
public class APIWrapper { class APIWrapper {
private final String version = "1.0"; private final String version = "1.0";
private static final String host = "https://mywaifulist.moe/api/v1/"; private static final String host = "https://mywaifulist.moe/api/v1/";
private String apiKey; private String apiKey;
private APIMapper apiMapper; private APIMapper apiMapper;
private final HttpClient httpClient; private final HttpClient httpClient;
private final Executor executor = Executors.newFixedThreadPool(10); private final Executor executor = Executors.newFixedThreadPool(10);
/** /**
* Instantiates an instance of {@link APIWrapper} to retrieve API Information. * Instantiates an instance of {@link APIWrapper} to retrieve API Information.
* An instance of {@link APIMapper} is created to be able to {@code deserialize} JSON to * An instance of {@link APIMapper} is created to be able to {@code deserialize} JSON to
* Java objects * Java objects
* *
* @param apiKey API Key to authorise API request * @param apiKey API Key to authorise API request
* @param httpClient The underlying {@link HttpClient} to use for HttpRequests * @param httpClient The underlying {@link HttpClient} to use for HttpRequests
* */
*/ APIWrapper(String apiKey, HttpClient httpClient) {
APIWrapper(String apiKey, HttpClient httpClient) { this.apiKey = apiKey;
this.apiKey = apiKey; this.httpClient = httpClient;
this.httpClient = httpClient; apiMapper = new APIMapper();
apiMapper = new APIMapper(); }
}
/**
/** * Create base {@link HttpRequest.Builder} with custom url, default headers and timeout
* Create base {@link HttpRequest.Builder} with custom url, default headers and timeout *
* * @param param The end of the endpoint appended onto the host
* @param param The end of the endpoint appended onto the host * @return {@link HttpRequest.Builder}
* @return {@link HttpRequest.Builder} */
* private HttpRequest.Builder getBaseRequest(String param) {
*/ return HttpRequest.newBuilder()
private HttpRequest.Builder getBaseRequest(String param) { .uri(URI.create(host + param))
return HttpRequest.newBuilder() .timeout(Duration.ofSeconds(20))
.uri(URI.create(host + param)) .headers("Content-Type", "application/json", "apikey", apiKey);
.timeout(Duration.ofSeconds(20)) }
.headers("Content-Type", "application/json", "apikey", apiKey);
} /**
* Separate method for sending GET requests
/** *
* Separate method for sending GET requests * @param param The end of the endpoint appended onto the host
* * @return {@link Result}
* @param param The end of the endpoint appended onto the host * @throws APIResponseException If {@link #sendRequest(HttpRequest)} cannot retrieve the proper data from the API
* @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();
*/ return sendRequest(request);
Result sendGetRequest(String param) throws APIResponseException { }
HttpRequest request = getBaseRequest(param).GET().build();
return sendRequest(request); /**
} * Separate method for sending POST requests
*
/** * @param param The end of the endpoint appended onto the host
* Separate method for sending POST requests * @param headers Headers as Key/Value pairs for POST requests
* * @return {@link Result}
* @param param The end of the endpoint appended onto the host * @throws APIResponseException If {@link #sendRequest(HttpRequest)} cannot retrieve the proper data from the API
* @param headers Headers as Key/Value pairs for POST requests * @throws APIMapperException If {@link APIMapper#getObjectAsString(Object)} cannot properly serialize object
* @return {@link Result} */
* @throws APIResponseException If {@link #sendRequest(HttpRequest)} cannot retrieve the proper data from the API private Result sendPostRequest(String param, Map<String, String> headers) throws APIResponseException, APIMapperException {
* @throws APIMapperException If {@link APIMapper#getObjectAsString(Object)} cannot properly serialize object HttpRequest request = getBaseRequest(param)
* .POST(HttpRequest.BodyPublishers.ofString(apiMapper.getObjectAsString(headers)))
*/ .build();
private Result sendPostRequest(String param, Map<String, String> headers) throws APIResponseException, APIMapperException { return sendRequest(request);
HttpRequest request = getBaseRequest(param) }
.POST(HttpRequest.BodyPublishers.ofString(apiMapper.getObjectAsString(headers)))
.build(); /**
return sendRequest(request); * Handles sending a request to the API asynchronously using {@link HttpRequest}
} * and the underlying {@link HttpClient}
*
/** * @param httpRequest The {@link HttpRequest} to be sent by the {@link HttpClient}
* Handles sending a request to the API asynchronously using {@link HttpRequest} * @return {@link Result}
* and the underlying {@link HttpClient} * @throws APIResponseException If the {@link CompletableFuture Response}
* * cannot be decoded or the thread was interrupted while waiting to receive the data
* @param httpRequest The {@link HttpRequest} to be sent by the {@link HttpClient} */
* @return {@link Result} private Result sendRequest(HttpRequest httpRequest) throws APIResponseException {
* @throws APIResponseException If the {@link CompletableFuture Response} CompletableFuture<Result> futureResult = CompletableFuture.supplyAsync(() -> {
* cannot be decoded or the thread was interrupted while waiting to receive the data try {
* return httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
*/ } catch (IOException | InterruptedException exp) {
private Result sendRequest(HttpRequest httpRequest) throws APIResponseException { exp.printStackTrace();
CompletableFuture<Result> futureResult = CompletableFuture.supplyAsync(() -> { }
try { return null;
return httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString()); }, executor).thenApply(httpResponse -> new Result(httpResponse.statusCode(), httpResponse.body()));
} catch (IOException | InterruptedException exp) {
exp.printStackTrace(); try {
} return futureResult.get();
return null; } catch (InterruptedException | ExecutionException exp) {
}, executor).thenApply(httpResponse -> new Result(httpResponse.statusCode(), httpResponse.body())); throw new APIResponseException(exp.getMessage(), exp);
}
try { }
return futureResult.get();
} catch (InterruptedException | ExecutionException exp) { /**
throw new APIResponseException(exp.getMessage(), exp); * Retrieve detailed information about the {@link Waifu} by sending request to API
} *
} * @param waifuId The id of the {@link Waifu}
* @return {@link Response} of {@link Waifu}
/** * @throws APIResponseException If {@link APIWrapper} could not return information properly
* Retrieve detailed information about the {@link Waifu} by sending request to API * @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
* */
* @param waifuId The id of the {@link Waifu} Response<Waifu> getWaifu(String waifuId) throws APIResponseException, APIMapperException {
* @return {@link Response} of {@link Waifu} Result waifuResult = sendGetRequest("waifu/" + waifuId);
* @throws APIResponseException If {@link APIWrapper} could not return information properly return apiMapper.deserialize(waifuResult, Waifu.class);
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model }
*
*/ /**
Response<Waifu> getWaifu(String waifuId) throws APIResponseException, APIMapperException { * Retrieve paginated images from the gallery, in sets of 10, by sending request to API
Result waifuResult = sendGetRequest("waifu/" + waifuId); *
return apiMapper.deserialize(waifuResult, Waifu.class); * @param waifuId The id of the {@link Waifu}
} * @param pageNum The page number of the gallery
* @return {@link Response} of {@link WaifuImage}
/** * @throws APIResponseException If {@link APIWrapper} could not return information properly
* Retrieve paginated images from the gallery, in sets of 10, by sending request to API * @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
* */
* @param waifuId The id of the {@link Waifu} Response<PaginationData<WaifuImage>> getWaifuImages(String waifuId, String pageNum) throws APIResponseException, APIMapperException {
* @param pageNum The page number of the gallery Result waifuImagesResult = sendGetRequest("waifu/" + waifuId + "/images?page=" + pageNum);
* @return {@link Response} of {@link WaifuImage} return apiMapper.deserializeToPaginationData(waifuImagesResult, paginationData(WaifuImage.class));
* @throws APIResponseException If {@link APIWrapper} could not return information properly }
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
* /**
*/ * Retrieve an array of {@link FilteredWaifu}'s, sorted alphabetically, by sending request to API
Response<PaginationData<WaifuImage>> getWaifuImages(String waifuId, String pageNum) throws APIResponseException, APIMapperException { *
Result waifuImagesResult = sendGetRequest("waifu/" + waifuId + "/images?page=" + pageNum); * @param pageNum The page number of the gallery
return apiMapper.deserializeToPaginationData(waifuImagesResult, paginationData(WaifuImage.class)); * @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
/** */
* Retrieve an array of {@link FilteredWaifu}'s, sorted alphabetically, by sending request to API Response<PaginationData<FilteredWaifu>> getWaifusByPage(String pageNum) throws APIResponseException, APIMapperException {
* Result waifusByPageResult = sendGetRequest("waifu?page=" + pageNum);
* @param pageNum The page number of the gallery return apiMapper.deserializeToPaginationData(waifusByPageResult, paginationData(FilteredWaifu.class));
* @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 /**
* * Retrieve the Waifu of the Day by sending request to API
*/ *
Response<PaginationData<FilteredWaifu>> getWaifusByPage(String pageNum) throws APIResponseException, APIMapperException { * @return {@link Response} of {@link FilteredWaifu}
Result waifusByPageResult = sendGetRequest("waifu?page=" + pageNum); * @throws APIResponseException If {@link APIWrapper} could not return information properly
return apiMapper.deserializeToPaginationData(waifusByPageResult, paginationData(FilteredWaifu.class)); * @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
} */
Response<FilteredWaifu> getDailyWaifu() throws APIResponseException, APIMapperException {
/** Result dailyWaifuResult = sendGetRequest("meta/daily");
* Retrieve the Waifu of the Day by sending request to API return apiMapper.deserialize(dailyWaifuResult, FilteredWaifu.class);
* }
* @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 * Retrieve a Random Waifu from the Website by sending request to API
* *
*/ * @return {@link Response} of {@link FilteredWaifu}
Response<FilteredWaifu> getDailyWaifu() throws APIResponseException, APIMapperException { * @throws APIResponseException If {@link APIWrapper} could not return information properly
Result dailyWaifuResult = sendGetRequest("meta/daily"); * @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
return apiMapper.deserialize(dailyWaifuResult, FilteredWaifu.class); */
} Response<FilteredWaifu> getRandomWaifu() throws APIResponseException, APIMapperException {
Result randomWaifuResult = sendGetRequest("meta/random");
/** return apiMapper.deserialize(randomWaifuResult, FilteredWaifu.class);
* Retrieve a Random Waifu from the Website by sending request to API }
*
* @return {@link Response} of {@link FilteredWaifu} /**
* @throws APIResponseException If {@link APIWrapper} could not return information properly * Retrieve a List of Currently Airing Anim by sending request to API
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model *
* * @return {@link Response} of {@link List} with {@link FilteredSeries}
*/ * @throws APIResponseException If {@link APIWrapper} could not return information properly
Response<FilteredWaifu> getRandomWaifu() throws APIResponseException, APIMapperException { * @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
Result randomWaifuResult = sendGetRequest("meta/random"); */
return apiMapper.deserialize(randomWaifuResult, FilteredWaifu.class); Response<List<FilteredSeries>> getSeasonalAnime() throws APIResponseException, APIMapperException {
} Result seasonalAnimeResult = sendGetRequest("airing");
return apiMapper.deserializeToList(seasonalAnimeResult, listOf(FilteredSeries.class));
/** }
* Retrieve a List of Currently Airing Anim by sending request to API
* /**
* @return {@link Response} of {@link List} with {@link FilteredSeries} * Retrieve the Best Waifus of the Current Season by sending request to API
* @throws APIResponseException If {@link APIWrapper} could not return information properly *
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model * @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<FilteredSeries>> getSeasonalAnime() throws APIResponseException, APIMapperException { */
Result seasonalAnimeResult = sendGetRequest("airing"); Response<List<FilteredWaifu>> getBestWaifus() throws APIResponseException, APIMapperException {
return apiMapper.deserializeToList(seasonalAnimeResult, listOf(FilteredSeries.class)); Result waifuResults = sendGetRequest("airing/best");
} return apiMapper.deserializeToList(waifuResults, listOf(FilteredWaifu.class));
}
/**
* Retrieve the Best Waifus of the Current Season by sending request to API /**
* * Retrieve a List of Popular Waifus <i>(Raw Count of Total Votes)</i> of the Current Season
* @return {@link Response} of {@link List} with {@link FilteredWaifu} * by sending request to API
* @throws APIResponseException If {@link APIWrapper} could not return information properly *
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model * @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"); Response<List<FilteredWaifu>> getPopularWaifus() throws APIResponseException, APIMapperException {
return apiMapper.deserializeToList(waifuResults, listOf(FilteredWaifu.class)); Result waifuResults = sendGetRequest("airing/popular");
} return apiMapper.deserializeToList(waifuResults, listOf(FilteredWaifu.class));
}
/**
* Retrieve a List of Popular Waifus <i>(Raw Count of Total Votes)</i> of the Current Season /**
* by sending request to API * Retrieve the Most Disliked Waifus of the Current Season by sending request to API
* *
* @return {@link Response} of {@link List} with {@link FilteredWaifu} * @return {@link Response} of {@link List} with {@link FilteredWaifu}
* @throws APIResponseException If {@link APIWrapper} could not return information properly * @throws APIResponseException If {@link APIWrapper} could not return information properly
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model * @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
* */
*/ Response<List<FilteredWaifu>> getTrashWaifus() throws APIResponseException, APIMapperException {
Response<List<FilteredWaifu>> getPopularWaifus() throws APIResponseException, APIMapperException { Result waifuResults = sendGetRequest("airing/trash");
Result waifuResults = sendGetRequest("airing/popular"); return apiMapper.deserializeToList(waifuResults, listOf(FilteredWaifu.class));
return apiMapper.deserializeToList(waifuResults, listOf(FilteredWaifu.class)); }
}
/**
/** * Retrieve detailed information about a given {@link Series} by sending request to API
* Retrieve the Most Disliked Waifus of the Current Season by sending request to API *
* * @param seriesId The id of the {@link Series}
* @return {@link Response} of {@link List} with {@link FilteredWaifu} * @return {@link Response} of {@link Series}
* @throws APIResponseException If {@link APIWrapper} could not return information properly * @throws APIResponseException If {@link APIWrapper} could not return information properly
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model * @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
* */
*/ Response<Series> getSeries(String seriesId) throws APIResponseException, APIMapperException {
Response<List<FilteredWaifu>> getTrashWaifus() throws APIResponseException, APIMapperException { Result seriesResult = sendGetRequest("series/" + seriesId);
Result waifuResults = sendGetRequest("airing/trash"); return apiMapper.deserialize(seriesResult, Series.class);
return apiMapper.deserializeToList(waifuResults, listOf(FilteredWaifu.class)); }
}
/**
/** * Retrieve paginated information about a Series by sending request to API
* Retrieve detailed information about a given {@link Series} by sending request to API *
* * @param pageNum The page number of the gallery
* @param seriesId The id of the {@link Series} * @return {@link Response} of {@link PaginationData} with {@link FilteredSeries}
* @return {@link Response} of {@link Series} * @throws APIResponseException If {@link APIWrapper} could not return information properly
* @throws APIResponseException If {@link APIWrapper} could not return information properly * @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
* @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);
Response<Series> getSeries(String seriesId) throws APIResponseException, APIMapperException { return apiMapper.deserializeToPaginationData(seriesPageResult, paginationData(FilteredSeries.class));
Result seriesResult = sendGetRequest("series/" + seriesId); }
return apiMapper.deserialize(seriesResult, Series.class);
} /**
* Retrieve the List of Anime that Aired in a given Season and Year by sending request to API
/** *
* Retrieve paginated information about a Series by sending request to API * @param season The specified season from {@link Season}
* * @param year The specified year
* @param pageNum The page number of the gallery * @return {@link Response} of {@link List} with {@link FilteredSeries}
* @return {@link Response} of {@link PaginationData} with {@link FilteredSeries} * @throws APIResponseException If {@link APIWrapper} could not return information properly
* @throws APIResponseException If {@link APIWrapper} could not return information properly * @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
* @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);
Response<PaginationData<FilteredSeries>> getSeriesByPage(String pageNum) throws APIResponseException, APIMapperException { return apiMapper.deserializeToList(allSeriesResult, listOf(FilteredSeries.class));
Result seriesPageResult = sendGetRequest("series?page=" + pageNum); }
return apiMapper.deserializeToPaginationData(seriesPageResult, paginationData(FilteredSeries.class));
} /**
* Retrieve a set of Waifus for a given {@link Series} by sending request to API
/** *
* Retrieve the List of Anime that Aired in a given Season and Year by sending request to API * @param seriesId The id of the {@link Series}
* * @return {@link Response} of {@link List} with {@link FilteredWaifu}
* @param season The specified season from {@link Season} * @throws APIResponseException If {@link APIWrapper} could not return information properly
* @param year The specified year * @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
* @return {@link Response} of {@link List} with {@link FilteredSeries} */
* @throws APIResponseException If {@link APIWrapper} could not return information properly Response<List<FilteredWaifu>> getSeriesWaifus(String seriesId) throws APIResponseException, APIMapperException {
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model Result allWaifusFromSeriesResults = sendGetRequest("series/" + seriesId + "/waifus");
* return apiMapper.deserializeToList(allWaifusFromSeriesResults, listOf(FilteredWaifu.class));
*/ }
Response<List<FilteredSeries>> getAllSeries(Season season, Integer year) throws APIResponseException, APIMapperException {
Result allSeriesResult = sendGetRequest("airing/" + season.getSeason() + "/" + year); /**
return apiMapper.deserializeToList(allSeriesResult, listOf(FilteredSeries.class)); * Retrieve information about the {@link User} by sending request to API
} *
* @param userId The id of the {@link User}
/** * @return {@link Response} of {@link User}
* Retrieve a set of Waifus for a given {@link Series} by sending request to API * @throws APIResponseException If {@link APIWrapper} could not return information properly
* * @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
* @param seriesId The id of the {@link Series} */
* @return {@link Response} of {@link List} with {@link FilteredWaifu} Response<User> getUserProfile(String userId) throws APIResponseException, APIMapperException {
* @throws APIResponseException If {@link APIWrapper} could not return information properly Result userProfileResult = sendGetRequest("user/" + userId);
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model return apiMapper.deserialize(userProfileResult, User.class);
* }
*/
Response<List<FilteredWaifu>> getSeriesWaifus(String seriesId) throws APIResponseException, APIMapperException { /**
Result allWaifusFromSeriesResults = sendGetRequest("series/" + seriesId + "/waifus"); * Retrieve the Waifus Created, Liked, or Trashed for the given {@link User} id by sending request to API
return apiMapper.deserializeToList(allWaifusFromSeriesResults, listOf(FilteredWaifu.class)); *
} * @param userId The id of the {@link User}
* @param listType The specified action E.g {@link WaifuListType#LIKED}
/** * @param pageNum The page number of the gallery
* Retrieve information about the {@link User} by sending request to API * @return {@link Response} of {@link PaginationData} with {@link FilteredWaifu}
* * @throws APIResponseException If {@link APIWrapper} could not return information properly
* @param userId The id of the {@link User} * @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
* @return {@link Response} of {@link User} */
* @throws APIResponseException If {@link APIWrapper} could not return information properly Response<PaginationData<FilteredWaifu>> getUserWaifus(String userId, String listType, String pageNum) throws APIResponseException, APIMapperException {
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model Result userWaifusResult = sendGetRequest("user/" + userId + "/" + listType + "?page=" + pageNum);
* return apiMapper.deserializeToPaginationData(userWaifusResult, paginationData(FilteredWaifu.class));
*/ }
Response<User> getUserProfile(String userId) throws APIResponseException, APIMapperException {
Result userProfileResult = sendGetRequest("user/" + userId); /**
return apiMapper.deserialize(userProfileResult, User.class); * Retrieve a List of all {@link UserList}'s shown by sending request to API
} *
* @param userId The id of the {@link User}
/** * @return {@link Response} of {@link List} with {@link UserList}
* Retrieve the Waifus Created, Liked, or Trashed for the given {@link User} id by sending request to API * @throws APIResponseException If {@link APIWrapper} could not return information properly
* * @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
* @param userId The id of the {@link User} */
* @param listType The specified action E.g {@link WaifuListType#LIKED} Response<List<UserList>> getUserLists(String userId) throws APIResponseException, APIMapperException {
* @param pageNum The page number of the gallery Result userProfileResult = sendGetRequest("user/" + userId + "/lists");
* @return {@link Response} of {@link PaginationData} with {@link FilteredWaifu} return apiMapper.deserializeToList(userProfileResult, listOf(UserList.class));
* @throws APIResponseException If {@link APIWrapper} could not return information properly }
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
* /**
*/ * Retrieve the Specific {@link UserList}, with {@link Waifu}'s by sending request to API
Response<PaginationData<FilteredWaifu>> getUserWaifus(String userId, String listType, String pageNum) throws APIResponseException, APIMapperException { *
Result userWaifusResult = sendGetRequest("user/" + userId + "/" + listType + "?page=" + pageNum); * @param userId The id of the {@link User}
return apiMapper.deserializeToPaginationData(userWaifusResult, paginationData(FilteredWaifu.class)); * @param listId The id of the {@link UserList}
} * @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
* Retrieve a List of all {@link UserList}'s shown by sending request to API */
* Response<UserList> getUserList(String userId, String listId) throws APIResponseException, APIMapperException {
* @param userId The id of the {@link User} Result userProfileResult = sendGetRequest("user/" + userId + "/lists/" + listId);
* @return {@link Response} of {@link List} with {@link UserList} return apiMapper.deserialize(userProfileResult, UserList.class);
* @throws APIResponseException If {@link APIWrapper} could not return information properly }
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
* /**
*/ * Retrieve a {@link List} of {@link FilteredWaifu} with a search term by sending a POST request to the API
Response<List<UserList>> getUserLists(String userId) throws APIResponseException, APIMapperException { *
Result userProfileResult = sendGetRequest("user/" + userId + "/lists"); * @param searchString {@link String} that should be searched for
return apiMapper.deserializeToList(userProfileResult, listOf(UserList.class)); * @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
/** */
* Retrieve the Specific {@link UserList}, with {@link Waifu}'s by sending request to API Response<List<FilteredWaifu>> betaSearch(String searchString) throws APIMapperException, APIResponseException {
* Result betaSearchResult = sendPostRequest("search/beta", Map.of("term", searchString));
* @param userId The id of the {@link User} return apiMapper.deserializeToList(betaSearchResult, listOf(FilteredWaifu.class));
* @param listId The id of the {@link UserList} }
* @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 * Retrieve a List of {@link FilteredWaifu}'s given a query, by sending POST request to API
* *
*/ * @param waifuName The name of the Waifu
Response<UserList> getUserList(String userId, String listId) throws APIResponseException, APIMapperException { * @return {@link Response} of {@link List} with {@link FilteredWaifu}
Result userProfileResult = sendGetRequest("user/" + userId + "/lists/" + listId); * @throws APIResponseException If {@link APIWrapper} could not return information properly
return apiMapper.deserialize(userProfileResult, UserList.class); * @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));
* Retrieve a {@link List} of {@link FilteredWaifu} with a search term by sending a POST request to the API return apiMapper.deserializeToList(searchWaifusResult, listOf(FilteredWaifu.class));
* }
* @param searchString {@link String} that should be searched for
* @return {@link Response} of {@link List} with {@link FilteredWaifu} /**
* @throws APIResponseException If {@link APIWrapper} could not return information properly * Retrieve a List of {@link FilteredSeries}'s given a query, by sending POST request to API
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model *
* * @param seriesName The name of the Series
*/ * @return {@link Response} of {@link List} with {@link FilteredSeries}
Response<List<FilteredWaifu>> betaSearch(String searchString) throws APIMapperException, APIResponseException { * @throws APIResponseException If {@link APIWrapper} could not return information properly
Result betaSearchResult = sendPostRequest("search/beta", Map.of("term", searchString)); * @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
return apiMapper.deserializeToList(betaSearchResult, listOf(FilteredWaifu.class)); */
} Response<List<FilteredSeries>> searchSeries(String seriesName) throws APIMapperException, APIResponseException {
Result searchSeriesResult = sendPostRequest("search/series", Map.of("term", seriesName));
/** return apiMapper.deserializeToList(searchSeriesResult, listOf(FilteredSeries.class));
* Retrieve a List of {@link FilteredWaifu}'s given a query, by sending POST request to API }
*
* @param waifuName The name of the Waifu void setApiKey(String apiKey) {
* @return {@link Response} of {@link List} with {@link FilteredWaifu} this.apiKey = apiKey;
* @throws APIResponseException If {@link APIWrapper} could not return information properly }
* @throws APIMapperException If {@link APIMapper} could not correctly {@code deserialize} model
* void setApiMapper(APIMapper apiMapper) {
*/ this.apiMapper = apiMapper;
Response<List<FilteredWaifu>> searchWaifus(String waifuName) throws APIMapperException, APIResponseException { }
Result searchWaifusResult = sendPostRequest("search/waifus", Map.of("term", waifuName));
return apiMapper.deserializeToList(searchWaifusResult, listOf(FilteredWaifu.class));
}
/**
* Retrieve a List of {@link FilteredSeries}'s given a query, by sending POST request to API
*
* @param seriesName The name of the Series
* @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));
return apiMapper.deserializeToList(searchSeriesResult, listOf(FilteredSeries.class));
}
void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
void setApiMapper(APIMapper apiMapper) {
this.apiMapper = apiMapper;
}
} }

@ -1,10 +1,9 @@
package me.goudham.exception; package me.goudham.exception;
import me.goudham.APIWrapper;
import me.goudham.Response; import me.goudham.Response;
/** /**
* Thrown when {@link APIWrapper} fails to deserialize json into Java POJO's ({@link Response#getModel()}) * Thrown when {@code APIWrapper} fails to deserialize json into Java POJO's ({@link Response#getModel()})
* *
*/ */
public class APIMapperException extends Throwable { public class APIMapperException extends Throwable {

@ -1,9 +1,7 @@
package me.goudham.exception; package me.goudham.exception;
import me.goudham.APIWrapper;
/** /**
* Thrown when {@link APIWrapper} fails to return API information * Thrown when {@code APIWrapper} fails to return API information
* *
*/ */
public class APIResponseException extends Throwable { public class APIResponseException extends Throwable {

Loading…
Cancel
Save