commit
b69edfcf2e
@ -0,0 +1,5 @@
|
||||
FROM maven:3.8.1-adoptopenjdk-11
|
||||
MAINTAINER Goudham Suresh
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
gpg
|
@ -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 <T> The type of model to be returned. E.g {@link Waifu} or {@link Series}
|
||||
* @return {@link JavaType} of {@link List}
|
||||
*
|
||||
*/
|
||||
static <T> JavaType listOf(Class<T> model) {
|
||||
return TypeFactory.defaultInstance().constructCollectionType(List.class, model);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param model The actual class of the given model. E.g {@link Waifu#getClass()}
|
||||
* @param <T> The type of model to be returned. E.g {@link Waifu} or {@link Series}
|
||||
* @return {@link JavaType} of {@link PaginationData}
|
||||
*/
|
||||
static <T> JavaType paginationData(Class<T> model) {
|
||||
return TypeFactory.defaultInstance().constructParametricType(PaginationData.class, model);
|
||||
}
|
||||
}
|
@ -0,0 +1,168 @@
|
||||
package me.goudham;
|
||||
|
||||
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.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* Returns API information to {@link MyWaifuClient}
|
||||
*
|
||||
*/
|
||||
public class APIWrapper {
|
||||
private final String version = "1.0";
|
||||
private static final String host = "https://mywaifulist.moe/api/v1/";
|
||||
private final String apiKey;
|
||||
|
||||
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 {@code deserialize} JSON to
|
||||
* Java objects
|
||||
*
|
||||
* @param apiKey API Key to authorise API request
|
||||
* @param httpClient The underlying {@link HttpClient} to use for HttpRequests
|
||||
*
|
||||
*/
|
||||
APIWrapper(String apiKey, HttpClient httpClient) {
|
||||
this.apiKey = apiKey;
|
||||
this.httpClient = httpClient;
|
||||
apiMapper = new APIMapper();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles sending a request to the API asynchronously using {@link HttpRequest}
|
||||
* and the underlying {@link HttpClient}
|
||||
*
|
||||
* @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(String param) throws APIResponseException {
|
||||
CompletableFuture<Result> 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 {
|
||||
return futureResult.get();
|
||||
} catch (InterruptedException | ExecutionException exp) {
|
||||
throw new APIResponseException(exp.getMessage(), exp);
|
||||
}
|
||||
}
|
||||
|
||||
Response<Waifu> getWaifu(String waifuId) throws APIResponseException, APIMapperException {
|
||||
Result waifuResult = sendRequest("waifu/" + waifuId);
|
||||
return apiMapper.deserialize(waifuResult, Waifu.class);
|
||||
}
|
||||
|
||||
Response<PaginationData<WaifuImage>> getWaifuImages(String waifuId, String pageNum) throws APIResponseException, APIMapperException {
|
||||
Result waifuImagesResult = sendRequest("waifu/" + waifuId + "/images?page=" + pageNum);
|
||||
return apiMapper.deserializeToPaginationData(waifuImagesResult, paginationData(WaifuImage.class));
|
||||
}
|
||||
|
||||
Response<FilteredWaifu> getDailyWaifu() throws APIResponseException, APIMapperException {
|
||||
Result dailyWaifuResult = sendRequest("meta/daily");
|
||||
return apiMapper.deserialize(dailyWaifuResult, FilteredWaifu.class);
|
||||
}
|
||||
|
||||
Response<FilteredWaifu> getRandomWaifu() throws APIResponseException, APIMapperException {
|
||||
Result randomWaifuResult = sendRequest("meta/random");
|
||||
return apiMapper.deserialize(randomWaifuResult, FilteredWaifu.class);
|
||||
}
|
||||
|
||||
Response<List<FilteredSeries>> getSeasonalAnime() throws APIResponseException, APIMapperException {
|
||||
Result seasonalAnimeResult = sendRequest("airing");
|
||||
return apiMapper.deserializeToList(seasonalAnimeResult, listOf(FilteredSeries.class));
|
||||
}
|
||||
|
||||
Response<List<FilteredWaifu>> getBestWaifus() throws APIResponseException, APIMapperException {
|
||||
Result waifuResults = sendRequest("airing/best");
|
||||
return apiMapper.deserializeToList(waifuResults, listOf(FilteredWaifu.class));
|
||||
}
|
||||
|
||||
Response<List<FilteredWaifu>> getPopularWaifus() throws APIResponseException, APIMapperException {
|
||||
Result waifuResults = sendRequest("airing/popular");
|
||||
return apiMapper.deserializeToList(waifuResults, listOf(FilteredWaifu.class));
|
||||
}
|
||||
|
||||
Response<List<FilteredWaifu>> getTrashWaifus() throws APIResponseException, APIMapperException {
|
||||
Result waifuResults = sendRequest("airing/trash");
|
||||
return apiMapper.deserializeToList(waifuResults, listOf(FilteredWaifu.class));
|
||||
}
|
||||
|
||||
Response<Series> getSeries(String seriesId) throws APIResponseException, APIMapperException {
|
||||
Result seriesResult = sendRequest("series/" + seriesId);
|
||||
return apiMapper.deserialize(seriesResult, Series.class);
|
||||
}
|
||||
|
||||
Response<PaginationData<FilteredSeries>> getSeriesByPage(String pageNum) throws APIResponseException, APIMapperException {
|
||||
Result seriesPageResult = sendRequest("series?page=" + pageNum);
|
||||
return apiMapper.deserializeToPaginationData(seriesPageResult, paginationData(FilteredSeries.class));
|
||||
}
|
||||
|
||||
Response<List<FilteredSeries>> getAllSeries(Season season, Integer year) throws APIResponseException, APIMapperException {
|
||||
Result allSeriesResult = sendRequest("airing/" + season.getSeason() + "/" + year);
|
||||
return apiMapper.deserializeToList(allSeriesResult, listOf(FilteredSeries.class));
|
||||
}
|
||||
|
||||
Response<List<FilteredWaifu>> getSeriesWaifus(String seriesId) throws APIResponseException, APIMapperException {
|
||||
Result allWaifusFromSeriesResults = sendRequest("series/" + seriesId + "/waifus");
|
||||
return apiMapper.deserializeToList(allWaifusFromSeriesResults, listOf(FilteredWaifu.class));
|
||||
}
|
||||
|
||||
Response<User> getUserProfile(String userId) throws APIResponseException, APIMapperException {
|
||||
Result userProfileResult = sendRequest("user/" + userId);
|
||||
return apiMapper.deserialize(userProfileResult, User.class);
|
||||
}
|
||||
|
||||
Response<List<UserList>> getUserLists(String userId) throws APIResponseException, APIMapperException {
|
||||
Result userProfileResult = sendRequest("user/" + userId + "/lists");
|
||||
return apiMapper.deserializeToList(userProfileResult, listOf(UserList.class));
|
||||
}
|
||||
|
||||
Response<UserList> getUserList(String userId, String listId) throws APIResponseException, APIMapperException {
|
||||
Result userProfileResult = sendRequest("user/" + userId + "/lists/" + listId);
|
||||
return apiMapper.deserialize(userProfileResult, UserList.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,214 @@
|
||||
package me.goudham;
|
||||
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.net.ssl.SSLParameters;
|
||||
import java.net.Authenticator;
|
||||
import java.net.CookieHandler;
|
||||
import java.net.ProxySelector;
|
||||
import java.net.http.HttpClient;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* A MyWaifuClient, the underlying client used for making requests is {@link HttpClient}
|
||||
*
|
||||
*
|
||||
* <p> Main entry point for retrieving information from MyWaifuList.</p>
|
||||
* <p> {@link APIWrapper} is utilised to make the API requests </p>
|
||||
*/
|
||||
public class MyWaifuClient {
|
||||
private final APIWrapper APIWrapper;
|
||||
|
||||
/**
|
||||
* Creates an instance of {@link MyWaifuClient}
|
||||
*
|
||||
* <p>See <a href="https://mywaifulist.docs.stoplight.io/">MyWaifuList</a> for obtaining an API Key</p>
|
||||
* @param apiKey API Key to authorise API request
|
||||
* @param httpClient The underlying {@link HttpClient} to use for HttpRequests
|
||||
*
|
||||
*/
|
||||
MyWaifuClient(@NotNull String apiKey, @NotNull HttpClient httpClient) {
|
||||
APIWrapper = new APIWrapper(apiKey, httpClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of {@link MyWaifuClient} with default {@link HttpClient} settings
|
||||
*
|
||||
* @param apiKey API Key to authorise API request
|
||||
* @return {@link MyWaifuClient}
|
||||
*/
|
||||
public static MyWaifuClient createDefault(@NotNull String apiKey) {
|
||||
HttpClient httpClient = HttpClient.newBuilder()
|
||||
.version(HttpClient.Version.HTTP_2)
|
||||
.followRedirects(HttpClient.Redirect.NORMAL)
|
||||
.connectTimeout(Duration.ofSeconds(20))
|
||||
.build();
|
||||
|
||||
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<Waifu> 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<Waifu> getWaifu(@NotNull Integer id) throws APIResponseException, APIMapperException {
|
||||
return APIWrapper.getWaifu(String.valueOf(id));
|
||||
}
|
||||
|
||||
public Response<PaginationData<WaifuImage>> getWaifuImages(@NotNull Integer id, @NotNull Integer pageNum) throws APIResponseException, APIMapperException {
|
||||
return APIWrapper.getWaifuImages(String.valueOf(id), String.valueOf(pageNum));
|
||||
}
|
||||
|
||||
public Response<FilteredWaifu> getDailyWaifu() throws APIResponseException, APIMapperException {
|
||||
return APIWrapper.getDailyWaifu();
|
||||
}
|
||||
|
||||
public Response<FilteredWaifu> getRandomWaifu() throws APIResponseException, APIMapperException {
|
||||
return APIWrapper.getRandomWaifu();
|
||||
}
|
||||
|
||||
public Response<List<FilteredSeries>> getSeasonalAnime() throws APIMapperException, APIResponseException {
|
||||
return APIWrapper.getSeasonalAnime();
|
||||
}
|
||||
|
||||
public Response<List<FilteredWaifu>> getBestWaifus() throws APIMapperException, APIResponseException {
|
||||
return APIWrapper.getBestWaifus();
|
||||
}
|
||||
|
||||
public Response<List<FilteredWaifu>> getPopularWaifus() throws APIMapperException, APIResponseException {
|
||||
return APIWrapper.getPopularWaifus();
|
||||
}
|
||||
|
||||
public Response<List<FilteredWaifu>> getTrashWaifus() throws APIMapperException, APIResponseException {
|
||||
return APIWrapper.getTrashWaifus();
|
||||
}
|
||||
|
||||
public Response<Series> getSeries(@NotNull String slug) throws APIMapperException, APIResponseException {
|
||||
return APIWrapper.getSeries(slug);
|
||||
}
|
||||
|
||||
public Response<Series> getSeries(@NotNull Integer id) throws APIMapperException, APIResponseException {
|
||||
return APIWrapper.getSeries(String.valueOf(id));
|
||||
}
|
||||
|
||||
public Response<PaginationData<FilteredSeries>> getSeriesByPage(@NotNull Integer pageNum) throws APIMapperException, APIResponseException {
|
||||
return APIWrapper.getSeriesByPage(String.valueOf(pageNum));
|
||||
}
|
||||
|
||||
public Response<List<FilteredSeries>> getAllSeries(@NotNull Season season, @NotNull Integer year) throws APIResponseException, APIMapperException {
|
||||
return APIWrapper.getAllSeries(season, year);
|
||||
}
|
||||
|
||||
public Response<List<FilteredWaifu>> getSeriesWaifus(@NotNull String slug) throws APIMapperException, APIResponseException {
|
||||
return APIWrapper.getSeriesWaifus(slug);
|
||||
}
|
||||
|
||||
public Response<List<FilteredWaifu>> getSeriesWaifus(@NotNull Integer id) throws APIMapperException, APIResponseException {
|
||||
return APIWrapper.getSeriesWaifus(String.valueOf(id));
|
||||
}
|
||||
|
||||
public Response<User> getUserProfile(@NotNull Integer id) throws APIMapperException, APIResponseException {
|
||||
return APIWrapper.getUserProfile(String.valueOf(id));
|
||||
}
|
||||
|
||||
public Response<List<UserList>> getUserLists(@NotNull Integer id) throws APIMapperException, APIResponseException {
|
||||
return APIWrapper.getUserLists(String.valueOf(id));
|
||||
}
|
||||
|
||||
public Response<UserList> getUserList(@NotNull Integer userId, @NotNull Integer listId) throws APIMapperException, APIResponseException {
|
||||
return APIWrapper.getUserList(String.valueOf(userId), String.valueOf(listId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for {@link MyWaifuClient}
|
||||
*
|
||||
*/
|
||||
public static class Builder {
|
||||
private final String apiKey;
|
||||
private final HttpClient.Builder httpClientBuilder = HttpClient.newBuilder();
|
||||
|
||||
public Builder(@NotNull String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
public Builder withCookieHandler(CookieHandler cookieHandler) {
|
||||
httpClientBuilder.cookieHandler(cookieHandler);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withConnectTimeout(@NotNull Duration duration) {
|
||||
httpClientBuilder.connectTimeout(duration);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withSslParameters(@NotNull SSLParameters sslParameters) {
|
||||
httpClientBuilder.sslParameters(sslParameters);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withExecutor(@NotNull Executor executor) {
|
||||
httpClientBuilder.executor(executor);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withFollowRedirects(@NotNull HttpClient.Redirect policy) {
|
||||
httpClientBuilder.followRedirects(policy);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withVersion(@NotNull HttpClient.Version version) {
|
||||
httpClientBuilder.version(version);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withPriority(int priority) {
|
||||
httpClientBuilder.priority(priority);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withProxy(@NotNull ProxySelector proxySelector) {
|
||||
httpClientBuilder.proxy(proxySelector);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withAuthenticator(@NotNull Authenticator authenticator) {
|
||||
httpClientBuilder.authenticator(authenticator);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyWaifuClient build() {
|
||||
return new MyWaifuClient(apiKey, httpClientBuilder.build());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package me.goudham;
|
||||
|
||||
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)}
|
||||
* <br>
|
||||
* Given a successful response, {@link #model} will be populated with the requested model.
|
||||
* <br>
|
||||
* 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 <T> The type of model to be returned. E.g {@link Waifu} or {@link Series}
|
||||
*
|
||||
*/
|
||||
public class Response<T> {
|
||||
private final T model;
|
||||
private final Integer statusCode;
|
||||
private final String body;
|
||||
|
||||
Response(Integer statusCode, String body, T model) {
|
||||
this.statusCode = statusCode;
|
||||
this.body = body;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public T getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public Integer getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
}
|
@ -1,5 +1,11 @@
|
||||
package org.goudham.me;
|
||||
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;
|
@ -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}
|
||||
* <p>Contains gallery API links for {@link Meta}</p>
|
||||
*
|
||||
* <p> Fields included are: </p>
|
||||
* <ul>
|
||||
* <li>{@link String first}</li>
|
||||
* <li>{@link String last}</li>
|
||||
* <li>{@link String next}</li>
|
||||
* <li>{@link String prev}</li>
|
||||
* </ul>
|
||||
*
|
||||
*/
|
||||
@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 + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,177 @@
|
||||
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 Meta}
|
||||
* <p>Contains standard Pagination data from the API</p>
|
||||
*
|
||||
* <p> Fields included are: </p>
|
||||
* <ul>
|
||||
* <li>{@link Integer currentPage}</li>
|
||||
* <li>{@link Integer from}</li>
|
||||
* <li>{@link Integer lastPage}</li>
|
||||
* <li>{@link String path}</li>
|
||||
* <li>{@link Integer perPage}</li>
|
||||
* <li>{@link Integer to}</li>
|
||||
* <li>{@link Integer total}</li>
|
||||
* </ul>
|
||||
*
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({
|
||||
"current_page",
|
||||
"from",
|
||||
"last_page",
|
||||
"path",
|
||||
"per_page",
|
||||
"to",
|
||||
"total"
|
||||
})
|
||||
public class Meta {
|
||||
/**
|
||||
* Current requested page
|
||||
*
|
||||
*/
|
||||
@JsonProperty("current_page")
|
||||
@JsonPropertyDescription("Current requested page")
|
||||
private Integer currentPage;
|
||||
|
||||
/**
|
||||
* Starting gallery image number
|
||||
*
|
||||
*/
|
||||
@JsonProperty("from")
|
||||
@JsonPropertyDescription("Starting gallery image number")
|
||||
private Integer from;
|
||||
|
||||
/**
|
||||
* Last available page
|
||||
*
|
||||
*/
|
||||
@JsonProperty("last_page")
|
||||
@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
|
||||
*
|
||||
*/
|
||||
@JsonProperty("per_page")
|
||||
@JsonPropertyDescription("Total number of items per page")
|
||||
private Integer perPage;
|
||||
|
||||
/**
|
||||
* Last gallery image number
|
||||
*
|
||||
*/
|
||||
@JsonProperty("to")
|
||||
@JsonPropertyDescription("Last gallery image number")
|
||||
private Integer to;
|
||||
|
||||
/**
|
||||
* Total number of items within the gallery
|
||||
*
|
||||
*/
|
||||
@JsonProperty("total")
|
||||
@JsonPropertyDescription("Total number of items")
|
||||
private Integer total;
|
||||
|
||||
@JsonProperty("current_page")
|
||||
public Integer getCurrentPage() {
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
@JsonProperty("current_page")
|
||||
public void setCurrentPage(Integer currentPage) {
|
||||
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;
|
||||
}
|
||||
|
||||
@JsonProperty("last_page")
|
||||
public void setLastPage(Integer lastPage) {
|
||||
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;
|
||||
}
|
||||
|
||||
@JsonProperty("per_page")
|
||||
public void setPerPage(Integer perPage) {
|
||||
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;
|
||||
}
|
||||
|
||||
@JsonProperty("total")
|
||||
public void setTotal(Integer total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
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, from, lastPage, path, perPage, to, total);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Meta{" +
|
||||
"currentPage=" + currentPage +
|
||||
", from=" + from +
|
||||
", lastPage=" + lastPage +
|
||||
", path=" + path +
|
||||
", perPage=" + perPage +
|
||||
", to=" + to +
|
||||
", total=" + total +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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}
|
||||
* <p>Contains standard Pagination data from the API including images</p>
|
||||
*
|
||||
* <p> Fields included are: </p>
|
||||
* <ul>
|
||||
* <li>{@link Object data}</li>
|
||||
* <li>{@link Links links}</li>
|
||||
* <li>{@link Meta meta}</li>
|
||||
* </ul>
|
||||
*
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({
|
||||
"data",
|
||||
"links",
|
||||
"meta"
|
||||
})
|
||||
public class PaginationData<T> {
|
||||
|
||||
/**
|
||||
* Data returned from the gallery
|
||||
*
|
||||
*/
|
||||
@JsonProperty("data")
|
||||
@JsonPropertyDescription("Data returned from the gallery")
|
||||
private List<T> 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<T> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@JsonProperty("data")
|
||||
public void setData(List<T> 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;
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
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()})
|
||||
* Thrown when {@link APIWrapper} fails to deserialize json into Java POJO's ({@link Response#getModel()})
|
||||
*
|
||||
*/
|
||||
public class APIMapperException extends Throwable {
|
@ -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
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
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.Waifu;
|
||||
import org.goudham.me.exception.APIMapperException;
|
||||
import org.goudham.me.exception.APIResponseException;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
|
||||
/**
|
||||
* Returns API information to {@link MyWaifuClient}
|
||||
*/
|
||||
public class APIWrapper {
|
||||
private final String version = "1.0";
|
||||
private static final String host = "https://mywaifulist.moe/api/v1/";
|
||||
private final String apiKey;
|
||||
|
||||
private final APIMapper apiMapper;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Java objects
|
||||
*
|
||||
* @param apiKey API Key to authorise API request
|
||||
*
|
||||
*/
|
||||
APIWrapper(String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
apiMapper = new APIMapper();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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(20))
|
||||
.headers("Content-Type", "application/json", "apikey", apiKey)
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
CompletableFuture<HttpResponse<String>> response = httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
int responseCode;
|
||||
String responseBody;
|
||||
try {
|
||||
responseCode = response.thenApply(HttpResponse::statusCode).get();
|
||||
responseBody = response.thenApply(HttpResponse::body).get();
|
||||
} catch (InterruptedException | ExecutionException exp) {
|
||||
throw new APIResponseException(exp.getMessage(), exp);
|
||||
}
|
||||
|
||||
return new Result(responseCode, responseBody);
|
||||
}
|
||||
|
||||
Response<Waifu> getWaifu(HttpClient httpClient, String param) throws APIResponseException, APIMapperException {
|
||||
Result waifuResult = sendRequest(httpClient, "waifu/" + param);
|
||||
return apiMapper.deserialize(waifuResult, Waifu.class);
|
||||
}
|
||||
|
||||
Response<Series> getSeries(HttpClient httpClient, String param) throws APIResponseException, APIMapperException {
|
||||
Result seriesResult = sendRequest(httpClient, "series/" + param);
|
||||
return apiMapper.deserialize(seriesResult, Series.class);
|
||||
}
|
||||
|
||||
Response<List<FilteredSeries>> getAiringAnime(HttpClient httpClient) throws APIResponseException, APIMapperException {
|
||||
Result seriesResult = sendRequest(httpClient, "airing");
|
||||
return apiMapper.deserializeToList(seriesResult, FilteredSeries.class);
|
||||
}
|
||||
}
|
@ -1,146 +0,0 @@
|
||||
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.Waifu;
|
||||
import org.goudham.me.exception.APIMapperException;
|
||||
import org.goudham.me.exception.APIResponseException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.net.ssl.SSLParameters;
|
||||
import java.net.Authenticator;
|
||||
import java.net.CookieHandler;
|
||||
import java.net.ProxySelector;
|
||||
import java.net.http.HttpClient;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* A MyWaifuClient, the underlying client used for making requests is {@link HttpClient}
|
||||
*
|
||||
*
|
||||
* <p> Main entry point for retrieving information from MyWaifuList.</p>
|
||||
* <p> {@link APIWrapper} is utilised to make the API requests </p>
|
||||
*/
|
||||
public class MyWaifuClient {
|
||||
private final APIWrapper APIWrapper;
|
||||
private HttpClient httpClient;
|
||||
|
||||
/**
|
||||
* Creates an instance of {@link MyWaifuClient}
|
||||
*
|
||||
* <p>See <a href="https://mywaifulist.docs.stoplight.io/">MyWaifuList</a> for obtaining an API Key</p>
|
||||
* @param apiKey API Key to authorise API request
|
||||
*/
|
||||
MyWaifuClient(@NotNull String apiKey) {
|
||||
APIWrapper = new APIWrapper(apiKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of {@link MyWaifuClient} with default {@link HttpClient} settings
|
||||
*
|
||||
* @param apiKey API Key to authorise API request
|
||||
* @return {@link MyWaifuClient}
|
||||
*/
|
||||
public static MyWaifuClient createDefault(@NotNull String apiKey) {
|
||||
MyWaifuClient myWaifuClient = new MyWaifuClient(apiKey);
|
||||
myWaifuClient.setHttpClient(HttpClient.newBuilder()
|
||||
.version(HttpClient.Version.HTTP_2)
|
||||
.followRedirects(HttpClient.Redirect.NORMAL)
|
||||
.connectTimeout(Duration.ofSeconds(20))
|
||||
.build());
|
||||
|
||||
return myWaifuClient;
|
||||
}
|
||||
|
||||
public Response<Waifu> getWaifu(String slug) throws APIResponseException, APIMapperException {
|
||||
return APIWrapper.getWaifu(httpClient, slug);
|
||||
}
|
||||
|
||||
public Response<Waifu> getWaifu(Integer id) throws APIResponseException, APIMapperException {
|
||||
return APIWrapper.getWaifu(httpClient, String.valueOf(id));
|
||||
}
|
||||
|
||||
public Response<Series> getSeries(Integer id) throws APIMapperException, APIResponseException {
|
||||
return APIWrapper.getSeries(httpClient, String.valueOf(id));
|
||||
}
|
||||
|
||||
public Response<List<FilteredSeries>> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for MyWaifuClient
|
||||
*/
|
||||
public static class Builder {
|
||||
private final String apiKey;
|
||||
private final APIWrapper APIWrapper;
|
||||
private HttpClient.Builder httpClientBuilder;
|
||||
|
||||
public Builder(String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
APIWrapper = new APIWrapper(apiKey);
|
||||
}
|
||||
|
||||
public Builder withCookieHandler(CookieHandler cookieHandler) {
|
||||
httpClientBuilder.cookieHandler(cookieHandler);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withConnectTimeout(Duration duration) {
|
||||
httpClientBuilder.connectTimeout(duration);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withSslParameters(SSLParameters sslParameters) {
|
||||
httpClientBuilder.sslParameters(sslParameters);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withExecutor(Executor executor) {
|
||||
httpClientBuilder.executor(executor);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withFollowRedirects(HttpClient.Redirect policy) {
|
||||
httpClientBuilder.followRedirects(policy);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withVersion(HttpClient.Version version) {
|
||||
httpClientBuilder.version(version);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withPriority(int priority) {
|
||||
httpClientBuilder.priority(priority);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withProxy(ProxySelector proxySelector) {
|
||||
httpClientBuilder.proxy(proxySelector);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withAuthenticator(Authenticator authenticator) {
|
||||
httpClientBuilder.authenticator(authenticator);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MyWaifuClient build() {
|
||||
MyWaifuClient myWaifuClient = new MyWaifuClient(apiKey);
|
||||
myWaifuClient.setHttpClient(httpClientBuilder.build());
|
||||
return myWaifuClient;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
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)}
|
||||
* <br>
|
||||
* Given a successful response, {@link #entity} will be populated with the requested entity.
|
||||
* <br>
|
||||
* 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 <T> The type of entity to be returned. E.g {@link Waifu} or {@link Series}
|
||||
*
|
||||
*/
|
||||
public class Response<T> {
|
||||
private T entity;
|
||||
private final Integer responseCode;
|
||||
private final String responseBody;
|
||||
|
||||
Response(Integer responseCode, String responseBody, T entity) {
|
||||
this.responseCode = responseCode;
|
||||
this.responseBody = responseBody;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
Response(Integer responseCode, String responseBody) {
|
||||
this.responseCode = responseCode;
|
||||
this.responseBody = responseBody;
|
||||
}
|
||||
|
||||
public T getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public Integer getResponseCode() {
|
||||
return responseCode;
|
||||
}
|
||||
|
||||
public String getResponseBody() {
|
||||
return responseBody;
|
||||
}
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
package org.goudham.me.api.entity;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* {@link PaginationData}
|
||||
* <p>Contains standard Pagination data from the API</p>
|
||||
*
|
||||
* <p> Fields included are: </p>
|
||||
* <ul>
|
||||
* <li>{@link Integer currentPage}</li>
|
||||
* <li>{@link Integer lastPage}</li>
|
||||
* <li>{@link Integer perPage}</li>
|
||||
* <li>{@link Integer total}</li>
|
||||
* </ul>
|
||||
*
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({
|
||||
"current_page",
|
||||
"last_page",
|
||||
"per_page",
|
||||
"total"
|
||||
})
|
||||
@Generated("jsonschema2pojo")
|
||||
public class PaginationData {
|
||||
/**
|
||||
* Current requested page
|
||||
*
|
||||
*/
|
||||
@JsonProperty("current_page")
|
||||
@JsonPropertyDescription("Current requested page")
|
||||
private Integer currentPage;
|
||||
|
||||
/**
|
||||
* Last available page
|
||||
*
|
||||
*/
|
||||
@JsonProperty("last_page")
|
||||
@JsonPropertyDescription("Last available page")
|
||||
private Integer lastPage;
|
||||
|
||||
/**
|
||||
* Total number of items per page
|
||||
*
|
||||
*/
|
||||
@JsonProperty("per_page")
|
||||
@JsonPropertyDescription("Total number of items per page")
|
||||
private Integer perPage;
|
||||
|
||||
/**
|
||||
* Total number of items
|
||||
*
|
||||
*/
|
||||
@JsonProperty("total")
|
||||
@JsonPropertyDescription("Total number of items")
|
||||
private Integer total;
|
||||
|
||||
@JsonProperty("current_page")
|
||||
public Integer getCurrentPage() {
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
@JsonProperty("current_page")
|
||||
public void setCurrentPage(Integer currentPage) {
|
||||
this.currentPage = currentPage;
|
||||
}
|
||||
|
||||
@JsonProperty("last_page")
|
||||
public Integer getLastPage() {
|
||||
return lastPage;
|
||||
}
|
||||
|
||||
@JsonProperty("last_page")
|
||||
public void setLastPage(Integer lastPage) {
|
||||
this.lastPage = lastPage;
|
||||
}
|
||||
|
||||
@JsonProperty("per_page")
|
||||
public Integer getPerPage() {
|
||||
return perPage;
|
||||
}
|
||||
|
||||
@JsonProperty("per_page")
|
||||
public void setPerPage(Integer perPage) {
|
||||
this.perPage = perPage;
|
||||
}
|
||||
|
||||
@JsonProperty("total")
|
||||
public Integer getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
@JsonProperty("total")
|
||||
public void setTotal(Integer total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
}
|
@ -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 );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue