Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ And if you thought APIs were complicated, think again! With ConnectLib, it's lik

---

```java
```java[build.gradle](build.gradle)
Support Lib : Java 23

Hook -----------------------|
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'fr.sandro642.github'
version = '0.3.8-STABLE'
version = '0.3.8.1-DEV_BUILD'

// Générer une classe de version automatiquement
task generateVersionClass {
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/fr/sandro642/github/ConnectLib.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package fr.sandro642.github;

import fr.sandro642.github.enums.LangType;
import fr.sandro642.github.enums.ResourceType;
import fr.sandro642.github.enums.lang.CategoriesType;
import fr.sandro642.github.hook.HookManager;
import fr.sandro642.github.hook.LangSupport;
import fr.sandro642.github.hook.MCSupport;
import fr.sandro642.github.misc.*;
import fr.sandro642.github.jobs.JobGetInfos;
import fr.sandro642.github.enums.ResourceType;
import fr.sandro642.github.misc.*;
import fr.sandro642.github.update.RetrieveLastVersion;

import java.util.HashMap;
Expand All @@ -16,6 +16,7 @@
/**
* ConnectLib is the main class of the ConnectorAPI library for Standard API.
* It provides methods to initialize the library with resource types, routes, and schemas,
*
* @author Sandro642
* @version 1.0
* @see ConnectLib#JobGetInfos()
Expand All @@ -33,15 +34,16 @@ public class ConnectLib {
private static Logger logger = new Logger();
private static StoreAndRetrieve storeAndRetrieve = new StoreAndRetrieve();
private static YamlUtils yamlUtils = new YamlUtils();
private static final Map<String,String> routes = new HashMap<>();
private static final Map<String, String> routes = new HashMap<>();
private static Logs logs = new Logs();
private static LangManager langManager;
private static RetrieveLastVersion rlv;

/**
* Init the ConnectLib with the specified resource type and routes.
*
* @param resourceType the type of resource to initialize
* @param routes the routes to be used in the ConnectLib
* @param routes the routes to be used in the ConnectLib
*/
public void Init(ResourceType resourceType, LangType langType, Class<? extends Enum<?>>... routes) {
try {
Expand Down Expand Up @@ -87,6 +89,7 @@ public void Init(ResourceType resourceType, LangType langType, Class<? extends E

/**
* Return the route associated with the given route name.
*
* @param routeName the name of the route to retrieve
* @return the route as a String
*/
Expand All @@ -101,6 +104,7 @@ public String getRoute(String routeName) {

/**
* Return an instance of JobGetInfos.
*
* @return JobGetInfos instance
*/
public JobGetInfos JobGetInfos() {
Expand All @@ -109,6 +113,7 @@ public JobGetInfos JobGetInfos() {

/**
* Return the instance of Logger.
*
* @return Logger instance
*/
public Logger Logger() {
Expand All @@ -120,6 +125,7 @@ public Logger Logger() {

/**
* Return the instance of StoreAndRetrieve.
*
* @return StoreAndRetrieve instance
*/
public StoreAndRetrieve StoreAndRetrieve() {
Expand All @@ -131,6 +137,7 @@ public StoreAndRetrieve StoreAndRetrieve() {

/**
* Return the instance of YamlUtils.
*
* @return YamlUtils instance
*/
public YamlUtils YamlUtils() {
Expand All @@ -142,6 +149,7 @@ public YamlUtils YamlUtils() {

/**
* Return the instance of Logs.
*
* @return Logs instance
*/
public MCSupport MCSupport() {
Expand All @@ -150,6 +158,7 @@ public MCSupport MCSupport() {

/**
* Return the instance of HookManager.
*
* @return HookManager instance
*/
public HookManager HookManager() {
Expand All @@ -158,6 +167,7 @@ public HookManager HookManager() {

/**
* Return the instance of LangSupport.
*
* @return LangSupport instance
*/
public LangSupport LangSupport() {
Expand All @@ -167,6 +177,7 @@ public LangSupport LangSupport() {

/**
* Return the instance of LangManager.
*
* @return LangManager instance
*/
public LangManager LangManager() {
Expand Down
28 changes: 19 additions & 9 deletions src/main/java/fr/sandro642/github/api/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ApiClient extends ApiFactory {
/**
* connectLib is an instance of ConnectLib that provides access to the library's configuration and utilities.
*/
private ConnectLib connectLib = new ConnectLib();
private final ConnectLib connectLib = new ConnectLib();

/**
* WebClient is a non-blocking, reactive HTTP client for making requests to the API.
Expand Down Expand Up @@ -63,13 +63,15 @@ public ApiClient(String baseUrlLambda) {

/**
* Method to call the API with a GET request.
*
* @param routeName Name of the route to call.
* @return a Mono that emits the ApiFactory response containing the parsed JSON data.
*/
public Mono<ApiFactory> callAPIGet(String routeName) {
connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.get", Map.of("routename", routeName)));

record ResponseData(int statusCode, String body) {}
record ResponseData(int statusCode, String body) {
}

return webClient.get()
.uri(routeName)
Expand All @@ -92,14 +94,16 @@ record ResponseData(int statusCode, String body) {}

/**
* Method to call the API with a POST request.
*
* @param routeName Name of the route to call.
* @param body Body of the request (can be null for a request without body).
* @param body Body of the request (can be null for a request without body).
* @return a Mono that emits the ApiFactory response containing the parsed JSON data.
*/
public Mono<ApiFactory> callAPIPost(String routeName, Map<String, Object> body) {
connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.post", Map.of("routename", routeName)));

record ResponseData(int statusCode, String body) {}
record ResponseData(int statusCode, String body) {
}

return webClient.post()
.uri(routeName)
Expand All @@ -123,14 +127,16 @@ record ResponseData(int statusCode, String body) {}

/**
* Method to call the API with a PUT request.
*
* @param routeName Name of the route to call.
* @param body Body of the request (can be null for a request without body).
* @param body Body of the request (can be null for a request without body).
* @return a Mono that emits the ApiFactory response containing the parsed JSON data.
*/
public Mono<ApiFactory> callAPIPut(String routeName, Map<String, Object> body) {
connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.put", Map.of("routename", routeName)));

record ResponseData(int statusCode, String body) {}
record ResponseData(int statusCode, String body) {
}

return webClient.put()
.uri(routeName)
Expand All @@ -154,14 +160,16 @@ record ResponseData(int statusCode, String body) {}

/**
* Method to call the API with a PATCH request.
*
* @param routeName Name of the route to call.
* @param body Body of the request (can be null for a request without body).
* @param body Body of the request (can be null for a request without body).
* @return a Mono that emits the ApiFactory response containing the parsed JSON data.
*/
public Mono<ApiFactory> callAPIPatch(String routeName, Map<String, Object> body) {
connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.patch", Map.of("routename", routeName)));

record ResponseData(int statusCode, String body) {}
record ResponseData(int statusCode, String body) {
}

return webClient.patch()
.uri(routeName)
Expand All @@ -185,13 +193,15 @@ record ResponseData(int statusCode, String body) {}

/**
* Method to call the API with a DELETE request.
*
* @param routeName Name of the route to call.
* @return a Mono that emits the ApiFactory response containing the parsed JSON data.
*/
public Mono<ApiFactory> callAPIDelete(String routeName) {
connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.delete", Map.of("routename", routeName)));

record ResponseData(int statusCode, String body) {}
record ResponseData(int statusCode, String body) {
}

return webClient.delete()
.uri(routeName)
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/fr/sandro642/github/api/ApiFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ApiFactory {
/**
* connectLib is an instance of ConnectLib that provides access to the library's configuration and utilities.
*/
private ConnectLib connectLib = new ConnectLib();
private final ConnectLib connectLib = new ConnectLib();

/**
* rawData is a Map that holds the parsed JSON data.
Expand Down Expand Up @@ -49,7 +49,8 @@ protected void parseFromRawJson(String rawJson) {
this.rawJson = rawJson;
try {
ObjectMapper mapper = new ObjectMapper();
this.rawData = mapper.readValue(rawJson, new TypeReference<Map<String, Object>>() {});
this.rawData = mapper.readValue(rawJson, new TypeReference<Map<String, Object>>() {
});
} catch (Exception e) {
connectLib.Logger().ERROR(connectLib.LangManager().getMessage(CategoriesType.APIFACTORY_CLASS, "parsefromrawjson.error", Map.of("json", rawJson, "exception", e.getMessage())));
}
Expand Down Expand Up @@ -99,8 +100,7 @@ public <O, K> Object getSpecData(O type, K value) {
}

Object nested = rawData.get(type.toString().toLowerCase());
if (nested instanceof Map) {
Map<?, ?> nestedMap = (Map<?, ?>) nested;
if (nested instanceof Map<?, ?> nestedMap) {
return nestedMap.get(value.toString().toLowerCase());
}
} catch (Exception e) {
Expand Down Expand Up @@ -136,11 +136,11 @@ public int getStatusCode() {
*/
public Object display() {
try {
if (rawData == null) {
connectLib.Logger().ERROR(connectLib.LangManager().getMessage(CategoriesType.APIFACTORY_CLASS, "general.mustbe"));
return null;
}
return rawData;
if (rawData == null) {
connectLib.Logger().ERROR(connectLib.LangManager().getMessage(CategoriesType.APIFACTORY_CLASS, "general.mustbe"));
return null;
}
return rawData;
} catch (Exception e) {
connectLib.Logger().ERROR(connectLib.LangManager().getMessage(CategoriesType.APIFACTORY_CLASS, "display.error", "exception", e.getMessage()));
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/fr/sandro642/github/enums/LangType.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum LangType {

/**
* Constructor to initialize the language code.
*
* @param lang
*/
LangType(String lang) {
Expand All @@ -31,6 +32,7 @@ public enum LangType {

/**
* Get the language code.
*
* @return the language code string
*/
public String getLang() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum CategoriesType {

/**
* Constructor to initialize the category.
*
* @param category
*/
CategoriesType(String category) {
Expand All @@ -38,6 +39,7 @@ public enum CategoriesType {

/**
* Get the category.
*
* @return the category string
*/
public String getCategory() {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/fr/sandro642/github/example/ExampleUsages.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import fr.sandro642.github.enums.ResourceType;
import fr.sandro642.github.enums.VersionType;
import fr.sandro642.github.jobs.RouteImport;
import fr.sandro642.github.misc.EnumLoader;

import java.util.Map;
import java.util.concurrent.CompletableFuture;
Expand All @@ -24,7 +23,7 @@

public class ExampleUsages {

private ConnectLib connectLib = new ConnectLib();
private final ConnectLib connectLib = new ConnectLib();

public enum ExampleRoutes implements RouteImport {
EXAMPLE_ROUTE("/api/example/route");
Expand Down Expand Up @@ -93,7 +92,7 @@ public void exampleMethodAsync() {
// Example to use all methods in JobGetInfos
public void exampleJobGetInfos() {
Map<String, ?> body = Map.of();
Map<String,?> params = Map.of();
Map<String, ?> params = Map.of();
Map<String, ?> query = Map.of();

connectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE, body, params, query);
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/fr/sandro642/github/hook/HookManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import fr.sandro642.github.ConnectLib;
import fr.sandro642.github.enums.ResourceType;
import fr.sandro642.github.enums.lang.CategoriesType;
import fr.sandro642.github.misc.Logger;

/**
* HookManager is a class that manages hooks for different resource types.
* It allows for the initialization and management of hooks based on the specified resource type.
* @see HookManager#BASE_PATH()
* @see HookManager#FILE_LOCATION_KEY()
*
* @author Sandro642
* @version 1.0
* @see HookManager#BASE_PATH()
* @see HookManager#FILE_LOCATION_KEY()
*/

public class HookManager {
Expand All @@ -26,7 +26,7 @@ public class HookManager {
* connectLib is an instance of ConnectLib that provides access to the library's configuration and utilities.
* It is used throughout the HookManager class to log messages and access other functionalities.
*/
private ConnectLib connectLib = new ConnectLib();
private final ConnectLib connectLib = new ConnectLib();

/**
* Initializes the HookManager with the specified resource type.
Expand All @@ -43,8 +43,8 @@ public class HookManager {
* @return the initialized resource type
*/
public ResourceType initHook(ResourceType resourceType) {
this.resourceType = resourceType;
return this.resourceType;
HookManager.resourceType = resourceType;
return HookManager.resourceType;
}

/**
Expand All @@ -55,7 +55,7 @@ public ResourceType initHook(ResourceType resourceType) {
public void FILE_LOCATION_KEY() {
switch (resourceType) {
case MC_RESOURCES:
connectLib.StoreAndRetrieve().store.put(connectLib.StoreAndRetrieve().FILE_LOCATION_KEY, connectLib.MCSupport().getPluginPath());
connectLib.StoreAndRetrieve().store.put(connectLib.StoreAndRetrieve().FILE_LOCATION_KEY, connectLib.MCSupport().getPluginPath());
break;
case MAIN_RESOURCES, TEST_RESOURCES:
connectLib.StoreAndRetrieve().store.put(connectLib.StoreAndRetrieve().FILE_LOCATION_KEY, resourceType.getPath());
Expand Down
Loading