diff --git a/src/main/java/org/goudham/me/MyWaifuClient.java b/src/main/java/org/goudham/me/MyWaifuClient.java index bc174e3..9fde196 100644 --- a/src/main/java/org/goudham/me/MyWaifuClient.java +++ b/src/main/java/org/goudham/me/MyWaifuClient.java @@ -26,7 +26,7 @@ public class MyWaifuClient { *
See MyWaifuList for obtaining an API Key
* @param apiKey API Key to authorise API request */ - public MyWaifuClient(@NotNull String apiKey) { + MyWaifuClient(@NotNull String apiKey) { myWaifuWrapper = new MyWaifuWrapper(apiKey); } @@ -47,6 +47,14 @@ public class MyWaifuClient { return myWaifuClient; } + public void getWaifu(String slug) { + myWaifuWrapper.getWaifu(httpClient, slug); + } + + public void getWaifu(Integer id) { + myWaifuWrapper.getWaifu(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 f116755..15dfa4c 100644 --- a/src/main/java/org/goudham/me/MyWaifuWrapper.java +++ b/src/main/java/org/goudham/me/MyWaifuWrapper.java @@ -1,13 +1,25 @@ package org.goudham.me; +import com.fasterxml.jackson.databind.ObjectMapper; + +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.concurrent.CompletableFuture; + + /** * Returns API information to {@link MyWaifuClient} */ class MyWaifuWrapper { private final String version = "1.0"; - private final String host = "https://mywaifulist.moe/api/v1/"; + private static final String host = "https://mywaifulist.moe/api/v1/"; private final String apiKey; + private final ObjectMapper objectMapper = new ObjectMapper(); + /** * Instantiates an instance of {@link MyWaifuWrapper} to retrieve API Information * @param apiKey API Key to authorise API request @@ -15,4 +27,45 @@ class MyWaifuWrapper { MyWaifuWrapper(String apiKey) { this.apiKey = apiKey; } + + private void sendRequest(HttpClient httpClient, String param) { + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create(host + param)) + .version(httpClient.version()) + .timeout(Duration.ofSeconds(30)) + .header("Content-Type", "application/json") + .header("apikey", apiKey) + .GET() + .build(); + + CompletableFuture