-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleUsages.java
More file actions
107 lines (86 loc) · 4.37 KB
/
ExampleUsages.java
File metadata and controls
107 lines (86 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package fr.sandro642.github.example;
import fr.sandro642.github.ConnectLib;
import fr.sandro642.github.api.ApiFactory;
import fr.sandro642.github.enums.LangType;
import fr.sandro642.github.enums.MethodType;
import fr.sandro642.github.enums.ResourceType;
import fr.sandro642.github.enums.VersionType;
import fr.sandro642.github.provider.RouteImport;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
/**
* ExampleUsages is a placeholder class that can be used to demonstrate how to use the ConnectLib library.
* It can contain example methods or code snippets that show how to interact with the API, handle responses,
* and utilize the features provided by the ConnectLib library.
*
* @author Sandro642
* @version 1.0
*/
public class ExampleUsages {
private ConnectLib connectLib = new ConnectLib();
public enum ExampleRoutes implements RouteImport {
EXAMPLE_ROUTE("/api/example/route");
final String route;
ExampleRoutes(String route) {
this.route = route;
}
@Override
public String getRoute() {
return route;
}
}
public void initializeLib() {
// Optionally, you can specify routes if needed
connectLib.init(ResourceType.MAIN_RESOURCES, LangType.FRENCH, ExampleRoutes.class);
// You can also initialize without specifying routes
connectLib.init(ResourceType.MAIN_RESOURCES, LangType.FRENCH);
}
// Example method to demonstrate usage
public void exampleMethodSync() {
try {
// This method can be used to demonstrate how to interact with the API
// For example, making a GET request to the EXAMPLE_ROUTE
CompletableFuture<ApiFactory> apiFactoryCompletableFuture = connectLib.JobGetInfos()
.getRoutes(VersionType.V1_BRANCH, MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE)
.getResponse();
ApiFactory response = apiFactoryCompletableFuture.get(5, TimeUnit.SECONDS);
System.out.println(response.display());
System.out.println("Response Code: " + response.getData("code"));
System.out.println("Response Message: " + response.getData("message"));
System.out.println("Response Data: " + response.getSpecData("data", "exampleKey"));
System.out.println("Status Code: " + response.getStatusCode());
} catch (Exception e) {
e.printStackTrace();
}
}
// Example method to demonstrate asynchronous usage
public void exampleMethodAsync() {
try {
// This method can be used to demonstrate how to interact with the API asynchronously
CompletableFuture<ApiFactory> apiFactoryCompletableFuture = connectLib.JobGetInfos()
.getRoutes(VersionType.V1_BRANCH, MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE)
.getResponse();
ApiFactory response = apiFactoryCompletableFuture.get(5, TimeUnit.SECONDS);
System.out.println(response.display());
System.out.println("Response Code: " + response.getData("code"));
System.out.println("Response Message: " + response.getData("message"));
System.out.println("Response Data: " + response.getSpecData("data", "exampleKey"));
} catch (Exception e) {
e.printStackTrace();
}
}
// Example to use all methods in JobGetInfos
public void exampleJobGetInfos() {
Map<String, ?> body = 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);
connectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.POST, ExampleRoutes.EXAMPLE_ROUTE, body);
connectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.PUT, ExampleRoutes.EXAMPLE_ROUTE, null, params, query);
connectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.PATCH, ExampleRoutes.EXAMPLE_ROUTE);
connectLib.JobGetInfos().getRoutes(MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE, body, params);
connectLib.JobGetInfos().getRoutes(MethodType.POST, ExampleRoutes.EXAMPLE_ROUTE, body);
connectLib.JobGetInfos().getRoutes(MethodType.DELETE, ExampleRoutes.EXAMPLE_ROUTE);
}
}