this is the way

This commit is contained in:
Minecon724 2024-06-20 16:09:05 +02:00
parent b30e65b946
commit c0b171d89b
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8

View file

@ -22,12 +22,10 @@ import eu.m724.wtapi.provider.exception.QuotaExceededException;
import eu.m724.wtapi.provider.exception.ServerProviderException; import eu.m724.wtapi.provider.exception.ServerProviderException;
public class OpenWeatherMapProvider extends WeatherProvider { public class OpenWeatherMapProvider extends WeatherProvider {
private String requestUrlFormat;
private String apiKey; private String apiKey;
public OpenWeatherMapProvider(String apiKey) { public OpenWeatherMapProvider(String apiKey) {
this.apiKey = apiKey; this.apiKey = apiKey;
this.requestUrlFormat = "https://api.openweathermap.org/data/2.5/weather?lat=%f&lon=%f&appid=" + apiKey;
} }
@Override @Override
@ -44,8 +42,8 @@ public class OpenWeatherMapProvider extends WeatherProvider {
@Override @Override
public CompletableFuture<Weather> getWeather(Coordinates coordinates) { public CompletableFuture<Weather> getWeather(Coordinates coordinates) {
String url = String.format( String url = "https://api.openweathermap.org/data/2.5/weather?lat=%f&lon=%f&appid=%s"
requestUrlFormat, coordinates.latitude, coordinates.longitude); .formatted(coordinates.latitude, coordinates.longitude, apiKey);
HttpRequest request = HttpRequest.newBuilder() HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url)) .uri(URI.create(url))