Remove public access from APIWrapper.java

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

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

@ -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