Skip to content

Commit 292eef8

Browse files
committed
Refactor version handling: replace VersionType with VersionProvider interface and update version to 0.3.6-STABLE
1 parent 2dcd09d commit 292eef8

6 files changed

Lines changed: 48 additions & 15 deletions

File tree

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.5-STABLE
20+
Stable Version: 0.3.6-STABLE
2121
```
2222

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

116116
dependencies {
117117

118-
implementation("fr.sandro642.github:ConnectLib:0.3.5-STABLE")
118+
implementation("fr.sandro642.github:ConnectLib:0.3.6-STABLE")
119119

120120
}
121121

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

1010
tasks.register('printVersion') {
1111
doLast {
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
package fr.sandro642.github.enums;
22

3+
import fr.sandro642.github.jobs.VersionProvider;
4+
35
/**
46
* VersionType is an enumeration representing different versions of the ConnectLib library.
57
*
68
* @author Sandro642
79
* @version 1.0
810
*/
911

10-
public enum VersionType {
12+
public enum VersionType implements VersionProvider {
1113
V1_BRANCH("v1"),
1214
V2_BRANCH("v2"),
1315
V3_BRANCH("v3"),
1416
V4_BRANCH("v4"),
1517
V5_BRANCH("v5");
1618

17-
private final String Version;
19+
private final String version;
1820

1921
VersionType(String version) {
20-
this.Version = version;
22+
this.version = version;
2123
}
2224

25+
@Override
2326
public String getVersion() {
24-
return Version;
27+
return version;
2528
}
2629
}

src/main/java/fr/sandro642/github/jobs/JobGetInfos.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private String getRouteName(Enum<?> routeName) {
6161
* @param body Body of the request for POST (can be null for GET)
6262
* @return JobGetInfos for chaining
6363
*/
64-
public JobGetInfos getRoutes(VersionType versionType, MethodType methodType, Enum<?> routeName, Map<String, ?> body) {
64+
public JobGetInfos getRoutes(VersionProvider versionType, MethodType methodType, Enum<?> routeName, Map<String, ?> body) {
6565
return getRoutes(versionType, methodType, getRouteName(routeName), body, null, null);
6666
}
6767

@@ -72,7 +72,7 @@ public JobGetInfos getRoutes(VersionType versionType, MethodType methodType, Enu
7272
* @param routeName Name of the route in the YAML file
7373
* @return JobGetInfos for chaining
7474
*/
75-
public JobGetInfos getRoutes(VersionType versionType, MethodType methodType, Enum<?> routeName) {
75+
public JobGetInfos getRoutes(VersionProvider versionType, MethodType methodType, Enum<?> routeName) {
7676
return getRoutes(versionType, methodType, getRouteName(routeName), null, null, null);
7777
}
7878

@@ -125,7 +125,7 @@ public JobGetInfos getRoutes(MethodType methodType, String routeName) {
125125
* @param routeName Nom de la route dans le fichier YAML
126126
* @return JobGetInfos pour chaînage
127127
*/
128-
public JobGetInfos getRoutes(VersionType versionType, MethodType methodType, String routeName) {
128+
public JobGetInfos getRoutes(VersionProvider versionType, MethodType methodType, String routeName) {
129129
return getRoutes(versionType, methodType, routeName, null, null, null);
130130
}
131131

@@ -137,7 +137,7 @@ public JobGetInfos getRoutes(VersionType versionType, MethodType methodType, Str
137137
* @param body Body of the request for POST (can be null for GET)
138138
* @return JobGetInfos for chaining
139139
*/
140-
public JobGetInfos getRoutes(VersionType versionType, MethodType methodType, String routeName, Map<String, ?> body) {
140+
public JobGetInfos getRoutes(VersionProvider versionType, MethodType methodType, String routeName, Map<String, ?> body) {
141141
return getRoutes(versionType, methodType, routeName, body, null, null);
142142
}
143143

@@ -176,7 +176,7 @@ public JobGetInfos getRoutes(MethodType methodType, Enum<?> routeName, Map<Strin
176176
* @param query Additional query parameters for the request
177177
* @return JobGetInfos for chaining
178178
*/
179-
public <R> JobGetInfos getRoutes(VersionType versionType, MethodType methodType, R routeName, Map<String, ?> body, Map<String, ?> params, Map<String, ?> query) {
179+
public <R> JobGetInfos getRoutes(VersionProvider versionType, MethodType methodType, R routeName, Map<String, ?> body, Map<String, ?> params, Map<String, ?> query) {
180180
try {
181181
String route = connectLib.getRoute(routeName.toString().toLowerCase());
182182

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package fr.sandro642.github.jobs;
2+
3+
/**
4+
* VersionProvider is an interface that provides a method to get the version of a class implementing it.
5+
* Classes implementing this interface must define the getVersion() method to return their version as a String
6+
*/
7+
8+
public interface VersionProvider {
9+
10+
/**
11+
* Gets the version of the class implementing this interface.
12+
* @return the version as a String
13+
*/
14+
String getVersion();
15+
}

src/test/java/fr/sandro642/github/test/MainTest.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
import fr.sandro642.github.enums.LangType;
77
import fr.sandro642.github.enums.MethodType;
88
import fr.sandro642.github.enums.ResourceType;
9-
import fr.sandro642.github.enums.VersionType;
9+
import fr.sandro642.github.jobs.VersionProvider;
1010
import fr.sandro642.github.misc.EnumLoader;
11-
import fr.sandro642.github.misc.Logger;
1211
import org.junit.jupiter.api.Test;
1312

1413
import java.util.Map;
@@ -43,9 +42,25 @@ public String route() {
4342
}
4443
}
4544

45+
public enum TestCustomVersion implements VersionProvider {
46+
DEV_BRANCH("dev"),
47+
;
48+
49+
private final String version;
50+
51+
TestCustomVersion(String version) {
52+
this.version = version;
53+
}
54+
55+
@Override
56+
public String getVersion() {
57+
return version;
58+
}
59+
}
60+
4661
@Test
4762
public void initializeCAPI() {
48-
connectLib.Init(ResourceType.TEST_RESOURCES, LangType.ENGLISH);
63+
connectLib.Init(ResourceType.TEST_RESOURCES, LangType.ENGLISH, TestRoutes.class);
4964
}
5065

5166

0 commit comments

Comments
 (0)