mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-01-10 11:56:44 +03:00
Package reorganizations. Small refactoring.
This commit is contained in:
parent
2c54375cfe
commit
10ba59652b
@ -20,7 +20,9 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.impl;
|
||||
package com.github.prominence.openweathermap.api.request;
|
||||
|
||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequesterImpl;
|
||||
|
||||
public class OpenWeatherMapClient {
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
package com.github.prominence.openweathermap.api.request;
|
||||
|
||||
import com.github.prominence.openweathermap.api.enums.Accuracy;
|
||||
import com.github.prominence.openweathermap.api.enums.Language;
|
||||
@ -20,7 +20,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
package com.github.prominence.openweathermap.api.request;
|
||||
|
||||
public interface RequestTerminator<T, S> {
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.impl;
|
||||
package com.github.prominence.openweathermap.api.request;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -28,14 +28,16 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class RequestUrlBuilder {
|
||||
|
||||
private StringBuilder builder = new StringBuilder();
|
||||
private Map<String, Object> requestParameters = new HashMap<>();
|
||||
private static final String API_KEY_PARAM_NAME = "appid";
|
||||
|
||||
public RequestUrlBuilder(String baseUrl) {
|
||||
builder.append(baseUrl);
|
||||
private final StringBuilder builder = new StringBuilder("http://api.openweathermap.org/data/2.5/");
|
||||
private final Map<String, Object> requestParameters = new HashMap<>();
|
||||
|
||||
public RequestUrlBuilder(String key) {
|
||||
requestParameters.put(API_KEY_PARAM_NAME, key);
|
||||
}
|
||||
|
||||
void append(String value) {
|
||||
public void append(String value) {
|
||||
builder.append(value);
|
||||
}
|
||||
|
||||
@ -43,7 +45,11 @@ public class RequestUrlBuilder {
|
||||
requestParameters.put(key, value);
|
||||
}
|
||||
|
||||
String buildUrl() {
|
||||
public void setAPIKey(String key) {
|
||||
requestParameters.put(API_KEY_PARAM_NAME, key);
|
||||
}
|
||||
|
||||
public String buildUrl() {
|
||||
final String joinedParameters = requestParameters.entrySet().stream()
|
||||
.map(entry -> entry.getKey() + "=" + entry.getValue())
|
||||
.collect(Collectors.joining("&"));
|
||||
@ -20,7 +20,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
package com.github.prominence.openweathermap.api.request;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -20,7 +20,9 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
package com.github.prominence.openweathermap.api.request.weather;
|
||||
|
||||
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
||||
|
||||
public interface CurrentWeatherRequestTerminator<T, S> extends RequestTerminator<T, S> {
|
||||
|
||||
@ -20,7 +20,10 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
package com.github.prominence.openweathermap.api.request.weather;
|
||||
|
||||
import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsWeatherRequester;
|
||||
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationWeatherRequester;
|
||||
|
||||
public interface CurrentWeatherRequester {
|
||||
|
||||
@ -20,18 +20,20 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.impl;
|
||||
package com.github.prominence.openweathermap.api.request.weather;
|
||||
|
||||
import com.github.prominence.openweathermap.api.CurrentWeatherRequester;
|
||||
import com.github.prominence.openweathermap.api.MultipleLocationsWeatherRequester;
|
||||
import com.github.prominence.openweathermap.api.SingleLocationWeatherRequester;
|
||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||
import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsCurrentWeatherRequesterImpl;
|
||||
import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsWeatherRequester;
|
||||
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequesterImpl;
|
||||
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationWeatherRequester;
|
||||
|
||||
public class CurrentWeatherRequesterImpl implements CurrentWeatherRequester {
|
||||
|
||||
private RequestUrlBuilder urlBuilder = new RequestUrlBuilder("http://api.openweathermap.org/data/2.5/");
|
||||
private final RequestUrlBuilder urlBuilder;
|
||||
|
||||
CurrentWeatherRequesterImpl(String apiKey) {
|
||||
urlBuilder.addRequestParameter("appid", apiKey);
|
||||
public CurrentWeatherRequesterImpl(String apiKey) {
|
||||
urlBuilder = new RequestUrlBuilder(apiKey);
|
||||
}
|
||||
|
||||
public SingleLocationWeatherRequester single() {
|
||||
@ -20,11 +20,11 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.impl;
|
||||
package com.github.prominence.openweathermap.api.request.weather;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.prominence.openweathermap.api.ResponseMapper;
|
||||
import com.github.prominence.openweathermap.api.request.ResponseMapper;
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
import com.github.prominence.openweathermap.api.model.*;
|
||||
|
||||
@ -81,9 +81,9 @@ import java.util.TimeZone;
|
||||
*/
|
||||
public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
|
||||
|
||||
private UnitSystem unitSystem;
|
||||
private final UnitSystem unitSystem;
|
||||
|
||||
CurrentWeatherResponseMapper(UnitSystem unitSystem) {
|
||||
public CurrentWeatherResponseMapper(UnitSystem unitSystem) {
|
||||
this.unitSystem = unitSystem != null ? unitSystem : UnitSystem.STANDARD;
|
||||
}
|
||||
|
||||
@ -20,18 +20,17 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.impl;
|
||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||
|
||||
import com.github.prominence.openweathermap.api.MultipleLocationsWeatherRequester;
|
||||
import com.github.prominence.openweathermap.api.MultipleResultCurrentWeatherRequestCustomizer;
|
||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
|
||||
|
||||
public class MultipleLocationsCurrentWeatherRequesterImpl implements MultipleLocationsWeatherRequester {
|
||||
|
||||
private RequestUrlBuilder urlBuilder;
|
||||
private final RequestUrlBuilder urlBuilder;
|
||||
|
||||
MultipleLocationsCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
|
||||
public MultipleLocationsCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
|
||||
@ -20,9 +20,10 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Weather;
|
||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequestTerminator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -20,9 +20,10 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.impl;
|
||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||
|
||||
import com.github.prominence.openweathermap.api.MultipleResultCurrentWeatherAsyncRequestTerminator;
|
||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
import com.github.prominence.openweathermap.api.model.Weather;
|
||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||
@ -32,8 +33,8 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class MultipleResultCurrentWeatherAsyncRequestTerminatorImpl implements MultipleResultCurrentWeatherAsyncRequestTerminator {
|
||||
|
||||
private RequestUrlBuilder urlBuilder;
|
||||
private UnitSystem unitSystem;
|
||||
private final RequestUrlBuilder urlBuilder;
|
||||
private final UnitSystem unitSystem;
|
||||
|
||||
MultipleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
@ -20,7 +20,9 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||
|
||||
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
||||
|
||||
public interface MultipleResultCurrentWeatherRequestCustomizer extends RequestCustomizer<MultipleResultCurrentWeatherRequestCustomizer> {
|
||||
|
||||
@ -20,18 +20,16 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.impl;
|
||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||
|
||||
import com.github.prominence.openweathermap.api.MultipleResultCurrentWeatherAsyncRequestTerminator;
|
||||
import com.github.prominence.openweathermap.api.MultipleResultCurrentWeatherRequestCustomizer;
|
||||
import com.github.prominence.openweathermap.api.MultipleResultCurrentWeatherRequestTerminator;
|
||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||
import com.github.prominence.openweathermap.api.enums.Accuracy;
|
||||
import com.github.prominence.openweathermap.api.enums.Language;
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
|
||||
public class MultipleResultCurrentWeatherRequestCustomizerImpl implements MultipleResultCurrentWeatherRequestCustomizer {
|
||||
|
||||
private RequestUrlBuilder urlBuilder;
|
||||
private final RequestUrlBuilder urlBuilder;
|
||||
|
||||
private Accuracy accuracy;
|
||||
private Language language;
|
||||
@ -20,9 +20,10 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Weather;
|
||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequestTerminator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -20,9 +20,10 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.impl;
|
||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||
|
||||
import com.github.prominence.openweathermap.api.MultipleResultCurrentWeatherRequestTerminator;
|
||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
import com.github.prominence.openweathermap.api.model.Weather;
|
||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||
@ -31,8 +32,8 @@ import java.util.List;
|
||||
|
||||
public class MultipleResultCurrentWeatherRequestTerminatorImpl implements MultipleResultCurrentWeatherRequestTerminator {
|
||||
|
||||
private RequestUrlBuilder urlBuilder;
|
||||
private UnitSystem unitSystem;
|
||||
private final RequestUrlBuilder urlBuilder;
|
||||
private final UnitSystem unitSystem;
|
||||
|
||||
MultipleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
@ -20,16 +20,16 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.impl;
|
||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||
|
||||
import com.github.prominence.openweathermap.api.SingleLocationWeatherRequester;
|
||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
|
||||
public class SingleLocationCurrentWeatherRequesterImpl implements SingleLocationWeatherRequester {
|
||||
|
||||
private RequestUrlBuilder urlBuilder;
|
||||
private final RequestUrlBuilder urlBuilder;
|
||||
|
||||
SingleLocationCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
|
||||
public SingleLocationCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
urlBuilder.append("weather");
|
||||
}
|
||||
@ -20,7 +20,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
|
||||
@ -20,9 +20,10 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Weather;
|
||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequestTerminator;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@ -20,9 +20,10 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.impl;
|
||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||
|
||||
import com.github.prominence.openweathermap.api.SingleResultCurrentWeatherAsyncRequestTerminator;
|
||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
import com.github.prominence.openweathermap.api.model.Weather;
|
||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||
@ -31,8 +32,8 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class SingleResultCurrentWeatherAsyncRequestTerminatorImpl implements SingleResultCurrentWeatherAsyncRequestTerminator {
|
||||
|
||||
private RequestUrlBuilder urlBuilder;
|
||||
private UnitSystem unitSystem;
|
||||
private final RequestUrlBuilder urlBuilder;
|
||||
private final UnitSystem unitSystem;
|
||||
|
||||
SingleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
@ -20,7 +20,9 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||
|
||||
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
||||
|
||||
public interface SingleResultCurrentWeatherRequestCustomizer extends RequestCustomizer<SingleResultCurrentWeatherRequestCustomizer> {
|
||||
|
||||
@ -20,18 +20,16 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.impl;
|
||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||
|
||||
import com.github.prominence.openweathermap.api.SingleResultCurrentWeatherAsyncRequestTerminator;
|
||||
import com.github.prominence.openweathermap.api.SingleResultCurrentWeatherRequestCustomizer;
|
||||
import com.github.prominence.openweathermap.api.SingleResultCurrentWeatherRequestTerminator;
|
||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||
import com.github.prominence.openweathermap.api.enums.Accuracy;
|
||||
import com.github.prominence.openweathermap.api.enums.Language;
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
|
||||
public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleResultCurrentWeatherRequestCustomizer {
|
||||
|
||||
private RequestUrlBuilder urlBuilder;
|
||||
private final RequestUrlBuilder urlBuilder;
|
||||
|
||||
private Accuracy accuracy;
|
||||
private Language language;
|
||||
@ -20,9 +20,10 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Weather;
|
||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequestTerminator;
|
||||
|
||||
public interface SingleResultCurrentWeatherRequestTerminator extends CurrentWeatherRequestTerminator<Weather, String> {
|
||||
}
|
||||
@ -20,17 +20,18 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.impl;
|
||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||
|
||||
import com.github.prominence.openweathermap.api.SingleResultCurrentWeatherRequestTerminator;
|
||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
import com.github.prominence.openweathermap.api.model.Weather;
|
||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||
|
||||
public class SingleResultCurrentWeatherRequestTerminatorImpl implements SingleResultCurrentWeatherRequestTerminator {
|
||||
|
||||
private RequestUrlBuilder urlBuilder;
|
||||
private UnitSystem unitSystem;
|
||||
private final RequestUrlBuilder urlBuilder;
|
||||
private final UnitSystem unitSystem;
|
||||
|
||||
SingleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||
this.urlBuilder = urlBuilder;
|
||||
@ -22,7 +22,7 @@
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
|
||||
import com.github.prominence.openweathermap.api.impl.OpenWeatherMapClient;
|
||||
import com.github.prominence.openweathermap.api.request.OpenWeatherMapClient;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class ApiTest {
|
||||
|
||||
@ -27,7 +27,7 @@ import com.github.prominence.openweathermap.api.enums.Language;
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
|
||||
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||
import com.github.prominence.openweathermap.api.impl.OpenWeatherMapClient;
|
||||
import com.github.prominence.openweathermap.api.request.OpenWeatherMapClient;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
|
||||
import com.github.prominence.openweathermap.api.model.Weather;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user