From 7c80d76c0a71dd2f1ddb30b448fda696c3c30ceb Mon Sep 17 00:00:00 2001 From: jalpp <92553013+jalpp@users.noreply.github.com> Date: Wed, 17 Apr 2024 22:42:25 -0400 Subject: [PATCH] add docs and fix page size change --- src/main/java/Fide/FideClient.java | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/Fide/FideClient.java b/src/main/java/Fide/FideClient.java index 6e725ff..10eb643 100644 --- a/src/main/java/Fide/FideClient.java +++ b/src/main/java/Fide/FideClient.java @@ -11,11 +11,15 @@ // represents the FIDE API client for Java +// Feel free to use the client in your codebase +// Full documentation for the API at http://fide.thanh.se/docs/index.html + public class FideClient { private static final String API_ENDPOINT = "https://fide.thanh.se/api/players"; + public FideClient(){ } @@ -26,12 +30,17 @@ public static void main(String[] args) { System.out.println(res); } + /** + * get the Top n (size) players by rating band of (bandName) + * size: the size of page + * bandName: the rating band + */ public static String getTopNPlayerForNRatingBand(int size, String bandName){ try { - //'fide.thanh.se/api/players?sort_by=standard&order=desc&size=10' - URL url = new URL(API_ENDPOINT + "?sort_by=" + bandName + "&order=desc&size=" + size); + + URL url = new URL(API_ENDPOINT + "?sort_by=" + bandName + "&order=desc&page_size=" + size); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); @@ -67,11 +76,16 @@ public static String getTopNPlayerForNRatingBand(int size, String bandName){ } + /** + * run a query on the fide api by providing query and searchTag + * query: query fields in FIDE API + * searchTag: the value to be searched for + */ + public static String getQueryByTag(String query, String searchTag){ try { - //'fide.thanh.se/api/players?sort_by=standard&order=desc&size=10' URL url = new URL(API_ENDPOINT + "?" + query+ "=" + searchTag); @@ -108,6 +122,11 @@ public static String getQueryByTag(String query, String searchTag){ } + /** + * creates a Top10 leaderboard String builder String, used for Discord app, can also be used for debugging + * responseData: A JSON FIDE data in string format + */ + public static String StringfyResponse(String responseData) { try { @@ -130,6 +149,7 @@ public static String StringfyResponse(String responseData) { } } + // helper method used in the app and command /fide public static String getTopNInString(String ratingBand, int size){ String res = getTopNPlayerForNRatingBand(size, ratingBand);