Add many new endpoints

Coverage of the API is sitting around 40%/50%
pull/9/head
Hammy 3 years ago
parent 087a2ce3d2
commit 7b0d341183

@ -2,8 +2,10 @@ package me.goudham;
import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory; import com.fasterxml.jackson.databind.type.TypeFactory;
import me.goudham.util.Season;
import me.goudham.api.entity.series.FilteredSeries; import me.goudham.api.entity.series.FilteredSeries;
import me.goudham.api.entity.series.Series; 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.FilteredWaifu;
import me.goudham.api.entity.waifu.Waifu; import me.goudham.api.entity.waifu.Waifu;
import me.goudham.exception.APIMapperException; import me.goudham.exception.APIMapperException;
@ -21,6 +23,7 @@ import java.util.concurrent.ExecutionException;
/** /**
* Returns API information to {@link MyWaifuClient} * Returns API information to {@link MyWaifuClient}
*
*/ */
public class APIWrapper { public class APIWrapper {
private final String version = "1.0"; private final String version = "1.0";
@ -97,8 +100,13 @@ public class APIWrapper {
} }
Response<FilteredWaifu> getDailyWaifu() throws APIResponseException, APIMapperException { Response<FilteredWaifu> getDailyWaifu() throws APIResponseException, APIMapperException {
Result waifuResult = sendRequest(httpClient, "meta/daily"); Result dailyWaifuResult = sendRequest(httpClient, "meta/daily");
return apiMapper.deserialize(waifuResult, FilteredWaifu.class); return apiMapper.deserialize(dailyWaifuResult, FilteredWaifu.class);
}
Response<FilteredWaifu> getRandomWaifu() throws APIResponseException, APIMapperException {
Result randomWaifuResult = sendRequest(httpClient, "meta/random");
return apiMapper.deserialize(randomWaifuResult, FilteredWaifu.class);
} }
Response<Series> getSeries(String param) throws APIResponseException, APIMapperException { Response<Series> getSeries(String param) throws APIResponseException, APIMapperException {
@ -106,8 +114,38 @@ public class APIWrapper {
return apiMapper.deserialize(seriesResult, Series.class); return apiMapper.deserialize(seriesResult, Series.class);
} }
Response<List<FilteredSeries>> getAiringAnime() throws APIResponseException, APIMapperException { Response<List<FilteredSeries>> getSeasonalAnime() throws APIResponseException, APIMapperException {
Result seriesResult = sendRequest(httpClient, "airing"); Result seasonalAnimeResult = sendRequest(httpClient, "airing");
return apiMapper.deserialize(seriesResult, listOf(FilteredSeries.class)); return apiMapper.deserialize(seasonalAnimeResult, listOf(FilteredSeries.class));
}
Response<List<FilteredWaifu>> getBestWaifus() throws APIResponseException, APIMapperException {
Result waifuResults = sendRequest(httpClient, "airing/best");
return apiMapper.deserialize(waifuResults, listOf(FilteredWaifu.class));
}
Response<List<FilteredWaifu>> getPopularWaifus() throws APIResponseException, APIMapperException {
Result waifuResults = sendRequest(httpClient, "airing/popular");
return apiMapper.deserialize(waifuResults, listOf(FilteredWaifu.class));
}
Response<List<FilteredWaifu>> getTrashWaifus() throws APIResponseException, APIMapperException {
Result waifuResults = sendRequest(httpClient, "airing/trash");
return apiMapper.deserialize(waifuResults, listOf(FilteredWaifu.class));
}
Response<List<FilteredSeries>> getAllSeries(Season season, Integer year) throws APIResponseException, APIMapperException {
Result allSeriesResult = sendRequest(httpClient, "airing/" + season.getSeason() + "/" + year);
return apiMapper.deserialize(allSeriesResult, listOf(FilteredSeries.class));
}
Response<List<FilteredWaifu>> getSeriesWaifus(String param) throws APIResponseException, APIMapperException {
Result allWaifusFromSeriesResults = sendRequest(httpClient, "series/" + param + "/waifus");
return apiMapper.deserialize(allWaifusFromSeriesResults, listOf(FilteredWaifu.class));
}
Response<User> getUserProfile(String param) throws APIResponseException, APIMapperException {
Result userProfileResult = sendRequest(httpClient, "user/" + param);
return apiMapper.deserialize(userProfileResult, User.class);
} }
} }

@ -1,7 +1,9 @@
package me.goudham; package me.goudham;
import me.goudham.util.Season;
import me.goudham.api.entity.series.FilteredSeries; import me.goudham.api.entity.series.FilteredSeries;
import me.goudham.api.entity.series.Series; 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.FilteredWaifu;
import me.goudham.api.entity.waifu.Waifu; import me.goudham.api.entity.waifu.Waifu;
import me.goudham.exception.APIMapperException; import me.goudham.exception.APIMapperException;
@ -35,7 +37,7 @@ public class MyWaifuClient {
* @param httpClient The underlying {@link HttpClient} to use for HttpRequests * @param httpClient The underlying {@link HttpClient} to use for HttpRequests
* *
*/ */
MyWaifuClient(@NotNull String apiKey, HttpClient httpClient) { MyWaifuClient(@NotNull String apiKey, @NotNull HttpClient httpClient) {
APIWrapper = new APIWrapper(apiKey, httpClient); APIWrapper = new APIWrapper(apiKey, httpClient);
} }
@ -59,7 +61,7 @@ public class MyWaifuClient {
return APIWrapper.getWaifu(slug); return APIWrapper.getWaifu(slug);
} }
public Response<Waifu> getWaifu(@NotNull Integer id) throws APIResponseException, APIMapperException { Response<Waifu> getWaifu(@NotNull Integer id) throws APIResponseException, APIMapperException {
return APIWrapper.getWaifu(String.valueOf(id)); return APIWrapper.getWaifu(String.valueOf(id));
} }
@ -67,22 +69,59 @@ public class MyWaifuClient {
return APIWrapper.getDailyWaifu(); return APIWrapper.getDailyWaifu();
} }
public Response<FilteredWaifu> getRandomWaifu() throws APIResponseException, APIMapperException {
return APIWrapper.getRandomWaifu();
}
public Response<Series> getSeries(@NotNull String param) throws APIMapperException, APIResponseException {
return APIWrapper.getSeries(param);
}
public Response<Series> getSeries(@NotNull Integer id) throws APIMapperException, APIResponseException { public Response<Series> getSeries(@NotNull Integer id) throws APIMapperException, APIResponseException {
return APIWrapper.getSeries(String.valueOf(id)); return APIWrapper.getSeries(String.valueOf(id));
} }
public Response<List<FilteredSeries>> getAiringAnime() throws APIMapperException, APIResponseException { public Response<List<FilteredSeries>> getSeasonalAnime() throws APIMapperException, APIResponseException {
return APIWrapper.getAiringAnime(); 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<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));
} }
/** /**
* Builder for MyWaifuClient * Builder for {@link MyWaifuClient}
*
*/ */
public static class Builder { public static class Builder {
private final String apiKey; private final String apiKey;
private final HttpClient.Builder httpClientBuilder = HttpClient.newBuilder(); private final HttpClient.Builder httpClientBuilder = HttpClient.newBuilder();
public Builder(String apiKey) { public Builder(@NotNull String apiKey) {
this.apiKey = apiKey; this.apiKey = apiKey;
} }
@ -91,27 +130,27 @@ public class MyWaifuClient {
return this; return this;
} }
public Builder withConnectTimeout(Duration duration) { public Builder withConnectTimeout(@NotNull Duration duration) {
httpClientBuilder.connectTimeout(duration); httpClientBuilder.connectTimeout(duration);
return this; return this;
} }
public Builder withSslParameters(SSLParameters sslParameters) { public Builder withSslParameters(@NotNull SSLParameters sslParameters) {
httpClientBuilder.sslParameters(sslParameters); httpClientBuilder.sslParameters(sslParameters);
return this; return this;
} }
public Builder withExecutor(Executor executor) { public Builder withExecutor(@NotNull Executor executor) {
httpClientBuilder.executor(executor); httpClientBuilder.executor(executor);
return this; return this;
} }
public Builder withFollowRedirects(HttpClient.Redirect policy) { public Builder withFollowRedirects(@NotNull HttpClient.Redirect policy) {
httpClientBuilder.followRedirects(policy); httpClientBuilder.followRedirects(policy);
return this; return this;
} }
public Builder withVersion(HttpClient.Version version) { public Builder withVersion(@NotNull HttpClient.Version version) {
httpClientBuilder.version(version); httpClientBuilder.version(version);
return this; return this;
} }
@ -121,12 +160,12 @@ public class MyWaifuClient {
return this; return this;
} }
public Builder withProxy(ProxySelector proxySelector) { public Builder withProxy(@NotNull ProxySelector proxySelector) {
httpClientBuilder.proxy(proxySelector); httpClientBuilder.proxy(proxySelector);
return this; return this;
} }
public Builder withAuthenticator(Authenticator authenticator) { public Builder withAuthenticator(@NotNull Authenticator authenticator) {
httpClientBuilder.authenticator(authenticator); httpClientBuilder.authenticator(authenticator);
return this; return this;
} }

Loading…
Cancel
Save