diff --git a/pom.xml b/pom.xml
index 7729845..fba8660 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,8 +9,8 @@
1.2.3
- 11
- 11
+ 17
+ 17
@@ -23,19 +23,29 @@
- org.json
- json
- 20190722
+ com.google.code.gson
+ gson
+ 2.9.0
org.jsoup
jsoup
- 1.11.2
+ 1.14.3
- junit
- junit
- 4.12
+ org.projectlombok
+ lombok
+ 1.18.22
+
+
+ org.jetbrains
+ annotations
+ 22.0.0
+
+
+ org.junit.jupiter
+ junit-jupiter
+ 5.8.2
test
diff --git a/src/main/java/dev/coly/weather/HttpHandler.java b/src/main/java/dev/coly/weather/HttpHandler.java
deleted file mode 100644
index 29c1849..0000000
--- a/src/main/java/dev/coly/weather/HttpHandler.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package dev.coly.weather;
-
-import org.jsoup.Jsoup;
-
-import java.io.IOException;
-
-/**
- * Created by Gregyyy on 02.12.2017.
- */
-public class HttpHandler {
-
- public static String getContentFromWebsite(String url) throws IOException {
- return Jsoup.connect(url).ignoreContentType(true).execute().body();
- }
-
-}
diff --git a/src/main/java/dev/coly/weather/JSONHelper.java b/src/main/java/dev/coly/weather/JSONHelper.java
deleted file mode 100644
index 19e55e5..0000000
--- a/src/main/java/dev/coly/weather/JSONHelper.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package dev.coly.weather;
-
-import org.json.JSONObject;
-
-/**
- * Created by Gregyyy on 19.04.2018.
- */
-public class JSONHelper{
-
- public static String getString(JSONObject json, String object, String key){
- if(!json.has(object)) return null;
- if(!json.getJSONObject(object).has(key)) return null;
- return json.getJSONObject(object).getString(key);
- }
-
- public static int getInt(JSONObject json, String object, String key){
- if(!json.has(object)) return -1;
- if(!json.getJSONObject(object).has(key)) return -1;
- return json.getJSONObject(object).getInt(key);
- }
-
- public static double getDouble(JSONObject json, String object, String key){
- if(!json.has(object)) return -1;
- if(!json.getJSONObject(object).has(key)) return -1;
- return json.getJSONObject(object).getDouble(key);
- }
-
- public static long getLong(JSONObject json, String object, String key){
- if(!json.has(object)) return -1;
- if(!json.getJSONObject(object).has(key)) return -1;
- return json.getJSONObject(object).getLong(key);
- }
-
- public static String getString(JSONObject json, String array, int index, String key){
- if(!json.has(array)) return null;
- if(json.getJSONArray(array).length() <= index) return null;
- if(!json.getJSONArray(array).getJSONObject(index).has(key)) return null;
- return json.getJSONArray(array).getJSONObject(index).getString(key);
- }
-
- public static int getInt(JSONObject json, String array, int index, String key){
- if(!json.has(array)) return -1;
- if(json.getJSONArray(array).length() >= index) return -1;
- if(!json.getJSONArray(array).getJSONObject(index).has(key)) return -1;
- return json.getJSONArray(array).getJSONObject(index).getInt(key);
- }
-
- public static double getDouble(JSONObject json, String array, int index, String key){
- if(!json.has(array)) return -1;
- if(json.getJSONArray(array).length() <= index) return -1;
- if(!json.getJSONArray(array).getJSONObject(index).has(key)) return -1;
- return json.getJSONArray(array).getJSONObject(index).getDouble(key);
- }
-
-}
diff --git a/src/main/java/dev/coly/weather/Station.java b/src/main/java/dev/coly/weather/Station.java
deleted file mode 100644
index 14fed64..0000000
--- a/src/main/java/dev/coly/weather/Station.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package dev.coly.weather;
-
-import org.json.JSONObject;
-
-/**
- * Created by Gregyyy on 02.12.2017.
- */
-public class Station {
-
- private String name;
- private int id;
- private double longitude;
- private double latitude;
- private String country;
- private Long sunrise;
- private Long sunset;
-
- public Station() {
- }
-
- public Station(String name, int id, double longitude, double latitude, String country, Long sunrise, Long sunset) {
- this.name = name;
- this.id = id;
- this.longitude = longitude;
- this.latitude = latitude;
- this.country = country;
- this.sunrise = sunrise;
- this.sunset = sunset;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public int getId() {
- return id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
-
- public double getLongitude() {
- return longitude;
- }
-
- public void setLongitude(double longitude) {
- this.longitude = longitude;
- }
-
- public double getLatitude() {
- return latitude;
- }
-
- public void setLatitude(double latitude) {
- this.latitude = latitude;
- }
-
- public String getCountry() {
- return country;
- }
-
- public void setCountry(String country) {
- this.country = country;
- }
-
- public Long getSunrise() {
- return sunrise;
- }
-
- public void setSunrise(Long sunrise) {
- this.sunrise = sunrise;
- }
-
- public Long getSunset() {
- return sunset;
- }
-
- public void setSunset(Long sunset) {
- this.sunset = sunset;
- }
-
- @Override
- public String toString() {
- return "Station{" +
- "name='" + name + '\'' +
- ", id=" + id +
- ", longitude=" + longitude +
- ", latitude=" + latitude +
- ", country='" + country + '\'' +
- ", sunrise=" + sunrise +
- ", sunset=" + sunset +
- '}';
- }
-
- public JSONObject toJSON() {
- return new JSONObject().append("name", name).append("id", id).append("longitude", longitude)
- .append("latitude", latitude).append("country", country).append("sunrise", sunrise).append("sunset", sunset);
- }
-}
diff --git a/src/main/java/dev/coly/weather/UVIndex.java b/src/main/java/dev/coly/weather/UVIndex.java
deleted file mode 100644
index 204f4e8..0000000
--- a/src/main/java/dev/coly/weather/UVIndex.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package dev.coly.weather;
-
-/**
- * Created by Gregyyy on 27.03.2018.
- */
-public class UVIndex{
-
- private Long date;
- private Float value;
-
- public UVIndex(){
- }
-
- public UVIndex(Long date, Float value){
- this.date = date;
- this.value = value;
- }
-
- public Long getDate(){
- return date;
- }
-
- public void setDate(Long date){
- this.date = date;
- }
-
- public Float getValue(){
- return value;
- }
-
- public void setValue(Float value){
- this.value = value;
- }
-
- @Override
- public String toString(){
- return "UVIndex{" +
- "date=" + date +
- ", value=" + value +
- '}';
- }
-}
diff --git a/src/main/java/dev/coly/weather/UnitType.java b/src/main/java/dev/coly/weather/UnitType.java
deleted file mode 100644
index 54836a0..0000000
--- a/src/main/java/dev/coly/weather/UnitType.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package dev.coly.weather;
-
-/**
- * Created by Gregyyy on 02.12.2017.
- */
-public enum UnitType {
-
- Standard, Metric, Imperial
-
-}
diff --git a/src/main/java/dev/coly/weather/WeatherAPI.java b/src/main/java/dev/coly/weather/WeatherAPI.java
new file mode 100644
index 0000000..8c0c702
--- /dev/null
+++ b/src/main/java/dev/coly/weather/WeatherAPI.java
@@ -0,0 +1,40 @@
+package dev.coly.weather;
+
+import dev.coly.weather.element.CurrentWeather;
+import dev.coly.weather.provider.Provider;
+import dev.coly.weather.provider.brightsky.BrightSkyProvider;
+import dev.coly.weather.provider.owm.OpenWeatherMapProvider;
+
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+
+public class WeatherAPI {
+
+ private List providers = new LinkedList<>();
+
+ public WeatherAPI addOpenWeatherMap(String apiKey) {
+ if (providers.stream().anyMatch(provider -> provider.getClass().equals(OpenWeatherMapProvider.class))) {
+ throw new IllegalStateException("Provider already added");
+ }
+
+ providers.add(new OpenWeatherMapProvider(apiKey));
+
+ return this;
+ }
+
+ public WeatherAPI addBrightSky() {
+ if (providers.stream().anyMatch(provider -> provider.getClass().equals(OpenWeatherMapProvider.class))) {
+ throw new IllegalStateException("Provider already added");
+ }
+
+ providers.add(new BrightSkyProvider());
+
+ return this;
+ }
+
+ public CurrentWeather getCurrentWeather(double longitude, double latitude) throws IOException {
+ return providers.get(0).getCurrentWeather(longitude, latitude);
+ }
+
+}
diff --git a/src/main/java/dev/coly/weather/WeatherClient.java b/src/main/java/dev/coly/weather/WeatherClient.java
deleted file mode 100644
index 502a1da..0000000
--- a/src/main/java/dev/coly/weather/WeatherClient.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package dev.coly.weather;
-
-import dev.coly.weather.apis.CurrentUVIndex;
-import dev.coly.weather.apis.CurrentWeather;
-import dev.coly.weather.apis.ForecastUVIndex;
-import dev.coly.weather.apis.ForecastWeather;
-
-import java.io.IOException;
-
-/**
- * Created by Gregyyy on 02.12.2017.
- */
-public class WeatherClient {
-
- private String API_KEY;
-
- public WeatherClient(String API_KEY){
- this.API_KEY = API_KEY;
- }
-
- public CurrentWeather getCurrentWeatherByCoordinates(double latitude, double longitude, UnitType unitType, String langCode) throws IOException{
- return getCurrentWeatherByURL("http://api.openweathermap.org/data/2.5/weather?lat=" + latitude + "&lon=" + longitude + "&APPID=" + API_KEY + addUnit(unitType) + "&lang=" + langCode);
- }
-
- public CurrentWeather getCurrentWeatherByCityID(String cityID, UnitType unitType, String langCode) throws IOException{
- return getCurrentWeatherByURL("http://api.openweathermap.org/data/2.5/weather?id=" + cityID + "&APPID=" + API_KEY + addUnit(unitType) + "&lang=" + langCode);
- }
-
- public CurrentWeather getCurrentWeatherByCityName(String cityName, UnitType unitType, String langCode) throws IOException{
- return getCurrentWeatherByURL("http://api.openweathermap.org/data/2.5/weather?q=" + cityName + "&APPID=" + API_KEY + addUnit(unitType) + "&lang=" + langCode);
- }
-
- public CurrentWeather getCurrentWeatherByURL(String url) throws IOException {
- return new CurrentWeather().parseContent(url);
- }
- public ForecastWeather getForecastWeatherByCoordinates(double latitude, double longitude, UnitType unitType, String langCode) throws IOException{
- return getForecastWeatherByURL("http://api.openweathermap.org/data/2.5/forecast?lat=" + latitude + "&lon=" + longitude + "&APPID=" + API_KEY + addUnit(unitType) + "&lang=" + langCode);
- }
-
- public ForecastWeather getForecastWeatherByCityID(String cityID, UnitType unitType, String langCode) throws IOException{
- return getForecastWeatherByURL("http://api.openweathermap.org/data/2.5/forecast?id=" + cityID + "&APPID=" + API_KEY + addUnit(unitType) + "&lang=" + langCode);
- }
-
- public ForecastWeather getForecastWeatherByCityName(String cityName, UnitType unitType, String langCode) throws IOException{
- return getForecastWeatherByURL("http://api.openweathermap.org/data/2.5/forecast?q=" + cityName + "&APPID=" + API_KEY + addUnit(unitType) + "&lang=" + langCode);
- }
-
- public ForecastWeather getForecastWeatherByURL(String url) throws IOException {
- return new ForecastWeather().parseContent(url);
- }
-
- public CurrentUVIndex getCurrentUVByURL(String url) throws IOException {
- return new CurrentUVIndex().parseContent(url);
- }
-
- public CurrentUVIndex getCurrentUVByCoordinates(double latitude, double longitude, UnitType unitType, String langCode) throws IOException{
- return getCurrentUVByURL("http://api.openweathermap.org/data/2.5/uvi?lat=" + latitude + "&lon=" + longitude + "&APPID=" + API_KEY + addUnit(unitType) + "&lang=" + langCode);
- }
-
- public ForecastUVIndex getForecastUVByURL(String url) throws IOException {
- return new ForecastUVIndex().parseContent(url);
- }
-
- public ForecastUVIndex getForecastUVByCoordinates(double latitude, double longitude, UnitType unitType, String langCode) throws IOException{
- return getForecastUVByURL("http://api.openweathermap.org/data/2.5/uvi/forecast?lat=" + latitude + "&lon=" + longitude + "&APPID=" + API_KEY + addUnit(unitType) + "&lang=" + langCode);
- }
-
- public String addUnit(UnitType unitType){
- if(unitType == UnitType.Standard){
- return "";
- }
- if(unitType == UnitType.Metric){
- return "&units=metric";
- }
- if(unitType == UnitType.Imperial){
- return "&units=imperial";
- }
- return "";
- }
-
-}
diff --git a/src/main/java/dev/coly/weather/WeatherState.java b/src/main/java/dev/coly/weather/WeatherState.java
deleted file mode 100644
index 087a90b..0000000
--- a/src/main/java/dev/coly/weather/WeatherState.java
+++ /dev/null
@@ -1,187 +0,0 @@
-package dev.coly.weather;
-
-import org.json.JSONObject;
-
-/**
- * Created by Gregyyy on 02.12.2017.
- */
-public class WeatherState {
-
- private String weather;
- private String weatherDescription;
- private int weatherId;
- private String weatherIcon;
- private Double temperature;
- private Double temperatureMin;
- private Double temperatureMax;
- private int pressure;
- private int humidity;
- private Double windSpeed;
- private int windDegree;
- private int cloudiness;
- private double seaLevel;
- private double groundLevel;
-
- public WeatherState(){
- }
-
- public WeatherState(String weather, String weatherDescription, int weatherId, String weatherIcon, Double temperature,
- Double temperatureMin, Double temperatureMax, int pressure, int humidity, Double windSpeed,
- int windDegree, int cloudiness, double seaLevel, double groundLevel) {
- this.weather = weather;
- this.weatherDescription = weatherDescription;
- this.weatherId = weatherId;
- this.weatherIcon = weatherIcon;
- this.temperature = temperature;
- this.temperatureMin = temperatureMin;
- this.temperatureMax = temperatureMax;
- this.pressure = pressure;
- this.humidity = humidity;
- this.windSpeed = windSpeed;
- this.windDegree = windDegree;
- this.cloudiness = cloudiness;
- this.seaLevel = seaLevel;
- this.groundLevel = groundLevel;
- }
-
- public String getWeather() {
- return weather;
- }
-
- public void setWeather(String weather) {
- this.weather = weather;
- }
-
- public String getWeatherDescription() {
- return weatherDescription;
- }
-
- public void setWeatherDescription(String weatherDescription) {
- this.weatherDescription = weatherDescription;
- }
-
- public int getWeatherId() {
- return weatherId;
- }
-
- public void setWeatherId(int weatherId) {
- this.weatherId = weatherId;
- }
-
- public String getWeatherIcon() {
- return weatherIcon;
- }
-
- public void setWeatherIcon(String weatherIcon) {
- this.weatherIcon = weatherIcon;
- }
-
- public Double getTemperature() {
- return temperature;
- }
-
- public void setTemperature(Double temperature) {
- this.temperature = temperature;
- }
-
- public Double getTemperatureMin() {
- return temperatureMin;
- }
-
- public void setTemperatureMin(Double temperatureMin) {
- this.temperatureMin = temperatureMin;
- }
-
- public Double getTemperatureMax() {
- return temperatureMax;
- }
-
- public void setTemperatureMax(Double temperatureMax) {
- this.temperatureMax = temperatureMax;
- }
-
- public int getPressure() {
- return pressure;
- }
-
- public void setPressure(int pressure) {
- this.pressure = pressure;
- }
-
- public int getHumidity() {
- return humidity;
- }
-
- public void setHumidity(int humidity) {
- this.humidity = humidity;
- }
-
- public Double getWindSpeed() {
- return windSpeed;
- }
-
- public void setWindSpeed(Double windSpeed) {
- this.windSpeed = windSpeed;
- }
-
- public int getWindDegree() {
- return windDegree;
- }
-
- public void setWindDegree(int windDegree) {
- this.windDegree = windDegree;
- }
-
- public int getCloudiness() {
- return cloudiness;
- }
-
- public void setCloudiness(int cloudiness) {
- this.cloudiness = cloudiness;
- }
-
- public double getSeaLevel(){
- return seaLevel;
- }
-
- public void setSeaLevel(double seaLevel){
- this.seaLevel = seaLevel;
- }
-
- public double getGroundLevel(){
- return groundLevel;
- }
-
- public void setGroundLevel(double groundLevel){
- this.groundLevel = groundLevel;
- }
-
- @Override
- public String toString(){
- return "WeatherState{" +
- "weather='" + weather + '\'' +
- ", weatherDescription='" + weatherDescription + '\'' +
- ", weatherId=" + weatherId +
- ", weatherIcon='" + weatherIcon + '\'' +
- ", temperature=" + temperature +
- ", temperatureMin=" + temperatureMin +
- ", temperatureMax=" + temperatureMax +
- ", pressure=" + pressure +
- ", humidity=" + humidity +
- ", windSpeed=" + windSpeed +
- ", windDegree=" + windDegree +
- ", cloudiness=" + cloudiness +
- ", seaLevel=" + seaLevel +
- ", groundLevel=" + groundLevel +
- '}';
- }
-
- public JSONObject toJSON() {
- return new JSONObject().append("weather", weather).append("weatherDescription", weatherDescription)
- .append("weatherId", weatherId).append("weatherIcon", weatherIcon).append("temperature", temperature)
- .append("temperatureMin", temperatureMin).append("temperatureMax", temperatureMax)
- .append("pressure", pressure).append("humidity", humidity).append("windSpeed", windSpeed)
- .append("windDegree", windDegree).append("cloudiness", cloudiness).append("seaLevel", seaLevel)
- .append("groundLevel", groundLevel);
- }
-}
diff --git a/src/main/java/dev/coly/weather/apis/CurrentUVIndex.java b/src/main/java/dev/coly/weather/apis/CurrentUVIndex.java
deleted file mode 100644
index 0c368e1..0000000
--- a/src/main/java/dev/coly/weather/apis/CurrentUVIndex.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package dev.coly.weather.apis;
-
-import dev.coly.weather.HttpHandler;
-import dev.coly.weather.UVIndex;
-import org.json.JSONObject;
-
-import java.io.IOException;
-
-/**
- * Created by Gregyyy on 27.03.2018.
- */
-public class CurrentUVIndex{
-
- private Float latitude;
- private Float longitude;
- private UVIndex uvIndex;
-
- public CurrentUVIndex(){
- }
-
- public CurrentUVIndex parseContent(String url) throws IOException{
- String content = HttpHandler.getContentFromWebsite(url);
- JSONObject json = new JSONObject(content);
-
- latitude = json.getFloat("lat");
- longitude = json.getFloat("lon");
- UVIndex index = new UVIndex();
- index.setValue(json.getFloat("value"));
- index.setDate(json.getLong("date"));
- uvIndex = index;
-
- return this;
- }
-
- public CurrentUVIndex(Float latitude, Float longitude, UVIndex uvIndex){
- this.latitude = latitude;
- this.longitude = longitude;
- this.uvIndex = uvIndex;
- }
-
- public Float getLatitude(){
- return latitude;
- }
-
- public void setLatitude(Float latitude){
- this.latitude = latitude;
- }
-
- public Float getLongitude(){
- return longitude;
- }
-
- public void setLongitude(Float longitude){
- this.longitude = longitude;
- }
-
- public UVIndex getUvIndex(){
- return uvIndex;
- }
-
- public void setUvIndex(UVIndex uvIndex){
- this.uvIndex = uvIndex;
- }
-
- @Override
- public String toString(){
- return "CurrentUVIndex{" +
- "latitude=" + latitude +
- ", longitude=" + longitude +
- ", uvIndex=" + uvIndex +
- '}';
- }
-}
-
diff --git a/src/main/java/dev/coly/weather/apis/CurrentWeather.java b/src/main/java/dev/coly/weather/apis/CurrentWeather.java
deleted file mode 100644
index c59b25d..0000000
--- a/src/main/java/dev/coly/weather/apis/CurrentWeather.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package dev.coly.weather.apis;
-
-import dev.coly.weather.HttpHandler;
-import dev.coly.weather.JSONHelper;
-import dev.coly.weather.Station;
-import dev.coly.weather.WeatherState;
-import org.json.JSONObject;
-
-import java.io.IOException;
-
-/**
- * Created by Gregyyy on 02.12.2017.
- */
-public class CurrentWeather {
-
- private Station station;
- private WeatherState weatherState;
- private long timeOfData;
-
- public CurrentWeather(){
- }
-
- public CurrentWeather parseContent(String url) throws IOException{
- String content = HttpHandler.getContentFromWebsite(url);
- JSONObject json = new JSONObject(content);
- Station station = new Station();
- WeatherState weatherState = new WeatherState();
-
- this.setTimeOfData(json.getLong("dt"));
-
- station.setName(json.getString("name"));
- station.setId(json.getInt("id"));
- station.setLongitude(JSONHelper.getDouble(json, "coord", "lon"));
- station.setLatitude(JSONHelper.getDouble(json, "coord", "lat"));
- station.setCountry(JSONHelper.getString(json, "sys", "country"));
- station.setSunrise(JSONHelper.getLong(json, "sys", "sunrise"));
- station.setSunset(JSONHelper.getLong(json, "sys", "sunset"));
- this.setStation(station);
-
- weatherState.setWeather(JSONHelper.getString(json, "weather", 0, "main"));
- weatherState.setWeatherDescription(JSONHelper.getString(json, "weather", 0, "description"));
- weatherState.setWeatherId(JSONHelper.getInt(json, "weather", 0, "id"));
- weatherState.setWeatherIcon(JSONHelper.getString(json, "weather", 0, "icon"));
- weatherState.setTemperature(JSONHelper.getDouble(json, "main", "temp"));
- weatherState.setTemperatureMin(JSONHelper.getDouble(json, "main", "temp_min"));
- weatherState.setTemperatureMax(JSONHelper.getDouble(json, "main", "temp_max"));
- weatherState.setPressure(JSONHelper.getInt(json, "main", "pressure"));
- weatherState.setHumidity(JSONHelper.getInt(json, "main", "humidity"));
- weatherState.setWindSpeed(JSONHelper.getDouble(json, "wind", "speed"));
- weatherState.setWindDegree(JSONHelper.getInt(json, "wind", "deg"));
- weatherState.setCloudiness(JSONHelper.getInt(json, "clouds", "all"));
- weatherState.setSeaLevel(JSONHelper.getDouble(json, "main", "sea_level"));
- weatherState.setGroundLevel(JSONHelper.getDouble(json, "main", "grnd_level"));
- this.setWeatherState(weatherState);
-
- return this;
- }
-
- public CurrentWeather(Station station, WeatherState weatherState, long timeOfData){
- this.station = station;
- this.weatherState = weatherState;
- this.timeOfData = timeOfData;
- }
-
- public Station getStation() {
- return station;
- }
-
- public void setStation(Station station) {
- this.station = station;
- }
-
- public WeatherState getWeatherState() {
- return weatherState;
- }
-
- public void setWeatherState(WeatherState weatherState) {
- this.weatherState = weatherState;
- }
-
- public long getTimeOfData(){
- return timeOfData;
- }
-
- public void setTimeOfData(long timeOfData){
- this.timeOfData = timeOfData;
- }
-
- @Override
- public String toString(){
- return "CurrentWeather{" +
- "station=" + station +
- ", weatherState=" + weatherState +
- ", timeOfData=" + timeOfData +
- '}';
- }
-
- public JSONObject toJSON(){
- return new JSONObject().append("station", station.toJSON()).append("weatherState", weatherState.toJSON())
- .append("timeOfDate", timeOfData);
- }
-}
diff --git a/src/main/java/dev/coly/weather/apis/ForecastUVIndex.java b/src/main/java/dev/coly/weather/apis/ForecastUVIndex.java
deleted file mode 100644
index 09e6487..0000000
--- a/src/main/java/dev/coly/weather/apis/ForecastUVIndex.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package dev.coly.weather.apis;
-
-import dev.coly.weather.HttpHandler;
-import dev.coly.weather.UVIndex;
-import org.json.JSONObject;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.regex.Pattern;
-
-/**
- * Created by Gregyyy on 27.03.2018.
- */
-public class ForecastUVIndex{
-
- private Float latitude;
- private Float longitude;
- private ArrayList uvIndexes;
-
- public ForecastUVIndex(){
- }
-
- public ForecastUVIndex parseContent(String url) throws IOException{
- String content = HttpHandler.getContentFromWebsite(url);
- JSONObject json = new JSONObject(content.replaceFirst(Pattern.quote("["), "{[").replaceAll(Pattern.quote("]"), "]}"));
-
- Iterator iterator = json.keys();
- while(iterator.hasNext()){
- System.out.println("Name: '" + iterator.next() + "'");
- /*latitude = json.getJSONObject("" + i).getFloat("lat");
- longitude = json.getJSONObject("" + i).getFloat("lon");
- UVIndex index = new UVIndex();
- index.setValue(json.getJSONObject("" + i).getFloat("value"));
- index.setDate(json.getJSONObject("" + i).getLong("date"));
- uvIndexes.add(index);*/
- }
-
- return this;
- }
-
- public ForecastUVIndex(Float latitude, Float longitude, ArrayList uvIndexes){
- this.latitude = latitude;
- this.longitude = longitude;
- this.uvIndexes = uvIndexes;
- }
-
- public Float getLatitude(){
- return latitude;
- }
-
- public void setLatitude(Float latitude){
- this.latitude = latitude;
- }
-
- public Float getLongitude(){
- return longitude;
- }
-
- public void setLongitude(Float longitude){
- this.longitude = longitude;
- }
-
- public ArrayList getUvIndexes(){
- return uvIndexes;
- }
-
- public void setUvIndexes(ArrayList uvIndexes){
- this.uvIndexes = uvIndexes;
- }
-
- @Override
- public String toString(){
- return "ForecastUVIndex{" +
- "latitude=" + latitude +
- ", longitude=" + longitude +
- ", uvIndexes=" + uvIndexes +
- '}';
- }
-}
-
diff --git a/src/main/java/dev/coly/weather/apis/ForecastWeather.java b/src/main/java/dev/coly/weather/apis/ForecastWeather.java
deleted file mode 100644
index 7b54142..0000000
--- a/src/main/java/dev/coly/weather/apis/ForecastWeather.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package dev.coly.weather.apis;
-
-import dev.coly.weather.HttpHandler;
-import dev.coly.weather.Station;
-import dev.coly.weather.WeatherState;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.io.IOException;
-import java.util.HashMap;
-
-/**
- * Created by Gregyyy on 03.12.2017.
- */
-public class ForecastWeather {
-
- private Station station;
- private HashMap weatherStates = new HashMap<>();
-
- public ForecastWeather(){
- }
-
- public ForecastWeather parseContent(String url) throws IOException{
- String content = HttpHandler.getContentFromWebsite(url);
- JSONObject json = new JSONObject(content);
- Station station = new Station();
- HashMap weatherStates = new HashMap<>();
-
- station.setName(json.getJSONObject("city").getString("name"));
- station.setId(json.getJSONObject("city").getInt("id"));
- station.setLongitude(json.getJSONObject("city").getJSONObject("coord").getDouble("lon"));
- station.setLatitude(json.getJSONObject("city").getJSONObject("coord").getDouble("lat"));
- station.setCountry(json.getJSONObject("city").getString("country"));
- this.setStation(station);
-
- int count = json.getInt("cnt");
- for(int i = 0; i < count; i++){
- WeatherState weatherState = new WeatherState();
-
- weatherState.setWeather(json.getJSONArray("list").getJSONObject(i).getJSONArray("weather").getJSONObject(0).getString("main"));
- weatherState.setWeatherDescription(json.getJSONArray("list").getJSONObject(i).getJSONArray("weather").getJSONObject(0).getString("description"));
- weatherState.setWeatherId(json.getJSONArray("list").getJSONObject(i).getJSONArray("weather").getJSONObject(0).getInt("id"));
- weatherState.setWeatherIcon(json.getJSONArray("list").getJSONObject(i).getJSONArray("weather").getJSONObject(0).getString("icon"));
- weatherState.setTemperature(json.getJSONArray("list").getJSONObject(i).getJSONObject("main").getDouble("temp"));
- weatherState.setTemperatureMin(json.getJSONArray("list").getJSONObject(i).getJSONObject("main").getDouble("temp_min"));
- weatherState.setTemperatureMax(json.getJSONArray("list").getJSONObject(i).getJSONObject("main").getDouble("temp_max"));
- weatherState.setPressure(json.getJSONArray("list").getJSONObject(i).getJSONObject("main").getInt("pressure"));
- weatherState.setHumidity(json.getJSONArray("list").getJSONObject(i).getJSONObject("main").getInt("humidity"));
- weatherState.setWindSpeed(json.getJSONArray("list").getJSONObject(i).getJSONObject("wind").getDouble("speed"));
- weatherState.setWindDegree(json.getJSONArray("list").getJSONObject(i).getJSONObject("wind").getInt("deg"));
- weatherState.setCloudiness(json.getJSONArray("list").getJSONObject(i).getJSONObject("clouds").getInt("all"));
- try{ weatherState.setSeaLevel(json.getJSONObject("main").getDouble("sea_level")); }catch(JSONException ignore){}
- try{ weatherState.setGroundLevel(json.getJSONObject("main").getDouble("grnd_level")); }catch(JSONException ignore){}
-
- weatherStates.put(json.getJSONArray("list").getJSONObject(i).getLong("dt"), weatherState);
- }
-
- this.setWeatherStates(weatherStates);
- return this;
- }
-
- public ForecastWeather(Station station, HashMap weatherStates){
- this.station = station;
- this.weatherStates = weatherStates;
- }
-
- public Station getStation() {
- return station;
- }
-
- public void setStation(Station station) {
- this.station = station;
- }
-
- public HashMap getWeatherStates() {
- return weatherStates;
- }
-
- public void setWeatherStates(HashMap weatherStates) {
- this.weatherStates = weatherStates;
- }
-
- @Override
- public String toString() {
- return "ForecastWeather{" +
- "station=" + station +
- ", weatherStates=" + weatherStates +
- '}';
- }
-
- public JSONObject toJSON(){
- return new JSONObject().append("station", station.toJSON()).append("weatherStates", new JSONObject(weatherStates));
- }
-}
diff --git a/src/main/java/dev/coly/weather/element/CurrentWeather.java b/src/main/java/dev/coly/weather/element/CurrentWeather.java
new file mode 100644
index 0000000..774e69e
--- /dev/null
+++ b/src/main/java/dev/coly/weather/element/CurrentWeather.java
@@ -0,0 +1,7 @@
+package dev.coly.weather.element;
+
+import java.util.Date;
+
+public record CurrentWeather(Station station, Weather weather, Date timestamp) {
+
+}
diff --git a/src/main/java/dev/coly/weather/element/Station.java b/src/main/java/dev/coly/weather/element/Station.java
new file mode 100644
index 0000000..1881caa
--- /dev/null
+++ b/src/main/java/dev/coly/weather/element/Station.java
@@ -0,0 +1,7 @@
+package dev.coly.weather.element;
+
+import org.jetbrains.annotations.Nullable;
+
+public record Station(double longitude, double latitude, @Nullable String city) {
+
+}
diff --git a/src/main/java/dev/coly/weather/element/Weather.java b/src/main/java/dev/coly/weather/element/Weather.java
new file mode 100644
index 0000000..a17b633
--- /dev/null
+++ b/src/main/java/dev/coly/weather/element/Weather.java
@@ -0,0 +1,14 @@
+package dev.coly.weather.element;
+
+public record Weather(Description description, double temperature, double temperatureFeelsLike, Wind wind,
+ double cloudiness, int pressure, double humidity) {
+
+ public enum Description {
+ RAIN, SNOW, CLEAR, CLOUDS, THUNDERSTORMS, WIND, FOG, UNKNOWN
+ }
+
+ public record Wind(double speed, int degree) {
+
+ }
+
+}
diff --git a/src/main/java/dev/coly/weather/provider/Provider.java b/src/main/java/dev/coly/weather/provider/Provider.java
new file mode 100644
index 0000000..3bbe0fb
--- /dev/null
+++ b/src/main/java/dev/coly/weather/provider/Provider.java
@@ -0,0 +1,11 @@
+package dev.coly.weather.provider;
+
+import dev.coly.weather.element.CurrentWeather;
+
+import java.io.IOException;
+
+public abstract class Provider {
+
+ public abstract CurrentWeather getCurrentWeather(double longitude, double latitude) throws IOException;
+
+}
diff --git a/src/main/java/dev/coly/weather/provider/brightsky/BrightSkyProvider.java b/src/main/java/dev/coly/weather/provider/brightsky/BrightSkyProvider.java
new file mode 100644
index 0000000..1629933
--- /dev/null
+++ b/src/main/java/dev/coly/weather/provider/brightsky/BrightSkyProvider.java
@@ -0,0 +1,60 @@
+package dev.coly.weather.provider.brightsky;
+
+import com.google.gson.Gson;
+import dev.coly.weather.element.CurrentWeather;
+import dev.coly.weather.element.Station;
+import dev.coly.weather.element.Weather;
+import dev.coly.weather.provider.Provider;
+import dev.coly.weather.provider.brightsky.api.BSCurrentWeather;
+import org.jsoup.Jsoup;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class BrightSkyProvider extends Provider {
+
+ private final Gson gson;
+
+ private static final String HOST = "https://api.brightsky.dev/";
+
+ public BrightSkyProvider() {
+ gson = new Gson();
+ }
+
+ @Override
+ public CurrentWeather getCurrentWeather(double longitude, double latitude) throws IOException {
+ String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
+
+ String content = Jsoup.connect(HOST + "/current_weather?lat=" + latitude + "&lon=" + longitude + "&date=" + date)
+ .ignoreContentType(true).execute().body();
+ BSCurrentWeather bsResponse = gson.fromJson(content, BSCurrentWeather.class);
+
+ BSCurrentWeather.Source source = bsResponse.getSources()[0];
+
+ Station station = new Station(source.getLat(), source.getLon(), source.getStationName());
+
+ BSCurrentWeather.Weather bsWeather = bsResponse.getWeather();
+
+ Weather.Wind wind = new Weather.Wind(bsWeather.getWindSpeed(), bsWeather.getWindDirection());
+
+ Weather.Description description = Weather.Description.UNKNOWN;
+ switch (bsWeather.getIcon()) {
+ case "clear-day", "clear-night" -> description = Weather.Description.CLEAR;
+ case "partly_cloud_day", "partly_cloud_night", "cloudy" -> description = Weather.Description.CLOUDS;
+ case "rain" -> description = Weather.Description.RAIN;
+ case "snow", "sleet", "hail" -> description = Weather.Description.SNOW;
+ case "wind" -> description = Weather.Description.WIND;
+ case "thunderstorm" -> description = Weather.Description.THUNDERSTORMS;
+ case "fog" -> description = Weather.Description.FOG;
+ }
+
+ Weather weather = new Weather(description,
+ bsWeather.getTemperature(), bsWeather.getTemperature(), wind,
+ bsWeather.getCloudCover() / 100d, (int) bsWeather.getPressure(),
+ bsWeather.getHumidity() / 100d);
+
+ return new CurrentWeather(station, weather, bsWeather.getTimestamp());
+ }
+
+}
diff --git a/src/main/java/dev/coly/weather/provider/brightsky/api/BSCurrentWeather.java b/src/main/java/dev/coly/weather/provider/brightsky/api/BSCurrentWeather.java
new file mode 100644
index 0000000..83ea284
--- /dev/null
+++ b/src/main/java/dev/coly/weather/provider/brightsky/api/BSCurrentWeather.java
@@ -0,0 +1,92 @@
+package dev.coly.weather.provider.brightsky.api;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.Getter;
+
+import java.util.Date;
+
+public class BSCurrentWeather {
+
+ @Getter
+ private Weather weather;
+ public class Weather {
+
+ @Getter
+ private int sourceId;
+ @Getter
+ private Date timestamp;
+ @Getter
+ @SerializedName("cloud_cover")
+ private int cloudCover;
+ @Getter
+ private String condition;
+ @Getter
+ private double dewPoint;
+ @Getter
+ private String icon;
+ @Getter
+ @SerializedName("precipitation_60")
+ private int precipitation;
+ @Getter
+ @SerializedName("pressure_msl")
+ private double pressure;
+ @Getter
+ @SerializedName("relative_humidity")
+ private int humidity;
+ @Getter
+ @SerializedName("sunshine_60")
+ private int sunshine;
+ @Getter
+ private double temperature;
+ @Getter
+ private int visibilty;
+ @Getter
+ @SerializedName("wind_direction_60")
+ private int windDirection;
+ @Getter
+ @SerializedName("wind_speed_60")
+ public double windSpeed;
+ @Getter
+ @SerializedName("wind_gust_direction_60")
+ public int windGustDirection;
+ @Getter
+ @SerializedName("wind_gust_speed_60")
+ public double windGustSpeed;
+
+ }
+
+ @Getter
+ public Source[] sources;
+ public class Source {
+
+ @Getter
+ private int id;
+ @Getter
+ private String dwdStationId;
+ @Getter
+ private String wmoStationId;
+ @Getter
+ private String stationName;
+ @Getter
+ private ObservationType observationType;
+ @Getter
+ private Date firstRecord;
+ @Getter
+ private Date lastRecord;
+ @Getter
+ private double lat;
+ @Getter
+ private double lon;
+ @Getter
+ private double height;
+ @Getter
+ private double distance;
+
+ public enum ObservationType {
+ FORECAST, SYNOP, CURRENT, HISTORICAL
+ }
+
+
+ }
+
+}
diff --git a/src/main/java/dev/coly/weather/provider/owm/OpenWeatherMapProvider.java b/src/main/java/dev/coly/weather/provider/owm/OpenWeatherMapProvider.java
new file mode 100644
index 0000000..ed225c3
--- /dev/null
+++ b/src/main/java/dev/coly/weather/provider/owm/OpenWeatherMapProvider.java
@@ -0,0 +1,51 @@
+package dev.coly.weather.provider.owm;
+
+import com.google.gson.Gson;
+import dev.coly.weather.element.CurrentWeather;
+import dev.coly.weather.element.Station;
+import dev.coly.weather.element.Weather;
+import dev.coly.weather.provider.Provider;
+import dev.coly.weather.provider.owm.api.OWMCurrentWeather;
+import org.jsoup.Jsoup;
+
+import java.io.IOException;
+import java.util.Date;
+
+public class OpenWeatherMapProvider extends Provider {
+
+ private final Gson gson;
+
+ private static final String HOST = "https://api.openweathermap.org/data/2.5";
+
+ private final String apiKey;
+
+ public OpenWeatherMapProvider(String apiKey) {
+ this.apiKey = apiKey;
+ this.gson = new Gson();
+ }
+
+
+ @Override
+ public CurrentWeather getCurrentWeather(double longitude, double latitude) throws IOException {
+ String content = Jsoup.connect(HOST + "/weather?lat=" + latitude + "&lon=" + longitude + "&appid=" + this.apiKey)
+ .ignoreContentType(true).execute().body();
+ OWMCurrentWeather owmResponse = gson.fromJson(content, OWMCurrentWeather.class);
+
+ Station station = new Station(owmResponse.getCoordinates().getLongitude(),
+ owmResponse.getCoordinates().getLatitude(), owmResponse.getCityName());
+
+ Weather.Wind wind = new Weather.Wind(owmResponse.getWind().getSpeed(), owmResponse.getWind().getDegree());
+
+ if (owmResponse.getWeatherDescription().length == 0) {
+ throw new RuntimeException("Could not load description of weather from location");
+ }
+
+ Weather weather = new Weather(Weather.Description.valueOf(
+ owmResponse.getWeatherDescription()[0].getType().toUpperCase()),
+ owmResponse.getWeather().getTemperature(), owmResponse.getWeather().getFeelsLike(), wind,
+ owmResponse.getClouds().getCloudiness() / 100, owmResponse.getWeather().getPressure(),
+ owmResponse.getWeather().getHumidity() / 100d);
+
+ return new CurrentWeather(station, weather, new Date(owmResponse.getDateTime() * 1000));
+ }
+}
diff --git a/src/main/java/dev/coly/weather/provider/owm/api/OWMCurrentWeather.java b/src/main/java/dev/coly/weather/provider/owm/api/OWMCurrentWeather.java
new file mode 100644
index 0000000..fd68bb8
--- /dev/null
+++ b/src/main/java/dev/coly/weather/provider/owm/api/OWMCurrentWeather.java
@@ -0,0 +1,102 @@
+package dev.coly.weather.provider.owm.api;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.Getter;
+
+public class OWMCurrentWeather {
+
+ @Getter
+ @SerializedName("coord")
+ private Coordinates coordinates;
+ public static class Coordinates {
+
+ @Getter
+ @SerializedName("lon")
+ private double longitude;
+ @Getter
+ @SerializedName("lat")
+ private double latitude;
+
+ }
+
+ @Getter
+ @SerializedName("weather")
+ private WeatherDescription[] weatherDescription;
+ public static class WeatherDescription {
+
+ @Getter
+ private int id;
+ @Getter
+ @SerializedName("main")
+ private String type;
+ @Getter
+ @SerializedName("description")
+ private String description;
+ @Getter
+ private String icon;
+
+ }
+
+ @Getter
+ public String base;
+
+ @Getter
+ @SerializedName("main")
+ private Weather weather;
+ public class Weather {
+
+ @Getter
+ @SerializedName("temp")
+ private double temperature;
+ @Getter
+ @SerializedName("feels_like")
+ private double feelsLike;
+ @Getter
+ @SerializedName("temp_min")
+ private double temperatureMin;
+ @Getter
+ @SerializedName("temp_max")
+ private double temperatureMax;
+ @Getter
+ private int pressure;
+ @Getter
+ private int humidity;
+
+ }
+
+ @Getter
+ private int visibility;
+
+ @Getter
+ private Wind wind;
+ public class Wind {
+
+ @Getter
+ private double speed;
+ @Getter
+ @SerializedName("deg")
+ private int degree;
+
+ }
+
+ @Getter
+ private Clouds clouds;
+ public class Clouds {
+
+ @Getter
+ @SerializedName("all")
+ private double cloudiness;
+
+ }
+
+ @Getter
+ @SerializedName("dt")
+ private long dateTime;
+ @Getter
+ @SerializedName("id")
+ private long cityId;
+ @Getter
+ @SerializedName("name")
+ private String cityName;
+
+}
diff --git a/src/test/java/dev/coly/weather/test/ClientTest.java b/src/test/java/dev/coly/weather/test/ClientTest.java
deleted file mode 100644
index 5ef3bbe..0000000
--- a/src/test/java/dev/coly/weather/test/ClientTest.java
+++ /dev/null
@@ -1,180 +0,0 @@
-package dev.coly.weather.test;
-
-import dev.coly.weather.UnitType;
-import dev.coly.weather.WeatherClient;
-import dev.coly.weather.apis.CurrentWeather;
-import dev.coly.weather.apis.ForecastWeather;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.IOException;
-
-/**
- * Created by Gregyyy on 30.10.2018.
- */
-public class ClientTest {
-
- private WeatherClient weatherClient;
- private final String API_KEY = System.getenv("API_KEY");
-
- public ClientTest(){
- weatherClient = new WeatherClient(API_KEY);
- }
-
- private WeatherClient getWeatherClient(){
- return weatherClient;
- }
-
- @Test
- public void testGetWeatherClient(){
- Assert.assertNotNull(getWeatherClient());
- }
-
- @Test
- public void testGetCurrentWeatherByCoordinates(){
- try{
- CurrentWeather currentWeather = weatherClient.getCurrentWeatherByCoordinates(54.09, 12.13, UnitType.Metric, "DE");
- Assert.assertNotNull(currentWeather);
- System.out.println("Current Weather by Coordinates");
- System.out.println(currentWeather.toString());
- }catch(IOException e){
- Assert.fail();
- }
- }
-
- @Test
- public void testGetCurrentWeatherByCityID(){
- try{
- CurrentWeather currentWeather = weatherClient.getCurrentWeatherByCityID("2844588", UnitType.Metric, "DE");
- Assert.assertNotNull(currentWeather);
- System.out.println("Current Weather by City ID");
- System.out.println(currentWeather.toString());
- }catch(IOException e){
- Assert.fail();
- }
- }
-
- @Test
- public void testGetCurrentWeatherByCityName(){
- try{
- CurrentWeather currentWeather = weatherClient.getCurrentWeatherByCityName("Berlin", UnitType.Metric, "DE");
- Assert.assertNotNull(currentWeather);
- Assert.assertNotNull(currentWeather.getWeatherState());
- Assert.assertNotNull(currentWeather.getWeatherState().getWeather());
- System.out.println("Current Weather by City Name");
- System.out.println(currentWeather.toString());
- }catch(IOException e){
- Assert.fail();
- }
- }
-
- @Test
- public void testGetCurrentWeatherByURL() {
- try{
- CurrentWeather currentWeather = weatherClient.getCurrentWeatherByURL("http://api.openweathermap.org/data/2.5/weather?id=2844588&APPID=" + API_KEY + weatherClient.addUnit(UnitType.Metric) + "&lang=DE");
- Assert.assertNotNull(currentWeather);
- System.out.println("Current Weather by URL");
- System.out.println(currentWeather.toString());
- }catch(IOException e){
- Assert.fail();
- }
- }
-
- @Test
- public void testGetForecastWeatherByCoordinates(){
- try{
- ForecastWeather forecastWeather = weatherClient.getForecastWeatherByCoordinates(54.09, 12.13, UnitType.Metric, "DE");
- Assert.assertNotNull(forecastWeather);
- System.out.println("Forecast Weather by Coordinates");
- System.out.println(forecastWeather.toString());
- }catch(IOException e){
- Assert.fail();
- }
- }
-
- @Test
- public void testGetForecastWeatherByCityID(){
- try{
- ForecastWeather forecastWeather = weatherClient.getForecastWeatherByCityID("2844588", UnitType.Metric, "DE");
- Assert.assertNotNull(forecastWeather);
- System.out.println("Forecast Weather by City ID");
- System.out.println(forecastWeather.toString());
- }catch(IOException e){
- Assert.fail();
- }
- }
-
- @Test
- public void testGetForecastWeatherByCityName(){
- try{
- ForecastWeather forecastWeather = weatherClient.getForecastWeatherByCityName("Rostock", UnitType.Metric, "DE");
- Assert.assertNotNull(forecastWeather);
- System.out.println("Forecast Weather by City Name");
- System.out.println(forecastWeather.toString());
- }catch(IOException e){
- Assert.fail(e.toString());
- }
- }
-
- @Test
- public void testGetForecastWeatherByURL(){
- try{
- ForecastWeather forecastWeather = weatherClient.getForecastWeatherByURL("http://api.openweathermap.org/data/2.5/forecast?id=2844588&APPID=" + API_KEY + weatherClient.addUnit(UnitType.Metric) + "&lang=DE");
- Assert.assertNotNull(forecastWeather);
- System.out.println("Forecast Weather by URL");
- System.out.println(forecastWeather.toString());
- }catch(IOException e){
- Assert.fail();
- }
- }
-
- /*
- NOT IN USE. BUGGY.
- @Test
- public void testGetCurrentUVByURL(){
- try{
- CurrentUVIndex currentUVIndex = weatherClient.getCurrentUVByURL("http://api.openweathermap.org/data/2.5/uvi?id=2844588&APPID=" + API_KEY + weatherClient.addUnit(UnitType.Metric) + "&lang=DE");
- Assert.assertNotNull(currentUVIndex);
- System.out.println("Current UV Index by URL");
- System.out.println(currentUVIndex.toString());
- }catch(IOException e){
- Assert.fail();
- }
- }
-
- @Test
- public void testGetCurrentUVByCoordinates(){
- try{
- CurrentUVIndex currentUVIndex = weatherClient.getCurrentUVByCoordinates(54.09, 12.13, UnitType.Metric, "DE");
- Assert.assertNotNull(currentUVIndex);
- System.out.println("Current UV Index by Coordinates");
- System.out.println(currentUVIndex.toString());
- }catch(IOException e){
- Assert.fail();
- }
- }
-
- @Test
- public void testGetForecastUVByURL(){
- try{
- ForecastUVIndex forecastUVIndex = weatherClient.getForecastUVByURL("http://api.openweathermap.org/data/2.5/uvi?id=2844588&APPID=" + API_KEY + weatherClient.addUnit(UnitType.Metric) + "&lang=DE");
- Assert.assertNotNull(forecastUVIndex);
- System.out.println("Forecast UV Index by URL");
- System.out.println(forecastUVIndex.toString());
- }catch(IOException e){
- Assert.fail();
- }
- }
-
- @Test
- public void testGetForecastUVByCoordinates(){
- try{
- ForecastUVIndex forecastUVIndex = weatherClient.getForecastUVByCoordinates(54.09, 12.13, UnitType.Metric, "DE");
- Assert.assertNotNull(forecastUVIndex);
- System.out.println("Forecast UV Index by Coordinates");
- System.out.println(forecastUVIndex.toString());
- }catch(IOException e){
- Assert.fail();
- }
- }*/
-}
diff --git a/src/test/java/dev/coly/weather/test/TestBrightSky.java b/src/test/java/dev/coly/weather/test/TestBrightSky.java
new file mode 100644
index 0000000..83edc8b
--- /dev/null
+++ b/src/test/java/dev/coly/weather/test/TestBrightSky.java
@@ -0,0 +1,44 @@
+package dev.coly.weather.test;
+
+import dev.coly.weather.WeatherAPI;
+import dev.coly.weather.element.CurrentWeather;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.Date;
+
+public class TestBrightSky {
+
+ @Test
+ public void testGetCurrentWeather() {
+ WeatherAPI api = new WeatherAPI().addBrightSky();
+
+ try {
+ CurrentWeather weather = api.getCurrentWeather(8.24, 49);
+
+ Assertions.assertNotNull(weather.weather());
+ Assertions.assertNotNull(weather.station());
+ Assertions.assertNotNull(weather.timestamp());
+
+ Assertions.assertNotNull(weather.weather().description());
+ Assertions.assertTrue(weather.weather().temperature() > -150 &&
+ weather.weather().temperature() < 400);
+ Assertions.assertTrue(weather.weather().temperatureFeelsLike() > -200 &&
+ weather.weather().temperatureFeelsLike() < 400);
+ Assertions.assertNotNull(weather.weather().wind());
+ Assertions.assertTrue(weather.weather().wind().speed() >= 0 &&
+ weather.weather().wind().speed() < 300);
+ Assertions.assertTrue(weather.weather().wind().degree() >= 0 &&
+ weather.weather().wind().degree() < 365);
+ Assertions.assertTrue(weather.weather().cloudiness() >= 0 && weather.weather().cloudiness() <= 1);
+ Assertions.assertTrue(weather.weather().pressure() > 0);
+ Assertions.assertTrue(weather.weather().humidity() >= 0 && weather.weather().humidity() <= 1);
+
+ Assertions.assertTrue(weather.timestamp().before(new Date()));
+ } catch (IOException e) {
+ Assertions.fail(e);
+ }
+ }
+
+}
diff --git a/src/test/java/dev/coly/weather/test/TestOpenWeatherMap.java b/src/test/java/dev/coly/weather/test/TestOpenWeatherMap.java
new file mode 100644
index 0000000..3343903
--- /dev/null
+++ b/src/test/java/dev/coly/weather/test/TestOpenWeatherMap.java
@@ -0,0 +1,44 @@
+package dev.coly.weather.test;
+
+import dev.coly.weather.WeatherAPI;
+import dev.coly.weather.element.CurrentWeather;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.Date;
+
+public class TestOpenWeatherMap {
+
+ @Test
+ public void testGetCurrentWeather() {
+ WeatherAPI api = new WeatherAPI().addOpenWeatherMap(System.getenv("OWM_KEY"));
+
+ try {
+ CurrentWeather weather = api.getCurrentWeather(8.24, 49);
+
+ Assertions.assertNotNull(weather.weather());
+ Assertions.assertNotNull(weather.station());
+ Assertions.assertNotNull(weather.timestamp());
+
+ Assertions.assertNotNull(weather.weather().description());
+ Assertions.assertTrue(weather.weather().temperature() > -150 &&
+ weather.weather().temperature() < 400);
+ Assertions.assertTrue(weather.weather().temperatureFeelsLike() > -200 &&
+ weather.weather().temperatureFeelsLike() < 400);
+ Assertions.assertNotNull(weather.weather().wind());
+ Assertions.assertTrue(weather.weather().wind().speed() >= 0 &&
+ weather.weather().wind().speed() < 300);
+ Assertions.assertTrue(weather.weather().wind().degree() >= 0 &&
+ weather.weather().wind().degree() < 365);
+ Assertions.assertTrue(weather.weather().cloudiness() >= 0 && weather.weather().cloudiness() <= 1);
+ Assertions.assertTrue(weather.weather().pressure() > 0);
+ Assertions.assertTrue(weather.weather().humidity() >= 0 && weather.weather().humidity() <= 1);
+
+ Assertions.assertTrue(weather.timestamp().before(new Date()));
+ } catch (IOException e) {
+ Assertions.fail(e);
+ }
+ }
+
+}