diff --git a/Jenkinsfile b/Jenkinsfile
index f45816b..adba505 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -64,6 +64,7 @@ pipeline {
error "*** Files could not be found";
}
}
+ archiveArtifacts artifacts: 'target/*.jar', onlyIfSuccessful: true
}
}
}
diff --git a/src/main/java/org/goudham/me/MyWaifuClient.java b/src/main/java/org/goudham/me/MyWaifuClient.java
index ba2fb2f..fbcff31 100644
--- a/src/main/java/org/goudham/me/MyWaifuClient.java
+++ b/src/main/java/org/goudham/me/MyWaifuClient.java
@@ -1,6 +1,8 @@
package org.goudham.me;
+import org.goudham.me.api.entity.series.Series;
import org.goudham.me.api.entity.waifu.Waifu;
+import org.goudham.me.exception.APIMapperException;
import org.goudham.me.exception.APIResponseException;
import org.jetbrains.annotations.NotNull;
@@ -13,7 +15,8 @@ import java.time.Duration;
import java.util.concurrent.Executor;
/**
- * A MyWaifuClient
+ * A MyWaifuClient, the underlying client used for making requests is {@link HttpClient}
+ *
*
*
Main entry point for retrieving information from MyWaifuList.
* {@link MyWaifuWrapper} is utilised to make the API requests
@@ -49,14 +52,18 @@ public class MyWaifuClient {
return myWaifuClient;
}
- public Response getWaifu(String slug) throws APIResponseException {
+ public Response getWaifu(String slug) throws APIResponseException, APIMapperException {
return myWaifuWrapper.getWaifu(httpClient, slug);
}
- public Response getWaifu(Integer id) throws APIResponseException {
+ public Response getWaifu(Integer id) throws APIResponseException, APIMapperException {
return myWaifuWrapper.getWaifu(httpClient, String.valueOf(id));
}
+ public Response getSeries(Integer id) throws APIMapperException, APIResponseException {
+ return myWaifuWrapper.getSeries(httpClient, String.valueOf(id));
+ }
+
/**
* Sets an instance of HttpClient
*
diff --git a/src/main/java/org/goudham/me/MyWaifuWrapper.java b/src/main/java/org/goudham/me/MyWaifuWrapper.java
index 662da1c..aa71979 100644
--- a/src/main/java/org/goudham/me/MyWaifuWrapper.java
+++ b/src/main/java/org/goudham/me/MyWaifuWrapper.java
@@ -3,7 +3,9 @@ package org.goudham.me;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.goudham.me.api.entity.series.Series;
import org.goudham.me.api.entity.waifu.Waifu;
+import org.goudham.me.exception.APIMapperException;
import org.goudham.me.exception.APIResponseException;
import java.net.URI;
@@ -33,19 +35,24 @@ public class MyWaifuWrapper {
this.apiKey = apiKey;
}
+
/**
- *
+ * 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 {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(host + param))
.version(httpClient.version())
- .timeout(Duration.ofSeconds(30))
- .header("Content-Type", "application/json")
- .header("apikey", apiKey)
+ .timeout(Duration.ofSeconds(20))
+ .headers("Content-Type", "application/json", "apikey", apiKey)
.GET()
.build();
@@ -63,26 +70,35 @@ public class MyWaifuWrapper {
return new Result(responseCode, responseBody);
}
- Response getWaifu(HttpClient httpClient, String param) throws APIResponseException {
- Result waifuResult = sendRequest(httpClient, "waifu/" + param);
- Integer statusCode = waifuResult.getStatusCode();
- String body = waifuResult.getBody();
- Waifu waifu = null;
+ private Response getPopulatedResponse(Result result, Class entity) throws APIMapperException {
+ Integer statusCode = result.getStatusCode();
+ String body = result.getBody();
+ T newEntity = null;
if (statusCode == 200) {
try {
JsonNode parent = objectMapper.readTree(body);
- String waifuData = parent.get("data").toString();
- waifu = objectMapper.readValue(waifuData, Waifu.class);
+ String data = parent.get("data").toString();
+ newEntity = objectMapper.readValue(data, entity);
} catch (JsonProcessingException jpe) {
- jpe.printStackTrace();
+ String customExceptionMessage = "If you are seeing this message, this is more than likely a fault in my logic. " +
+ "Please raise an issue including the printed stacktrace :D";
+ String exceptionMessage = "\n\n" + customExceptionMessage + "\n\n" + jpe.getMessage();
- statusCode = 100;
- body = "{\"message\":\"If you are seeing this message, this is more than likely a fault in my logic. " +
- "Please raise an issue with the printed stacktrace :D\",\"code\":Custom 100}";
+ throw new APIMapperException(exceptionMessage, jpe);
}
}
- return new Response<>(statusCode, body, waifu);
+ return new Response<>(statusCode, body, newEntity);
+ }
+
+ Response getWaifu(HttpClient httpClient, String param) throws APIResponseException, APIMapperException {
+ Result waifuResult = sendRequest(httpClient, "waifu/" + param);
+ return getPopulatedResponse(waifuResult, Waifu.class);
+ }
+
+ Response getSeries(HttpClient httpClient, String param) throws APIResponseException, APIMapperException {
+ Result seriesResult = sendRequest(httpClient, "series/" + param);
+ return getPopulatedResponse(seriesResult, Series.class);
}
}
diff --git a/src/main/java/org/goudham/me/Response.java b/src/main/java/org/goudham/me/Response.java
index c9e2e8e..56fa3fc 100644
--- a/src/main/java/org/goudham/me/Response.java
+++ b/src/main/java/org/goudham/me/Response.java
@@ -1,5 +1,22 @@
package org.goudham.me;
+import org.goudham.me.api.entity.series.Series;
+import org.goudham.me.api.entity.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.
+ *
+ * No matter successful or unsuccessful response, {@link #responseCode} and {@link #responseBody}
+ * will be populated to ensure the user has all the information for debugging or extra information within
+ * the {@link #responseBody}
+ *
+ * @param The type of entity to be returned. E.g {@link Waifu} or {@link Series}
+ *
+ */
public class Response {
private T entity;
private final Integer responseCode;
diff --git a/src/main/java/org/goudham/me/api/entity/Studio.java b/src/main/java/org/goudham/me/api/entity/Studio.java
index 29894bd..7234096 100644
--- a/src/main/java/org/goudham/me/api/entity/Studio.java
+++ b/src/main/java/org/goudham/me/api/entity/Studio.java
@@ -27,7 +27,8 @@ import java.util.Objects;
@Generated("jsonschema2pojo")
public class Studio {
- @JsonCreator
+ Studio() { }
+
Studio(String name) {
this.name = name;
}
diff --git a/src/main/java/org/goudham/me/api/entity/series/FilteredSeries.java b/src/main/java/org/goudham/me/api/entity/series/FilteredSeries.java
index 3c30991..27b94b5 100644
--- a/src/main/java/org/goudham/me/api/entity/series/FilteredSeries.java
+++ b/src/main/java/org/goudham/me/api/entity/series/FilteredSeries.java
@@ -9,7 +9,6 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.util.Objects;
-
/**
* {@link FilteredSeries}
* Contains basic series information for most endpoints
@@ -18,9 +17,12 @@ import java.util.Objects;
*
* - {@link String name}
* - {@link String originalName}
+ * - {@link Integer relevance}
* - {@link String romajiName}
* - {@link String slug}
+ * - {@link String} type
* - {@link String description}
+ * - {@link String displayPicture}
* - {@link String url}
* - {@link Integer id}
*
@@ -30,9 +32,12 @@ import java.util.Objects;
@JsonPropertyOrder({
"name",
"original_name",
+ "relevance",
"romaji_name",
"slug",
+ "type",
"description",
+ "displayPicture",
"url",
"id"
})
@@ -55,30 +60,52 @@ public class FilteredSeries {
private String originalName;
/**
- * If this {@link Series} has a romaji name, we'll put it here.
+ * Relevancy of {@link FilteredSeries}
+ */
+ @JsonProperty("relevance")
+ @JsonPropertyDescription("Relevancy of FilteredSeries")
+ private Integer relevance;
+
+ /**
+ * If this {@link FilteredSeries} has a romaji name, we'll put it here.
*
*/
@JsonProperty("romaji_name")
- @JsonPropertyDescription("if this character has a romaji name, we'll put it here. ")
+ @JsonPropertyDescription("if this series has a romaji name, we'll put it here. ")
private String romajiName;
/**
- * Readable URL's for this {@link Series}
+ * Readable URL's for this {@link FilteredSeries}
*
*/
@JsonProperty("slug")
- @JsonPropertyDescription("Used to generate readable URL's for the Waifu")
+ @JsonPropertyDescription("Used to generate readable URL's for the FilteredSeries")
private String slug;
+ /**
+ * Type of {@link FilteredSeries}. E.g TV, Game
+ *
+ */
+ @JsonProperty("type")
+ @JsonPropertyDescription("Type of FilteredSeries. E.g TV, Game")
+ private String type;
/**
- * Truncated, spoiler-free description of this {@link Series}
+ * Truncated, spoiler-free description of this {@link FilteredSeries}
*
*/
@JsonProperty("description")
- @JsonPropertyDescription("Truncated, spoiler-free description of this Waifu")
+ @JsonPropertyDescription("Truncated, spoiler-free description of this FilteredSeries")
private String description;
+ /**
+ * URL of the display picture
+ *
+ */
+ @JsonProperty("display_picture")
+ @JsonPropertyDescription("URL of the display picture")
+ private String displayPicture;
+
/**
* URL to view in browser
*
@@ -88,10 +115,10 @@ public class FilteredSeries {
private String url;
/**
- * Interal ID of this {@link Series}
+ * Interal ID of this {@link FilteredSeries}
*/
@JsonProperty("id")
- @JsonPropertyDescription("Internal ID of the series")
+ @JsonPropertyDescription("Internal ID of this FilteredSeries")
private Integer id;
@JsonProperty("name")
@@ -114,6 +141,12 @@ public class FilteredSeries {
this.originalName = originalName;
}
+ @JsonProperty("relevance")
+ public Integer getRelevance() { return relevance; }
+
+ @JsonProperty("relevance")
+ public void setRelevance(Integer relevance) { this.relevance = relevance; }
+
@JsonProperty("romaji_name")
public String getRomajiName() {
return romajiName;
@@ -134,6 +167,12 @@ public class FilteredSeries {
this.slug = slug;
}
+ @JsonProperty("type")
+ public String getType() { return type; }
+
+ @JsonProperty("type")
+ public void setType(String type) { this.type = type; }
+
@JsonProperty("description")
public String getDescription() {
return description;
@@ -144,6 +183,16 @@ public class FilteredSeries {
this.description = description;
}
+ @JsonProperty("display_picture")
+ public String getDisplayPicture() {
+ return displayPicture;
+ }
+
+ @JsonProperty("display_picture")
+ public void setDisplayPicture(String displayPicture) {
+ this.displayPicture = displayPicture;
+ }
+
@JsonProperty("url")
public String getUrl() {
return url;
diff --git a/src/main/java/org/goudham/me/api/entity/series/Series.java b/src/main/java/org/goudham/me/api/entity/series/Series.java
index f35546e..ef86aed 100644
--- a/src/main/java/org/goudham/me/api/entity/series/Series.java
+++ b/src/main/java/org/goudham/me/api/entity/series/Series.java
@@ -26,6 +26,7 @@ import java.util.Objects;
* {@link String displayPicture}
* {@link String url}
* {@link Studio}
+ * {@link String} type
* {@link Integer id}
*
*
@@ -44,6 +45,7 @@ import java.util.Objects;
"display_picture",
"url",
"studio",
+ "type",
"id"
})
@Generated("jsonschema2pojo")
@@ -145,6 +147,14 @@ public class Series {
@JsonPropertyDescription("Contains information on a given animation or game development studio")
private Studio studio;
+ /**
+ * Type of {@link Series}. E.g TV, Game
+ *
+ */
+ @JsonProperty("type")
+ @JsonPropertyDescription("Type of FilteredSeries. E.g TV, Game")
+ private String type;
+
/**
* The internal ID of the {@link Series}
*
@@ -271,6 +281,12 @@ public class Series {
this.studio = studio;
}
+ @JsonProperty("type")
+ public String getType() { return type; }
+
+ @JsonProperty("type")
+ public void setType(String type) { this.type = type; }
+
@JsonProperty("id")
public Integer getId() {
return id;
diff --git a/src/main/java/org/goudham/me/api/entity/waifu/Appearance.java b/src/main/java/org/goudham/me/api/entity/waifu/Appearance.java
deleted file mode 100644
index ca7032a..0000000
--- a/src/main/java/org/goudham/me/api/entity/waifu/Appearance.java
+++ /dev/null
@@ -1,125 +0,0 @@
-package org.goudham.me.api.entity.waifu;
-
-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;
-
-
-/**
- * {@link Appearance}
- * Contains basic series information for most endpoints
- *
- * Fields included are:
- *
- * - {@link String name}
- * - {@link String originalName}
- * - {@link String romajiName}
- * - {@link String slug}
- * - {@link String description}
- * - {@link String url}
- * - {@link Integer id}
- *
- *
- */
-@JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonPropertyOrder({
- "name",
- "original_name",
- "romaji_name",
- "slug",
- "description",
- "url",
- "id"
-})
-@Generated("jsonschema2pojo")
-public class Appearance {
- @JsonProperty("name")
- private String name;
- @JsonProperty("original_name")
- private String originalName;
- @JsonProperty("romaji_name")
- private String romajiName;
- @JsonProperty("slug")
- private String slug;
- @JsonProperty("description")
- private String description;
- @JsonProperty("url")
- private String url;
- @JsonProperty("id")
- @JsonPropertyDescription("Internal ID of the series")
- private Integer id;
-
- @JsonProperty("name")
- public String getName() {
- return name;
- }
-
- @JsonProperty("name")
- public void setName(String name) {
- this.name = name;
- }
-
- @JsonProperty("original_name")
- public String getOriginalName() {
- return originalName;
- }
-
- @JsonProperty("original_name")
- public void setOriginalName(String originalName) {
- this.originalName = originalName;
- }
-
- @JsonProperty("romaji_name")
- public String getRomajiName() {
- return romajiName;
- }
-
- @JsonProperty("romaji_name")
- public void setRomajiName(String romajiName) {
- this.romajiName = romajiName;
- }
-
- @JsonProperty("slug")
- public String getSlug() {
- return slug;
- }
-
- @JsonProperty("slug")
- public void setSlug(String slug) {
- this.slug = slug;
- }
-
- @JsonProperty("description")
- public String getDescription() {
- return description;
- }
-
- @JsonProperty("description")
- public void setDescription(String description) {
- this.description = description;
- }
-
- @JsonProperty("url")
- public String getUrl() {
- return url;
- }
-
- @JsonProperty("url")
- public void setUrl(String url) {
- this.url = url;
- }
-
- @JsonProperty("id")
- public Integer getId() {
- return id;
- }
-
- @JsonProperty("id")
- public void setId(Integer id) {
- this.id = 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 ae2a827..5f65923 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,5 +1,7 @@
package org.goudham.me.api.entity.waifu;
+import org.goudham.me.api.entity.series.FilteredSeries;
+
import java.util.List;
import java.util.Objects;
import javax.annotation.processing.Generated;
@@ -19,13 +21,14 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
* {@link String slug}
* {@link String name}
* {@link String originalName}
+ * {@link Integer relevance}
* {@link String romajiName}
* {@link String displayPicture}
* {@link Integer likes}
* {@link Integer trash}
- * {@link Integer episodeCount}
+ * {@link String type}
* {@link String url}
- * {@link List} of {@link Appearance}'s
+ * {@link List} of {@link FilteredSeries}'s
* {@link Double id}
*
*
@@ -35,11 +38,13 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
"slug",
"name",
"original_name",
+ "relevance",
"romaji_name",
"display_picture",
"description",
"likes",
"trash",
+ "type",
"url",
"appearances",
"id"
@@ -47,11 +52,11 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@Generated("jsonschema2pojo")
public class FilteredWaifu {
/**
- * Used to generate readable URL's for the Waifu
+ * Used to generate readable URL's for the {@link FilteredWaifu}
*
*/
@JsonProperty("slug")
- @JsonPropertyDescription("Used to generate readable URL's for the Waifu")
+ @JsonPropertyDescription("Used to generate readable URL's for the FilteredWaifu")
private String slug;
/**
@@ -70,6 +75,13 @@ public class FilteredWaifu {
@JsonPropertyDescription("Name in the original language (\u65e5\u672c\u8a9e)")
private String originalName;
+ /**
+ * Relevancy of {@link FilteredWaifu}
+ */
+ @JsonProperty("relevance")
+ @JsonPropertyDescription("Relevancy of FilteredWaifu")
+ private Integer relevance;
+
/**
* If this character has a romaji name, we'll put it here.
*
@@ -87,29 +99,37 @@ public class FilteredWaifu {
private String displayPicture;
/**
- * Truncated, spoiler-free description of this Waifu
+ * Truncated, spoiler-free description of this {@link FilteredWaifu}
*
*/
@JsonProperty("description")
- @JsonPropertyDescription("Truncated, spoiler-free description of this Waifu")
+ @JsonPropertyDescription("Truncated, spoiler-free description of this FilteredWaifu")
private String description;
/**
- * Number of likes for this Waifu
+ * Number of likes for this {@link FilteredWaifu}
*
*/
@JsonProperty("likes")
- @JsonPropertyDescription("Number of likes for this Waifu")
+ @JsonPropertyDescription("Number of likes for this FilteredWaifu")
private Integer likes;
/**
- * Number of trashes for this Waifu
+ * Number of trashes for this {@link FilteredWaifu}
*
*/
@JsonProperty("trash")
- @JsonPropertyDescription("Number of trashes for this Waifu")
+ @JsonPropertyDescription("Number of trashes for this FilteredWaifu")
private Integer trash;
+ /**
+ * Type that is returned. Eg Waifu, Husbando
+ *
+ */
+ @JsonProperty("type")
+ @JsonPropertyDescription("Type that is returned. Eg Waifu, Husbando")
+ private String type;
+
/**
* URL to view in browser
*
@@ -119,10 +139,10 @@ public class FilteredWaifu {
private String url;
/**
- * {@link List} of Waifu's {@link Appearance}
+ * {@link List} of Waifu's appearances
*/
@JsonProperty("appearances")
- private List appearances;
+ private List appearances;
/**
* {@link FilteredWaifu} ID
@@ -140,7 +160,6 @@ public class FilteredWaifu {
this.slug = slug;
}
-
@JsonProperty("name")
public String getName() {
return name;
@@ -161,6 +180,12 @@ public class FilteredWaifu {
this.originalName = originalName;
}
+ @JsonProperty("relevance")
+ public Integer getRelevance() { return relevance; }
+
+ @JsonProperty("relevance")
+ public void setRelevance(Integer relevance) { this.relevance = relevance; }
+
@JsonProperty("romaji_name")
public String getRomajiName() {
return romajiName;
@@ -211,6 +236,12 @@ public class FilteredWaifu {
this.trash = trash;
}
+ @JsonProperty("type")
+ public String getType() { return type; }
+
+ @JsonProperty("type")
+ public void setType(String type) { this.type = type; }
+
@JsonProperty("url")
public String getUrl() {
return url;
@@ -222,13 +253,11 @@ public class FilteredWaifu {
}
@JsonProperty("appearances")
- public List getAppearances() {
- return appearances;
- }
+ public List getAppearances() { return appearances; }
@JsonProperty("appearances")
- public void setAppearances(List appearances) {
- this.appearances = appearances;
+ public void setAppearances(List filteredSeries) {
+ this.appearances = filteredSeries;
}
@JsonProperty("id")
diff --git a/src/main/java/org/goudham/me/exception/APIMapperException.java b/src/main/java/org/goudham/me/exception/APIMapperException.java
new file mode 100644
index 0000000..c016e9f
--- /dev/null
+++ b/src/main/java/org/goudham/me/exception/APIMapperException.java
@@ -0,0 +1,15 @@
+package org.goudham.me.exception;
+
+
+import org.goudham.me.MyWaifuWrapper;
+import org.goudham.me.Response;
+
+/**
+ * Thrown when {@link MyWaifuWrapper} fails to unmarshal json into Java POJO's ({@link Response#getEntity()})
+ *
+ */
+public class APIMapperException extends Throwable {
+ public APIMapperException(String errorMessage, Throwable error) {
+ super(errorMessage, error);
+ }
+}