|
| 1 | +package fr.sandro642.github.example; |
| 2 | + |
| 3 | +import fr.sandro642.github.ConnectLib; |
| 4 | +import fr.sandro642.github.api.ApiFactory; |
| 5 | +import fr.sandro642.github.enums.MethodType; |
| 6 | +import fr.sandro642.github.enums.ResourceType; |
| 7 | +import fr.sandro642.github.enums.VersionType; |
| 8 | +import fr.sandro642.github.jobs.JobGetInfos; |
| 9 | +import fr.sandro642.github.utils.ConvertEnum; |
| 10 | + |
| 11 | +import java.util.Map; |
| 12 | +import java.util.concurrent.CompletableFuture; |
| 13 | + |
| 14 | +/** |
| 15 | + * ExampleUsages is a placeholder class that can be used to demonstrate how to use the ConnectLib library. |
| 16 | + * It can contain example methods or code snippets that show how to interact with the API, handle responses, |
| 17 | + * and utilize the features provided by the ConnectLib library. |
| 18 | + * |
| 19 | + * @author Sandro642 |
| 20 | + * @version 1.0 |
| 21 | + */ |
| 22 | + |
| 23 | +public class ExampleUsages { |
| 24 | + |
| 25 | + public enum ExampleRoutes implements ConvertEnum.RouteImport { |
| 26 | + EXAMPLE_ROUTE("/api/example/route"); |
| 27 | + |
| 28 | + final String route; |
| 29 | + |
| 30 | + ExampleRoutes(String route) { |
| 31 | + this.route = route; |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + public String route() { |
| 36 | + return route; |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + public void initializeLib() { |
| 41 | + |
| 42 | + // Optionally, you can specify routes if needed |
| 43 | + ConnectLib.initialize(ResourceType.MAIN_RESOURCES, ExampleRoutes.class); |
| 44 | + // You can also initialize without specifying routes |
| 45 | + ConnectLib.initialize(ResourceType.MAIN_RESOURCES); |
| 46 | + } |
| 47 | + |
| 48 | + // Add methods here to demonstrate how to use the ConnectLib library |
| 49 | + // For example, you can create methods to make API calls, handle responses, etc. |
| 50 | + |
| 51 | + // Example method to demonstrate usage |
| 52 | + public void exampleMethodSync() { |
| 53 | + // This method can be used to demonstrate how to interact with the API |
| 54 | + // For example, making a GET request to the EXAMPLE_ROUTE |
| 55 | + ApiFactory response = ConnectLib.JobGetInfos() |
| 56 | + .getRoutes(VersionType.V1_BRANCH, MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE) |
| 57 | + .getResponse() |
| 58 | + .block(); |
| 59 | + |
| 60 | + System.out.println(response.display()); |
| 61 | + System.out.println("Response Code: " + response.getData("code")); |
| 62 | + System.out.println("Response Message: " + response.getData("message")); |
| 63 | + System.out.println("Response Data: " + response.getSpecData("data", "exampleKey")); |
| 64 | + } |
| 65 | + |
| 66 | + // Example method to demonstrate asynchronous usage |
| 67 | + public void exampleMethodAsync() { |
| 68 | + try { |
| 69 | + // This method can be used to demonstrate how to interact with the API asynchronously |
| 70 | + |
| 71 | + // Create a CompletableFuture to handle the asynchronous response |
| 72 | + CompletableFuture<ApiFactory> futureResponse = new CompletableFuture<>(); |
| 73 | + |
| 74 | + ConnectLib.JobGetInfos() |
| 75 | + .getRoutes(VersionType.V1_BRANCH, MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE) |
| 76 | + .getResponse() |
| 77 | + .subscribe( |
| 78 | + futureResponse::complete, |
| 79 | + futureResponse::completeExceptionally |
| 80 | + ); |
| 81 | + |
| 82 | + // Handle the response when it completes |
| 83 | + ApiFactory response = futureResponse.get(10, TimeUnit.SECONDS); |
| 84 | + |
| 85 | + System.out.println(response.display()); |
| 86 | + System.out.println("Response Code: " + response.getData("code")); |
| 87 | + System.out.println("Response Message: " + response.getData("message")); |
| 88 | + System.out.println("Response Data: " + response.getSpecData("data", "exampleKey")); |
| 89 | + } catch (java.util.concurrent.TimeoutException e) { |
| 90 | + System.err.println("The operation timed out: " + e.getMessage()); |
| 91 | + } catch (Exception e) { |
| 92 | + e.printStackTrace(); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + // Example to use all methods in JobGetInfos |
| 97 | + public void exampleJobGetInfos() { |
| 98 | + Map<String, ?> body = Map.of(); |
| 99 | + Map<String,?> params = Map.of(); |
| 100 | + |
| 101 | + ConnectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE, body, params); |
| 102 | + ConnectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.POST, ExampleRoutes.EXAMPLE_ROUTE, body); |
| 103 | + ConnectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.PUT, ExampleRoutes.EXAMPLE_ROUTE, null, params); |
| 104 | + ConnectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.PATCH, ExampleRoutes.EXAMPLE_ROUTE); |
| 105 | + ConnectLib.JobGetInfos().getRoutes(MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE, body, params); |
| 106 | + ConnectLib.JobGetInfos().getRoutes(MethodType.POST, ExampleRoutes.EXAMPLE_ROUTE, body); |
| 107 | + ConnectLib.JobGetInfos().getRoutes(MethodType.DELETE, ExampleRoutes.EXAMPLE_ROUTE); |
| 108 | + } |
| 109 | + |
| 110 | +} |
0 commit comments