From d93133075029b0d8042eef19c939035cce2fe6bb Mon Sep 17 00:00:00 2001 From: Hammy Date: Tue, 8 Jun 2021 02:43:11 +0100 Subject: [PATCH 01/48] Update pom.xml Getting pom.xml ready for possible deployment to MavenCentral() --- pom.xml | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cf9c10c..58fbea3 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.goudham.me MyWaifuWrapper 0.1.4 - MyWaifuWrapper + jar UTF-8 @@ -15,6 +15,32 @@ 11 + MyWaifuWrapper + An Asynchronous Java API Wrapper for MyWaifuList. + https://github.com/sgoudham/MyWaifuWrapper + + + scm:git:git://github.com/sgoudham/MyWaifuWrapper.git + scm:git:ssh://github.com:sgoudham/MyWaifuWrapper.git + https://github.com/sgoudham/MyWaifuWrapper/tree/main + + + + + Goudham Suresh + sgoudham@gmail.com + Github + https://github.com/sgoudham + + + + + + MIT License + https://www.opensource.org/licenses/mit-license.php + + + org.junit.jupiter From 69c0ea55f38a603a51b05be003266b7a0c508549 Mon Sep 17 00:00:00 2001 From: Hammy Date: Tue, 8 Jun 2021 02:44:34 +0100 Subject: [PATCH 02/48] Remove HttpClient from MyWaifuClient.java MyWaifuClient should not have to pass in HttpClient into the APIWrapper, the httpClient is now managed by the APIWrapper --- .../java/org/goudham/me/MyWaifuClient.java | 45 +++++++------------ 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/goudham/me/MyWaifuClient.java b/src/main/java/org/goudham/me/MyWaifuClient.java index ce5ce2d..7aaabf4 100644 --- a/src/main/java/org/goudham/me/MyWaifuClient.java +++ b/src/main/java/org/goudham/me/MyWaifuClient.java @@ -25,16 +25,17 @@ import java.util.concurrent.Executor; */ public class MyWaifuClient { private final APIWrapper APIWrapper; - private HttpClient httpClient; /** * Creates an instance of {@link MyWaifuClient} * *

See MyWaifuList for obtaining an API Key

* @param apiKey API Key to authorise API request + * @param httpClient The underlying {@link HttpClient} to use for HttpRequests + * */ - MyWaifuClient(@NotNull String apiKey) { - APIWrapper = new APIWrapper(apiKey); + MyWaifuClient(@NotNull String apiKey, HttpClient httpClient) { + APIWrapper = new APIWrapper(apiKey, httpClient); } /** @@ -44,39 +45,29 @@ public class MyWaifuClient { * @return {@link MyWaifuClient} */ public static MyWaifuClient createDefault(@NotNull String apiKey) { - MyWaifuClient myWaifuClient = new MyWaifuClient(apiKey); - myWaifuClient.setHttpClient(HttpClient.newBuilder() + HttpClient httpClient = HttpClient.newBuilder() .version(HttpClient.Version.HTTP_2) .followRedirects(HttpClient.Redirect.NORMAL) .connectTimeout(Duration.ofSeconds(20)) - .build()); + .build(); - return myWaifuClient; + return new MyWaifuClient(apiKey, httpClient); } - public Response getWaifu(String slug) throws APIResponseException, APIMapperException { - return APIWrapper.getWaifu(httpClient, slug); + public Response getWaifu(@NotNull String slug) throws APIResponseException, APIMapperException { + return APIWrapper.getWaifu(slug); } - public Response getWaifu(Integer id) throws APIResponseException, APIMapperException { - return APIWrapper.getWaifu(httpClient, String.valueOf(id)); + public Response getWaifu(@NotNull Integer id) throws APIResponseException, APIMapperException { + return APIWrapper.getWaifu(String.valueOf(id)); } - public Response getSeries(Integer id) throws APIMapperException, APIResponseException { - return APIWrapper.getSeries(httpClient, String.valueOf(id)); + public Response getSeries(@NotNull Integer id) throws APIMapperException, APIResponseException { + return APIWrapper.getSeries(String.valueOf(id)); } public Response> getAiringAnime() throws APIMapperException, APIResponseException { - return APIWrapper.getAiringAnime(httpClient); - } - - /** - * Sets an instance of HttpClient - * - * @param httpClient HttpClient for executing API requests - */ - void setHttpClient(HttpClient httpClient) { - this.httpClient = httpClient; + return APIWrapper.getAiringAnime(); } /** @@ -84,12 +75,10 @@ public class MyWaifuClient { */ public static class Builder { private final String apiKey; - private final APIWrapper APIWrapper; - private HttpClient.Builder httpClientBuilder; + private final HttpClient.Builder httpClientBuilder = HttpClient.newBuilder(); public Builder(String apiKey) { this.apiKey = apiKey; - APIWrapper = new APIWrapper(apiKey); } public Builder withCookieHandler(CookieHandler cookieHandler) { @@ -138,9 +127,7 @@ public class MyWaifuClient { } public MyWaifuClient build() { - MyWaifuClient myWaifuClient = new MyWaifuClient(apiKey); - myWaifuClient.setHttpClient(httpClientBuilder.build()); - return myWaifuClient; + return new MyWaifuClient(apiKey, httpClientBuilder.build()); } } } From 32068c4c554b0ede54d30862bb04cab743cde3cb Mon Sep 17 00:00:00 2001 From: Hammy Date: Tue, 8 Jun 2021 02:45:33 +0100 Subject: [PATCH 03/48] Refactor deserialize & deserializeToList() methods Making methods more readable through type signatures and how the method is being called within APIWrapper.java --- src/main/java/org/goudham/me/APIMapper.java | 19 +++----------- src/main/java/org/goudham/me/APIWrapper.java | 26 ++++++++++++++++---- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/goudham/me/APIMapper.java b/src/main/java/org/goudham/me/APIMapper.java index b398f76..1eea24a 100644 --- a/src/main/java/org/goudham/me/APIMapper.java +++ b/src/main/java/org/goudham/me/APIMapper.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.type.TypeFactory; import org.goudham.me.api.entity.series.FilteredSeries; import org.goudham.me.api.entity.series.Series; import org.goudham.me.api.entity.waifu.Waifu; @@ -23,18 +22,6 @@ class APIMapper { objectMapper = new ObjectMapper(); } - /** - * Honestly I don't really know how this works - * - * @param entity The actual class of the given entity. E.g {@link Waifu#getClass()} - * @param The type of entity to be returned. E.g {@link Waifu} or {@link Series} - * @return {@link JavaType} - * - */ - private JavaType listOf(Class entity) { - return TypeFactory.defaultInstance().constructCollectionType(List.class, entity); - } - /** * Using the given {@code entity}, {@link ObjectMapper} deserializes the given Json * into a Java POJO @@ -67,13 +54,13 @@ class APIMapper { * Using the given {@code entity}, {@link ObjectMapper} deserializes the given Json * into a Java POJO. This method enables support for retrieving {@link List} of entities * + * @param List of entities to be returned. E.g {@link List} of {@link FilteredSeries} * @param result The result of the previous API response * @param entity The actual class of the given entity. E.g {@link Waifu#getClass()} - * @param List of entities to be returned. E.g {@link List} of {@link FilteredSeries} * @return {@link Response} * @throws APIMapperException If {@link ObjectMapper} is not able to deserialize JSON to Java POJO properly */ - Response> deserializeToList(Result result, Class entity) throws APIMapperException { + Response> deserialize(Result result, JavaType entity) throws APIMapperException { Integer statusCode = result.getStatusCode(); String body = result.getBody(); List listOfEntity = null; @@ -81,7 +68,7 @@ class APIMapper { if (statusCode == 200) { try { String data = getJsonTree(body); - listOfEntity = objectMapper.readValue(data, listOf(entity)); + listOfEntity = objectMapper.readValue(data, entity); } catch (JsonProcessingException jpe) { throwAPIMapperException(jpe); } diff --git a/src/main/java/org/goudham/me/APIWrapper.java b/src/main/java/org/goudham/me/APIWrapper.java index 8838ffe..5d59f2a 100644 --- a/src/main/java/org/goudham/me/APIWrapper.java +++ b/src/main/java/org/goudham/me/APIWrapper.java @@ -1,5 +1,7 @@ package org.goudham.me; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.type.TypeFactory; import org.goudham.me.api.entity.series.FilteredSeries; import org.goudham.me.api.entity.series.Series; import org.goudham.me.api.entity.waifu.Waifu; @@ -25,6 +27,7 @@ public class APIWrapper { private final String apiKey; private final APIMapper apiMapper; + private final HttpClient httpClient; /** * Instantiates an instance of {@link APIWrapper} to retrieve API Information. @@ -32,13 +35,26 @@ public class APIWrapper { * Java objects * * @param apiKey API Key to authorise API request + * @param httpClient The underlying {@link HttpClient} to use for HttpRequests * */ - APIWrapper(String apiKey) { + APIWrapper(String apiKey, HttpClient httpClient) { this.apiKey = apiKey; + this.httpClient = httpClient; apiMapper = new APIMapper(); } + /** + * Honestly I don't really know how this works + * + * @param entity The actual class of the given entity. E.g {@link Waifu#getClass()} + * @param The type of entity to be returned. E.g {@link Waifu} or {@link Series} + * @return {@link JavaType} + * + */ + private JavaType listOf(Class entity) { + return TypeFactory.defaultInstance().constructCollectionType(List.class, entity); + } /** * Handles sending a request to the API asynchronously using {@link HttpRequest} @@ -74,18 +90,18 @@ public class APIWrapper { return new Result(responseCode, responseBody); } - Response getWaifu(HttpClient httpClient, String param) throws APIResponseException, APIMapperException { + Response getWaifu(String param) throws APIResponseException, APIMapperException { Result waifuResult = sendRequest(httpClient, "waifu/" + param); return apiMapper.deserialize(waifuResult, Waifu.class); } - Response getSeries(HttpClient httpClient, String param) throws APIResponseException, APIMapperException { + Response getSeries(String param) throws APIResponseException, APIMapperException { Result seriesResult = sendRequest(httpClient, "series/" + param); return apiMapper.deserialize(seriesResult, Series.class); } - Response> getAiringAnime(HttpClient httpClient) throws APIResponseException, APIMapperException { + Response> getAiringAnime() throws APIResponseException, APIMapperException { Result seriesResult = sendRequest(httpClient, "airing"); - return apiMapper.deserializeToList(seriesResult, FilteredSeries.class); + return apiMapper.deserialize(seriesResult, listOf(FilteredSeries.class)); } } From 781342159784956b16b0e88591701115ec13c46a Mon Sep 17 00:00:00 2001 From: Hammy Date: Tue, 8 Jun 2021 02:48:37 +0100 Subject: [PATCH 04/48] Delete useless test --- src/test/java/org/goudham/me/AppTest.java | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 src/test/java/org/goudham/me/AppTest.java diff --git a/src/test/java/org/goudham/me/AppTest.java b/src/test/java/org/goudham/me/AppTest.java deleted file mode 100644 index 9840d16..0000000 --- a/src/test/java/org/goudham/me/AppTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.goudham.me; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * Unit test for simple App. - */ -public class AppTest -{ - /** - * Rigorous Test :-) - */ - @Test - public void shouldAnswerWithTrue() - { - assertTrue( true ); - } -} From 61c1c0e7b0853faa26d3247def2b27bd26d096c4 Mon Sep 17 00:00:00 2001 From: Hammy Date: Tue, 8 Jun 2021 02:52:38 +0100 Subject: [PATCH 05/48] Update FilteredWaifu.java to better reflect API information --- .../me/api/entity/waifu/FilteredWaifu.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/org/goudham/me/api/entity/waifu/FilteredWaifu.java b/src/main/java/org/goudham/me/api/entity/waifu/FilteredWaifu.java index 5f65923..c12e091 100644 --- a/src/main/java/org/goudham/me/api/entity/waifu/FilteredWaifu.java +++ b/src/main/java/org/goudham/me/api/entity/waifu/FilteredWaifu.java @@ -22,6 +22,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; *
  • {@link String name}
  • *
  • {@link String originalName}
  • *
  • {@link Integer relevance}
  • + *
  • {@link String romaji}
  • *
  • {@link String romajiName}
  • *
  • {@link String displayPicture}
  • *
  • {@link Integer likes}
  • @@ -39,6 +40,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; "name", "original_name", "relevance", + "romaji", "romaji_name", "display_picture", "description", @@ -82,6 +84,14 @@ public class FilteredWaifu { @JsonPropertyDescription("Relevancy of FilteredWaifu") private Integer relevance; + /** + * If this character has a romaji name, we'll put it here. + * + */ + @JsonProperty("romaji") + @JsonPropertyDescription("if this character has a romaji name, we'll put it here. ") + private String romaji; + /** * If this character has a romaji name, we'll put it here. * @@ -186,6 +196,12 @@ public class FilteredWaifu { @JsonProperty("relevance") public void setRelevance(Integer relevance) { this.relevance = relevance; } + @JsonProperty("romaji") + public String getRomaji() { return romaji; } + + @JsonProperty("romaji") + public void setRomaji(String romaji) { this.romaji = romaji; } + @JsonProperty("romaji_name") public String getRomajiName() { return romajiName; From 59508153edda514082efd2d4d97db55d4fad655e Mon Sep 17 00:00:00 2001 From: Hammy Date: Tue, 8 Jun 2021 02:57:38 +0100 Subject: [PATCH 06/48] Add new endpoint - getDailyWaifu() --- src/main/java/org/goudham/me/APIWrapper.java | 6 ++++++ src/main/java/org/goudham/me/MyWaifuClient.java | 5 +++++ .../org/goudham/me/api/entity/waifu/FilteredWaifu.java | 7 ++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/goudham/me/APIWrapper.java b/src/main/java/org/goudham/me/APIWrapper.java index 5d59f2a..648c7aa 100644 --- a/src/main/java/org/goudham/me/APIWrapper.java +++ b/src/main/java/org/goudham/me/APIWrapper.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.type.TypeFactory; import org.goudham.me.api.entity.series.FilteredSeries; import org.goudham.me.api.entity.series.Series; +import org.goudham.me.api.entity.waifu.FilteredWaifu; import org.goudham.me.api.entity.waifu.Waifu; import org.goudham.me.exception.APIMapperException; import org.goudham.me.exception.APIResponseException; @@ -95,6 +96,11 @@ public class APIWrapper { return apiMapper.deserialize(waifuResult, Waifu.class); } + Response getDailyWaifu() throws APIResponseException, APIMapperException { + Result waifuResult = sendRequest(httpClient, "meta/daily"); + return apiMapper.deserialize(waifuResult, FilteredWaifu.class); + } + Response getSeries(String param) throws APIResponseException, APIMapperException { Result seriesResult = sendRequest(httpClient, "series/" + param); return apiMapper.deserialize(seriesResult, Series.class); diff --git a/src/main/java/org/goudham/me/MyWaifuClient.java b/src/main/java/org/goudham/me/MyWaifuClient.java index 7aaabf4..2c5890f 100644 --- a/src/main/java/org/goudham/me/MyWaifuClient.java +++ b/src/main/java/org/goudham/me/MyWaifuClient.java @@ -2,6 +2,7 @@ package org.goudham.me; import org.goudham.me.api.entity.series.FilteredSeries; import org.goudham.me.api.entity.series.Series; +import org.goudham.me.api.entity.waifu.FilteredWaifu; import org.goudham.me.api.entity.waifu.Waifu; import org.goudham.me.exception.APIMapperException; import org.goudham.me.exception.APIResponseException; @@ -62,6 +63,10 @@ public class MyWaifuClient { return APIWrapper.getWaifu(String.valueOf(id)); } + public Response getDailyWaifu() throws APIResponseException, APIMapperException { + return APIWrapper.getDailyWaifu(); + } + public Response getSeries(@NotNull Integer id) throws APIMapperException, APIResponseException { return APIWrapper.getSeries(String.valueOf(id)); } diff --git a/src/main/java/org/goudham/me/api/entity/waifu/FilteredWaifu.java b/src/main/java/org/goudham/me/api/entity/waifu/FilteredWaifu.java index c12e091..52abbe1 100644 --- a/src/main/java/org/goudham/me/api/entity/waifu/FilteredWaifu.java +++ b/src/main/java/org/goudham/me/api/entity/waifu/FilteredWaifu.java @@ -1,16 +1,12 @@ package org.goudham.me.api.entity.waifu; +import com.fasterxml.jackson.annotation.*; import org.goudham.me.api.entity.series.FilteredSeries; import java.util.List; import java.util.Objects; import javax.annotation.processing.Generated; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyDescription; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - /** * Filtered Waifu @@ -52,6 +48,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; "id" }) @Generated("jsonschema2pojo") +@JsonIgnoreProperties(ignoreUnknown = true) public class FilteredWaifu { /** * Used to generate readable URL's for the {@link FilteredWaifu} From 31bf9cbc7cac810df47692eed92ec5a451212aac Mon Sep 17 00:00:00 2001 From: Hammy Date: Tue, 8 Jun 2021 18:20:05 +0100 Subject: [PATCH 07/48] Update README.md Include license badge --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 1c03c44..5166dc5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@

    MyWaifuWrapper | An Asynchronous Java API Wrapper for MyWaifuList

    +

    + +

    +

    From 7c30a24cd1d1361d4e34dc1cc6da9a7c778fa6c6 Mon Sep 17 00:00:00 2001 From: Hammy Date: Tue, 8 Jun 2021 19:34:05 +0100 Subject: [PATCH 08/48] Rename package org.goudham.me to me.goudham --- .../goudham/me => me/goudham}/APIMapper.java | 10 +++++----- .../goudham/me => me/goudham}/APIWrapper.java | 14 +++++++------- .../goudham/me => me/goudham}/MyWaifuClient.java | 16 ++++++++-------- .../{org/goudham/me => me/goudham}/Response.java | 6 +++--- .../{org/goudham/me => me/goudham}/Result.java | 2 +- .../goudham}/api/entity/PaginationData.java | 2 +- .../me => me/goudham}/api/entity/Studio.java | 2 +- .../api/entity/series/FilteredSeries.java | 2 +- .../goudham}/api/entity/series/Series.java | 6 +++--- .../goudham}/api/entity/user/Creator.java | 4 ++-- .../goudham}/api/entity/user/TrueLove.java | 4 ++-- .../me => me/goudham}/api/entity/user/User.java | 4 ++-- .../goudham}/api/entity/user/UserList.java | 4 ++-- .../goudham}/api/entity/waifu/FilteredWaifu.java | 4 ++-- .../goudham}/api/entity/waifu/Waifu.java | 6 +++--- .../goudham}/api/entity/waifu/WaifuImage.java | 2 +- .../goudham}/exception/APIMapperException.java | 6 +++--- .../goudham}/exception/APIResponseException.java | 4 ++-- 18 files changed, 49 insertions(+), 49 deletions(-) rename src/main/java/{org/goudham/me => me/goudham}/APIMapper.java (94%) rename src/main/java/{org/goudham/me => me/goudham}/APIWrapper.java (92%) rename src/main/java/{org/goudham/me => me/goudham}/MyWaifuClient.java (92%) rename src/main/java/{org/goudham/me => me/goudham}/Response.java (91%) rename src/main/java/{org/goudham/me => me/goudham}/Result.java (93%) rename src/main/java/{org/goudham/me => me/goudham}/api/entity/PaginationData.java (98%) rename src/main/java/{org/goudham/me => me/goudham}/api/entity/Studio.java (98%) rename src/main/java/{org/goudham/me => me/goudham}/api/entity/series/FilteredSeries.java (99%) rename src/main/java/{org/goudham/me => me/goudham}/api/entity/series/Series.java (98%) rename src/main/java/{org/goudham/me => me/goudham}/api/entity/user/Creator.java (95%) rename src/main/java/{org/goudham/me => me/goudham}/api/entity/user/TrueLove.java (96%) rename src/main/java/{org/goudham/me => me/goudham}/api/entity/user/User.java (98%) rename src/main/java/{org/goudham/me => me/goudham}/api/entity/user/UserList.java (97%) rename src/main/java/{org/goudham/me => me/goudham}/api/entity/waifu/FilteredWaifu.java (98%) rename src/main/java/{org/goudham/me => me/goudham}/api/entity/waifu/Waifu.java (99%) rename src/main/java/{org/goudham/me => me/goudham}/api/entity/waifu/WaifuImage.java (98%) rename src/main/java/{org/goudham/me => me/goudham}/exception/APIMapperException.java (74%) rename src/main/java/{org/goudham/me => me/goudham}/exception/APIResponseException.java (78%) diff --git a/src/main/java/org/goudham/me/APIMapper.java b/src/main/java/me/goudham/APIMapper.java similarity index 94% rename from src/main/java/org/goudham/me/APIMapper.java rename to src/main/java/me/goudham/APIMapper.java index 1eea24a..4e98ded 100644 --- a/src/main/java/org/goudham/me/APIMapper.java +++ b/src/main/java/me/goudham/APIMapper.java @@ -1,13 +1,13 @@ -package org.goudham.me; +package me.goudham; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import org.goudham.me.api.entity.series.FilteredSeries; -import org.goudham.me.api.entity.series.Series; -import org.goudham.me.api.entity.waifu.Waifu; -import org.goudham.me.exception.APIMapperException; +import me.goudham.api.entity.series.Series; +import me.goudham.exception.APIMapperException; +import me.goudham.api.entity.series.FilteredSeries; +import me.goudham.api.entity.waifu.Waifu; import java.util.List; diff --git a/src/main/java/org/goudham/me/APIWrapper.java b/src/main/java/me/goudham/APIWrapper.java similarity index 92% rename from src/main/java/org/goudham/me/APIWrapper.java rename to src/main/java/me/goudham/APIWrapper.java index 648c7aa..d982453 100644 --- a/src/main/java/org/goudham/me/APIWrapper.java +++ b/src/main/java/me/goudham/APIWrapper.java @@ -1,13 +1,13 @@ -package org.goudham.me; +package me.goudham; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.type.TypeFactory; -import org.goudham.me.api.entity.series.FilteredSeries; -import org.goudham.me.api.entity.series.Series; -import org.goudham.me.api.entity.waifu.FilteredWaifu; -import org.goudham.me.api.entity.waifu.Waifu; -import org.goudham.me.exception.APIMapperException; -import org.goudham.me.exception.APIResponseException; +import me.goudham.api.entity.series.FilteredSeries; +import me.goudham.api.entity.series.Series; +import me.goudham.api.entity.waifu.FilteredWaifu; +import me.goudham.api.entity.waifu.Waifu; +import me.goudham.exception.APIMapperException; +import me.goudham.exception.APIResponseException; import java.net.URI; import java.net.http.HttpClient; diff --git a/src/main/java/org/goudham/me/MyWaifuClient.java b/src/main/java/me/goudham/MyWaifuClient.java similarity index 92% rename from src/main/java/org/goudham/me/MyWaifuClient.java rename to src/main/java/me/goudham/MyWaifuClient.java index 2c5890f..cc8f197 100644 --- a/src/main/java/org/goudham/me/MyWaifuClient.java +++ b/src/main/java/me/goudham/MyWaifuClient.java @@ -1,11 +1,11 @@ -package org.goudham.me; - -import org.goudham.me.api.entity.series.FilteredSeries; -import org.goudham.me.api.entity.series.Series; -import org.goudham.me.api.entity.waifu.FilteredWaifu; -import org.goudham.me.api.entity.waifu.Waifu; -import org.goudham.me.exception.APIMapperException; -import org.goudham.me.exception.APIResponseException; +package me.goudham; + +import me.goudham.api.entity.series.FilteredSeries; +import me.goudham.api.entity.series.Series; +import me.goudham.api.entity.waifu.FilteredWaifu; +import me.goudham.api.entity.waifu.Waifu; +import me.goudham.exception.APIMapperException; +import me.goudham.exception.APIResponseException; import org.jetbrains.annotations.NotNull; import javax.net.ssl.SSLParameters; diff --git a/src/main/java/org/goudham/me/Response.java b/src/main/java/me/goudham/Response.java similarity index 91% rename from src/main/java/org/goudham/me/Response.java rename to src/main/java/me/goudham/Response.java index 61c9079..fdf91aa 100644 --- a/src/main/java/org/goudham/me/Response.java +++ b/src/main/java/me/goudham/Response.java @@ -1,7 +1,7 @@ -package org.goudham.me; +package me.goudham; -import org.goudham.me.api.entity.series.Series; -import org.goudham.me.api.entity.waifu.Waifu; +import me.goudham.api.entity.series.Series; +import me.goudham.api.entity.waifu.Waifu; /** * This is returned to the User when called by methods in {@link MyWaifuClient}. diff --git a/src/main/java/org/goudham/me/Result.java b/src/main/java/me/goudham/Result.java similarity index 93% rename from src/main/java/org/goudham/me/Result.java rename to src/main/java/me/goudham/Result.java index 483e752..c56fcbb 100644 --- a/src/main/java/org/goudham/me/Result.java +++ b/src/main/java/me/goudham/Result.java @@ -1,4 +1,4 @@ -package org.goudham.me; +package me.goudham; class Result { private final Integer statusCode; diff --git a/src/main/java/org/goudham/me/api/entity/PaginationData.java b/src/main/java/me/goudham/api/entity/PaginationData.java similarity index 98% rename from src/main/java/org/goudham/me/api/entity/PaginationData.java rename to src/main/java/me/goudham/api/entity/PaginationData.java index 6c08c9d..2036561 100644 --- a/src/main/java/org/goudham/me/api/entity/PaginationData.java +++ b/src/main/java/me/goudham/api/entity/PaginationData.java @@ -1,4 +1,4 @@ -package org.goudham.me.api.entity; +package me.goudham.api.entity; import javax.annotation.processing.Generated; diff --git a/src/main/java/org/goudham/me/api/entity/Studio.java b/src/main/java/me/goudham/api/entity/Studio.java similarity index 98% rename from src/main/java/org/goudham/me/api/entity/Studio.java rename to src/main/java/me/goudham/api/entity/Studio.java index 7234096..8ce0145 100644 --- a/src/main/java/org/goudham/me/api/entity/Studio.java +++ b/src/main/java/me/goudham/api/entity/Studio.java @@ -1,4 +1,4 @@ -package org.goudham.me.api.entity; +package me.goudham.api.entity; import javax.annotation.processing.Generated; diff --git a/src/main/java/org/goudham/me/api/entity/series/FilteredSeries.java b/src/main/java/me/goudham/api/entity/series/FilteredSeries.java similarity index 99% rename from src/main/java/org/goudham/me/api/entity/series/FilteredSeries.java rename to src/main/java/me/goudham/api/entity/series/FilteredSeries.java index 27b94b5..07b9c7b 100644 --- a/src/main/java/org/goudham/me/api/entity/series/FilteredSeries.java +++ b/src/main/java/me/goudham/api/entity/series/FilteredSeries.java @@ -1,4 +1,4 @@ -package org.goudham.me.api.entity.series; +package me.goudham.api.entity.series; import javax.annotation.processing.Generated; diff --git a/src/main/java/org/goudham/me/api/entity/series/Series.java b/src/main/java/me/goudham/api/entity/series/Series.java similarity index 98% rename from src/main/java/org/goudham/me/api/entity/series/Series.java rename to src/main/java/me/goudham/api/entity/series/Series.java index ef86aed..d3eda50 100644 --- a/src/main/java/org/goudham/me/api/entity/series/Series.java +++ b/src/main/java/me/goudham/api/entity/series/Series.java @@ -1,10 +1,10 @@ -package org.goudham.me.api.entity.series; +package me.goudham.api.entity.series; import javax.annotation.processing.Generated; import com.fasterxml.jackson.annotation.*; -import org.goudham.me.api.entity.Studio; -import org.goudham.me.api.entity.waifu.Waifu; +import me.goudham.api.entity.Studio; +import me.goudham.api.entity.waifu.Waifu; import java.util.Objects; diff --git a/src/main/java/org/goudham/me/api/entity/user/Creator.java b/src/main/java/me/goudham/api/entity/user/Creator.java similarity index 95% rename from src/main/java/org/goudham/me/api/entity/user/Creator.java rename to src/main/java/me/goudham/api/entity/user/Creator.java index 5b42b91..a731470 100644 --- a/src/main/java/org/goudham/me/api/entity/user/Creator.java +++ b/src/main/java/me/goudham/api/entity/user/Creator.java @@ -1,9 +1,9 @@ -package org.goudham.me.api.entity.user; +package me.goudham.api.entity.user; import javax.annotation.processing.Generated; import com.fasterxml.jackson.annotation.JsonPropertyDescription; -import org.goudham.me.api.entity.waifu.Waifu; +import me.goudham.api.entity.waifu.Waifu; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/org/goudham/me/api/entity/user/TrueLove.java b/src/main/java/me/goudham/api/entity/user/TrueLove.java similarity index 96% rename from src/main/java/org/goudham/me/api/entity/user/TrueLove.java rename to src/main/java/me/goudham/api/entity/user/TrueLove.java index 3606c89..b8b36eb 100644 --- a/src/main/java/org/goudham/me/api/entity/user/TrueLove.java +++ b/src/main/java/me/goudham/api/entity/user/TrueLove.java @@ -1,11 +1,11 @@ -package org.goudham.me.api.entity.user; +package me.goudham.api.entity.user; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyDescription; import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import org.goudham.me.api.entity.series.Series; +import me.goudham.api.entity.series.Series; import javax.annotation.processing.Generated; import java.util.Objects; diff --git a/src/main/java/org/goudham/me/api/entity/user/User.java b/src/main/java/me/goudham/api/entity/user/User.java similarity index 98% rename from src/main/java/org/goudham/me/api/entity/user/User.java rename to src/main/java/me/goudham/api/entity/user/User.java index 71fad46..cea7567 100644 --- a/src/main/java/org/goudham/me/api/entity/user/User.java +++ b/src/main/java/me/goudham/api/entity/user/User.java @@ -1,4 +1,4 @@ -package org.goudham.me.api.entity.user; +package me.goudham.api.entity.user; import javax.annotation.processing.Generated; @@ -6,7 +6,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyDescription; import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import org.goudham.me.api.entity.waifu.Waifu; +import me.goudham.api.entity.waifu.Waifu; import java.util.Objects; diff --git a/src/main/java/org/goudham/me/api/entity/user/UserList.java b/src/main/java/me/goudham/api/entity/user/UserList.java similarity index 97% rename from src/main/java/org/goudham/me/api/entity/user/UserList.java rename to src/main/java/me/goudham/api/entity/user/UserList.java index a962aaf..4ee0a43 100644 --- a/src/main/java/org/goudham/me/api/entity/user/UserList.java +++ b/src/main/java/me/goudham/api/entity/user/UserList.java @@ -1,4 +1,4 @@ -package org.goudham.me.api.entity.user; +package me.goudham.api.entity.user; import java.util.List; import java.util.Objects; @@ -8,7 +8,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyDescription; import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import org.goudham.me.api.entity.waifu.Waifu; +import me.goudham.api.entity.waifu.Waifu; /** * {@link UserList} diff --git a/src/main/java/org/goudham/me/api/entity/waifu/FilteredWaifu.java b/src/main/java/me/goudham/api/entity/waifu/FilteredWaifu.java similarity index 98% rename from src/main/java/org/goudham/me/api/entity/waifu/FilteredWaifu.java rename to src/main/java/me/goudham/api/entity/waifu/FilteredWaifu.java index 52abbe1..71b0866 100644 --- a/src/main/java/org/goudham/me/api/entity/waifu/FilteredWaifu.java +++ b/src/main/java/me/goudham/api/entity/waifu/FilteredWaifu.java @@ -1,7 +1,7 @@ -package org.goudham.me.api.entity.waifu; +package me.goudham.api.entity.waifu; import com.fasterxml.jackson.annotation.*; -import org.goudham.me.api.entity.series.FilteredSeries; +import me.goudham.api.entity.series.FilteredSeries; import java.util.List; import java.util.Objects; diff --git a/src/main/java/org/goudham/me/api/entity/waifu/Waifu.java b/src/main/java/me/goudham/api/entity/waifu/Waifu.java similarity index 99% rename from src/main/java/org/goudham/me/api/entity/waifu/Waifu.java rename to src/main/java/me/goudham/api/entity/waifu/Waifu.java index e80b849..2005e31 100644 --- a/src/main/java/org/goudham/me/api/entity/waifu/Waifu.java +++ b/src/main/java/me/goudham/api/entity/waifu/Waifu.java @@ -1,4 +1,4 @@ -package org.goudham.me.api.entity.waifu; +package me.goudham.api.entity.waifu; import java.util.HashMap; import java.util.List; @@ -7,8 +7,8 @@ import java.util.Objects; import javax.annotation.processing.Generated; import com.fasterxml.jackson.annotation.*; -import org.goudham.me.api.entity.series.Series; -import org.goudham.me.api.entity.user.Creator; +import me.goudham.api.entity.series.Series; +import me.goudham.api.entity.user.Creator; /** diff --git a/src/main/java/org/goudham/me/api/entity/waifu/WaifuImage.java b/src/main/java/me/goudham/api/entity/waifu/WaifuImage.java similarity index 98% rename from src/main/java/org/goudham/me/api/entity/waifu/WaifuImage.java rename to src/main/java/me/goudham/api/entity/waifu/WaifuImage.java index 06ef5d7..1ae4af0 100644 --- a/src/main/java/org/goudham/me/api/entity/waifu/WaifuImage.java +++ b/src/main/java/me/goudham/api/entity/waifu/WaifuImage.java @@ -1,4 +1,4 @@ -package org.goudham.me.api.entity.waifu; +package me.goudham.api.entity.waifu; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/org/goudham/me/exception/APIMapperException.java b/src/main/java/me/goudham/exception/APIMapperException.java similarity index 74% rename from src/main/java/org/goudham/me/exception/APIMapperException.java rename to src/main/java/me/goudham/exception/APIMapperException.java index 79bad38..4c7d9f3 100644 --- a/src/main/java/org/goudham/me/exception/APIMapperException.java +++ b/src/main/java/me/goudham/exception/APIMapperException.java @@ -1,7 +1,7 @@ -package org.goudham.me.exception; +package me.goudham.exception; -import org.goudham.me.APIWrapper; -import org.goudham.me.Response; +import me.goudham.APIWrapper; +import me.goudham.Response; /** * Thrown when {@link APIWrapper} fails to deserialize json into Java POJO's ({@link Response#getEntity()}) diff --git a/src/main/java/org/goudham/me/exception/APIResponseException.java b/src/main/java/me/goudham/exception/APIResponseException.java similarity index 78% rename from src/main/java/org/goudham/me/exception/APIResponseException.java rename to src/main/java/me/goudham/exception/APIResponseException.java index 53259d2..f1a3439 100644 --- a/src/main/java/org/goudham/me/exception/APIResponseException.java +++ b/src/main/java/me/goudham/exception/APIResponseException.java @@ -1,6 +1,6 @@ -package org.goudham.me.exception; +package me.goudham.exception; -import org.goudham.me.APIWrapper; +import me.goudham.APIWrapper; /** * Thrown when {@link APIWrapper} fails to return API information From 55f91bbddfc8588ea1273710907b58006fae0a3b Mon Sep 17 00:00:00 2001 From: Hammy Date: Tue, 8 Jun 2021 19:36:45 +0100 Subject: [PATCH 09/48] Add documentation --- src/main/java/me/goudham/Result.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/me/goudham/Result.java b/src/main/java/me/goudham/Result.java index c56fcbb..387ce84 100644 --- a/src/main/java/me/goudham/Result.java +++ b/src/main/java/me/goudham/Result.java @@ -1,5 +1,11 @@ package me.goudham; +import java.net.http.HttpRequest; + +/** + * Represents a Result from a {@link HttpRequest} with the resulting + * {@code statusCode} and {@code body} + */ class Result { private final Integer statusCode; private final String body; From aab72afde1dae29e11d2711b3f634eb0537d8b5a Mon Sep 17 00:00:00 2001 From: Hammy Date: Tue, 8 Jun 2021 19:37:37 +0100 Subject: [PATCH 10/48] Delete unused code --- src/main/java/me/goudham/Response.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/me/goudham/Response.java b/src/main/java/me/goudham/Response.java index fdf91aa..3cd5c27 100644 --- a/src/main/java/me/goudham/Response.java +++ b/src/main/java/me/goudham/Response.java @@ -17,7 +17,7 @@ import me.goudham.api.entity.waifu.Waifu; * */ public class Response { - private T entity; + private final T entity; private final Integer responseCode; private final String responseBody; @@ -27,11 +27,6 @@ public class Response { this.entity = entity; } - Response(Integer responseCode, String responseBody) { - this.responseCode = responseCode; - this.responseBody = responseBody; - } - public T getEntity() { return entity; } From 8af51c289e87d4377a63d8ba6d7c51a8cfaaa42b Mon Sep 17 00:00:00 2001 From: Hammy Date: Tue, 8 Jun 2021 19:47:12 +0100 Subject: [PATCH 11/48] Update WaifuImage.java to better reflect API --- .../goudham/api/entity/waifu/WaifuImage.java | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/goudham/api/entity/waifu/WaifuImage.java b/src/main/java/me/goudham/api/entity/waifu/WaifuImage.java index 1ae4af0..d0e420f 100644 --- a/src/main/java/me/goudham/api/entity/waifu/WaifuImage.java +++ b/src/main/java/me/goudham/api/entity/waifu/WaifuImage.java @@ -16,7 +16,8 @@ import java.util.Objects; *

    * */ @@ -24,9 +25,9 @@ import java.util.Objects; @JsonPropertyOrder({ "id", "thumbnail", - "path" + "image", + "nsfw" }) -@Generated("jsonschema2pojo") public class WaifuImage { /** @@ -51,7 +52,15 @@ public class WaifuImage { */ @JsonProperty("path") @JsonPropertyDescription("Final URL of the original resolution image") - private String path; + private String image; + + /** + * If image is NSFW or not + * + */ + @JsonProperty("nsfw") + @JsonPropertyDescription("If image is NSFW or not") + private String nsfw; @JsonProperty("id") public Integer getId() { @@ -74,26 +83,32 @@ public class WaifuImage { } @JsonProperty("path") - public String getPath() { - return path; + public String getImage() { + return image; } @JsonProperty("path") - public void setPath(String path) { - this.path = path; + public void setImage(String image) { + this.image = image; } + @JsonProperty("nsfw") + public String getNsfw() { return nsfw; } + + @JsonProperty("nsfw") + public void setNsfw(String nsfw) { this.nsfw = nsfw; } + @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; WaifuImage that = (WaifuImage) o; - return Objects.equals(id, that.id) && Objects.equals(thumbnail, that.thumbnail) && Objects.equals(path, that.path); + return Objects.equals(id, that.id) && Objects.equals(thumbnail, that.thumbnail) && Objects.equals(image, that.image) && Objects.equals(nsfw, that.nsfw); } @Override public int hashCode() { - return Objects.hash(id, thumbnail, path); + return Objects.hash(id, thumbnail, image, nsfw); } @Override @@ -101,7 +116,8 @@ public class WaifuImage { return "WaifuImage{" + "id=" + id + ", thumbnail='" + thumbnail + '\'' + - ", path='" + path + '\'' + + ", image='" + image + '\'' + + ", nsfw='" + nsfw + '\'' + '}'; } } From 3fd6f9f9173df0cc8e5598a8797e4bf9c942a197 Mon Sep 17 00:00:00 2001 From: Hammy Date: Tue, 8 Jun 2021 19:54:34 +0100 Subject: [PATCH 12/48] Remove unused import --- src/main/java/me/goudham/api/entity/waifu/WaifuImage.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/me/goudham/api/entity/waifu/WaifuImage.java b/src/main/java/me/goudham/api/entity/waifu/WaifuImage.java index d0e420f..622a675 100644 --- a/src/main/java/me/goudham/api/entity/waifu/WaifuImage.java +++ b/src/main/java/me/goudham/api/entity/waifu/WaifuImage.java @@ -5,7 +5,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyDescription; import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import javax.annotation.processing.Generated; import java.util.Objects; /** From 82a136dee00a0f1ce7889a5c1e75ad24c1f3d6e9 Mon Sep 17 00:00:00 2001 From: Hammy Date: Tue, 8 Jun 2021 22:40:11 +0100 Subject: [PATCH 13/48] Update instance variables Instance variables were updated for better clarity and readability to end users --- src/main/java/me/goudham/Response.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/goudham/Response.java b/src/main/java/me/goudham/Response.java index 3cd5c27..973b8c6 100644 --- a/src/main/java/me/goudham/Response.java +++ b/src/main/java/me/goudham/Response.java @@ -9,21 +9,21 @@ import me.goudham.api.entity.waifu.Waifu; *
    * Given a successful response, {@link #entity} will be populated with the requested entity. *
    - * No matter successful or unsuccessful response, {@link #responseCode} and {@link #responseBody} + * No matter successful or unsuccessful response, {@link #statusCode} and {@link #body} * will be populated to ensure the user has all the information for debugging or extra information within - * the {@link #responseBody} + * the {@link #body} * * @param The type of entity to be returned. E.g {@link Waifu} or {@link Series} * */ public class Response { private final T entity; - private final Integer responseCode; - private final String responseBody; + private final Integer statusCode; + private final String body; - Response(Integer responseCode, String responseBody, T entity) { - this.responseCode = responseCode; - this.responseBody = responseBody; + Response(Integer statusCode, String body, T entity) { + this.statusCode = statusCode; + this.body = body; this.entity = entity; } @@ -31,11 +31,11 @@ public class Response { return entity; } - public Integer getResponseCode() { - return responseCode; + public Integer getStatusCode() { + return statusCode; } - public String getResponseBody() { - return responseBody; + public String getBody() { + return body; } } From 3733925aa09a9ca0076de045c1549c11b4a454a0 Mon Sep 17 00:00:00 2001 From: Hammy Date: Tue, 8 Jun 2021 22:41:18 +0100 Subject: [PATCH 14/48] Ignore Series from FilteredWaifu This value seems to be always null when returned from the API, hence it is now going to be ignored --- src/main/java/me/goudham/api/entity/waifu/FilteredWaifu.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/me/goudham/api/entity/waifu/FilteredWaifu.java b/src/main/java/me/goudham/api/entity/waifu/FilteredWaifu.java index 71b0866..a41af72 100644 --- a/src/main/java/me/goudham/api/entity/waifu/FilteredWaifu.java +++ b/src/main/java/me/goudham/api/entity/waifu/FilteredWaifu.java @@ -5,7 +5,6 @@ import me.goudham.api.entity.series.FilteredSeries; import java.util.List; import java.util.Objects; -import javax.annotation.processing.Generated; /** @@ -47,8 +46,7 @@ import javax.annotation.processing.Generated; "appearances", "id" }) -@Generated("jsonschema2pojo") -@JsonIgnoreProperties(ignoreUnknown = true) +@JsonIgnoreProperties(value = { "series" }) public class FilteredWaifu { /** * Used to generate readable URL's for the {@link FilteredWaifu} From 8e64742fde33a6001464803576c6cf83b3ce0eee Mon Sep 17 00:00:00 2001 From: Hammy Date: Wed, 9 Jun 2021 00:06:34 +0100 Subject: [PATCH 15/48] Add enum for seasons of the year Reduces the chance of user error to near 0 as they will choose from an enum instead of string --- src/main/java/me/goudham/util/Season.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/me/goudham/util/Season.java diff --git a/src/main/java/me/goudham/util/Season.java b/src/main/java/me/goudham/util/Season.java new file mode 100644 index 0000000..e44a2b8 --- /dev/null +++ b/src/main/java/me/goudham/util/Season.java @@ -0,0 +1,22 @@ +package me.goudham.util; + +/** + * Listing all 4 {@link Season}'s + * + */ +public enum Season { + SPRING("spring"), + SUMMER("summer"), + FALL("fall"), + WINTER("winter"); + + private final String season; + + Season(String season) { + this.season = season; + } + + public String getSeason() { + return season; + } +} From 087a2ce3d2ab298a55aacb5b1d712ccce37823c2 Mon Sep 17 00:00:00 2001 From: Hammy Date: Wed, 9 Jun 2021 00:07:17 +0100 Subject: [PATCH 16/48] Update User.java to better reflect the API --- .../java/me/goudham/api/entity/user/User.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/goudham/api/entity/user/User.java b/src/main/java/me/goudham/api/entity/user/User.java index cea7567..eb2eedb 100644 --- a/src/main/java/me/goudham/api/entity/user/User.java +++ b/src/main/java/me/goudham/api/entity/user/User.java @@ -1,11 +1,6 @@ package me.goudham.api.entity.user; -import javax.annotation.processing.Generated; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyDescription; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.annotation.*; import me.goudham.api.entity.waifu.Waifu; import java.util.Objects; @@ -17,6 +12,7 @@ import java.util.Objects; * *

    Fields included are:

    *
    * From c8ec37a1f52592b77743ca1e872a94ce7c905591 Mon Sep 17 00:00:00 2001 From: Hammy Date: Sat, 12 Jun 2021 04:23:06 +0100 Subject: [PATCH 34/48] Rename package --- src/main/java/me/goudham/MyWaifuClient.java | 41 +++++++++++++++---- src/main/java/me/goudham/Response.java | 18 ++++---- .../entity => domain}/PaginationData.java | 2 +- .../{api/entity => domain}/Studio.java | 2 +- .../series/FilteredSeries.java | 3 +- .../{api/entity => domain}/series/Series.java | 6 +-- .../{api/entity => domain}/user/Creator.java | 4 +- .../{api/entity => domain}/user/TrueLove.java | 4 +- .../{api/entity => domain}/user/User.java | 4 +- .../{api/entity => domain}/user/UserList.java | 4 +- .../waifu/FilteredWaifu.java | 4 +- .../{api/entity => domain}/waifu/Waifu.java | 6 +-- .../entity => domain}/waifu/WaifuImage.java | 2 +- 13 files changed, 63 insertions(+), 37 deletions(-) rename src/main/java/me/goudham/{api/entity => domain}/PaginationData.java (99%) rename src/main/java/me/goudham/{api/entity => domain}/Studio.java (98%) rename src/main/java/me/goudham/{api/entity => domain}/series/FilteredSeries.java (98%) rename src/main/java/me/goudham/{api/entity => domain}/series/Series.java (98%) rename src/main/java/me/goudham/{api/entity => domain}/user/Creator.java (95%) rename src/main/java/me/goudham/{api/entity => domain}/user/TrueLove.java (96%) rename src/main/java/me/goudham/{api/entity => domain}/user/User.java (98%) rename src/main/java/me/goudham/{api/entity => domain}/user/UserList.java (97%) rename src/main/java/me/goudham/{api/entity => domain}/waifu/FilteredWaifu.java (98%) rename src/main/java/me/goudham/{api/entity => domain}/waifu/Waifu.java (99%) rename src/main/java/me/goudham/{api/entity => domain}/waifu/WaifuImage.java (98%) diff --git a/src/main/java/me/goudham/MyWaifuClient.java b/src/main/java/me/goudham/MyWaifuClient.java index e137e94..057c4ee 100644 --- a/src/main/java/me/goudham/MyWaifuClient.java +++ b/src/main/java/me/goudham/MyWaifuClient.java @@ -1,11 +1,12 @@ package me.goudham; +import me.goudham.domain.user.UserList; import me.goudham.util.Season; -import me.goudham.api.entity.series.FilteredSeries; -import me.goudham.api.entity.series.Series; -import me.goudham.api.entity.user.User; -import me.goudham.api.entity.waifu.FilteredWaifu; -import me.goudham.api.entity.waifu.Waifu; +import me.goudham.domain.series.FilteredSeries; +import me.goudham.domain.series.Series; +import me.goudham.domain.user.User; +import me.goudham.domain.waifu.FilteredWaifu; +import me.goudham.domain.waifu.Waifu; import me.goudham.exception.APIMapperException; import me.goudham.exception.APIResponseException; import org.jetbrains.annotations.NotNull; @@ -57,10 +58,28 @@ public class MyWaifuClient { return new MyWaifuClient(apiKey, httpClient); } + /** + * Retrieves information about the {@link Waifu} specified by the given slug + * + * @param slug The slug of the {@link Waifu} + * @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 getWaifu(@NotNull String slug) throws APIResponseException, APIMapperException { return APIWrapper.getWaifu(slug); } + /** + * Retrieves information about the {@link Waifu} specified by the given id + * + * @param id The id of the {@link Waifu} + * @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 getWaifu(@NotNull Integer id) throws APIResponseException, APIMapperException { return APIWrapper.getWaifu(String.valueOf(id)); } @@ -73,8 +92,8 @@ public class MyWaifuClient { return APIWrapper.getRandomWaifu(); } - public Response getSeries(@NotNull String param) throws APIMapperException, APIResponseException { - return APIWrapper.getSeries(param); + public Response getSeries(@NotNull String slug) throws APIMapperException, APIResponseException { + return APIWrapper.getSeries(slug); } public Response getSeries(@NotNull Integer id) throws APIMapperException, APIResponseException { @@ -113,6 +132,14 @@ public class MyWaifuClient { return APIWrapper.getUserProfile(String.valueOf(id)); } + public Response> getUserLists(@NotNull Integer id) throws APIMapperException, APIResponseException { + return APIWrapper.getUserLists(String.valueOf(id)); + } + + public Response getUserList(@NotNull Integer userId, @NotNull Integer listId) throws APIMapperException, APIResponseException { + return APIWrapper.getUserList(String.valueOf(userId), String.valueOf(listId)); + } + /** * Builder for {@link MyWaifuClient} * diff --git a/src/main/java/me/goudham/Response.java b/src/main/java/me/goudham/Response.java index 973b8c6..0d228fa 100644 --- a/src/main/java/me/goudham/Response.java +++ b/src/main/java/me/goudham/Response.java @@ -1,34 +1,34 @@ package me.goudham; -import me.goudham.api.entity.series.Series; -import me.goudham.api.entity.waifu.Waifu; +import me.goudham.domain.series.Series; +import me.goudham.domain.waifu.Waifu; /** * This is returned to the User when called by methods in {@link MyWaifuClient}. * E.g {@link MyWaifuClient#getWaifu(Integer)} *
    - * Given a successful response, {@link #entity} will be populated with the requested entity. + * Given a successful response, {@link #model} will be populated with the requested model. *
    * No matter successful or unsuccessful response, {@link #statusCode} and {@link #body} * will be populated to ensure the user has all the information for debugging or extra information within * the {@link #body} * - * @param The type of entity to be returned. E.g {@link Waifu} or {@link Series} + * @param The type of model to be returned. E.g {@link Waifu} or {@link Series} * */ public class Response { - private final T entity; + private final T model; private final Integer statusCode; private final String body; - Response(Integer statusCode, String body, T entity) { + Response(Integer statusCode, String body, T model) { this.statusCode = statusCode; this.body = body; - this.entity = entity; + this.model = model; } - public T getEntity() { - return entity; + public T getModel() { + return model; } public Integer getStatusCode() { diff --git a/src/main/java/me/goudham/api/entity/PaginationData.java b/src/main/java/me/goudham/domain/PaginationData.java similarity index 99% rename from src/main/java/me/goudham/api/entity/PaginationData.java rename to src/main/java/me/goudham/domain/PaginationData.java index 42acd8e..8ba619e 100644 --- a/src/main/java/me/goudham/api/entity/PaginationData.java +++ b/src/main/java/me/goudham/domain/PaginationData.java @@ -1,4 +1,4 @@ -package me.goudham.api.entity; +package me.goudham.domain; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/me/goudham/api/entity/Studio.java b/src/main/java/me/goudham/domain/Studio.java similarity index 98% rename from src/main/java/me/goudham/api/entity/Studio.java rename to src/main/java/me/goudham/domain/Studio.java index fc797f8..2dab95c 100644 --- a/src/main/java/me/goudham/api/entity/Studio.java +++ b/src/main/java/me/goudham/domain/Studio.java @@ -1,4 +1,4 @@ -package me.goudham.api.entity; +package me.goudham.domain; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/me/goudham/api/entity/series/FilteredSeries.java b/src/main/java/me/goudham/domain/series/FilteredSeries.java similarity index 98% rename from src/main/java/me/goudham/api/entity/series/FilteredSeries.java rename to src/main/java/me/goudham/domain/series/FilteredSeries.java index df25e0a..59feee3 100644 --- a/src/main/java/me/goudham/api/entity/series/FilteredSeries.java +++ b/src/main/java/me/goudham/domain/series/FilteredSeries.java @@ -1,11 +1,10 @@ -package me.goudham.api.entity.series; +package me.goudham.domain.series; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyDescription; import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import javax.annotation.processing.Generated; import java.util.Objects; /** diff --git a/src/main/java/me/goudham/api/entity/series/Series.java b/src/main/java/me/goudham/domain/series/Series.java similarity index 98% rename from src/main/java/me/goudham/api/entity/series/Series.java rename to src/main/java/me/goudham/domain/series/Series.java index e8eee6f..6b8c9b1 100644 --- a/src/main/java/me/goudham/api/entity/series/Series.java +++ b/src/main/java/me/goudham/domain/series/Series.java @@ -1,8 +1,8 @@ -package me.goudham.api.entity.series; +package me.goudham.domain.series; import com.fasterxml.jackson.annotation.*; -import me.goudham.api.entity.Studio; -import me.goudham.api.entity.waifu.Waifu; +import me.goudham.domain.Studio; +import me.goudham.domain.waifu.Waifu; import java.util.Objects; diff --git a/src/main/java/me/goudham/api/entity/user/Creator.java b/src/main/java/me/goudham/domain/user/Creator.java similarity index 95% rename from src/main/java/me/goudham/api/entity/user/Creator.java rename to src/main/java/me/goudham/domain/user/Creator.java index 547388a..477107c 100644 --- a/src/main/java/me/goudham/api/entity/user/Creator.java +++ b/src/main/java/me/goudham/domain/user/Creator.java @@ -1,10 +1,10 @@ -package me.goudham.api.entity.user; +package me.goudham.domain.user; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyDescription; import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import me.goudham.api.entity.waifu.Waifu; +import me.goudham.domain.waifu.Waifu; import java.util.Objects; diff --git a/src/main/java/me/goudham/api/entity/user/TrueLove.java b/src/main/java/me/goudham/domain/user/TrueLove.java similarity index 96% rename from src/main/java/me/goudham/api/entity/user/TrueLove.java rename to src/main/java/me/goudham/domain/user/TrueLove.java index a80f5c3..0c7c1f4 100644 --- a/src/main/java/me/goudham/api/entity/user/TrueLove.java +++ b/src/main/java/me/goudham/domain/user/TrueLove.java @@ -1,11 +1,11 @@ -package me.goudham.api.entity.user; +package me.goudham.domain.user; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyDescription; import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import me.goudham.api.entity.series.Series; +import me.goudham.domain.series.Series; import java.util.Objects; diff --git a/src/main/java/me/goudham/api/entity/user/User.java b/src/main/java/me/goudham/domain/user/User.java similarity index 98% rename from src/main/java/me/goudham/api/entity/user/User.java rename to src/main/java/me/goudham/domain/user/User.java index 3519e11..fcc50ea 100644 --- a/src/main/java/me/goudham/api/entity/user/User.java +++ b/src/main/java/me/goudham/domain/user/User.java @@ -1,7 +1,7 @@ -package me.goudham.api.entity.user; +package me.goudham.domain.user; import com.fasterxml.jackson.annotation.*; -import me.goudham.api.entity.waifu.Waifu; +import me.goudham.domain.waifu.Waifu; import java.util.Objects; diff --git a/src/main/java/me/goudham/api/entity/user/UserList.java b/src/main/java/me/goudham/domain/user/UserList.java similarity index 97% rename from src/main/java/me/goudham/api/entity/user/UserList.java rename to src/main/java/me/goudham/domain/user/UserList.java index 1c1cffb..0764307 100644 --- a/src/main/java/me/goudham/api/entity/user/UserList.java +++ b/src/main/java/me/goudham/domain/user/UserList.java @@ -1,7 +1,7 @@ -package me.goudham.api.entity.user; +package me.goudham.domain.user; import com.fasterxml.jackson.annotation.*; -import me.goudham.api.entity.waifu.Waifu; +import me.goudham.domain.waifu.Waifu; import java.util.List; import java.util.Objects; diff --git a/src/main/java/me/goudham/api/entity/waifu/FilteredWaifu.java b/src/main/java/me/goudham/domain/waifu/FilteredWaifu.java similarity index 98% rename from src/main/java/me/goudham/api/entity/waifu/FilteredWaifu.java rename to src/main/java/me/goudham/domain/waifu/FilteredWaifu.java index 74a0b47..9cce0fb 100644 --- a/src/main/java/me/goudham/api/entity/waifu/FilteredWaifu.java +++ b/src/main/java/me/goudham/domain/waifu/FilteredWaifu.java @@ -1,7 +1,7 @@ -package me.goudham.api.entity.waifu; +package me.goudham.domain.waifu; import com.fasterxml.jackson.annotation.*; -import me.goudham.api.entity.series.FilteredSeries; +import me.goudham.domain.series.FilteredSeries; import java.util.List; import java.util.Objects; diff --git a/src/main/java/me/goudham/api/entity/waifu/Waifu.java b/src/main/java/me/goudham/domain/waifu/Waifu.java similarity index 99% rename from src/main/java/me/goudham/api/entity/waifu/Waifu.java rename to src/main/java/me/goudham/domain/waifu/Waifu.java index 6cb527a..12711a4 100644 --- a/src/main/java/me/goudham/api/entity/waifu/Waifu.java +++ b/src/main/java/me/goudham/domain/waifu/Waifu.java @@ -1,8 +1,8 @@ -package me.goudham.api.entity.waifu; +package me.goudham.domain.waifu; import com.fasterxml.jackson.annotation.*; -import me.goudham.api.entity.series.Series; -import me.goudham.api.entity.user.Creator; +import me.goudham.domain.series.Series; +import me.goudham.domain.user.Creator; import javax.annotation.processing.Generated; import java.util.HashMap; diff --git a/src/main/java/me/goudham/api/entity/waifu/WaifuImage.java b/src/main/java/me/goudham/domain/waifu/WaifuImage.java similarity index 98% rename from src/main/java/me/goudham/api/entity/waifu/WaifuImage.java rename to src/main/java/me/goudham/domain/waifu/WaifuImage.java index 622a675..838a3c1 100644 --- a/src/main/java/me/goudham/api/entity/waifu/WaifuImage.java +++ b/src/main/java/me/goudham/domain/waifu/WaifuImage.java @@ -1,4 +1,4 @@ -package me.goudham.api.entity.waifu; +package me.goudham.domain.waifu; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; From b50e4363d62e451aeb880cf39277e25bca8f9115 Mon Sep 17 00:00:00 2001 From: Hammy Date: Sat, 12 Jun 2021 04:23:45 +0100 Subject: [PATCH 35/48] Change mentions of 'entity' to 'model' --- src/main/java/me/goudham/APIMapper.java | 32 +++++++++---------- .../goudham/exception/APIMapperException.java | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/goudham/APIMapper.java b/src/main/java/me/goudham/APIMapper.java index 4e98ded..aa9b12b 100644 --- a/src/main/java/me/goudham/APIMapper.java +++ b/src/main/java/me/goudham/APIMapper.java @@ -4,10 +4,10 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import me.goudham.api.entity.series.Series; +import me.goudham.domain.series.Series; import me.goudham.exception.APIMapperException; -import me.goudham.api.entity.series.FilteredSeries; -import me.goudham.api.entity.waifu.Waifu; +import me.goudham.domain.series.FilteredSeries; +import me.goudham.domain.waifu.Waifu; import java.util.List; @@ -23,58 +23,58 @@ class APIMapper { } /** - * Using the given {@code entity}, {@link ObjectMapper} deserializes the given Json + * Using the given {@code model}, {@link ObjectMapper} deserializes the given Json * into a Java POJO * * @param result The result of the previous API response - * @param entity The actual class of the given entity. E.g {@link Waifu#getClass()} - * @param The type of entity to be returned. E.g {@link Waifu} or {@link Series} + * @param model The actual class of the given model. E.g {@link Waifu#getClass()} + * @param The type of model to be returned. E.g {@link Waifu} or {@link Series} * @return {@link Response} * @throws APIMapperException If {@link ObjectMapper} is not able to deserialize JSON to Java POJO properly * */ - Response deserialize(Result result, Class entity) throws APIMapperException { + Response deserialize(Result result, Class model) throws APIMapperException { Integer statusCode = result.getStatusCode(); String body = result.getBody(); - T newEntity = null; + T newModel = null; if (statusCode == 200) { try { String data = getJsonTree(body); - newEntity = objectMapper.readValue(data, entity); + newModel = objectMapper.readValue(data, model); } catch (JsonProcessingException jpe) { throwAPIMapperException(jpe); } } - return new Response<>(statusCode, body, newEntity); + return new Response<>(statusCode, body, newModel); } /** - * Using the given {@code entity}, {@link ObjectMapper} deserializes the given Json + * Using the given {@code model}, {@link ObjectMapper} deserializes the given Json * into a Java POJO. This method enables support for retrieving {@link List} of entities * * @param List of entities to be returned. E.g {@link List} of {@link FilteredSeries} * @param result The result of the previous API response - * @param entity The actual class of the given entity. E.g {@link Waifu#getClass()} + * @param model The actual class of the given model. E.g {@link Waifu#getClass()} * @return {@link Response} * @throws APIMapperException If {@link ObjectMapper} is not able to deserialize JSON to Java POJO properly */ - Response> deserialize(Result result, JavaType entity) throws APIMapperException { + Response> deserialize(Result result, JavaType model) throws APIMapperException { Integer statusCode = result.getStatusCode(); String body = result.getBody(); - List listOfEntity = null; + List listOfModels = null; if (statusCode == 200) { try { String data = getJsonTree(body); - listOfEntity = objectMapper.readValue(data, entity); + listOfModels = objectMapper.readValue(data, model); } catch (JsonProcessingException jpe) { throwAPIMapperException(jpe); } } - return new Response<>(statusCode, body, listOfEntity); + return new Response<>(statusCode, body, listOfModels); } /** diff --git a/src/main/java/me/goudham/exception/APIMapperException.java b/src/main/java/me/goudham/exception/APIMapperException.java index 4c7d9f3..9e5dd04 100644 --- a/src/main/java/me/goudham/exception/APIMapperException.java +++ b/src/main/java/me/goudham/exception/APIMapperException.java @@ -4,7 +4,7 @@ import me.goudham.APIWrapper; import me.goudham.Response; /** - * Thrown when {@link APIWrapper} fails to deserialize json into Java POJO's ({@link Response#getEntity()}) + * Thrown when {@link APIWrapper} fails to deserialize json into Java POJO's ({@link Response#getModel()}) * */ public class APIMapperException extends Throwable { From 69d0187f770081e67d78a5577133da60afe98e6c Mon Sep 17 00:00:00 2001 From: Hammy Date: Sat, 12 Jun 2021 04:24:23 +0100 Subject: [PATCH 36/48] Refactor parameters to be more descriptive --- src/main/java/me/goudham/APIWrapper.java | 45 +++++++++++++++--------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/goudham/APIWrapper.java b/src/main/java/me/goudham/APIWrapper.java index e8a9d5b..c9ffd93 100644 --- a/src/main/java/me/goudham/APIWrapper.java +++ b/src/main/java/me/goudham/APIWrapper.java @@ -2,12 +2,13 @@ package me.goudham; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.type.TypeFactory; +import me.goudham.domain.user.UserList; import me.goudham.util.Season; -import me.goudham.api.entity.series.FilteredSeries; -import me.goudham.api.entity.series.Series; -import me.goudham.api.entity.user.User; -import me.goudham.api.entity.waifu.FilteredWaifu; -import me.goudham.api.entity.waifu.Waifu; +import me.goudham.domain.series.FilteredSeries; +import me.goudham.domain.series.Series; +import me.goudham.domain.user.User; +import me.goudham.domain.waifu.FilteredWaifu; +import me.goudham.domain.waifu.Waifu; import me.goudham.exception.APIMapperException; import me.goudham.exception.APIResponseException; @@ -51,13 +52,13 @@ public class APIWrapper { /** * Honestly I don't really know how this works * - * @param entity The actual class of the given entity. E.g {@link Waifu#getClass()} - * @param The type of entity to be returned. E.g {@link Waifu} or {@link Series} + * @param model The actual class of the given model. E.g {@link Waifu#getClass()} + * @param The type of model to be returned. E.g {@link Waifu} or {@link Series} * @return {@link JavaType} * */ - private JavaType listOf(Class entity) { - return TypeFactory.defaultInstance().constructCollectionType(List.class, entity); + private JavaType listOf(Class model) { + return TypeFactory.defaultInstance().constructCollectionType(List.class, model); } /** @@ -94,8 +95,8 @@ public class APIWrapper { return new Result(responseCode, responseBody); } - Response getWaifu(String param) throws APIResponseException, APIMapperException { - Result waifuResult = sendRequest(httpClient, "waifu/" + param); + Response getWaifu(String waifuId) throws APIResponseException, APIMapperException { + Result waifuResult = sendRequest(httpClient, "waifu/" + waifuId); return apiMapper.deserialize(waifuResult, Waifu.class); } @@ -109,8 +110,8 @@ public class APIWrapper { return apiMapper.deserialize(randomWaifuResult, FilteredWaifu.class); } - Response getSeries(String param) throws APIResponseException, APIMapperException { - Result seriesResult = sendRequest(httpClient, "series/" + param); + Response getSeries(String seriesId) throws APIResponseException, APIMapperException { + Result seriesResult = sendRequest(httpClient, "series/" + seriesId); return apiMapper.deserialize(seriesResult, Series.class); } @@ -139,13 +140,23 @@ public class APIWrapper { return apiMapper.deserialize(allSeriesResult, listOf(FilteredSeries.class)); } - Response> getSeriesWaifus(String param) throws APIResponseException, APIMapperException { - Result allWaifusFromSeriesResults = sendRequest(httpClient, "series/" + param + "/waifus"); + Response> getSeriesWaifus(String seriesId) throws APIResponseException, APIMapperException { + Result allWaifusFromSeriesResults = sendRequest(httpClient, "series/" + seriesId + "/waifus"); return apiMapper.deserialize(allWaifusFromSeriesResults, listOf(FilteredWaifu.class)); } - Response getUserProfile(String param) throws APIResponseException, APIMapperException { - Result userProfileResult = sendRequest(httpClient, "user/" + param); + Response getUserProfile(String userId) throws APIResponseException, APIMapperException { + Result userProfileResult = sendRequest(httpClient, "user/" + userId); return apiMapper.deserialize(userProfileResult, User.class); } + + Response> getUserLists(String userId) throws APIResponseException, APIMapperException { + Result userProfileResult = sendRequest(httpClient, "user/" + userId + "/lists"); + return apiMapper.deserialize(userProfileResult, listOf(UserList.class)); + } + + Response getUserList(String userId, String listId) throws APIResponseException, APIMapperException { + Result userProfileResult = sendRequest(httpClient, "user/" + userId + "/lists/" + listId); + return apiMapper.deserialize(userProfileResult, UserList.class); + } } From ed85f99294e6880401b8f4559ccfa8edc209a91f Mon Sep 17 00:00:00 2001 From: Hammy Date: Sat, 12 Jun 2021 06:14:35 +0100 Subject: [PATCH 37/48] Rename existing PaginationData.java to 'Meta' --- .../Meta.java} | 67 ++++++++++++++++--- 1 file changed, 59 insertions(+), 8 deletions(-) rename src/main/java/me/goudham/domain/{PaginationData.java => pagination/Meta.java} (60%) diff --git a/src/main/java/me/goudham/domain/PaginationData.java b/src/main/java/me/goudham/domain/pagination/Meta.java similarity index 60% rename from src/main/java/me/goudham/domain/PaginationData.java rename to src/main/java/me/goudham/domain/pagination/Meta.java index 8ba619e..41479b2 100644 --- a/src/main/java/me/goudham/domain/PaginationData.java +++ b/src/main/java/me/goudham/domain/pagination/Meta.java @@ -1,4 +1,4 @@ -package me.goudham.domain; +package me.goudham.domain.pagination; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -9,14 +9,17 @@ import java.util.Objects; /** - * {@link PaginationData} + * {@link Meta} *

    Contains standard Pagination data from the API

    * *

    Fields included are:

    *
      *
    • {@link Integer currentPage}
    • + *
    • {@link Integer from}
    • *
    • {@link Integer lastPage}
    • + *
    • {@link String path}
    • *
    • {@link Integer perPage}
    • + *
    • {@link Integer to}
    • *
    • {@link Integer total}
    • *
    * @@ -24,11 +27,14 @@ import java.util.Objects; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({ "current_page", + "from", "last_page", + "path", "per_page", + "to", "total" }) -public class PaginationData { +public class Meta { /** * Current requested page * @@ -37,6 +43,14 @@ public class PaginationData { @JsonPropertyDescription("Current requested page") private Integer currentPage; + /** + * Starting gallery image number + * + */ + @JsonProperty("from") + @JsonPropertyDescription("Starting gallery image number") + private Integer from; + /** * Last available page * @@ -45,6 +59,14 @@ public class PaginationData { @JsonPropertyDescription("Last available page") private Integer lastPage; + /** + * API url for gallery + * + */ + @JsonProperty("path") + @JsonPropertyDescription("API url for gallery") + private String path; + /** * Total number of items per page * @@ -54,7 +76,15 @@ public class PaginationData { private Integer perPage; /** - * Total number of items + * Last gallery image number + * + */ + @JsonProperty("to") + @JsonPropertyDescription("Last gallery image number") + private Integer to; + + /** + * Total number of items within the gallery * */ @JsonProperty("total") @@ -71,6 +101,12 @@ public class PaginationData { this.currentPage = currentPage; } + @JsonProperty("from") + public Integer getFrom() { return from; } + + @JsonProperty("from") + public void setFrom(Integer from) { this.from = from; } + @JsonProperty("last_page") public Integer getLastPage() { return lastPage; @@ -81,6 +117,12 @@ public class PaginationData { this.lastPage = lastPage; } + @JsonProperty("path") + public String getPath() { return path; } + + @JsonProperty("path") + public void setPath(String path) { this.path = path; } + @JsonProperty("per_page") public Integer getPerPage() { return perPage; @@ -91,6 +133,12 @@ public class PaginationData { this.perPage = perPage; } + @JsonProperty("to") + public Integer getTo() { return to; } + + @JsonProperty("to") + public void setTo(Integer to) { this.to = to; } + @JsonProperty("total") public Integer getTotal() { return total; @@ -105,21 +153,24 @@ public class PaginationData { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - PaginationData that = (PaginationData) o; - return Objects.equals(currentPage, that.currentPage) && Objects.equals(lastPage, that.lastPage) && Objects.equals(perPage, that.perPage) && Objects.equals(total, that.total); + Meta meta = (Meta) o; + return Objects.equals(currentPage, meta.currentPage) && Objects.equals(from, meta.from) && Objects.equals(lastPage, meta.lastPage) && Objects.equals(path, meta.path) && Objects.equals(perPage, meta.perPage) && Objects.equals(to, meta.to) && Objects.equals(total, meta.total); } @Override public int hashCode() { - return Objects.hash(currentPage, lastPage, perPage, total); + return Objects.hash(currentPage, from, lastPage, path, perPage, to, total); } @Override public String toString() { - return "PaginationData{" + + return "Meta{" + "currentPage=" + currentPage + + ", from=" + from + ", lastPage=" + lastPage + + ", path=" + path + ", perPage=" + perPage + + ", to=" + to + ", total=" + total + '}'; } From 13a3e75c4a121f5364acfe5d1ec76af73ad0117e Mon Sep 17 00:00:00 2001 From: Hammy Date: Sat, 12 Jun 2021 06:14:52 +0100 Subject: [PATCH 38/48] Fix @JsonProperty value for 'image' --- src/main/java/me/goudham/domain/waifu/WaifuImage.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/goudham/domain/waifu/WaifuImage.java b/src/main/java/me/goudham/domain/waifu/WaifuImage.java index 838a3c1..c0eca02 100644 --- a/src/main/java/me/goudham/domain/waifu/WaifuImage.java +++ b/src/main/java/me/goudham/domain/waifu/WaifuImage.java @@ -49,7 +49,7 @@ public class WaifuImage { * Final URL of the original resolution image * */ - @JsonProperty("path") + @JsonProperty("image") @JsonPropertyDescription("Final URL of the original resolution image") private String image; @@ -81,12 +81,12 @@ public class WaifuImage { this.thumbnail = thumbnail; } - @JsonProperty("path") + @JsonProperty("image") public String getImage() { return image; } - @JsonProperty("path") + @JsonProperty("image") public void setImage(String image) { this.image = image; } From 773e726accacf6864571262d78c8697fd41c52e9 Mon Sep 17 00:00:00 2001 From: Hammy Date: Sat, 12 Jun 2021 06:15:24 +0100 Subject: [PATCH 39/48] Add support for PaginationData.java in models --- .../me/goudham/domain/pagination/Links.java | 125 ++++++++++++++++++ .../domain/pagination/PaginationData.java | 84 ++++++++++++ 2 files changed, 209 insertions(+) create mode 100644 src/main/java/me/goudham/domain/pagination/Links.java create mode 100644 src/main/java/me/goudham/domain/pagination/PaginationData.java diff --git a/src/main/java/me/goudham/domain/pagination/Links.java b/src/main/java/me/goudham/domain/pagination/Links.java new file mode 100644 index 0000000..5494764 --- /dev/null +++ b/src/main/java/me/goudham/domain/pagination/Links.java @@ -0,0 +1,125 @@ +package me.goudham.domain.pagination; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import java.util.Objects; + +/** + * {@link Links} + *

    Contains gallery API links for {@link Meta}

    + * + *

    Fields included are:

    + *
      + *
    • {@link String first}
    • + *
    • {@link String last}
    • + *
    • {@link String next}
    • + *
    • {@link String prev}
    • + *
    + * + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "first", + "last", + "next", + "prev" +}) +public class Links { + /** + * First page of the gallery + * + */ + @JsonProperty("first") + @JsonPropertyDescription("First page of the gallery") + private String first; + + /** + * Last page of the gallery + * + */ + @JsonProperty("last") + @JsonPropertyDescription("Last page of the gallery") + private String last; + + /** + * Next page of the gallery + * + */ + @JsonProperty("next") + @JsonPropertyDescription("Next page of the gallery") + private String next; + + /** + * Previous page of the gallery + * + */ + @JsonProperty("prev") + @JsonPropertyDescription("Previous page of the gallery") + private String prev; + + @JsonProperty("first") + public String getFirst() { + return first; + } + + @JsonProperty("first") + public void setFirst(String first) { + this.first = first; + } + + @JsonProperty("last") + public String getLast() { + return last; + } + + @JsonProperty("last") + public void setLast(String last) { + this.last = last; + } + + @JsonProperty("next") + public String getNext() { + return next; + } + + @JsonProperty("next") + public void setNext(String next) { + this.next = next; + } + + @JsonProperty("prev") + public String getPrev() { + return prev; + } + + @JsonProperty("prev") + public void setPrev(String prev) { + this.prev = prev; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Links links = (Links) o; + return Objects.equals(first, links.first) && Objects.equals(last, links.last) && Objects.equals(next, links.next) && Objects.equals(prev, links.prev); + } + + @Override + public int hashCode() { + return Objects.hash(first, last, next, prev); + } + + @Override + public String toString() { + return "Links{" + + "first='" + first + '\'' + + ", last='" + last + '\'' + + ", next='" + next + '\'' + + ", prev='" + prev + '\'' + + '}'; + } +} diff --git a/src/main/java/me/goudham/domain/pagination/PaginationData.java b/src/main/java/me/goudham/domain/pagination/PaginationData.java new file mode 100644 index 0000000..2437e4e --- /dev/null +++ b/src/main/java/me/goudham/domain/pagination/PaginationData.java @@ -0,0 +1,84 @@ +package me.goudham.domain.pagination; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import java.util.List; + +/** + * {@link PaginationData} + *

    Contains standard Pagination data from the API including images

    + * + *

    Fields included are:

    + *
      + *
    • {@link Object data}
    • + *
    • {@link Links links}
    • + *
    • {@link Meta meta}
    • + *
    + * + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "data", + "links", + "meta" +}) +public class PaginationData { + + /** + * Data returned from the gallery + * + */ + @JsonProperty("data") + @JsonPropertyDescription("Data returned from the gallery") + private List data; + + /** + * {@link Links} to other data within the gallery + * + */ + @JsonProperty("links") + @JsonPropertyDescription("Links to other data within the gallery") + private Links links; + + /** + * Extra pagination information + * + */ + @JsonProperty("meta") + @JsonPropertyDescription("Extra pagination information") + private Meta meta; + + @JsonProperty("data") + public List getData() { + return data; + } + + @JsonProperty("data") + public void setData(List data) { + this.data = data; + } + + @JsonProperty("links") + public Links getLinks() { + return links; + } + + @JsonProperty("links") + public void setLinks(Links links) { + this.links = links; + } + + @JsonProperty("meta") + public Meta getMeta() { + return meta; + } + + @JsonProperty("meta") + public void setMeta(Meta meta) { + this.meta = meta; + } + +} \ No newline at end of file From 761b651fd7bcef139c29c1da6e20c9e8e3ceac19 Mon Sep 17 00:00:00 2001 From: Hammy Date: Sat, 12 Jun 2021 06:48:51 +0100 Subject: [PATCH 40/48] Add extra method to deserialize JSON to PaginationData --- src/main/java/me/goudham/APIMapper.java | 46 +++++++++++++++++++------ 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/goudham/APIMapper.java b/src/main/java/me/goudham/APIMapper.java index aa9b12b..e7d460d 100644 --- a/src/main/java/me/goudham/APIMapper.java +++ b/src/main/java/me/goudham/APIMapper.java @@ -4,10 +4,10 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import me.goudham.domain.pagination.PaginationData; import me.goudham.domain.series.Series; -import me.goudham.exception.APIMapperException; -import me.goudham.domain.series.FilteredSeries; import me.goudham.domain.waifu.Waifu; +import me.goudham.exception.APIMapperException; import java.util.List; @@ -40,7 +40,7 @@ class APIMapper { if (statusCode == 200) { try { - String data = getJsonTree(body); + String data = getData(body); newModel = objectMapper.readValue(data, model); } catch (JsonProcessingException jpe) { throwAPIMapperException(jpe); @@ -52,22 +52,22 @@ class APIMapper { /** * Using the given {@code model}, {@link ObjectMapper} deserializes the given Json - * into a Java POJO. This method enables support for retrieving {@link List} of entities + * into a Java POJO. This method enables support for retrieving {@link List} of models * - * @param List of entities to be returned. E.g {@link List} of {@link FilteredSeries} * @param result The result of the previous API response * @param model The actual class of the given model. E.g {@link Waifu#getClass()} + * @param The type of model to be returned. E.g {@link Waifu} or {@link Series} * @return {@link Response} * @throws APIMapperException If {@link ObjectMapper} is not able to deserialize JSON to Java POJO properly */ - Response> deserialize(Result result, JavaType model) throws APIMapperException { + Response> deserializeToList(Result result, JavaType model) throws APIMapperException { Integer statusCode = result.getStatusCode(); String body = result.getBody(); List listOfModels = null; if (statusCode == 200) { try { - String data = getJsonTree(body); + String data = getData(body); listOfModels = objectMapper.readValue(data, model); } catch (JsonProcessingException jpe) { throwAPIMapperException(jpe); @@ -77,18 +77,42 @@ class APIMapper { return new Response<>(statusCode, body, listOfModels); } + /** + * Using the given {@code model}, {@link ObjectMapper} deserializes the given Json + * into a Java POJO. This method enables support for retrieving {@link PaginationData} of specific models + * + * @param result The result of the previous API response + * @param model The actual class of the given model. E.g {@link Waifu#getClass()} + * @param The type of model to be returned. E.g {@link Waifu} or {@link Series} + * @return {@link Response} + * @throws APIMapperException If {@link ObjectMapper} is not able to deserialize JSON to Java POJO properly + */ + Response> deserializeToPaginationData(Result result, JavaType model) throws APIMapperException { + Integer statusCode = result.getStatusCode(); + String body = result.getBody(); + PaginationData newModel = null; + + if (statusCode == 200) { + try { + newModel = objectMapper.readValue(body, model); + } catch (JsonProcessingException jpe) { + throwAPIMapperException(jpe); + } + } + + return new Response<>(statusCode, body, newModel); + } + /** * Helper method for reducing duplicate code in {@code deserialize()} * and {@code deserializeToList()} - *
    - * Returns the proper json data to deserialize * * @param jsonBody jsonBody returned by the API - * @return {@link String} + * @return {@link String} — The proper json data to deserialize * @throws JsonProcessingException If {@link ObjectMapper} is not able to * read the given {@code jsonBody} */ - private String getJsonTree(String jsonBody) throws JsonProcessingException { + private String getData(String jsonBody) throws JsonProcessingException { JsonNode parent = objectMapper.readTree(jsonBody); return parent.get("data").toString(); } From 115710353fb5921efede6c5b194fd02cada55ca3 Mon Sep 17 00:00:00 2001 From: Hammy Date: Sat, 12 Jun 2021 06:49:26 +0100 Subject: [PATCH 41/48] Add support for retrieving Waifu Images in sets of 10 --- src/main/java/me/goudham/APIWrapper.java | 58 ++++++++++++--------- src/main/java/me/goudham/MyWaifuClient.java | 6 +++ 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/main/java/me/goudham/APIWrapper.java b/src/main/java/me/goudham/APIWrapper.java index c9ffd93..88c1173 100644 --- a/src/main/java/me/goudham/APIWrapper.java +++ b/src/main/java/me/goudham/APIWrapper.java @@ -2,15 +2,17 @@ package me.goudham; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.type.TypeFactory; -import me.goudham.domain.user.UserList; -import me.goudham.util.Season; +import me.goudham.domain.pagination.PaginationData; import me.goudham.domain.series.FilteredSeries; import me.goudham.domain.series.Series; import me.goudham.domain.user.User; +import me.goudham.domain.user.UserList; import me.goudham.domain.waifu.FilteredWaifu; import me.goudham.domain.waifu.Waifu; +import me.goudham.domain.waifu.WaifuImage; import me.goudham.exception.APIMapperException; import me.goudham.exception.APIResponseException; +import me.goudham.util.Season; import java.net.URI; import java.net.http.HttpClient; @@ -61,18 +63,21 @@ public class APIWrapper { return TypeFactory.defaultInstance().constructCollectionType(List.class, model); } + private JavaType paginationData(Class model) { + return TypeFactory.defaultInstance().constructParametricType(PaginationData.class, model); + } + /** * Handles sending a request to the API asynchronously using {@link HttpRequest} * and the underlying {@link HttpClient} * - * @param httpClient The {@link HttpClient} to use for sending {@link HttpRequest}'s * @param param The end of the endpoint appended onto the host * @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(HttpClient httpClient, String param) throws APIResponseException { + private Result sendRequest(String param) throws APIResponseException { HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(host + param)) .version(httpClient.version()) @@ -96,67 +101,72 @@ public class APIWrapper { } Response getWaifu(String waifuId) throws APIResponseException, APIMapperException { - Result waifuResult = sendRequest(httpClient, "waifu/" + waifuId); + Result waifuResult = sendRequest("waifu/" + waifuId); return apiMapper.deserialize(waifuResult, Waifu.class); } + Response> getWaifuImages(String waifuId, String pageNum) throws APIResponseException, APIMapperException { + Result waifuImagesResult = sendRequest("waifu/" + waifuId + "/images?page=" + pageNum); + return apiMapper.deserializeToPaginationData(waifuImagesResult, paginationData(WaifuImage.class)); + } + Response getDailyWaifu() throws APIResponseException, APIMapperException { - Result dailyWaifuResult = sendRequest(httpClient, "meta/daily"); + Result dailyWaifuResult = sendRequest("meta/daily"); return apiMapper.deserialize(dailyWaifuResult, FilteredWaifu.class); } Response getRandomWaifu() throws APIResponseException, APIMapperException { - Result randomWaifuResult = sendRequest(httpClient, "meta/random"); + Result randomWaifuResult = sendRequest("meta/random"); return apiMapper.deserialize(randomWaifuResult, FilteredWaifu.class); } Response getSeries(String seriesId) throws APIResponseException, APIMapperException { - Result seriesResult = sendRequest(httpClient, "series/" + seriesId); + Result seriesResult = sendRequest("series/" + seriesId); return apiMapper.deserialize(seriesResult, Series.class); } Response> getSeasonalAnime() throws APIResponseException, APIMapperException { - Result seasonalAnimeResult = sendRequest(httpClient, "airing"); - return apiMapper.deserialize(seasonalAnimeResult, listOf(FilteredSeries.class)); + Result seasonalAnimeResult = sendRequest("airing"); + return apiMapper.deserializeToList(seasonalAnimeResult, listOf(FilteredSeries.class)); } Response> getBestWaifus() throws APIResponseException, APIMapperException { - Result waifuResults = sendRequest(httpClient, "airing/best"); - return apiMapper.deserialize(waifuResults, listOf(FilteredWaifu.class)); + Result waifuResults = sendRequest("airing/best"); + return apiMapper.deserializeToList(waifuResults, listOf(FilteredWaifu.class)); } Response> getPopularWaifus() throws APIResponseException, APIMapperException { - Result waifuResults = sendRequest(httpClient, "airing/popular"); - return apiMapper.deserialize(waifuResults, listOf(FilteredWaifu.class)); + Result waifuResults = sendRequest("airing/popular"); + return apiMapper.deserializeToList(waifuResults, listOf(FilteredWaifu.class)); } Response> getTrashWaifus() throws APIResponseException, APIMapperException { - Result waifuResults = sendRequest(httpClient, "airing/trash"); - return apiMapper.deserialize(waifuResults, listOf(FilteredWaifu.class)); + Result waifuResults = sendRequest("airing/trash"); + return apiMapper.deserializeToList(waifuResults, listOf(FilteredWaifu.class)); } Response> getAllSeries(Season season, Integer year) throws APIResponseException, APIMapperException { - Result allSeriesResult = sendRequest(httpClient, "airing/" + season.getSeason() + "/" + year); - return apiMapper.deserialize(allSeriesResult, listOf(FilteredSeries.class)); + Result allSeriesResult = sendRequest("airing/" + season.getSeason() + "/" + year); + return apiMapper.deserializeToList(allSeriesResult, listOf(FilteredSeries.class)); } Response> getSeriesWaifus(String seriesId) throws APIResponseException, APIMapperException { - Result allWaifusFromSeriesResults = sendRequest(httpClient, "series/" + seriesId + "/waifus"); - return apiMapper.deserialize(allWaifusFromSeriesResults, listOf(FilteredWaifu.class)); + Result allWaifusFromSeriesResults = sendRequest("series/" + seriesId + "/waifus"); + return apiMapper.deserializeToList(allWaifusFromSeriesResults, listOf(FilteredWaifu.class)); } Response getUserProfile(String userId) throws APIResponseException, APIMapperException { - Result userProfileResult = sendRequest(httpClient, "user/" + userId); + Result userProfileResult = sendRequest("user/" + userId); return apiMapper.deserialize(userProfileResult, User.class); } Response> getUserLists(String userId) throws APIResponseException, APIMapperException { - Result userProfileResult = sendRequest(httpClient, "user/" + userId + "/lists"); - return apiMapper.deserialize(userProfileResult, listOf(UserList.class)); + Result userProfileResult = sendRequest("user/" + userId + "/lists"); + return apiMapper.deserializeToList(userProfileResult, listOf(UserList.class)); } Response getUserList(String userId, String listId) throws APIResponseException, APIMapperException { - Result userProfileResult = sendRequest(httpClient, "user/" + userId + "/lists/" + listId); + Result userProfileResult = sendRequest("user/" + userId + "/lists/" + listId); return apiMapper.deserialize(userProfileResult, UserList.class); } } diff --git a/src/main/java/me/goudham/MyWaifuClient.java b/src/main/java/me/goudham/MyWaifuClient.java index 057c4ee..7ca4f98 100644 --- a/src/main/java/me/goudham/MyWaifuClient.java +++ b/src/main/java/me/goudham/MyWaifuClient.java @@ -1,6 +1,8 @@ package me.goudham; +import me.goudham.domain.pagination.PaginationData; import me.goudham.domain.user.UserList; +import me.goudham.domain.waifu.WaifuImage; import me.goudham.util.Season; import me.goudham.domain.series.FilteredSeries; import me.goudham.domain.series.Series; @@ -84,6 +86,10 @@ public class MyWaifuClient { return APIWrapper.getWaifu(String.valueOf(id)); } + public Response> getWaifuImages(@NotNull Integer id, @NotNull Integer pageNum) throws APIResponseException, APIMapperException { + return APIWrapper.getWaifuImages(String.valueOf(id), String.valueOf(pageNum)); + } + public Response getDailyWaifu() throws APIResponseException, APIMapperException { return APIWrapper.getDailyWaifu(); } From d3db82e3224eaf52e51640355f079af6053655cf Mon Sep 17 00:00:00 2001 From: Hammy Date: Sat, 12 Jun 2021 06:51:26 +0100 Subject: [PATCH 42/48] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 53f48e2..2cd4ef9 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,12 @@

    MyWaifuWrapper

    An Asynchronous Java API Wrapper for MyWaifuList

    +# Disclaimer + +This API is currently in an Alpha state, the data returned may not be at its best quality and not all the fields +will be populated. +As MyWaifuList is a primarily user-driven website, the data returned may not be fully complete + # Summary This is an Asynchronous API Wrapper for [MyWaifuList](https://mywaifulist.moe/dash) From 0bbf8860ffd8936fc622367a90f2f1e034976949 Mon Sep 17 00:00:00 2001 From: Hammy Date: Sun, 13 Jun 2021 00:49:00 +0100 Subject: [PATCH 43/48] Add APIUtils.java for utility methods to be used by APIWrapper.java --- src/main/java/me/goudham/APIUtils.java | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/java/me/goudham/APIUtils.java diff --git a/src/main/java/me/goudham/APIUtils.java b/src/main/java/me/goudham/APIUtils.java new file mode 100644 index 0000000..f0b7566 --- /dev/null +++ b/src/main/java/me/goudham/APIUtils.java @@ -0,0 +1,35 @@ +package me.goudham; + +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.type.TypeFactory; +import me.goudham.domain.pagination.PaginationData; +import me.goudham.domain.series.Series; +import me.goudham.domain.waifu.Waifu; + +import java.util.List; + +/** + * Includes helper methods to use within {@link APIWrapper} + * + */ +class APIUtils { + + /** + * @param model The actual class of the given model. E.g {@link Waifu#getClass()} + * @param The type of model to be returned. E.g {@link Waifu} or {@link Series} + * @return {@link JavaType} of {@link List} + * + */ + static JavaType listOf(Class model) { + return TypeFactory.defaultInstance().constructCollectionType(List.class, model); + } + + /** + * @param model The actual class of the given model. E.g {@link Waifu#getClass()} + * @param The type of model to be returned. E.g {@link Waifu} or {@link Series} + * @return {@link JavaType} of {@link PaginationData} + */ + static JavaType paginationData(Class model) { + return TypeFactory.defaultInstance().constructParametricType(PaginationData.class, model); + } +} From 4b4d987996d86b6e53a69f59a10abcba235d6ded Mon Sep 17 00:00:00 2001 From: Hammy Date: Sun, 13 Jun 2021 00:49:12 +0100 Subject: [PATCH 44/48] Update README.md --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2cd4ef9..2730d07 100644 --- a/README.md +++ b/README.md @@ -15,15 +15,14 @@

    MyWaifuWrapper

    An Asynchronous Java API Wrapper for MyWaifuList

    -# Disclaimer +# Summary -This API is currently in an Alpha state, the data returned may not be at its best quality and not all the fields -will be populated. -As MyWaifuList is a primarily user-driven website, the data returned may not be fully complete +This is an Asynchronous API Wrapper for [MyWaifuList](https://mywaifulist.moe/dash) -# Summary +# Disclaimer -This is an Asynchronous API Wrapper for [MyWaifuList](https://mywaifulist.moe/dash) +Given that MyWaifuList is a primarily user-driven website and this API is currently in an Alpha state, +the data returned may not be fully complete and at its best quality # Download From 2b9d47cc8dca378c1524b86defb06d3c075a196f Mon Sep 17 00:00:00 2001 From: Hammy Date: Sun, 13 Jun 2021 00:59:08 +0100 Subject: [PATCH 45/48] Update Jenkinsfile Add support for deploying to OSSRH --- Jenkinsfile | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8d92a5f..6974d2f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -48,42 +48,13 @@ pipeline { } } } - stage("Deploy To Nexus") { + stage("Deploy") { when { branch 'release' } steps { - script { - pom = readMavenPom file: "pom.xml"; - filesByGlob = findFiles(glob: "target/*.${pom.packaging}"); - - javadocsArtifact = filesByGlob[0].path; - jarWithSourcesArtifact = filesByGlob[1].path; - jarArtifact = filesByGlob[2].path; - - if (fileExists(javadocsArtifact) && fileExists(jarWithSourcesArtifact) && fileExists(jarArtifact)) { - echo "*** File: ${javadocsArtifact}, group: ${pom.groupId}, packaging: ${pom.packaging}, version ${pom.version}"; - echo "*** File: ${jarWithSourcesArtifact}, group: ${pom.groupId}, packaging: ${pom.packaging}, version ${pom.version}"; - echo "*** File: ${jarArtifact}, group: ${pom.groupId}, packaging: ${pom.packaging}, version ${pom.version}"; - - nexusArtifactUploader( - nexusVersion: NEXUS_VERSION, - protocol: NEXUS_PROTOCOL, - nexusUrl: NEXUS_URL, - groupId: pom.groupId, - version: pom.version, - repository: NEXUS_REPOSITORY, - credentialsId: NEXUS_CREDENTIAL_ID, - artifacts: [ - [artifactId: pom.artifactId, classifier: '', file: jarArtifact, type: pom.packaging], - [artifactId: pom.artifactId, classifier: 'javadocs', file: javadocsArtifact, type: pom.packaging], - [artifactId: pom.artifactId, classifier: 'sources', file: jarWithSourcesArtifact, type: pom.packaging], - [artifactId: pom.artifactId, classifier: '', file: "pom.xml", type: "pom"] - ] - ) - } else { - error "*** Files could not be found"; - } + withCredentials([file(credentialsId: '076a36e8-d448-46fc-af11-7e7181a6cb99', variable: 'MAVEN_SETTINGS')]) { + sh 'mvn -s $MAVEN_SETTINGS -B -DskipTests clean deploy' } } post { From eb43a8baf9e0abdd450b09c15874be30d6b1679a Mon Sep 17 00:00:00 2001 From: Hammy Date: Sun, 13 Jun 2021 01:23:29 +0100 Subject: [PATCH 46/48] Add support for retrieving series by page --- src/main/java/me/goudham/APIWrapper.java | 76 ++++++++++----------- src/main/java/me/goudham/MyWaifuClient.java | 26 ++++--- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/main/java/me/goudham/APIWrapper.java b/src/main/java/me/goudham/APIWrapper.java index 88c1173..95aff97 100644 --- a/src/main/java/me/goudham/APIWrapper.java +++ b/src/main/java/me/goudham/APIWrapper.java @@ -1,7 +1,5 @@ package me.goudham; -import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.type.TypeFactory; import me.goudham.domain.pagination.PaginationData; import me.goudham.domain.series.FilteredSeries; import me.goudham.domain.series.Series; @@ -14,6 +12,7 @@ import me.goudham.exception.APIMapperException; import me.goudham.exception.APIResponseException; import me.goudham.util.Season; +import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; @@ -22,6 +21,11 @@ import java.time.Duration; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; + +import static me.goudham.APIUtils.listOf; +import static me.goudham.APIUtils.paginationData; /** @@ -35,10 +39,11 @@ public class APIWrapper { private final APIMapper apiMapper; private final HttpClient httpClient; + private final Executor executor = Executors.newFixedThreadPool(10); /** * Instantiates an instance of {@link APIWrapper} to retrieve API Information. - * An instance of {@link APIMapper} is created to be able to {@link APIMapper#deserialize(Result, Class)} JSON to + * An instance of {@link APIMapper} is created to be able to {@code deserialize} JSON to * Java objects * * @param apiKey API Key to authorise API request @@ -51,22 +56,6 @@ public class APIWrapper { apiMapper = new APIMapper(); } - /** - * Honestly I don't really know how this works - * - * @param model The actual class of the given model. E.g {@link Waifu#getClass()} - * @param The type of model to be returned. E.g {@link Waifu} or {@link Series} - * @return {@link JavaType} - * - */ - private JavaType listOf(Class model) { - return TypeFactory.defaultInstance().constructCollectionType(List.class, model); - } - - private JavaType paginationData(Class model) { - return TypeFactory.defaultInstance().constructParametricType(PaginationData.class, model); - } - /** * Handles sending a request to the API asynchronously using {@link HttpRequest} * and the underlying {@link HttpClient} @@ -78,26 +67,28 @@ public class APIWrapper { * */ private Result sendRequest(String param) throws APIResponseException { - HttpRequest request = HttpRequest.newBuilder() - .uri(URI.create(host + param)) - .version(httpClient.version()) - .timeout(Duration.ofSeconds(20)) - .headers("Content-Type", "application/json", "apikey", apiKey) - .GET() - .build(); - - CompletableFuture> response = httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString()); - - int responseCode; - String responseBody; + CompletableFuture futureResult = CompletableFuture.supplyAsync(() -> { + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create(host + param)) + .version(httpClient.version()) + .timeout(Duration.ofSeconds(20)) + .headers("Content-Type", "application/json", "apikey", apiKey) + .GET() + .build(); + + try { + return httpClient.send(request, HttpResponse.BodyHandlers.ofString()); + } catch (IOException | InterruptedException exp) { + exp.printStackTrace(); + } + return null; + }, executor).thenApply(httpResponse -> new Result(httpResponse.statusCode(), httpResponse.body())); + try { - responseCode = response.thenApply(HttpResponse::statusCode).get(); - responseBody = response.thenApply(HttpResponse::body).get(); + return futureResult.get(); } catch (InterruptedException | ExecutionException exp) { throw new APIResponseException(exp.getMessage(), exp); } - - return new Result(responseCode, responseBody); } Response getWaifu(String waifuId) throws APIResponseException, APIMapperException { @@ -120,11 +111,6 @@ public class APIWrapper { return apiMapper.deserialize(randomWaifuResult, FilteredWaifu.class); } - Response getSeries(String seriesId) throws APIResponseException, APIMapperException { - Result seriesResult = sendRequest("series/" + seriesId); - return apiMapper.deserialize(seriesResult, Series.class); - } - Response> getSeasonalAnime() throws APIResponseException, APIMapperException { Result seasonalAnimeResult = sendRequest("airing"); return apiMapper.deserializeToList(seasonalAnimeResult, listOf(FilteredSeries.class)); @@ -145,6 +131,16 @@ public class APIWrapper { return apiMapper.deserializeToList(waifuResults, listOf(FilteredWaifu.class)); } + Response getSeries(String seriesId) throws APIResponseException, APIMapperException { + Result seriesResult = sendRequest("series/" + seriesId); + return apiMapper.deserialize(seriesResult, Series.class); + } + + Response> getSeriesByPage(String pageNum) throws APIResponseException, APIMapperException { + Result seriesPageResult = sendRequest("series?page=" + pageNum); + return apiMapper.deserializeToPaginationData(seriesPageResult, paginationData(FilteredSeries.class)); + } + Response> getAllSeries(Season season, Integer year) throws APIResponseException, APIMapperException { Result allSeriesResult = sendRequest("airing/" + season.getSeason() + "/" + year); return apiMapper.deserializeToList(allSeriesResult, listOf(FilteredSeries.class)); diff --git a/src/main/java/me/goudham/MyWaifuClient.java b/src/main/java/me/goudham/MyWaifuClient.java index 7ca4f98..67bc5cb 100644 --- a/src/main/java/me/goudham/MyWaifuClient.java +++ b/src/main/java/me/goudham/MyWaifuClient.java @@ -1,16 +1,16 @@ package me.goudham; import me.goudham.domain.pagination.PaginationData; -import me.goudham.domain.user.UserList; -import me.goudham.domain.waifu.WaifuImage; -import me.goudham.util.Season; import me.goudham.domain.series.FilteredSeries; import me.goudham.domain.series.Series; import me.goudham.domain.user.User; +import me.goudham.domain.user.UserList; import me.goudham.domain.waifu.FilteredWaifu; import me.goudham.domain.waifu.Waifu; +import me.goudham.domain.waifu.WaifuImage; import me.goudham.exception.APIMapperException; import me.goudham.exception.APIResponseException; +import me.goudham.util.Season; import org.jetbrains.annotations.NotNull; import javax.net.ssl.SSLParameters; @@ -98,14 +98,6 @@ public class MyWaifuClient { return APIWrapper.getRandomWaifu(); } - public Response getSeries(@NotNull String slug) throws APIMapperException, APIResponseException { - return APIWrapper.getSeries(slug); - } - - public Response getSeries(@NotNull Integer id) throws APIMapperException, APIResponseException { - return APIWrapper.getSeries(String.valueOf(id)); - } - public Response> getSeasonalAnime() throws APIMapperException, APIResponseException { return APIWrapper.getSeasonalAnime(); } @@ -122,6 +114,18 @@ public class MyWaifuClient { return APIWrapper.getTrashWaifus(); } + public Response getSeries(@NotNull String slug) throws APIMapperException, APIResponseException { + return APIWrapper.getSeries(slug); + } + + public Response getSeries(@NotNull Integer id) throws APIMapperException, APIResponseException { + return APIWrapper.getSeries(String.valueOf(id)); + } + + public Response> getSeriesByPage(@NotNull Integer pageNum) throws APIMapperException, APIResponseException { + return APIWrapper.getSeriesByPage(String.valueOf(pageNum)); + } + public Response> getAllSeries(@NotNull Season season, @NotNull Integer year) throws APIResponseException, APIMapperException { return APIWrapper.getAllSeries(season, year); } From 029220f519d2412ce43731d13ccdf26c3f5965eb Mon Sep 17 00:00:00 2001 From: Hammy Date: Sun, 13 Jun 2021 01:25:02 +0100 Subject: [PATCH 47/48] Increment version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e79fcb7..6c323e5 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.goudham MyWaifuWrapper - 0.1.0 + 0.1.1 jar MyWaifuWrapper From a36a013611e3b874ebc5c5a21ed773719018a7ad Mon Sep 17 00:00:00 2001 From: Hammy Date: Sun, 13 Jun 2021 01:25:40 +0100 Subject: [PATCH 48/48] Update pom.xml Don't auto release to OSSRH --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6c323e5..cd0f603 100644 --- a/pom.xml +++ b/pom.xml @@ -150,7 +150,7 @@ ossrh https://s01.oss.sonatype.org/ - true + false