Skip to content

Commit

Permalink
add docs and fix page size change
Browse files Browse the repository at this point in the history
  • Loading branch information
jalpp authored Apr 18, 2024
1 parent 6d7b11b commit 7c80d76
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/main/java/Fide/FideClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(){

}
Expand All @@ -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();
Expand Down Expand Up @@ -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);


Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down

0 comments on commit 7c80d76

Please sign in to comment.