Skip to content

Commit 875a73c

Browse files
authored
Merge pull request #52 from Sandro642/DEV/BRANCH-0.3.8.1
Dev/branch 0.3.8.1
2 parents 3b42b3f + 0de1a0b commit 875a73c

23 files changed

Lines changed: 326 additions & 261 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ And if you thought APIs were complicated, think again! With ConnectLib, it's lik
1616
1717
---
1818

19-
```java
19+
```java[build.gradle](build.gradle)
2020
Support Lib : Java 23
2121
2222
Hook -----------------------|

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = 'fr.sandro642.github'
8-
version = '0.3.8-STABLE'
8+
version = '0.3.8.1-DEV_BUILD'
99

1010
// Générer une classe de version automatiquement
1111
task generateVersionClass {

src/main/java/fr/sandro642/github/ConnectLib.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package fr.sandro642.github;
22

33
import fr.sandro642.github.enums.LangType;
4+
import fr.sandro642.github.enums.ResourceType;
45
import fr.sandro642.github.enums.lang.CategoriesType;
56
import fr.sandro642.github.hook.HookManager;
67
import fr.sandro642.github.hook.LangSupport;
78
import fr.sandro642.github.hook.MCSupport;
8-
import fr.sandro642.github.misc.*;
99
import fr.sandro642.github.jobs.JobGetInfos;
10-
import fr.sandro642.github.enums.ResourceType;
10+
import fr.sandro642.github.misc.*;
1111
import fr.sandro642.github.update.RetrieveLastVersion;
1212

1313
import java.util.HashMap;
@@ -16,6 +16,7 @@
1616
/**
1717
* ConnectLib is the main class of the ConnectorAPI library for Standard API.
1818
* It provides methods to initialize the library with resource types, routes, and schemas,
19+
*
1920
* @author Sandro642
2021
* @version 1.0
2122
* @see ConnectLib#JobGetInfos()
@@ -33,15 +34,16 @@ public class ConnectLib {
3334
private static Logger logger = new Logger();
3435
private static StoreAndRetrieve storeAndRetrieve = new StoreAndRetrieve();
3536
private static YamlUtils yamlUtils = new YamlUtils();
36-
private static final Map<String,String> routes = new HashMap<>();
37+
private static final Map<String, String> routes = new HashMap<>();
3738
private static Logs logs = new Logs();
3839
private static LangManager langManager;
3940
private static RetrieveLastVersion rlv;
4041

4142
/**
4243
* Init the ConnectLib with the specified resource type and routes.
44+
*
4345
* @param resourceType the type of resource to initialize
44-
* @param routes the routes to be used in the ConnectLib
46+
* @param routes the routes to be used in the ConnectLib
4547
*/
4648
public void Init(ResourceType resourceType, LangType langType, Class<? extends Enum<?>>... routes) {
4749
try {
@@ -87,6 +89,7 @@ public void Init(ResourceType resourceType, LangType langType, Class<? extends E
8789

8890
/**
8991
* Return the route associated with the given route name.
92+
*
9093
* @param routeName the name of the route to retrieve
9194
* @return the route as a String
9295
*/
@@ -101,6 +104,7 @@ public String getRoute(String routeName) {
101104

102105
/**
103106
* Return an instance of JobGetInfos.
107+
*
104108
* @return JobGetInfos instance
105109
*/
106110
public JobGetInfos JobGetInfos() {
@@ -109,6 +113,7 @@ public JobGetInfos JobGetInfos() {
109113

110114
/**
111115
* Return the instance of Logger.
116+
*
112117
* @return Logger instance
113118
*/
114119
public Logger Logger() {
@@ -120,6 +125,7 @@ public Logger Logger() {
120125

121126
/**
122127
* Return the instance of StoreAndRetrieve.
128+
*
123129
* @return StoreAndRetrieve instance
124130
*/
125131
public StoreAndRetrieve StoreAndRetrieve() {
@@ -131,6 +137,7 @@ public StoreAndRetrieve StoreAndRetrieve() {
131137

132138
/**
133139
* Return the instance of YamlUtils.
140+
*
134141
* @return YamlUtils instance
135142
*/
136143
public YamlUtils YamlUtils() {
@@ -142,6 +149,7 @@ public YamlUtils YamlUtils() {
142149

143150
/**
144151
* Return the instance of Logs.
152+
*
145153
* @return Logs instance
146154
*/
147155
public MCSupport MCSupport() {
@@ -150,6 +158,7 @@ public MCSupport MCSupport() {
150158

151159
/**
152160
* Return the instance of HookManager.
161+
*
153162
* @return HookManager instance
154163
*/
155164
public HookManager HookManager() {
@@ -158,6 +167,7 @@ public HookManager HookManager() {
158167

159168
/**
160169
* Return the instance of LangSupport.
170+
*
161171
* @return LangSupport instance
162172
*/
163173
public LangSupport LangSupport() {
@@ -167,6 +177,7 @@ public LangSupport LangSupport() {
167177

168178
/**
169179
* Return the instance of LangManager.
180+
*
170181
* @return LangManager instance
171182
*/
172183
public LangManager LangManager() {

src/main/java/fr/sandro642/github/api/ApiClient.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ApiClient extends ApiFactory {
2424
/**
2525
* connectLib is an instance of ConnectLib that provides access to the library's configuration and utilities.
2626
*/
27-
private ConnectLib connectLib = new ConnectLib();
27+
private final ConnectLib connectLib = new ConnectLib();
2828

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

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

72-
record ResponseData(int statusCode, String body) {}
73+
record ResponseData(int statusCode, String body) {
74+
}
7375

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

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

102-
record ResponseData(int statusCode, String body) {}
105+
record ResponseData(int statusCode, String body) {
106+
}
103107

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

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

133-
record ResponseData(int statusCode, String body) {}
138+
record ResponseData(int statusCode, String body) {
139+
}
134140

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

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

164-
record ResponseData(int statusCode, String body) {}
171+
record ResponseData(int statusCode, String body) {
172+
}
165173

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

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

194-
record ResponseData(int statusCode, String body) {}
203+
record ResponseData(int statusCode, String body) {
204+
}
195205

196206
return webClient.delete()
197207
.uri(routeName)

src/main/java/fr/sandro642/github/api/ApiFactory.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ApiFactory {
2121
/**
2222
* connectLib is an instance of ConnectLib that provides access to the library's configuration and utilities.
2323
*/
24-
private ConnectLib connectLib = new ConnectLib();
24+
private final ConnectLib connectLib = new ConnectLib();
2525

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

101102
Object nested = rawData.get(type.toString().toLowerCase());
102-
if (nested instanceof Map) {
103-
Map<?, ?> nestedMap = (Map<?, ?>) nested;
103+
if (nested instanceof Map<?, ?> nestedMap) {
104104
return nestedMap.get(value.toString().toLowerCase());
105105
}
106106
} catch (Exception e) {
@@ -136,11 +136,11 @@ public int getStatusCode() {
136136
*/
137137
public Object display() {
138138
try {
139-
if (rawData == null) {
140-
connectLib.Logger().ERROR(connectLib.LangManager().getMessage(CategoriesType.APIFACTORY_CLASS, "general.mustbe"));
141-
return null;
142-
}
143-
return rawData;
139+
if (rawData == null) {
140+
connectLib.Logger().ERROR(connectLib.LangManager().getMessage(CategoriesType.APIFACTORY_CLASS, "general.mustbe"));
141+
return null;
142+
}
143+
return rawData;
144144
} catch (Exception e) {
145145
connectLib.Logger().ERROR(connectLib.LangManager().getMessage(CategoriesType.APIFACTORY_CLASS, "display.error", "exception", e.getMessage()));
146146
}

src/main/java/fr/sandro642/github/enums/LangType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public enum LangType {
2323

2424
/**
2525
* Constructor to initialize the language code.
26+
*
2627
* @param lang
2728
*/
2829
LangType(String lang) {
@@ -31,6 +32,7 @@ public enum LangType {
3132

3233
/**
3334
* Get the language code.
35+
*
3436
* @return the language code string
3537
*/
3638
public String getLang() {

src/main/java/fr/sandro642/github/enums/lang/CategoriesType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public enum CategoriesType {
3030

3131
/**
3232
* Constructor to initialize the category.
33+
*
3334
* @param category
3435
*/
3536
CategoriesType(String category) {
@@ -38,6 +39,7 @@ public enum CategoriesType {
3839

3940
/**
4041
* Get the category.
42+
*
4143
* @return the category string
4244
*/
4345
public String getCategory() {

src/main/java/fr/sandro642/github/example/ExampleUsages.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import fr.sandro642.github.enums.ResourceType;
88
import fr.sandro642.github.enums.VersionType;
99
import fr.sandro642.github.jobs.RouteImport;
10-
import fr.sandro642.github.misc.EnumLoader;
1110

1211
import java.util.Map;
1312
import java.util.concurrent.CompletableFuture;
@@ -24,7 +23,7 @@
2423

2524
public class ExampleUsages {
2625

27-
private ConnectLib connectLib = new ConnectLib();
26+
private final ConnectLib connectLib = new ConnectLib();
2827

2928
public enum ExampleRoutes implements RouteImport {
3029
EXAMPLE_ROUTE("/api/example/route");
@@ -93,7 +92,7 @@ public void exampleMethodAsync() {
9392
// Example to use all methods in JobGetInfos
9493
public void exampleJobGetInfos() {
9594
Map<String, ?> body = Map.of();
96-
Map<String,?> params = Map.of();
95+
Map<String, ?> params = Map.of();
9796
Map<String, ?> query = Map.of();
9897

9998
connectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE, body, params, query);

src/main/java/fr/sandro642/github/hook/HookManager.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import fr.sandro642.github.ConnectLib;
44
import fr.sandro642.github.enums.ResourceType;
55
import fr.sandro642.github.enums.lang.CategoriesType;
6-
import fr.sandro642.github.misc.Logger;
76

87
/**
98
* HookManager is a class that manages hooks for different resource types.
109
* It allows for the initialization and management of hooks based on the specified resource type.
11-
* @see HookManager#BASE_PATH()
12-
* @see HookManager#FILE_LOCATION_KEY()
10+
*
1311
* @author Sandro642
1412
* @version 1.0
13+
* @see HookManager#BASE_PATH()
14+
* @see HookManager#FILE_LOCATION_KEY()
1515
*/
1616

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

3131
/**
3232
* Initializes the HookManager with the specified resource type.
@@ -43,8 +43,8 @@ public class HookManager {
4343
* @return the initialized resource type
4444
*/
4545
public ResourceType initHook(ResourceType resourceType) {
46-
this.resourceType = resourceType;
47-
return this.resourceType;
46+
HookManager.resourceType = resourceType;
47+
return HookManager.resourceType;
4848
}
4949

5050
/**
@@ -55,7 +55,7 @@ public ResourceType initHook(ResourceType resourceType) {
5555
public void FILE_LOCATION_KEY() {
5656
switch (resourceType) {
5757
case MC_RESOURCES:
58-
connectLib.StoreAndRetrieve().store.put(connectLib.StoreAndRetrieve().FILE_LOCATION_KEY, connectLib.MCSupport().getPluginPath());
58+
connectLib.StoreAndRetrieve().store.put(connectLib.StoreAndRetrieve().FILE_LOCATION_KEY, connectLib.MCSupport().getPluginPath());
5959
break;
6060
case MAIN_RESOURCES, TEST_RESOURCES:
6161
connectLib.StoreAndRetrieve().store.put(connectLib.StoreAndRetrieve().FILE_LOCATION_KEY, resourceType.getPath());

0 commit comments

Comments
 (0)