-
Notifications
You must be signed in to change notification settings - Fork 0
Update version to 0.2.6.4-STABLE, add ExampleUsages class, and implem… #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/main/java/fr/sandro642/github/example/ExampleUsages.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| package fr.sandro642.github.example; | ||
|
|
||
| import fr.sandro642.github.ConnectLib; | ||
| import fr.sandro642.github.api.ApiFactory; | ||
| import fr.sandro642.github.enums.MethodType; | ||
| import fr.sandro642.github.enums.ResourceType; | ||
| import fr.sandro642.github.enums.VersionType; | ||
| import fr.sandro642.github.jobs.JobGetInfos; | ||
| import fr.sandro642.github.utils.ConvertEnum; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| /** | ||
| * 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 { | ||
|
|
||
| public enum ExampleRoutes implements ConvertEnum.RouteImport { | ||
| EXAMPLE_ROUTE("/api/example/route"); | ||
|
|
||
| final String route; | ||
|
|
||
| ExampleRoutes(String route) { | ||
| this.route = route; | ||
| } | ||
|
|
||
| @Override | ||
| public String route() { | ||
| return route; | ||
| } | ||
| } | ||
|
|
||
| public void initializeLib() { | ||
|
|
||
| // Optionally, you can specify routes if needed | ||
| ConnectLib.initialize(ResourceType.MAIN_RESOURCES, ExampleRoutes.class); | ||
| // You can also initialize without specifying routes | ||
| ConnectLib.initialize(ResourceType.MAIN_RESOURCES); | ||
| } | ||
|
|
||
| // Add methods here to demonstrate how to use the ConnectLib library | ||
| // For example, you can create methods to make API calls, handle responses, etc. | ||
|
|
||
| // Example method to demonstrate usage | ||
| public void exampleMethodSync() { | ||
| // This method can be used to demonstrate how to interact with the API | ||
| // For example, making a GET request to the EXAMPLE_ROUTE | ||
| ApiFactory response = ConnectLib.JobGetInfos() | ||
| .getRoutes(VersionType.V1_BRANCH, MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE) | ||
| .getResponse() | ||
| .block(); | ||
|
|
||
| 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")); | ||
| } | ||
|
|
||
| // Example method to demonstrate asynchronous usage | ||
| public void exampleMethodAsync() { | ||
| try { | ||
| // This method can be used to demonstrate how to interact with the API asynchronously | ||
|
|
||
| // Create a CompletableFuture to handle the asynchronous response | ||
| CompletableFuture<ApiFactory> futureResponse = new CompletableFuture<>(); | ||
|
|
||
| ConnectLib.JobGetInfos() | ||
| .getRoutes(VersionType.V1_BRANCH, MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE) | ||
| .getResponse() | ||
| .subscribe( | ||
| futureResponse::complete, | ||
| futureResponse::completeExceptionally | ||
| ); | ||
|
|
||
| // Handle the response when it completes | ||
| ApiFactory response = futureResponse.get(10, 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 (java.util.concurrent.TimeoutException e) { | ||
| System.err.println("The operation timed out: " + e.getMessage()); | ||
| } 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(); | ||
|
|
||
| ConnectLib.JobGetInfos().getRoutes(VersionType.V1_BRANCH, MethodType.GET, ExampleRoutes.EXAMPLE_ROUTE, body, params); | ||
| 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); | ||
| 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); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.