Skip to content

Commit 5ffae2b

Browse files
committed
Not Static method V 0.3.3 STABLE
1 parent 6c46fbc commit 5ffae2b

15 files changed

Lines changed: 175 additions & 122 deletions

File tree

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.2.1-STABLE'
8+
version = '0.3.3-STABLE'
99

1010
tasks.register('printVersion') {
1111
doLast {

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ And if you thought APIs were complicated, think again! With ConnectLib, it's lik
1717
---
1818

1919
```java
20-
Stable Version: 0.3.2.1-STABLE
20+
Stable Version: 0.3.3-STABLE
2121
```
2222

2323
---
@@ -115,7 +115,7 @@ repositories {
115115

116116
dependencies {
117117

118-
implementation("fr.sandro642.github:ConnectLib:0.3.2.1-STABLE")
118+
implementation("fr.sandro642.github:ConnectLib:0.3.3-STABLE")
119119

120120
}
121121

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

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

33
import fr.sandro642.github.enums.LangType;
4-
import fr.sandro642.github.enums.MethodType;
54
import fr.sandro642.github.enums.lang.CategoriesType;
65
import fr.sandro642.github.hook.HookManager;
76
import fr.sandro642.github.hook.LangSupport;
@@ -42,7 +41,7 @@ public class ConnectLib {
4241
* @param resourceType the type of resource to initialize
4342
* @param routes the routes to be used in the ConnectLib
4443
*/
45-
public static void initialize(ResourceType resourceType, LangType langType, Class<? extends Enum<?>>... routes) {
44+
public void Init(ResourceType resourceType, LangType langType, Class<? extends Enum<?>>... routes) {
4645
try {
4746
logger = new Logger();
4847
storeAndRetrieve = new StoreAndRetrieve();
@@ -58,7 +57,7 @@ public static void initialize(ResourceType resourceType, LangType langType, Clas
5857
Map<Enum<?>, String> routesEnums = new HashMap<>();
5958
for (Class<? extends Enum<?>> route : routes) {
6059
if (route == null) {
61-
ConnectLib.Logger().ERROR(langManager.getMessage(CategoriesType.CONNECTLIB_CLASS, "initialise.routeclass"));
60+
Logger().ERROR(langManager.getMessage(CategoriesType.CONNECTLIB_CLASS, "initialise.routeclass"));
6261
continue;
6362
}
6463
routesEnums.putAll(EnumLoader.convertRouteImport(route));
@@ -77,7 +76,7 @@ public static void initialize(ResourceType resourceType, LangType langType, Clas
7776
ConnectLib.routes.putAll(yamlRoutes);
7877
}
7978
} catch (Exception e) {
80-
ConnectLib.Logger().ERROR(langManager.getMessage(CategoriesType.CONNECTLIB_CLASS, "initialise.catcherror", Map.of("exception", e.getMessage())));
79+
Logger().ERROR(langManager.getMessage(CategoriesType.CONNECTLIB_CLASS, "initialise.catcherror", Map.of("exception", e.getMessage())));
8180
}
8281
}
8382

@@ -86,11 +85,11 @@ public static void initialize(ResourceType resourceType, LangType langType, Clas
8685
* @param routeName the name of the route to retrieve
8786
* @return the route as a String
8887
*/
89-
public static String getRoute(String routeName) {
88+
public String getRoute(String routeName) {
9089
if (routes.containsKey(routeName)) {
9190
return routes.get(routeName);
9291
} else {
93-
ConnectLib.Logger().ERROR(langManager.getMessage(CategoriesType.CONNECTLIB_CLASS, "getroute.error", Map.of("route", routeName)));
92+
Logger().ERROR(langManager.getMessage(CategoriesType.CONNECTLIB_CLASS, "getroute.error", Map.of("route", routeName)));
9493
return null;
9594
}
9695
}
@@ -101,23 +100,23 @@ public static String getRoute(String routeName) {
101100
* @param routeEnum the Enum representing the route
102101
* @return the route as a String
103102
*/
104-
public static String getRoute(Enum<?> routeEnum) {
103+
public String getRoute(Enum<?> routeEnum) {
105104
return getRoute(routeEnum.name().toLowerCase());
106105
}
107106

108107
/**
109108
* Return an instance of JobGetInfos.
110109
* @return JobGetInfos instance
111110
*/
112-
public static JobGetInfos JobGetInfos() {
111+
public JobGetInfos JobGetInfos() {
113112
return new JobGetInfos();
114113
}
115114

116115
/**
117116
* Return the instance of Logger.
118117
* @return Logger instance
119118
*/
120-
public static Logger Logger() {
119+
public Logger Logger() {
121120
if (logger == null) {
122121
logger = new Logger();
123122
}
@@ -128,7 +127,7 @@ public static Logger Logger() {
128127
* Return the instance of StoreAndRetrieve.
129128
* @return StoreAndRetrieve instance
130129
*/
131-
public static StoreAndRetrieve StoreAndRetrieve() {
130+
public StoreAndRetrieve StoreAndRetrieve() {
132131
if (storeAndRetrieve == null) {
133132
storeAndRetrieve = new StoreAndRetrieve();
134133
}
@@ -139,7 +138,7 @@ public static StoreAndRetrieve StoreAndRetrieve() {
139138
* Return the instance of YamlUtils.
140139
* @return YamlUtils instance
141140
*/
142-
public static YamlUtils YamlUtils() {
141+
public YamlUtils YamlUtils() {
143142
if (yamlUtils == null) {
144143
yamlUtils = new YamlUtils();
145144
}
@@ -150,23 +149,23 @@ public static YamlUtils YamlUtils() {
150149
* Return the instance of Logs.
151150
* @return Logs instance
152151
*/
153-
public static MCSupport MCSupport() {
152+
public MCSupport MCSupport() {
154153
return MCSupport.getInstance();
155154
}
156155

157156
/**
158157
* Return the instance of HookManager.
159158
* @return HookManager instance
160159
*/
161-
public static HookManager HookManager() {
160+
public HookManager HookManager() {
162161
return HookManager.getInstance();
163162
}
164163

165164
/**
166165
* Return the instance of LangSupport.
167166
* @return LangSupport instance
168167
*/
169-
public static LangSupport LangSupport() {
168+
public LangSupport LangSupport() {
170169
return LangSupport.getInstance();
171170

172171
}
@@ -175,7 +174,7 @@ public static LangSupport LangSupport() {
175174
* Return the instance of LangManager.
176175
* @return LangManager instance
177176
*/
178-
public static LangManager LangManager() {
177+
public LangManager LangManager() {
179178
return langManager;
180179
}
181180
}

src/main/java/fr/sandro642/github/annotations/AnnotHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
public class AnnotHandler {
3030

31+
private ConnectLib connectLib = new ConnectLib();
32+
3133
/**
3234
* AnnotConnect is an annotation used to mark methods that should be executed when a connection event occurs.
3335
* Methods annotated with this annotation will be invoked by the AnnotHandler when it discovers them.
@@ -68,7 +70,7 @@ private void discoverListeners() {
6870
}
6971
}
7072
} catch (Exception e) {
71-
ConnectLib.Logger().ERROR(ConnectLib.LangManager().getMessage(CategoriesType.ANNOTATION_PACKAGE, "discoverlistener.error"));
73+
connectLib.Logger().ERROR(connectLib.LangManager().getMessage(CategoriesType.ANNOTATION_PACKAGE, "discoverlistener.error"));
7274
}
7375
}
7476

@@ -101,7 +103,7 @@ private List<Class<?>> getClassesInPackage(String packageName) {
101103
}
102104
}
103105
} catch (Exception e) {
104-
ConnectLib.Logger().WARN(ConnectLib.LangManager().getMessage(CategoriesType.ANNOTATION_PACKAGE, "getclassesinpackage.error", Map.of("package", packageName, "exception", e.getMessage())));
106+
connectLib.Logger().WARN(connectLib.LangManager().getMessage(CategoriesType.ANNOTATION_PACKAGE, "getclassesinpackage.error", Map.of("package", packageName, "exception", e.getMessage())));
105107
}
106108
return classes;
107109
}

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

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import fr.sandro642.github.ConnectLib;
44
import fr.sandro642.github.enums.lang.CategoriesType;
5-
import fr.sandro642.github.misc.Logger;
65
import org.springframework.web.reactive.function.client.WebClient;
76
import reactor.core.publisher.Mono;
87
import reactor.core.scheduler.Schedulers;
@@ -22,6 +21,11 @@
2221

2322
public class ApiClient extends ApiFactory {
2423

24+
/**
25+
* connectLib is an instance of ConnectLib that provides access to the library's configuration and utilities.
26+
*/
27+
private ConnectLib connectLib = new ConnectLib();
28+
2529
/**
2630
* WebClient is a non-blocking, reactive HTTP client for making requests to the API.
2731
* It is initialized with the base URL from the ConnectLib configuration.
@@ -34,28 +38,22 @@ public class ApiClient extends ApiFactory {
3438
*/
3539
private final AtomicReference<ApiFactory> lastResponse = new AtomicReference<>();
3640

37-
/**
38-
* logger is an instance of Logger used for logging messages at different levels.
39-
* It provides methods to log informational, warning, error, and critical messages.
40-
*/
41-
private final Logger logger = new Logger();
42-
4341
/**
4442
* response is an instance of ApiFactory that is used to parse and store the raw JSON response from the API.
4543
* It provides methods to handle the response data.
4644
*/
47-
private final ApiFactory response = new ApiFactory();
45+
private final ApiFactory apiFactory = new ApiFactory();
4846

4947
/**
5048
* Constructor for ApiClient.
5149
* It initializes the WebClient with the base URL from the ConnectLib configuration.
5250
* If the base URL is not found, it throws a RuntimeException.
5351
*/
5452
public ApiClient() {
55-
String baseUrl = (String) ConnectLib.StoreAndRetrieve().store.get(ConnectLib.StoreAndRetrieve().URL_KEY);
53+
String baseUrl = (String) connectLib.StoreAndRetrieve().store.get(connectLib.StoreAndRetrieve().URL_KEY);
5654

5755
if (baseUrl == null) {
58-
logger.CRITICAL(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "construct.urlbase"));
56+
connectLib.Logger().CRITICAL(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "construct.urlbase"));
5957
}
6058

6159
this.webClient = WebClient.builder()
@@ -69,20 +67,20 @@ public ApiClient() {
6967
* @return a Mono that emits the ApiFactory response containing the parsed JSON data.
7068
*/
7169
public Mono<ApiFactory> callAPIGet(String routeName) {
72-
logger.INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.get", Map.of("routename", routeName)));
70+
connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.get", Map.of("routename", routeName)));
7371
return webClient.get()
7472
.uri(routeName)
7573
.retrieve()
7674
.bodyToMono(String.class)
7775
.subscribeOn(Schedulers.boundedElastic())
7876
.doOnNext(thread ->
79-
ConnectLib.Logger().INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.threadinuse", "thread", Thread.currentThread().getName())))
77+
connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.threadinuse", "thread", Thread.currentThread().getName())))
8078
.map(rawJson -> {
81-
response.parseFromRawJson(rawJson);
82-
return response;
79+
apiFactory.parseFromRawJson(rawJson);
80+
return apiFactory;
8381
})
8482
.doOnNext(lastResponse::set)
85-
.doOnError(error -> logger.CRITICAL(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "general.error", Map.of("method", "GET", "exception", error.getMessage()))));
83+
.doOnError(error -> connectLib.Logger().CRITICAL(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "general.error", Map.of("method", "GET", "exception", error.getMessage()))));
8684
}
8785

8886
/**
@@ -92,21 +90,21 @@ public Mono<ApiFactory> callAPIGet(String routeName) {
9290
* @return a Mono that emits the ApiFactory response containing the parsed JSON data.
9391
*/
9492
public Mono<ApiFactory> callAPIPost(String routeName, Map<String, Object> body) {
95-
logger.INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.post", Map.of("routename", routeName)));
93+
connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.post", Map.of("routename", routeName)));
9694
return webClient.post()
9795
.uri(routeName)
9896
.bodyValue(body != null ? body : Map.of())
9997
.retrieve()
10098
.bodyToMono(String.class)
10199
.subscribeOn(Schedulers.boundedElastic())
102100
.doOnNext(thread ->
103-
ConnectLib.Logger().INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.threadinuse", "thread", Thread.currentThread().getName())))
101+
connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.threadinuse", "thread", Thread.currentThread().getName())))
104102
.map(rawJson -> {
105-
response.parseFromRawJson(rawJson);
106-
return response;
103+
apiFactory.parseFromRawJson(rawJson);
104+
return apiFactory;
107105
})
108106
.doOnNext(lastResponse::set)
109-
.doOnError(error -> logger.CRITICAL(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "general.error", Map.of("method", "POST", "exception", error.getMessage()))));
107+
.doOnError(error -> connectLib.Logger().CRITICAL(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "general.error", Map.of("method", "POST", "exception", error.getMessage()))));
110108
}
111109

112110
/**
@@ -116,21 +114,21 @@ public Mono<ApiFactory> callAPIPost(String routeName, Map<String, Object> body)
116114
* @return a Mono that emits the ApiFactory response containing the parsed JSON data.
117115
*/
118116
public Mono<ApiFactory> callAPIPut(String routeName, Map<String, Object> body) {
119-
logger.INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.put", Map.of("routename", routeName)));
117+
connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.put", Map.of("routename", routeName)));
120118
return webClient.put()
121119
.uri(routeName)
122120
.bodyValue(body != null ? body : Map.of())
123121
.retrieve()
124122
.bodyToMono(String.class)
125123
.subscribeOn(Schedulers.boundedElastic())
126124
.doOnNext(thread ->
127-
ConnectLib.Logger().INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.threadinuse", "thread", Thread.currentThread().getName())))
125+
connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.threadinuse", "thread", Thread.currentThread().getName())))
128126
.map(rawJson -> {
129-
response.parseFromRawJson(rawJson);
130-
return response;
127+
apiFactory.parseFromRawJson(rawJson);
128+
return apiFactory;
131129
})
132130
.doOnNext(lastResponse::set)
133-
.doOnError(error -> logger.CRITICAL(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "general.error", Map.of("method", "PUT", "exception", error.getMessage()))));
131+
.doOnError(error -> connectLib.Logger().CRITICAL(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "general.error", Map.of("method", "PUT", "exception", error.getMessage()))));
134132
}
135133

136134
/**
@@ -140,21 +138,21 @@ public Mono<ApiFactory> callAPIPut(String routeName, Map<String, Object> body) {
140138
* @return a Mono that emits the ApiFactory response containing the parsed JSON data.
141139
*/
142140
public Mono<ApiFactory> callAPIPatch(String routeName, Map<String, Object> body) {
143-
logger.INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.patch", Map.of("routename", routeName)));
141+
connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.patch", Map.of("routename", routeName)));
144142
return webClient.patch()
145143
.uri(routeName)
146144
.bodyValue(body != null ? body : Map.of())
147145
.retrieve()
148146
.bodyToMono(String.class)
149147
.subscribeOn(Schedulers.boundedElastic())
150148
.doOnNext(thread ->
151-
ConnectLib.Logger().INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.threadinuse", "thread", Thread.currentThread().getName())))
149+
connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.threadinuse", "thread", Thread.currentThread().getName())))
152150
.map(rawJson -> {
153-
response.parseFromRawJson(rawJson);
154-
return response;
151+
apiFactory.parseFromRawJson(rawJson);
152+
return apiFactory;
155153
})
156154
.doOnNext(lastResponse::set)
157-
.doOnError(error -> logger.CRITICAL(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "general.error", Map.of("method", "PATCH", "exception", error.getMessage()))));
155+
.doOnError(error -> connectLib.Logger().CRITICAL(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "general.error", Map.of("method", "PATCH", "exception", error.getMessage()))));
158156
}
159157

160158
/**
@@ -163,19 +161,19 @@ public Mono<ApiFactory> callAPIPatch(String routeName, Map<String, Object> body)
163161
* @return a Mono that emits the ApiFactory response containing the parsed JSON data.
164162
*/
165163
public Mono<ApiFactory> callAPIDelete(String routeName) {
166-
logger.INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.delete", Map.of("routename", routeName)));
164+
connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.delete", Map.of("routename", routeName)));
167165
return webClient.delete()
168166
.uri(routeName)
169167
.retrieve()
170168
.bodyToMono(String.class)
171169
.subscribeOn(Schedulers.boundedElastic())
172170
.doOnNext(thread ->
173-
ConnectLib.Logger().INFO(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.threadinuse", "thread", Thread.currentThread().getName())))
171+
connectLib.Logger().INFO(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "call.threadinuse", "thread", Thread.currentThread().getName())))
174172
.map(rawJson -> {
175-
response.parseFromRawJson(rawJson);
176-
return response;
173+
apiFactory.parseFromRawJson(rawJson);
174+
return apiFactory;
177175
})
178176
.doOnNext(lastResponse::set)
179-
.doOnError(error -> logger.CRITICAL(ConnectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "general.error", Map.of("method", "DELETE", "exception", error.getMessage()))));
177+
.doOnError(error -> connectLib.Logger().CRITICAL(connectLib.LangManager().getMessage(CategoriesType.APICLIENT_CLASS, "general.error", Map.of("method", "DELETE", "exception", error.getMessage()))));
180178
}
181179
}

0 commit comments

Comments
 (0)