finished custom Riot Java API

This commit is contained in:
Sekuramis 2026-02-05 17:43:00 +01:00
commit fa0ba1343d
23 changed files with 1279 additions and 0 deletions

70
build.gradle.kts Normal file
View File

@ -0,0 +1,70 @@
plugins {
java
id("maven-publish")
id("com.gradleup.shadow") version "9.0.0-beta4"
application
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
withSourcesJar()
withJavadocJar()
}
group = "eu.sekunity"
version = "1.0-SNAPSHOT"
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
groupId = project.group.toString()
artifactId = "sekunity-riot-java-api"
version = project.version.toString()
}
}
repositories {
maven {
name = "sekunityRepositoryPrivate"
url = uri("https://repo.sekunity.eu/private")
credentials {
username = findProperty("sekunityUsername") as String? ?: ""
password = findProperty("sekunityPassword") as String? ?: ""
}
authentication {
create<BasicAuthentication>("basic")
}
}
}
}
repositories {
mavenCentral()
}
dependencies {
implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("com.fasterxml.jackson.core:jackson-databind:2.17.2")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.2")
compileOnly("org.projectlombok:lombok:1.18.42")
annotationProcessor("org.projectlombok:lombok:1.18.42")
implementation("org.yaml:snakeyaml:2.5")
}
application {
mainClass.set("eu.sekunity.riot.SekunityRiotAPI")
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
}
tasks.named("shadowJar") {
enabled = false
}

251
gradlew vendored Normal file
View File

@ -0,0 +1,251 @@
#!/bin/sh
#
# Copyright © 2015 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH="\\\"\\\""
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"

94
gradlew.bat vendored Normal file
View File

@ -0,0 +1,94 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
set CLASSPATH=
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

1
settings.gradle.kts Normal file
View File

@ -0,0 +1 @@
rootProject.name = "Sekunity-RiotAPI"

View File

@ -0,0 +1,37 @@
package eu.sekunity.riot.api;
import eu.sekunity.riot.config.RiotApiConfig;
import eu.sekunity.riot.core.RiotHttpClient;
import eu.sekunity.riot.service.AccountService;
import eu.sekunity.riot.service.LeagueService;
import eu.sekunity.riot.service.MatchService;
import eu.sekunity.riot.service.RankService;
import eu.sekunity.riot.service.SummonerService;
import lombok.Getter;
/**
* © Copyright 05.02.2026 - 15:50 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
@Getter
public final class RiotApi {
private final SummonerService summoner;
private final MatchService match;
private final AccountService account;
private final LeagueService league;
private final RankService rank;
public RiotApi(RiotApiConfig config) {
var http = new RiotHttpClient(config);
this.summoner = new SummonerService(http);
this.match = new MatchService(http);
this.account = new AccountService(http);
this.league = new LeagueService(http);
this.rank = new RankService(this.league);
}
}

View File

@ -0,0 +1,45 @@
package eu.sekunity.riot.config;
import eu.sekunity.riot.core.EuRouting;
import lombok.Builder;
import lombok.NonNull;
import lombok.Value;
/**
* © Copyright 05.02.2026 - 15:46 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
@Value
@Builder
public class RiotApiConfig {
@NonNull String apiKey;
@NonNull
EuRouting routing;
@Builder.Default int timeoutMillis = 10_000;
@Builder.Default int maxRetriesOn429 = 2;
public static RiotApiConfig fromYaml(RiotYamlConfig yaml) {
if (yaml == null || yaml.getRiot() == null) {
throw new IllegalStateException("Missing 'riot' section in config.yml");
}
var r = yaml.getRiot();
if (r.getApiKey() == null || r.getApiKey().isBlank()) {
throw new IllegalStateException("riot.api-key is missing in config.yml");
}
return RiotApiConfig.builder()
.apiKey(r.getApiKey())
.routing(EuRouting.valueOf(r.getRegion().toUpperCase()))
.timeoutMillis(r.getTimeoutMillis())
.maxRetriesOn429(r.getMaxRetriesOn429())
.build();
}
}

View File

@ -0,0 +1,24 @@
package eu.sekunity.riot.config;
import lombok.Data;
/**
* © Copyright 05.02.2026 - 15:48 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
@Data
public class RiotYamlConfig {
private Riot riot;
@Data
public static class Riot {
private String apiKey;
private String region = "EUW";
private int timeoutMillis = 10_000;
private int maxRetriesOn429 = 2;
}
}

View File

@ -0,0 +1,42 @@
package eu.sekunity.riot.config;
import java.io.InputStream;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import lombok.experimental.UtilityClass;
/**
* © Copyright 05.02.2026 - 15:49 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
@UtilityClass
public class YamlConfigLoader {
public RiotYamlConfig load() {
InputStream is = YamlConfigLoader.class
.getClassLoader()
.getResourceAsStream("config.yml");
if (is == null) {
throw new IllegalStateException("config.yml not found in resources");
}
LoaderOptions options = new LoaderOptions();
options.setAllowDuplicateKeys(false);
Yaml yaml = new Yaml(new Constructor(RiotYamlConfig.class, options));
RiotYamlConfig cfg = yaml.load(is);
if (cfg == null) {
throw new IllegalStateException("config.yml is empty or invalid");
}
return cfg;
}
}

View File

@ -0,0 +1,24 @@
package eu.sekunity.riot.core;
/**
* © Copyright 05.02.2026 - 15:46 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
public enum EuRouting {
EUW("https://euw1.api.riotgames.com", "https://europe.api.riotgames.com");
private final String platformBaseUrl; // euw1
private final String regionalBaseUrl; // europe
EuRouting(String platformBaseUrl, String regionalBaseUrl) {
this.platformBaseUrl = platformBaseUrl;
this.regionalBaseUrl = regionalBaseUrl;
}
public String platformBaseUrl() { return platformBaseUrl; }
public String regionalBaseUrl() { return regionalBaseUrl; }
}

View File

@ -0,0 +1,143 @@
package eu.sekunity.riot.core;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import okhttp3.Response;
/**
* © Copyright 05.02.2026 - 16:23 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
public final class RateLimiter {
// App-wide: learned from X-App-Rate-Limit (e.g. "20:1,100:120")
private volatile List<Window> appWindows = List.of();
private final Map<Window, Deque<Long>> appHits = new ConcurrentHashMap<>();
// Method-wide per groupKey (e.g. "GET lol/match/v5")
private final Map<String, MethodBucket> methodBuckets = new ConcurrentHashMap<>();
/** Call BEFORE executing a request. Sleeps if we would exceed learned limits. */
public void acquire(String groupKey) {
acquireForWindows(appWindows, appHits);
if (groupKey == null || groupKey.isBlank()) return;
MethodBucket bucket = methodBuckets.get(groupKey);
if (bucket == null) return;
acquireForWindows(bucket.windows, bucket.hits);
}
/** Call AFTER a response. Learns X-App-Rate-Limit and X-Method-Rate-Limit. */
public void learn(Response resp, String groupKey) {
if (resp == null) return;
String appLimit = resp.header("X-App-Rate-Limit");
if (appLimit != null && !appLimit.isBlank()) {
List<Window> parsed = parseWindows(appLimit);
if (!parsed.isEmpty()) {
appWindows = parsed;
for (Window w : parsed) {
appHits.computeIfAbsent(w, __ -> new ArrayDeque<>());
}
}
}
String methodLimit = resp.header("X-Method-Rate-Limit");
if (methodLimit != null && !methodLimit.isBlank() && groupKey != null && !groupKey.isBlank()) {
List<Window> parsed = parseWindows(methodLimit);
if (!parsed.isEmpty()) {
MethodBucket bucket = methodBuckets.computeIfAbsent(groupKey, __ -> new MethodBucket());
bucket.windows = parsed;
for (Window w : parsed) {
bucket.hits.computeIfAbsent(w, __ -> new ArrayDeque<>());
}
}
}
}
// -------- internals --------
private static void acquireForWindows(List<Window> windows, Map<Window, Deque<Long>> hitsByWindow) {
if (windows == null || windows.isEmpty()) return;
while (true) {
long now = System.currentTimeMillis();
long sleepMs = 0;
for (Window w : windows) {
Deque<Long> q = hitsByWindow.get(w);
if (q == null) continue;
synchronized (q) {
prune(q, now, w.windowMillis());
if (q.size() >= w.limit()) {
long oldest = q.peekFirst();
long until = (oldest + w.windowMillis()) - now;
sleepMs = Math.max(sleepMs, Math.max(1, until));
}
}
}
if (sleepMs <= 0) {
long t = System.currentTimeMillis();
for (Window w : windows) {
Deque<Long> q = hitsByWindow.get(w);
if (q == null) continue;
synchronized (q) { q.addLast(t); }
}
return;
}
try {
Thread.sleep(sleepMs);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
}
private static void prune(Deque<Long> q, long now, long windowMs) {
while (!q.isEmpty()) {
long t = q.peekFirst();
if (now - t >= windowMs) q.removeFirst();
else break;
}
}
private static List<Window> parseWindows(String header) {
// "20:1,100:120"
List<Window> out = new ArrayList<>();
for (String part : header.split(",")) {
String p = part.trim();
if (p.isEmpty()) continue;
String[] bits = p.split(":");
if (bits.length != 2) continue;
try {
int limit = Integer.parseInt(bits[0].trim());
int seconds = Integer.parseInt(bits[1].trim());
if (limit > 0 && seconds > 0) out.add(new Window(limit, seconds));
} catch (NumberFormatException ignored) {}
}
out.sort(Comparator.comparingInt(Window::windowSeconds));
return List.copyOf(out);
}
public record Window(int limit, int windowSeconds) {
public long windowMillis() { return windowSeconds * 1000L; }
}
private static final class MethodBucket {
volatile List<Window> windows = List.of();
final Map<Window, Deque<Long>> hits = new ConcurrentHashMap<>();
}
}

View File

@ -0,0 +1,24 @@
package eu.sekunity.riot.core;
import lombok.Getter;
/**
* © Copyright 05.02.2026 - 15:53 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
@Getter
public class RiotApiException extends RuntimeException
{
private final int statusCode;
private final String responseBody;
public RiotApiException(int statusCode, String message, String responseBody) {
super(message);
this.statusCode = statusCode;
this.responseBody = responseBody;
}
}

View File

@ -0,0 +1,116 @@
package eu.sekunity.riot.core;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.sekunity.riot.config.RiotApiConfig;
import okhttp3.*;
import java.io.IOException;
import java.time.Duration;
import java.util.List;
import java.util.Map;
/**
* © Copyright 05.02.2026 - 15:53 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
public final class RiotHttpClient {
private final RiotApiConfig config;
private final OkHttpClient http;
private final ObjectMapper om;
private final RateLimiter rateLimiter = new RateLimiter();
public RiotHttpClient(RiotApiConfig config) {
this.config = config;
this.http = new OkHttpClient.Builder()
.callTimeout(Duration.ofMillis(config.getTimeoutMillis()))
.build();
this.om = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
public <T> T getPlatform(String path, Map<String, String> query, Class<T> type) {
return get(config.getRouting().platformBaseUrl() + path, query, type);
}
public <T> T getRegional(String path, Map<String, String> query, Class<T> type) {
return get(config.getRouting().regionalBaseUrl() + path, query, type);
}
private <T> T get(String url, Map<String, String> query, Class<T> type) {
HttpUrl parsed = HttpUrl.parse(url);
if (parsed == null) throw new IllegalArgumentException("Invalid URL: " + url);
HttpUrl.Builder builder = parsed.newBuilder();
if (query != null) query.forEach(builder::addQueryParameter);
HttpUrl finalUrl = builder.build();
String key = groupKey(finalUrl, "GET");
Request request = new Request.Builder()
.url(finalUrl)
.addHeader("X-Riot-Token", config.getApiKey())
.get()
.build();
int attempt = 0;
while (true) {
attempt++;
rateLimiter.acquire(key);
try (Response resp = http.newCall(request).execute()) {
rateLimiter.learn(resp, key);
int code = resp.code();
String body = resp.body() != null ? resp.body().string() : "";
if (code == 429 && attempt <= (config.getMaxRetriesOn429() + 1)) {
long sleepMs = retryAfterMillis(resp);
try {
Thread.sleep(sleepMs);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new RiotApiException(429, "Interrupted during Retry-After sleep", body);
}
continue;
}
if (code < 200 || code >= 300) {
String msg = "Riot API request failed: HTTP " + code + " | " + finalUrl;
throw new RiotApiException(code, msg, body);
}
if (type == String.class) return type.cast(body);
return om.readValue(body, type);
} catch (com.fasterxml.jackson.core.JsonProcessingException e) {
throw new RiotApiException(-2, "JSON parse error: " + e.getMessage(), null);
} catch (IOException e) {
throw new RiotApiException(-1, "Network/IO error calling Riot API: " + e.getMessage(), null);
}
}
}
private static long retryAfterMillis(Response resp) {
String retryAfter = resp.header("Retry-After");
if (retryAfter != null) {
try {
long seconds = Long.parseLong(retryAfter.trim());
return Math.max(1, seconds) * 1000L;
} catch (NumberFormatException ignored) {}
}
return 1200L;
}
private static String groupKey(HttpUrl url, String httpMethod) {
// /lol/match/v5/... -> "GET lol/match/v5"
var seg = url.pathSegments();
if (seg.size() < 3) return httpMethod + " " + String.join("/", seg);
return httpMethod + " " + seg.get(0) + "/" + seg.get(1) + "/" + seg.get(2);
}
}

View File

@ -0,0 +1,15 @@
package eu.sekunity.riot.dto;
/**
* © Copyright 05.02.2026 - 16:03 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
public record AccountDto(
String puuid,
String gameName,
String tagLine
) {}

View File

@ -0,0 +1,32 @@
package eu.sekunity.riot.dto;
/**
* © Copyright 05.02.2026 - 16:47 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
public record LeagueEntryDto(
String leagueId,
String queueType, // RANKED_SOLO_5x5 / RANKED_FLEX_SR
String tier, // GOLD, PLATINUM, ...
String rank, // I, II, III, IV
String summonerId,
int leaguePoints,
int wins,
int losses,
boolean hotStreak,
boolean veteran,
boolean freshBlood,
boolean inactive,
MiniSeries miniSeries
) {
public record MiniSeries(
int losses,
String progress, // e.g. "WLN"
int target,
int wins
) {}
}

View File

@ -0,0 +1,47 @@
package eu.sekunity.riot.dto;
import java.util.List;
/**
* © Copyright 05.02.2026 - 16:23 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
public record MatchDto(
Metadata metadata,
Info info
) {
public record Metadata(
String dataVersion,
String matchId,
List<String> participants
) {}
public record Info(
long gameCreation,
long gameDuration,
long gameEndTimestamp,
String gameMode,
String gameType,
String gameVersion,
int queueId,
List<Participant> participants
) {}
public record Participant(
String puuid,
String summonerName,
String championName,
int championId,
int teamId,
boolean win,
int kills,
int deaths,
int assists,
int totalMinionsKilled,
int goldEarned
) {}
}

View File

@ -0,0 +1,19 @@
package eu.sekunity.riot.dto;
/**
* © Copyright 05.02.2026 - 15:54 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
public record SummonerDto(
String accountId,
int profileIconId,
long revisionDate,
String name,
String id,
String puuid,
long summonerLevel
) {}

View File

@ -0,0 +1,28 @@
package eu.sekunity.riot.model;
/**
* © Copyright 05.02.2026 - 16:21 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
public record RiotId(String summonerName, String tagline)
{
public static RiotId parse(String riotId) {
if (riotId == null || riotId.isBlank()) {
throw new IllegalArgumentException("riotId must not be blank. Example: \"Name#EUW\"");
}
int idx = riotId.lastIndexOf('#');
if (idx <= 0 || idx == riotId.length() - 1) {
throw new IllegalArgumentException("Invalid riotId format. Expected \"Name#TAG\" but got: " + riotId);
}
String gameName = riotId.substring(0, idx).trim();
String tagLine = riotId.substring(idx + 1).trim();
if (gameName.isEmpty() || tagLine.isEmpty()) {
throw new IllegalArgumentException("Invalid riotId format. Expected \"Name#TAG\" but got: " + riotId);
}
return new RiotId(gameName, tagLine);
}
}

View File

@ -0,0 +1,48 @@
package eu.sekunity.riot.service;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import eu.sekunity.riot.core.RiotHttpClient;
import eu.sekunity.riot.dto.AccountDto;
import eu.sekunity.riot.model.RiotId;
import lombok.RequiredArgsConstructor;
/**
* © Copyright 05.02.2026 - 16:04 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
@RequiredArgsConstructor
public final class AccountService {
private final RiotHttpClient client;
public AccountDto getByRiotId(String riotId) {
RiotId parsed = RiotId.parse(riotId);
return getByRiotId(parsed.summonerName(), parsed.tagline());
}
public AccountDto getByRiotId(String summonerName, String tagLine) {
String gn = URLEncoder.encode(summonerName, StandardCharsets.UTF_8);
String tl = URLEncoder.encode(tagLine, StandardCharsets.UTF_8);
return client.getRegional(
"/riot/account/v1/accounts/by-riot-id/" + gn + "/" + tl,
Map.of(),
AccountDto.class
);
}
public AccountDto getByPuuid(String puuid) {
return client.getRegional(
"/riot/account/v1/accounts/by-puuid/" + puuid,
Map.of(),
AccountDto.class
);
}
}

View File

@ -0,0 +1,34 @@
package eu.sekunity.riot.service;
import java.util.Map;
import eu.sekunity.riot.core.RiotHttpClient;
import eu.sekunity.riot.dto.LeagueEntryDto;
import lombok.RequiredArgsConstructor;
/**
* © Copyright 05.02.2026 - 16:48 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
@RequiredArgsConstructor
public final class LeagueService {
private final RiotHttpClient client;
// Bei dir offenbar verfügbar:
public LeagueEntryDto[] getEntriesByPuuid(String puuid) {
if (puuid == null || puuid.isBlank()) {
throw new IllegalArgumentException("puuid must not be blank");
}
return client.getPlatform(
"/lol/league/v4/entries/by-puuid/" + puuid,
Map.of(),
LeagueEntryDto[].class
);
}
}

View File

@ -0,0 +1,44 @@
package eu.sekunity.riot.service;
import java.util.Map;
import eu.sekunity.riot.core.RiotHttpClient;
import eu.sekunity.riot.dto.MatchDto;
import lombok.RequiredArgsConstructor;
/**
* © Copyright 05.02.2026 - 15:55 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
@RequiredArgsConstructor
public final class MatchService {
private final RiotHttpClient client;
public String[] listMatchIdsByPuuid(String puuid, int start, int count) {
return client.getRegional(
"/lol/match/v5/matches/by-puuid/" + puuid + "/ids",
Map.of("start", String.valueOf(start), "count", String.valueOf(count)),
String[].class
);
}
public MatchDto getMatch(String matchId) {
return client.getRegional(
"/lol/match/v5/matches/" + matchId,
Map.of(),
MatchDto.class
);
}
public String getMatchJson(String matchId) {
return client.getRegional(
"/lol/match/v5/matches/" + matchId,
Map.of(),
String.class
);
}
}

View File

@ -0,0 +1,21 @@
package eu.sekunity.riot.service;
import eu.sekunity.riot.dto.LeagueEntryDto;
import lombok.RequiredArgsConstructor;
/**
* © Copyright 05.02.2026 - 17:10 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
@RequiredArgsConstructor
public final class RankService {
private final LeagueService league;
public LeagueEntryDto[] bySummonerId(String encryptedSummonerId) {
return league.getEntriesByPuuid(encryptedSummonerId);
}
}

View File

@ -0,0 +1,41 @@
package eu.sekunity.riot.service;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import eu.sekunity.riot.core.RiotHttpClient;
import eu.sekunity.riot.dto.SummonerDto;
import lombok.RequiredArgsConstructor;
/**
* © Copyright 05.02.2026 - 15:54 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
@RequiredArgsConstructor
public final class SummonerService {
private final RiotHttpClient client;
/** Riot: deprecated, but still usable for conversions (name -> summonerId/puuid) */
@Deprecated
public SummonerDto getBySummonerName(String summonerName) {
String enc = URLEncoder.encode(summonerName, StandardCharsets.UTF_8);
return client.getPlatform(
"/lol/summoner/v4/summoners/by-name/" + enc,
Map.of(),
SummonerDto.class
);
}
public SummonerDto getByPuuid(String puuid) {
return client.getPlatform(
"/lol/summoner/v4/summoners/by-puuid/" + puuid,
Map.of(),
SummonerDto.class
);
}
}

View File

@ -0,0 +1,79 @@
package eu.sekunity.riot.util;
import java.util.Optional;
import eu.sekunity.riot.dto.LeagueEntryDto;
/**
* © Copyright 05.02.2026 - 16:52 Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
* muss Schadensersatz leisten (§ 97 UrhG).
*/
public final class RankUtils {
private RankUtils() {}
public static Optional<LeagueEntryDto> solo(LeagueEntryDto[] entries) {
return find(entries, "RANKED_SOLO_5x5");
}
public static Optional<LeagueEntryDto> flex(LeagueEntryDto[] entries) {
return find(entries, "RANKED_FLEX_SR");
}
public static String prettySolo(LeagueEntryDto[] entries) {
return pretty("SoloQ", solo(entries).orElse(null));
}
public static String prettyFlex(LeagueEntryDto[] entries) {
return pretty("FlexQ", flex(entries).orElse(null));
}
/** Prints both in one go */
public static String prettyBoth(LeagueEntryDto[] entries) {
return prettySolo(entries) + "\n" + prettyFlex(entries);
}
// -------- internals --------
private static Optional<LeagueEntryDto> find(LeagueEntryDto[] entries, String queueType) {
if (entries == null) return Optional.empty();
for (var e : entries) {
if (e != null && queueType.equals(e.queueType())) {
return Optional.of(e);
}
}
return Optional.empty();
}
private static String pretty(String label, LeagueEntryDto e) {
if (e == null) return label + ": Unranked";
String tier = titleCase(e.tier()); // "PLATINUM" -> "Platinum"
String div = e.rank(); // "II"
int lp = e.leaguePoints();
int wins = e.wins();
int losses = e.losses();
int games = wins + losses;
String wl = games > 0
? String.format("%d LP • %dW/%dL (%.1f%%)", lp, wins, losses, (wins * 100.0) / games)
: String.format("%d LP", lp);
String promo = (e.miniSeries() != null && e.miniSeries().progress() != null && !e.miniSeries().progress().isBlank())
? " • Promo " + e.miniSeries().progress()
: "";
return String.format("%s: %s %s • %s%s", label, tier, div, wl, promo);
}
private static String titleCase(String s) {
if (s == null || s.isBlank()) return "";
String lower = s.toLowerCase();
return Character.toUpperCase(lower.charAt(0)) + lower.substring(1);
}
}