From b7ea189164c0dd2e2a40217891c61f81ccf61465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haylee=20Sch=C3=A4fer?= Date: Tue, 19 Nov 2024 11:29:20 +0100 Subject: [PATCH] update readme example --- README.md | 50 ++++++++++++------- tests/src/main/java/org/mineskin/Example.java | 2 +- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 1e1c810..28ca13b 100644 --- a/README.md +++ b/README.md @@ -7,27 +7,38 @@ You can also use [mineskin.org](https://mineskin.org) to directly generate skin The API requires official Minecraft accounts to upload the skin textures. If you own a Minecraft account you don't actively use and want to contibute to the API's speed, -please [add your account here](https://mineskin.org/account)! +please [add your account here](https://account.mineskin.org)! ```java public class Example { private static final MineSkinClient CLIENT = MineSkinClient.builder() .requestHandler(JsoupRequestHandler::new) - .userAgent("MyMineSkinApp/v1.0") - .apiKey("your-api-key") + .userAgent("MyMineSkinApp/v1.0") // TODO: update this with your own user agent + .apiKey("your-api-key") // TODO: update this with your own API key (https://account.mineskin.org/keys) .build(); - public static void main(String[] args) throws FileNotFoundException { - GenerateOptions options = GenerateOptions.create() + public static void main(String[] args) { + File file = new File("skin.png"); + GenerateRequest request = GenerateRequest.upload(file) .name("My Skin") .visibility(Visibility.PUBLIC); - File file = new File("skin.jpg"); - CLIENT.generateUpload(file, options) - .thenAccept(response -> { - // get generated skin - Skin skin = response.getSkin(); - System.out.println(skin); + // submit queue request + CLIENT.queue().submit(request) + .thenCompose(queueResponse -> { + JobInfo job = queueResponse.getJob(); + // wait for job completion + return job.waitForCompletion(CLIENT); + }) + .thenCompose(jobResponse -> { + // get skin from job or load it from the API + return jobResponse.getOrLoadSkin(CLIENT); + }) + .thenAccept(skinInfo -> { + // do stuff with the skin + System.out.println(skinInfo); + System.out.println(skinInfo.texture().data().value()); + System.out.println(skinInfo.texture().data().signature()); }) .exceptionally(throwable -> { throwable.printStackTrace(); @@ -37,13 +48,16 @@ public class Example { if (throwable instanceof MineSkinRequestException requestException) { // get error details - MineSkinResponse response = requestException.getResponse(); - System.out.println(response.getMessageOrError()); + MineSkinResponse response = requestException.getResponse(); + Optional detailsOptional = response.getErrorOrMessage(); + detailsOptional.ifPresent(details -> { + System.out.println(details.code() + ": " + details.message()); + }); } return null; }); - CLIENT.getSkinByUuid("skinuuid") + CLIENT.skins().get("skinuuid") .thenAccept(response -> { // get existing skin Skin skin = response.getSkin(); @@ -60,24 +74,24 @@ public class Example { org.mineskin java-client - 2.1.1-SNAPSHOT + 3.0.0-SNAPSHOT org.mineskin java-client-jsoup - 2.1.1-SNAPSHOT + 3.0.0-SNAPSHOT - + - + ``` diff --git a/tests/src/main/java/org/mineskin/Example.java b/tests/src/main/java/org/mineskin/Example.java index be3c83a..86c9b4c 100644 --- a/tests/src/main/java/org/mineskin/Example.java +++ b/tests/src/main/java/org/mineskin/Example.java @@ -21,7 +21,7 @@ public class Example { .apiKey("your-api-key") // TODO: update this with your own API key (https://account.mineskin.org/keys) .build(); - public static void main(String[] args) throws FileNotFoundException { + public static void main(String[] args) { File file = new File("skin.png"); GenerateRequest request = GenerateRequest.upload(file) .name("My Skin")