Skip to content

Commit

Permalink
[feature] Adicionado novo endpoint na API v2
Browse files Browse the repository at this point in the history
- O método é semelhante com a versão v1, com a diferença que não é possivel receber mais de 1 score.
- Esse metodo foi adicionado recentemente na API V2 (alguns dias atras).
  • Loading branch information
Cristian-Sknz committed Feb 5, 2021
1 parent d895a2c commit 565a770
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.skiincraft.api.osu.requests.impl.endpoint;

import com.google.gson.Gson;
import com.google.gson.JsonParser;
import me.skiincraft.api.osu.entity.beatmap.Beatmap;
import me.skiincraft.api.osu.entity.beatmap.BeatmapSearch;
import me.skiincraft.api.osu.entity.beatmap.BeatmapSet;
Expand Down Expand Up @@ -32,6 +33,7 @@
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -97,6 +99,24 @@ public APIRequest<List<Score>> getUserScore(String username, ScoreOption option)
return getUserScore(getUserId(username).get(), option);
}

@Override
public APIRequest<List<Score>> getUserScore(long userId, long beatmapId) {
return new DefaultAPIRequest<>(URL_V2 + String.format("beatmaps/%s/scores/users/%s", beatmapId, userId),
(response -> {
try {
return Collections.singletonList(new Gson().fromJson(JsonParser.parseString(Objects.requireNonNull(response.body()).string()).getAsJsonObject().get("score"), ScoreImpl.class));
} catch (IOException e) {
e.printStackTrace();
return null;
}
}), token);
}

@Override
public APIRequest<List<Score>> getUserScore(String username, long beatmapId) {
return getUserScore(getUserId(username).get(), beatmapId);
}

@Override
public APIRequest<BeatmapScores> getBeatmapScores(long beatmapId) {
return new DefaultAPIRequest<>(URL_V2 + String.format("beatmaps/%s/scores", beatmapId),
Expand Down

0 comments on commit 565a770

Please sign in to comment.