mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-01-10 11:56:44 +03:00
Another portion of refactoring. Updated dependencies.
This commit is contained in:
parent
13b20fc7e9
commit
44b543e65c
8
pom.xml
8
pom.xml
@ -163,25 +163,25 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>2.12.4</version>
|
<version>2.13.2.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>1.7.32</version>
|
<version>1.7.36</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<version>5.7.2</version>
|
<version>5.8.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.platform</groupId>
|
<groupId>org.junit.platform</groupId>
|
||||||
<artifactId>junit-platform-runner</artifactId>
|
<artifactId>junit-platform-runner</artifactId>
|
||||||
<version>1.7.2</version>
|
<version>1.8.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@ -26,11 +26,8 @@ import com.github.prominence.openweathermap.api.annotation.SubscriptionAvailabil
|
|||||||
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequester;
|
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequester;
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequesterImpl;
|
|
||||||
import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThreeHourStepForecastRequester;
|
import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThreeHourStepForecastRequester;
|
||||||
import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThreeHourStepForecastRequesterImpl;
|
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherRequester;
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherRequesterImpl;
|
|
||||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester;
|
||||||
|
|
||||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.ALL;
|
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.ALL;
|
||||||
@ -74,7 +71,7 @@ public class OpenWeatherMapClient {
|
|||||||
*/
|
*/
|
||||||
@SubscriptionAvailability(plans = ALL)
|
@SubscriptionAvailability(plans = ALL)
|
||||||
public FiveDayThreeHourStepForecastRequester forecast5Day3HourStep() {
|
public FiveDayThreeHourStepForecastRequester forecast5Day3HourStep() {
|
||||||
return new FiveDayThreeHourStepForecastRequesterImpl(apiKey);
|
return new FiveDayThreeHourStepForecastRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,7 +81,7 @@ public class OpenWeatherMapClient {
|
|||||||
*/
|
*/
|
||||||
@SubscriptionAvailability(plans = ALL)
|
@SubscriptionAvailability(plans = ALL)
|
||||||
public OneCallWeatherRequester oneCall() {
|
public OneCallWeatherRequester oneCall() {
|
||||||
return new OneCallWeatherRequesterImpl(apiKey);
|
return new OneCallWeatherRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,6 +91,6 @@ public class OpenWeatherMapClient {
|
|||||||
*/
|
*/
|
||||||
@SubscriptionAvailability(plans = ALL)
|
@SubscriptionAvailability(plans = ALL)
|
||||||
public AirPollutionRequester airPollution() {
|
public AirPollutionRequester airPollution() {
|
||||||
return new AirPollutionRequesterImpl(apiKey);
|
return new AirPollutionRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The interface Async request terminator.
|
|
||||||
*
|
|
||||||
* @param <T> the type parameter
|
|
||||||
* @param <S> the type parameter
|
|
||||||
*/
|
|
||||||
public interface AsyncRequestTerminator<T, S> extends RequestTerminator<CompletableFuture<T>, CompletableFuture<S>> {
|
|
||||||
}
|
|
||||||
@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The interface Request customizer.
|
|
||||||
*
|
|
||||||
* @param <T> the type parameter
|
|
||||||
*/
|
|
||||||
public interface RequestCustomizer<T extends RequestCustomizer<?>> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Customize language.
|
|
||||||
*
|
|
||||||
* @param language the language
|
|
||||||
* @return the request customizer
|
|
||||||
*/
|
|
||||||
T language(Language language);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Customize unit system.
|
|
||||||
*
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
* @return the request customizer
|
|
||||||
*/
|
|
||||||
T unitSystem(UnitSystem unitSystem);
|
|
||||||
}
|
|
||||||
@ -82,6 +82,10 @@ public class RequestSettings {
|
|||||||
this.requestParameters.put(key, value);
|
this.requestParameters.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeRequestParameter(String key) {
|
||||||
|
this.requestParameters.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, String> getRequestParameters() {
|
public Map<String, String> getRequestParameters() {
|
||||||
return requestParameters;
|
return requestParameters;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The interface Request terminator.
|
|
||||||
*
|
|
||||||
* @param <T> the type parameter
|
|
||||||
* @param <S> the type parameter
|
|
||||||
*/
|
|
||||||
public interface RequestTerminator<T, S> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Java object response format.
|
|
||||||
*
|
|
||||||
* @return the java object
|
|
||||||
*/
|
|
||||||
T asJava();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JSON response format.
|
|
||||||
*
|
|
||||||
* @return the JSON string
|
|
||||||
*/
|
|
||||||
S asJSON();
|
|
||||||
}
|
|
||||||
@ -1,99 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Request url builder.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class RequestUrlBuilder {
|
|
||||||
|
|
||||||
private static final String API_KEY_PARAM_NAME = "appid";
|
|
||||||
|
|
||||||
private final StringBuilder builder = new StringBuilder("http://api.openweathermap.org/data/2.5/");
|
|
||||||
private final Map<String, Object> requestParameters = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Request url builder.
|
|
||||||
*
|
|
||||||
* @param key the API key
|
|
||||||
*/
|
|
||||||
public RequestUrlBuilder(String key) {
|
|
||||||
requestParameters.put(API_KEY_PARAM_NAME, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Appends value.
|
|
||||||
*
|
|
||||||
* @param value the value
|
|
||||||
*/
|
|
||||||
public void append(String value) {
|
|
||||||
builder.append(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds request parameter.
|
|
||||||
*
|
|
||||||
* @param key the key
|
|
||||||
* @param value the value
|
|
||||||
*/
|
|
||||||
public void addRequestParameter(String key, Object value) {
|
|
||||||
requestParameters.put(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Applies customization.
|
|
||||||
*
|
|
||||||
* @param language the language
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
public void applyCustomization(Language language, UnitSystem unitSystem) {
|
|
||||||
if (language != null) {
|
|
||||||
addRequestParameter("lang", language.getValue());
|
|
||||||
}
|
|
||||||
if (unitSystem != null && unitSystem != UnitSystem.STANDARD) {
|
|
||||||
addRequestParameter("units", unitSystem.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds url string.
|
|
||||||
*
|
|
||||||
* @return the string
|
|
||||||
*/
|
|
||||||
public String buildUrl() {
|
|
||||||
final String joinedParameters = requestParameters.entrySet().stream()
|
|
||||||
.map(entry -> entry.getKey() + "=" + entry.getValue())
|
|
||||||
.collect(Collectors.joining("&"));
|
|
||||||
builder.append('?');
|
|
||||||
builder.append(joinedParameters);
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -24,11 +24,37 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.AirPollutionResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
||||||
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Current air pollution async request terminator.
|
* The type Air pollution async request terminator.
|
||||||
*/
|
*/
|
||||||
public interface AirPollutionAsyncRequestTerminator extends AsyncRequestTerminator<AirPollutionDetails, String> {
|
public class AirPollutionAsyncRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Air pollution async request terminator.
|
||||||
|
*
|
||||||
|
* @param requestSettings request settings object.
|
||||||
|
*/
|
||||||
|
public AirPollutionAsyncRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<AirPollutionDetails> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new AirPollutionResponseMapper().mapToAirPollution(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.AirPollutionResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Air pollution async request terminator.
|
|
||||||
*/
|
|
||||||
public class AirPollutionAsyncRequestTerminatorImpl implements AirPollutionAsyncRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Air pollution async request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
public AirPollutionAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<AirPollutionDetails> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new AirPollutionResponseMapper().mapToAirPollution(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -24,21 +24,28 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Current air pollution request customizer.
|
* The Air Pollution request customizer.
|
||||||
*/
|
*/
|
||||||
public interface AirPollutionRequestCustomizer {
|
public class AirPollutionRequestCustomizer {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* Retrieve current air pollution request terminator.
|
|
||||||
*
|
|
||||||
* @return the current air pollution request terminator
|
|
||||||
*/
|
|
||||||
AirPollutionRequestTerminator retrieve();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve async current air pollution async request terminator.
|
* Instantiates a new Air pollution request customizer.
|
||||||
*
|
*
|
||||||
* @return the current air pollution async request terminator
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
AirPollutionAsyncRequestTerminator retrieveAsync();
|
public AirPollutionRequestCustomizer(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AirPollutionRequestTerminator retrieve() {
|
||||||
|
return new AirPollutionRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AirPollutionAsyncRequestTerminator retrieveAsync() {
|
||||||
|
return new AirPollutionAsyncRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
|
|
||||||
public class AirPollutionRequestCustomizerImpl implements AirPollutionRequestCustomizer {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
public AirPollutionRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AirPollutionRequestTerminator retrieve() {
|
|
||||||
return new AirPollutionRequestTerminatorImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AirPollutionAsyncRequestTerminator retrieveAsync() {
|
|
||||||
return new AirPollutionAsyncRequestTerminatorImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -24,11 +24,35 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.AirPollutionResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Current air pollution request terminator.
|
* The type Air pollution request terminator.
|
||||||
*/
|
*/
|
||||||
public interface AirPollutionRequestTerminator extends RequestTerminator<AirPollutionDetails, String> {
|
public class AirPollutionRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Air pollution request terminator.
|
||||||
|
*
|
||||||
|
* @param requestSettings request settings object.
|
||||||
|
*/
|
||||||
|
public AirPollutionRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AirPollutionDetails asJava() {
|
||||||
|
return new AirPollutionResponseMapper().mapToAirPollution(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.AirPollutionResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Air pollution request terminator.
|
|
||||||
*/
|
|
||||||
public class AirPollutionRequestTerminatorImpl implements AirPollutionRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Air pollution request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
public AirPollutionRequestTerminatorImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AirPollutionDetails asJava() {
|
|
||||||
return new AirPollutionResponseMapper().mapToAirPollution(getRawResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,53 +1,58 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* * Copyright (c) 2021 Alexey Zinchenko
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* *
|
||||||
* in the Software without restriction, including without limitation the rights
|
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* * of this software and associated documentation files (the "Software"), to deal
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* * in the Software without restriction, including without limitation the rights
|
||||||
* furnished to do so, subject to the following conditions:
|
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* * copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* * furnished to do so, subject to the following conditions:
|
||||||
|
* *
|
||||||
|
* * The above copyright notice and this permission notice shall be included in all
|
||||||
|
* * copies or substantial portions of the Software.
|
||||||
|
* *
|
||||||
|
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* * SOFTWARE.
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.current.CurrentAirPollutionRequester;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.forecast.ForecastAirPollutionRequester;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.historical.HistoricalAirPollutionRequester;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Air pollution requester.
|
* The type Air pollution requester.
|
||||||
*/
|
*/
|
||||||
public interface AirPollutionRequester {
|
public class AirPollutionRequester {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* Current current air pollution requester.
|
|
||||||
*
|
|
||||||
* @return the current air pollution requester
|
|
||||||
*/
|
|
||||||
CurrentAirPollutionRequester current();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forecast forecast air pollution requester.
|
* Instantiates a new Air pollution requester.
|
||||||
*
|
*
|
||||||
* @return the forecast air pollution requester
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
ForecastAirPollutionRequester forecast();
|
public AirPollutionRequester(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public CurrentAirPollutionRequester current() {
|
||||||
* Historical historical air pollution requester.
|
requestSettings.appendToURL("air_pollution");
|
||||||
*
|
return new CurrentAirPollutionRequester(requestSettings);
|
||||||
* @return the historical air pollution requester
|
}
|
||||||
*/
|
|
||||||
HistoricalAirPollutionRequester historical();
|
public ForecastAirPollutionRequester forecast() {
|
||||||
|
requestSettings.appendToURL("air_pollution/forecast");
|
||||||
|
return new ForecastAirPollutionRequester(requestSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HistoricalAirPollutionRequester historical() {
|
||||||
|
requestSettings.appendToURL("air_pollution/history");
|
||||||
|
return new HistoricalAirPollutionRequester(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.current.CurrentAirPollutionRequester;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.current.CurrentAirPollutionRequesterImpl;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.forecast.ForecastAirPollutionRequester;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.forecast.ForecastAirPollutionRequesterImpl;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.historical.HistoricalAirPollutionRequester;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.historical.HistoricalAirPollutionRequesterImpl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Air pollution requester.
|
|
||||||
*/
|
|
||||||
public class AirPollutionRequesterImpl implements AirPollutionRequester {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Air pollution requester.
|
|
||||||
*
|
|
||||||
* @param apiKey the api key
|
|
||||||
*/
|
|
||||||
public AirPollutionRequesterImpl(String apiKey) {
|
|
||||||
urlBuilder = new RequestUrlBuilder(apiKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CurrentAirPollutionRequester current() {
|
|
||||||
urlBuilder.append("air_pollution");
|
|
||||||
return new CurrentAirPollutionRequesterImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ForecastAirPollutionRequester forecast() {
|
|
||||||
urlBuilder.append("air_pollution/forecast");
|
|
||||||
return new ForecastAirPollutionRequesterImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HistoricalAirPollutionRequester historical() {
|
|
||||||
urlBuilder.append("air_pollution/history");
|
|
||||||
return new HistoricalAirPollutionRequesterImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,20 +20,29 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution.current;
|
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Current air pollution requester.
|
* The type Current air pollution requester.
|
||||||
*/
|
*/
|
||||||
public interface CurrentAirPollutionRequester {
|
public class CurrentAirPollutionRequester {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By coordinate current air pollution request customizer.
|
* Instantiates a new Current air pollution requester.
|
||||||
*
|
*
|
||||||
* @param coordinate the coordinate
|
* @param requestSettings request settings object.
|
||||||
* @return the current air pollution request customizer
|
|
||||||
*/
|
*/
|
||||||
AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate);
|
public CurrentAirPollutionRequester(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate) {
|
||||||
|
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||||
|
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||||
|
return new AirPollutionRequestCustomizer(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,31 +20,29 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type One call current weather requester.
|
* The type Forecast air pollution requester.
|
||||||
*/
|
*/
|
||||||
public class OneCallCurrentWeatherRequesterImpl implements OneCallCurrentWeatherRequester {
|
public class ForecastAirPollutionRequester {
|
||||||
private final RequestUrlBuilder urlBuilder;
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new One call current weather requester.
|
* Instantiates a new Forecast air pollution requester.
|
||||||
*
|
*
|
||||||
* @param urlBuilder the url builder
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
public OneCallCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
|
public ForecastAirPollutionRequester(RequestSettings requestSettings) {
|
||||||
this.urlBuilder = urlBuilder;
|
this.requestSettings = requestSettings;
|
||||||
urlBuilder.append("onecall");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate) {
|
||||||
public OneCallCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate) {
|
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||||
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||||
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
return new AirPollutionRequestCustomizer(requestSettings);
|
||||||
return new OneCallCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,32 +20,31 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type One call historical weather requester.
|
* The type Historical air pollution requester.
|
||||||
*/
|
*/
|
||||||
public class OneCallHistoricalWeatherRequesterImpl implements OneCallHistoricalWeatherRequester {
|
public class HistoricalAirPollutionRequester {
|
||||||
private final RequestUrlBuilder urlBuilder;
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new One call historical weather requester.
|
* Instantiates a new Historical air pollution requester.
|
||||||
*
|
*
|
||||||
* @param urlBuilder the url builder
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
public OneCallHistoricalWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
|
public HistoricalAirPollutionRequester(RequestSettings requestSettings) {
|
||||||
this.urlBuilder = urlBuilder;
|
this.requestSettings = requestSettings;
|
||||||
urlBuilder.append("onecall/timemachine");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public AirPollutionRequestCustomizer byCoordinateAndPeriod(Coordinate coordinate, long startUnixTime, long endUnixTime) {
|
||||||
public OneCallHistoricalWeatherRequestCustomizer byCoordinateAndTimestamp(Coordinate coordinate, long unixTime) {
|
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||||
urlBuilder.addRequestParameter("lat", coordinate.getLatitude());
|
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||||
urlBuilder.addRequestParameter("lon", coordinate.getLongitude());
|
requestSettings.putRequestParameter("start", String.valueOf(startUnixTime));
|
||||||
urlBuilder.addRequestParameter("dt", unixTime);
|
requestSettings.putRequestParameter("end", String.valueOf(endUnixTime));
|
||||||
return new OneCallHistoricalWeatherRequestCustomizerImpl(urlBuilder);
|
return new AirPollutionRequestCustomizer(requestSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution.current;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizerImpl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Current air pollution requester.
|
|
||||||
*/
|
|
||||||
public class CurrentAirPollutionRequesterImpl implements CurrentAirPollutionRequester {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Current air pollution requester.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
public CurrentAirPollutionRequesterImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate) {
|
|
||||||
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
|
||||||
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
|
||||||
return new AirPollutionRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution.forecast;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The interface Forecast air pollution requester.
|
|
||||||
*/
|
|
||||||
public interface ForecastAirPollutionRequester {
|
|
||||||
/**
|
|
||||||
* By coordinate forecast air pollution request customizer.
|
|
||||||
*
|
|
||||||
* @param coordinate the coordinate
|
|
||||||
* @return the forecast air pollution request customizer
|
|
||||||
*/
|
|
||||||
AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate);
|
|
||||||
}
|
|
||||||
@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution.forecast;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizerImpl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Forecast air pollution requester.
|
|
||||||
*/
|
|
||||||
public class ForecastAirPollutionRequesterImpl implements ForecastAirPollutionRequester {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Forecast air pollution requester.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
public ForecastAirPollutionRequesterImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate) {
|
|
||||||
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
|
||||||
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
|
||||||
return new AirPollutionRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution.historical;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The interface Historical air pollution requester.
|
|
||||||
*/
|
|
||||||
public interface HistoricalAirPollutionRequester {
|
|
||||||
/**
|
|
||||||
* By coordinate historical air pollution request customizer.
|
|
||||||
*
|
|
||||||
* @param coordinate the coordinate
|
|
||||||
* @param startUnixTime the start unix time
|
|
||||||
* @param endUnixTime the end unix time
|
|
||||||
* @return the historical air pollution request customizer
|
|
||||||
*/
|
|
||||||
AirPollutionRequestCustomizer byCoordinateAndPeriod(Coordinate coordinate, long startUnixTime, long endUnixTime);
|
|
||||||
}
|
|
||||||
@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution.historical;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizerImpl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Historical air pollution requester.
|
|
||||||
*/
|
|
||||||
public class HistoricalAirPollutionRequesterImpl implements HistoricalAirPollutionRequester {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Historical air pollution requester.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
public HistoricalAirPollutionRequesterImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AirPollutionRequestCustomizer byCoordinateAndPeriod(Coordinate coordinate, long startUnixTime, long endUnixTime) {
|
|
||||||
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
|
||||||
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
|
||||||
urlBuilder.addRequestParameter("start", String.valueOf(startUnixTime));
|
|
||||||
urlBuilder.addRequestParameter("end", String.valueOf(endUnixTime));
|
|
||||||
return new AirPollutionRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -22,21 +22,43 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.ResponseType;
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.FiveDayThreeHourStepForecastResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
||||||
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The forecast async request terminator interface.
|
* Async request terminator.
|
||||||
*/
|
*/
|
||||||
public interface FiveDayThreeHourStepForecastAsyncRequestTerminator extends AsyncRequestTerminator<Forecast, String> {
|
public class FiveDayThreeHourStepForecastAsyncRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XML response format.
|
* Instantiates a new async request terminator.
|
||||||
*
|
*
|
||||||
* @return the completable future
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
CompletableFuture<String> asXML();
|
FiveDayThreeHourStepForecastAsyncRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<Forecast> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new FiveDayThreeHourStepForecastResponseMapper(requestSettings.getUnitSystem()).mapToForecast(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<String> asXML() {
|
||||||
|
requestSettings.setResponseType(ResponseType.XML);
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.FiveDayThreeHourStepForecastResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Async request terminator.
|
|
||||||
*/
|
|
||||||
public class FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl implements FiveDayThreeHourStepForecastAsyncRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new async request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Forecast> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new FiveDayThreeHourStepForecastResponseMapper(unitSystem).mapToForecast(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<String> asXML() {
|
|
||||||
urlBuilder.addRequestParameter("mode", "xml");
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -22,31 +22,45 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The forecast request customizer interface.
|
* The forecast request customizer.
|
||||||
*/
|
*/
|
||||||
public interface FiveDayThreeHourStepForecastRequestCustomizer extends RequestCustomizer<FiveDayThreeHourStepForecastRequestCustomizer> {
|
public class FiveDayThreeHourStepForecastRequestCustomizer {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* Count customizer.
|
|
||||||
*
|
|
||||||
* @param numberOfTimestamps the number of timestamps
|
|
||||||
* @return forecast request customizer
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer count(int numberOfTimestamps);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve forecast request terminator.
|
* Instantiates a new forecast request customizer.
|
||||||
*
|
*
|
||||||
* @return forecast request terminator
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
FiveDayThreeHourStepForecastRequestTerminator retrieve();
|
FiveDayThreeHourStepForecastRequestCustomizer(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public FiveDayThreeHourStepForecastRequestCustomizer language(Language language) {
|
||||||
* Retrieve forecast async request terminator.
|
requestSettings.setLanguage(language);
|
||||||
*
|
return this;
|
||||||
* @return forecast async request terminator
|
}
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastAsyncRequestTerminator retrieveAsync();
|
public FiveDayThreeHourStepForecastRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
requestSettings.setUnitSystem(unitSystem);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer count(int numberOfTimestamps) {
|
||||||
|
requestSettings.putRequestParameter("cnt", Integer.toString(numberOfTimestamps));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FiveDayThreeHourStepForecastRequestTerminator retrieve() {
|
||||||
|
return new FiveDayThreeHourStepForecastRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FiveDayThreeHourStepForecastAsyncRequestTerminator retrieveAsync() {
|
||||||
|
return new FiveDayThreeHourStepForecastAsyncRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The forecast request customizer.
|
|
||||||
*/
|
|
||||||
public class FiveDayThreeHourStepForecastRequestCustomizerImpl implements FiveDayThreeHourStepForecastRequestCustomizer {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
private Language language;
|
|
||||||
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
|
||||||
private int count = -1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new forecast request customizer.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer language(Language language) {
|
|
||||||
this.language = language;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer count(int numberOfTimestamps) {
|
|
||||||
count = numberOfTimestamps;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestTerminator retrieve() {
|
|
||||||
applyCustomization();
|
|
||||||
return new FiveDayThreeHourStepForecastRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastAsyncRequestTerminator retrieveAsync() {
|
|
||||||
applyCustomization();
|
|
||||||
return new FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyCustomization() {
|
|
||||||
urlBuilder.applyCustomization(language, unitSystem);
|
|
||||||
if (count >= 0) {
|
|
||||||
urlBuilder.addRequestParameter("cnt", count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -22,19 +22,41 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.ResponseType;
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.FiveDayThreeHourStepForecastResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The forecast request terminator interface.
|
* The forecast request terminator.
|
||||||
*/
|
*/
|
||||||
public interface FiveDayThreeHourStepForecastRequestTerminator extends RequestTerminator<Forecast, String> {
|
public class FiveDayThreeHourStepForecastRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XML response format.
|
* Instantiates a new forecast request terminator.
|
||||||
*
|
*
|
||||||
* @return the XML string
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
String asXML();
|
FiveDayThreeHourStepForecastRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Forecast asJava() {
|
||||||
|
return new FiveDayThreeHourStepForecastResponseMapper(requestSettings.getUnitSystem()).mapToForecast(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asXML() {
|
||||||
|
requestSettings.setResponseType(ResponseType.XML);
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.FiveDayThreeHourStepForecastResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The forecast request terminator.
|
|
||||||
*/
|
|
||||||
public class FiveDayThreeHourStepForecastRequestTerminatorImpl implements FiveDayThreeHourStepForecastRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new forecast request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Forecast asJava() {
|
|
||||||
return new FiveDayThreeHourStepForecastResponseMapper(unitSystem).mapToForecast(getRawResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String asXML() {
|
|
||||||
urlBuilder.addRequestParameter("mode", "xml");
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -23,69 +23,57 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface for <a href="https://openweathermap.org/forecast5">API</a> methods.
|
* The forecast requester.
|
||||||
*/
|
*/
|
||||||
public interface FiveDayThreeHourStepForecastRequester {
|
public class FiveDayThreeHourStepForecastRequester {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By city name forecast request customizer.
|
* Instantiates a new forecast requester.
|
||||||
*
|
*
|
||||||
* @param cityName the city name
|
* @param requestSettings request settings object.
|
||||||
* @return the forecast request customizer
|
|
||||||
*/
|
*/
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName);
|
public FiveDayThreeHourStepForecastRequester(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
this.requestSettings.appendToURL("forecast");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName) {
|
||||||
* By city name forecast request customizer.
|
requestSettings.putRequestParameter("q", cityName);
|
||||||
*
|
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||||
* @param cityName the city name
|
}
|
||||||
* @param stateCode the state code
|
|
||||||
* @return the forecast request customizer
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode);
|
|
||||||
|
|
||||||
/**
|
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode) {
|
||||||
* By city name forecast request customizer.
|
requestSettings.putRequestParameter("q", cityName + "," + stateCode);
|
||||||
*
|
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||||
* @param cityName the city name
|
}
|
||||||
* @param stateCode the state code
|
|
||||||
* @param countryCode the country code
|
|
||||||
* @return the forecast request customizer
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode, String countryCode);
|
|
||||||
|
|
||||||
/**
|
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode, String countryCode) {
|
||||||
* By city id forecast request customizer.
|
requestSettings.putRequestParameter("q", cityName + "," + stateCode + "," + countryCode);
|
||||||
*
|
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||||
* @param cityId the city id
|
}
|
||||||
* @return the forecast request customizer
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer byCityId(long cityId);
|
|
||||||
|
|
||||||
/**
|
public FiveDayThreeHourStepForecastRequestCustomizer byCityId(long cityId) {
|
||||||
* By coordinate forecast request customizer.
|
requestSettings.putRequestParameter("id", Long.toString(cityId));
|
||||||
*
|
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||||
* @param coordinate the coordinate
|
}
|
||||||
* @return the forecast request customizer
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer byCoordinate(Coordinate coordinate);
|
|
||||||
|
|
||||||
/**
|
public FiveDayThreeHourStepForecastRequestCustomizer byCoordinate(Coordinate coordinate) {
|
||||||
* By zip code and country forecast request customizer.
|
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||||
*
|
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||||
* @param zipCode the zip code
|
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||||
* @param countryCode the country code
|
}
|
||||||
* @return the forecast request customizer
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode);
|
|
||||||
|
|
||||||
/**
|
public FiveDayThreeHourStepForecastRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode) {
|
||||||
* By zip code in USA forecast request customizer.
|
requestSettings.putRequestParameter("zip", zipCode + "," + countryCode);
|
||||||
*
|
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||||
* @param zipCode the zip code
|
}
|
||||||
* @return the forecast request customizer
|
|
||||||
*/
|
public FiveDayThreeHourStepForecastRequestCustomizer byZipCodeInUSA(String zipCode) {
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer byZipCodeInUSA(String zipCode);
|
requestSettings.putRequestParameter("zip", zipCode);
|
||||||
|
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The forecast requester.
|
|
||||||
*/
|
|
||||||
public class FiveDayThreeHourStepForecastRequesterImpl implements FiveDayThreeHourStepForecastRequester {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new forecast requester.
|
|
||||||
*
|
|
||||||
* @param apiKey the api key
|
|
||||||
*/
|
|
||||||
public FiveDayThreeHourStepForecastRequesterImpl(String apiKey) {
|
|
||||||
urlBuilder = new RequestUrlBuilder(apiKey);
|
|
||||||
urlBuilder.append("forecast");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName) {
|
|
||||||
urlBuilder.addRequestParameter("q", cityName);
|
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode) {
|
|
||||||
urlBuilder.addRequestParameter("q", cityName + "," + stateCode);
|
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode, String countryCode) {
|
|
||||||
urlBuilder.addRequestParameter("q", cityName + "," + stateCode + "," + countryCode);
|
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byCityId(long cityId) {
|
|
||||||
urlBuilder.addRequestParameter("id", cityId);
|
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byCoordinate(Coordinate coordinate) {
|
|
||||||
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
|
||||||
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode) {
|
|
||||||
urlBuilder.addRequestParameter("zip", zipCode + "," + countryCode);
|
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byZipCodeInUSA(String zipCode) {
|
|
||||||
urlBuilder.addRequestParameter("zip", zipCode);
|
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -22,24 +22,30 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall;
|
package com.github.prominence.openweathermap.api.request.onecall;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.current.OneCallCurrentWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.onecall.current.OneCallCurrentWeatherRequester;
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.historical.OneCallHistoricalWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.onecall.historical.OneCallHistoricalWeatherRequester;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call weather requester.
|
* The type One call weather requester.
|
||||||
*/
|
*/
|
||||||
public interface OneCallWeatherRequester {
|
public class OneCallWeatherRequester {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* Current one call current weather requester.
|
|
||||||
*
|
|
||||||
* @return the one call current weather requester
|
|
||||||
*/
|
|
||||||
OneCallCurrentWeatherRequester current();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Historical one call historical weather requester.
|
* Instantiates a new One call weather requester.
|
||||||
*
|
*
|
||||||
* @return the one call historical weather requester
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
OneCallHistoricalWeatherRequester historical();
|
public OneCallWeatherRequester(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallCurrentWeatherRequester current() {
|
||||||
|
return new OneCallCurrentWeatherRequester(requestSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallHistoricalWeatherRequester historical() {
|
||||||
|
return new OneCallHistoricalWeatherRequester(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.current.OneCallCurrentWeatherRequester;
|
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.current.OneCallCurrentWeatherRequesterImpl;
|
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.historical.OneCallHistoricalWeatherRequester;
|
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.historical.OneCallHistoricalWeatherRequesterImpl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type One call weather requester.
|
|
||||||
*/
|
|
||||||
public class OneCallWeatherRequesterImpl implements OneCallWeatherRequester {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call weather requester.
|
|
||||||
*
|
|
||||||
* @param apiKey the api key
|
|
||||||
*/
|
|
||||||
public OneCallWeatherRequesterImpl(String apiKey) {
|
|
||||||
urlBuilder = new RequestUrlBuilder(apiKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallCurrentWeatherRequester current() {
|
|
||||||
return new OneCallCurrentWeatherRequesterImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallHistoricalWeatherRequester historical() {
|
|
||||||
return new OneCallHistoricalWeatherRequesterImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -22,11 +22,37 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
package com.github.prominence.openweathermap.api.request.onecall.current;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
||||||
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call current weather async request terminator.
|
* The type One call current weather async request terminator.
|
||||||
*/
|
*/
|
||||||
public interface OneCallCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<CurrentWeatherData, String> {
|
public class OneCallCurrentWeatherAsyncRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new One call current weather async request terminator.
|
||||||
|
*
|
||||||
|
* @param requestSettings request settings object.
|
||||||
|
*/
|
||||||
|
OneCallCurrentWeatherAsyncRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<CurrentWeatherData> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new OneCallWeatherResponseMapper(requestSettings.getUnitSystem()).mapToCurrent(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type One call current weather async request terminator.
|
|
||||||
*/
|
|
||||||
public class OneCallCurrentWeatherAsyncRequestTerminatorImpl implements OneCallCurrentWeatherAsyncRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call current weather async request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
OneCallCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<CurrentWeatherData> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new OneCallWeatherResponseMapper(unitSystem).mapToCurrent(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -22,32 +22,53 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
package com.github.prominence.openweathermap.api.request.onecall.current;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
import com.github.prominence.openweathermap.api.enums.OneCallResultOptions;
|
import com.github.prominence.openweathermap.api.enums.OneCallResultOptions;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call current weather request customizer.
|
* The type One call current weather request customizer.
|
||||||
*/
|
*/
|
||||||
public interface OneCallCurrentWeatherRequestCustomizer extends RequestCustomizer<OneCallCurrentWeatherRequestCustomizer> {
|
public class OneCallCurrentWeatherRequestCustomizer {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* Exclude one call current weather request customizer.
|
|
||||||
*
|
|
||||||
* @param excludeOptions the exclude options
|
|
||||||
* @return the one call current weather request customizer
|
|
||||||
*/
|
|
||||||
OneCallCurrentWeatherRequestCustomizer exclude(OneCallResultOptions... excludeOptions);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve one call current weather request terminator.
|
* Instantiates a new One call current weather request customizer.
|
||||||
*
|
*
|
||||||
* @return the one call current weather request terminator
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
OneCallCurrentWeatherRequestTerminator retrieve();
|
OneCallCurrentWeatherRequestCustomizer(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public OneCallCurrentWeatherRequestCustomizer language(Language language) {
|
||||||
* Retrieve async one call current weather async request terminator.
|
requestSettings.setLanguage(language);
|
||||||
*
|
return this;
|
||||||
* @return the one call current weather async request terminator
|
}
|
||||||
*/
|
|
||||||
OneCallCurrentWeatherAsyncRequestTerminator retrieveAsync();
|
public OneCallCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
this.requestSettings.setUnitSystem(unitSystem);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallCurrentWeatherRequestCustomizer exclude(OneCallResultOptions... excludeOptions) {
|
||||||
|
if (excludeOptions != null && excludeOptions.length > 0) {
|
||||||
|
requestSettings.putRequestParameter("exclude", Stream.of(excludeOptions).map(OneCallResultOptions::getValue).collect(Collectors.joining(",")));
|
||||||
|
} else {
|
||||||
|
requestSettings.removeRequestParameter("exclude");
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallCurrentWeatherRequestTerminator retrieve() {
|
||||||
|
return new OneCallCurrentWeatherRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
||||||
|
return new OneCallCurrentWeatherAsyncRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.OneCallResultOptions;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type One call current weather request customizer.
|
|
||||||
*/
|
|
||||||
public class OneCallCurrentWeatherRequestCustomizerImpl implements OneCallCurrentWeatherRequestCustomizer {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
private Language language;
|
|
||||||
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
|
||||||
private OneCallResultOptions[] excludeOptions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call current weather request customizer.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
OneCallCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallCurrentWeatherRequestCustomizer language(Language language) {
|
|
||||||
this.language = language;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallCurrentWeatherRequestCustomizer exclude(OneCallResultOptions... excludeOptions) {
|
|
||||||
this.excludeOptions = excludeOptions;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallCurrentWeatherRequestTerminator retrieve() {
|
|
||||||
applyCustomization();
|
|
||||||
return new OneCallCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
|
||||||
applyCustomization();
|
|
||||||
return new OneCallCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyCustomization() {
|
|
||||||
urlBuilder.applyCustomization(language, unitSystem);
|
|
||||||
if (excludeOptions != null) {
|
|
||||||
urlBuilder.addRequestParameter("exclude", Stream.of(excludeOptions).map(OneCallResultOptions::getValue).collect(Collectors.joining(",")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -22,12 +22,35 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
package com.github.prominence.openweathermap.api.request.onecall.current;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call current weather request terminator.
|
* The type One call current weather request terminator.
|
||||||
*/
|
*/
|
||||||
public interface OneCallCurrentWeatherRequestTerminator extends RequestTerminator<CurrentWeatherData, String> {
|
public class OneCallCurrentWeatherRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new One call current weather request terminator.
|
||||||
|
*
|
||||||
|
* @param requestSettings request settings object.
|
||||||
|
*/
|
||||||
|
OneCallCurrentWeatherRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CurrentWeatherData asJava() {
|
||||||
|
return new OneCallWeatherResponseMapper(requestSettings.getUnitSystem()).mapToCurrent(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type One call current weather request terminator.
|
|
||||||
*/
|
|
||||||
public class OneCallCurrentWeatherRequestTerminatorImpl implements OneCallCurrentWeatherRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call current weather request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
OneCallCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CurrentWeatherData asJava() {
|
|
||||||
return new OneCallWeatherResponseMapper(unitSystem).mapToCurrent(getRawResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -23,16 +23,27 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
package com.github.prominence.openweathermap.api.request.onecall.current;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call current weather requester.
|
* The type One call current weather requester.
|
||||||
*/
|
*/
|
||||||
public interface OneCallCurrentWeatherRequester {
|
public class OneCallCurrentWeatherRequester {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By coordinate one call current weather request customizer.
|
* Instantiates a new One call current weather requester.
|
||||||
*
|
*
|
||||||
* @param coordinate the coordinate
|
* @param requestSettings request settings object.
|
||||||
* @return the one call current weather request customizer
|
|
||||||
*/
|
*/
|
||||||
OneCallCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate);
|
public OneCallCurrentWeatherRequester(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
this.requestSettings.appendToURL("onecall");
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate) {
|
||||||
|
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||||
|
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||||
|
return new OneCallCurrentWeatherRequestCustomizer(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,11 +22,37 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
||||||
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call historical weather async request terminator.
|
* The type One call historical weather async request terminator.
|
||||||
*/
|
*/
|
||||||
public interface OneCallHistoricalWeatherAsyncRequestTerminator extends AsyncRequestTerminator<HistoricalWeatherData, String> {
|
public class OneCallHistoricalWeatherAsyncRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new One call historical weather async request terminator.
|
||||||
|
*
|
||||||
|
* @param requestSettings request settings object.
|
||||||
|
*/
|
||||||
|
public OneCallHistoricalWeatherAsyncRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<HistoricalWeatherData> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new OneCallWeatherResponseMapper(requestSettings.getUnitSystem()).mapToHistorical(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type One call historical weather async request terminator.
|
|
||||||
*/
|
|
||||||
public class OneCallHistoricalWeatherAsyncRequestTerminatorImpl implements OneCallHistoricalWeatherAsyncRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call historical weather async request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
public OneCallHistoricalWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<HistoricalWeatherData> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new OneCallWeatherResponseMapper(unitSystem).mapToHistorical(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -22,23 +22,40 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call historical weather request customizer.
|
* The type One call historical weather request customizer.
|
||||||
*/
|
*/
|
||||||
public interface OneCallHistoricalWeatherRequestCustomizer extends RequestCustomizer<OneCallHistoricalWeatherRequestCustomizer> {
|
public class OneCallHistoricalWeatherRequestCustomizer {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* Retrieve one call historical weather request terminator.
|
|
||||||
*
|
|
||||||
* @return the one call historical weather request terminator
|
|
||||||
*/
|
|
||||||
OneCallHistoricalWeatherRequestTerminator retrieve();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve async one call historical weather async request terminator.
|
* Instantiates a new One call historical weather request customizer.
|
||||||
*
|
*
|
||||||
* @return the one call historical weather async request terminator
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
OneCallHistoricalWeatherAsyncRequestTerminator retrieveAsync();
|
public OneCallHistoricalWeatherRequestCustomizer(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallHistoricalWeatherRequestCustomizer language(Language language) {
|
||||||
|
requestSettings.setLanguage(language);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallHistoricalWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
requestSettings.setUnitSystem(unitSystem);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallHistoricalWeatherRequestTerminator retrieve() {
|
||||||
|
return new OneCallHistoricalWeatherRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallHistoricalWeatherAsyncRequestTerminator retrieveAsync() {
|
||||||
|
return new OneCallHistoricalWeatherAsyncRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type One call historical weather request customizer.
|
|
||||||
*/
|
|
||||||
public class OneCallHistoricalWeatherRequestCustomizerImpl implements OneCallHistoricalWeatherRequestCustomizer {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
private Language language;
|
|
||||||
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call historical weather request customizer.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
public OneCallHistoricalWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallHistoricalWeatherRequestCustomizer language(Language language) {
|
|
||||||
this.language = language;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallHistoricalWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallHistoricalWeatherRequestTerminator retrieve() {
|
|
||||||
urlBuilder.applyCustomization(language, unitSystem);
|
|
||||||
return new OneCallHistoricalWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallHistoricalWeatherAsyncRequestTerminator retrieveAsync() {
|
|
||||||
urlBuilder.applyCustomization(language, unitSystem);
|
|
||||||
return new OneCallHistoricalWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -22,11 +22,35 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call historical weather request terminator.
|
* The type One call historical weather request terminator.
|
||||||
*/
|
*/
|
||||||
public interface OneCallHistoricalWeatherRequestTerminator extends RequestTerminator<HistoricalWeatherData, String> {
|
public class OneCallHistoricalWeatherRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new One call historical weather request terminator.
|
||||||
|
*
|
||||||
|
* @param requestSettings request settings object.
|
||||||
|
*/
|
||||||
|
public OneCallHistoricalWeatherRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HistoricalWeatherData asJava() {
|
||||||
|
return new OneCallWeatherResponseMapper(requestSettings.getUnitSystem()).mapToHistorical(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type One call historical weather request terminator.
|
|
||||||
*/
|
|
||||||
public class OneCallHistoricalWeatherRequestTerminatorImpl implements OneCallHistoricalWeatherRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call historical weather request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
public OneCallHistoricalWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HistoricalWeatherData asJava() {
|
|
||||||
return new OneCallWeatherResponseMapper(unitSystem).mapToHistorical(getRawResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -23,17 +23,28 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call historical weather requester.
|
* The type One call historical weather requester.
|
||||||
*/
|
*/
|
||||||
public interface OneCallHistoricalWeatherRequester {
|
public class OneCallHistoricalWeatherRequester {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By coordinate and timestamp one call historical weather request customizer.
|
* Instantiates a new One call historical weather requester.
|
||||||
*
|
*
|
||||||
* @param coordinate the coordinate
|
* @param requestSettings request settings object.
|
||||||
* @param unixTime the unix time
|
|
||||||
* @return the one call historical weather request customizer
|
|
||||||
*/
|
*/
|
||||||
OneCallHistoricalWeatherRequestCustomizer byCoordinateAndTimestamp(Coordinate coordinate, long unixTime);
|
public OneCallHistoricalWeatherRequester(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
this.requestSettings.appendToURL("onecall/timemachine");
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallHistoricalWeatherRequestCustomizer byCoordinateAndTimestamp(Coordinate coordinate, long unixTime) {
|
||||||
|
requestSettings.putRequestParameter("lat", Double.toString(coordinate.getLatitude()));
|
||||||
|
requestSettings.putRequestParameter("lon", Double.toString(coordinate.getLongitude()));
|
||||||
|
requestSettings.putRequestParameter("dt", Long.toString(unixTime));
|
||||||
|
return new OneCallHistoricalWeatherRequestCustomizer(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,11 +22,9 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Multiple result current weather request customizer.
|
* The type Multiple result current weather request customizer.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user