Skip to content

Commit f6f13e9

Browse files
authored
Merge pull request #47 from Sandro642/feature/customTypeVersion
Feature/custom type version
2 parents 2dcd09d + 0886a86 commit f6f13e9

9 files changed

Lines changed: 72 additions & 28 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/example/ExampleUsages.java

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

1112
import java.util.Map;
@@ -25,7 +26,7 @@ public class ExampleUsages {
2526

2627
private ConnectLib connectLib = new ConnectLib();
2728

28-
public enum ExampleRoutes implements EnumLoader.RouteImport {
29+
public enum ExampleRoutes implements RouteImport {
2930
EXAMPLE_ROUTE("/api/example/route");
3031

3132
final String route;
@@ -35,7 +36,7 @@ public enum ExampleRoutes implements EnumLoader.RouteImport {
3536
}
3637

3738
@Override
38-
public String route() {
39+
public String getRoute() {
3940
return route;
4041
}
4142
}

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+
* RouteImport is an interface that should be implemented by enums that provide a route.
5+
* Enums implementing this interface must define the route() method to return their associated route as a String.
6+
*/
7+
8+
public interface RouteImport {
9+
10+
/**
11+
* Gets the route associated with the enum constant.
12+
* @return the route as a String
13+
*/
14+
String getRoute();
15+
}
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/main/java/fr/sandro642/github/misc/EnumLoader.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package fr.sandro642.github.misc;
22

3+
import fr.sandro642.github.jobs.RouteImport;
4+
35
import java.util.HashMap;
46
import java.util.Map;
57

@@ -13,14 +15,6 @@
1315

1416
public class EnumLoader {
1517

16-
/**
17-
* RouteImport is an interface that should be implemented by enums that provide a route.
18-
* Enums implementing this interface must define the route() method to return their associated route as a String.
19-
*/
20-
public interface RouteImport {
21-
String route();
22-
}
23-
2418
/**
2519
* Converts an enum class that implements RouteImport into a map.
2620
* The keys of the map are the enum constants, and the values are their corresponding routes.
@@ -33,7 +27,7 @@ public static Map<Enum<?>, String> convertRouteImport(Class<? extends Enum<?>> e
3327
HashMap<Enum<?>, String> map = new HashMap<>();
3428
for (Enum<?> e : enums) {
3529
if (e instanceof RouteImport routeImport) {
36-
map.put((Enum<?>) routeImport, routeImport.route());
30+
map.put((Enum<?>) routeImport, routeImport.getRoute());
3731
}
3832
}
3933
return map;

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
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.RouteImport;
10+
import fr.sandro642.github.jobs.VersionProvider;
1011
import fr.sandro642.github.misc.EnumLoader;
11-
import fr.sandro642.github.misc.Logger;
1212
import org.junit.jupiter.api.Test;
1313

1414
import java.util.Map;
@@ -26,7 +26,7 @@ public class MainTest {
2626

2727
private static ConnectLib connectLib = new ConnectLib();
2828

29-
public enum TestRoutes implements EnumLoader.RouteImport {
29+
public enum TestRoutes implements RouteImport {
3030
HELLO("/hello"),
3131
GREET("/greet$name$")
3232
;
@@ -38,14 +38,30 @@ public enum TestRoutes implements EnumLoader.RouteImport {
3838
}
3939

4040
@Override
41-
public String route() {
41+
public String getRoute() {
4242
return route;
4343
}
4444
}
4545

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

5167

0 commit comments

Comments
 (0)