From 10669b8e4c3bff3c44e75368799bfa63457d00e8 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Sun, 28 Apr 2024 21:29:22 -0400 Subject: [PATCH] Update README.md --- README.md | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2254b90..1ec4f81 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ A Java API wrapper for the [Pelican](https://pelican.dev) and [Pterodactyl](http - [Maven](#maven) - [Gradle (Kotlin DSL)](#gradle-kotlin-dsl) - [Getting Started](#-getting-started) + - [Creating A Client](#creating-a-pelican-client) --- @@ -40,7 +41,48 @@ implementation("me.braydon:Pelican4J:VERSION") ``` ## 🏃‍♂️ Getting Started -`TODO` +Below is an example on how to create a client, and send an action to the panel. + +```java +Pelican4J client = Pelican4J.forPelican(ClientConfig.builder() + .panelUrl("https://pelican.app") + .apiKey("YOUR_API_KEY") + .build()); // Create a new Pelican client + +// Queuing an action - this will get the node with the ID of 1, and print it's name. +ApplicationNodeActions nodeActions = client.actions().application().nodes(); +nodeActions.getDetails(1).queue(node -> { + System.out.println("Name of node: " + node.getName()); +}); + +// Instantly sending an action +Node node = nodeActions.getDetails(1).execute(); +System.out.println("Name of node: " + node.getName()); +``` + +## 🔨 Panel Actions +Every action that is executed on the panel will return a [PanelAction](./src/main/java/me/braydon/pelican/action/PanelAction.java), this action has several different functions: + +- `queue(callback)` - This will allow you to queue an action, and await its response asynchronously. +- `execute()` - This will immediately execute the action synchronously, and return the result. + +### ⌛ Rate Limiting +When an action is being queued, it will try to immediately execute the action, and if a rate limit is hit, that action will be queued to be re-tried later once the rate limit has been lifted. If the action is re-tried more than **25 Times**, it will respond with an error. + +### ⚠️ Error Handling +When an error is raised by the panel API, an [PanelAPIException](./src/main/java/me/braydon/pelican/exception/PanelAPIException.java) exception will be thrown. + +When queuing an action, errors are automatically handled and are printed to the terminal. To handle the error yourself, you can modify the callback function to contain both the response, and the exception: +```java +ApplicationNodeActions nodeActions = client.actions().application().nodes(); +nodeActions.getDetails(1).queue((node, ex) -> { + if (ex != null) { + // Handle the error... + return; + } + // ... +}); +``` ---