mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-01-10 11:56:44 +03:00
Basic raw implementation.
This commit is contained in:
parent
b11a0e2a4d
commit
77f38e2b9a
7
.gitignore
vendored
7
.gitignore
vendored
@ -7,9 +7,6 @@
|
|||||||
# BlueJ files
|
# BlueJ files
|
||||||
*.ctxt
|
*.ctxt
|
||||||
|
|
||||||
# Mobile Tools for Java (J2ME)
|
|
||||||
.mtj.tmp/
|
|
||||||
|
|
||||||
# Package Files #
|
# Package Files #
|
||||||
*.jar
|
*.jar
|
||||||
*.war
|
*.war
|
||||||
@ -21,3 +18,7 @@
|
|||||||
|
|
||||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
.idea/
|
||||||
|
**/ApplicationTest.java
|
||||||
28
pom.xml
Normal file
28
pom.xml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>openweather-api</groupId>
|
||||||
|
<artifactId>by.prominence.openweater.api</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
<version>4.5.5</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>1.2.44</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 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 by.prominence.openweather.api;
|
||||||
|
|
||||||
|
import by.prominence.openweather.api.provider.DefaultWeatherProvider;
|
||||||
|
import by.prominence.openweather.api.provider.WeatherProvider;
|
||||||
|
|
||||||
|
public class WeatherProviderManager {
|
||||||
|
|
||||||
|
private String authToken;
|
||||||
|
|
||||||
|
public WeatherProviderManager(String token) {
|
||||||
|
this.authToken = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WeatherProvider getProvider() {
|
||||||
|
return new DefaultWeatherProvider(authToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 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 by.prominence.openweather.api.model;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Clouds {
|
||||||
|
|
||||||
|
@JSONField(name = "all")
|
||||||
|
// Cloudiness, %
|
||||||
|
private byte cloudiness;
|
||||||
|
|
||||||
|
public byte getCloudiness() {
|
||||||
|
return cloudiness;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCloudiness(byte cloudiness) {
|
||||||
|
this.cloudiness = cloudiness;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Clouds{" +
|
||||||
|
"cloudiness=" + cloudiness + "%" +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Clouds clouds = (Clouds) o;
|
||||||
|
return cloudiness == clouds.cloudiness;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
|
||||||
|
return Objects.hash(cloudiness);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 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 by.prominence.openweather.api.model;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Coordinates {
|
||||||
|
|
||||||
|
@JSONField(name = "lat")
|
||||||
|
// City geo location, latitude
|
||||||
|
private float latitude;
|
||||||
|
@JSONField(name = "lon")
|
||||||
|
// City geo location, longitude
|
||||||
|
private float longitude;
|
||||||
|
|
||||||
|
public Coordinates(float latitude, float longitude) {
|
||||||
|
this.latitude = latitude;
|
||||||
|
this.longitude = longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Coordinates{" +
|
||||||
|
"latitude=" + latitude +
|
||||||
|
", longitude=" + longitude +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Coordinates that = (Coordinates) o;
|
||||||
|
return Double.compare(that.latitude, latitude) == 0 &&
|
||||||
|
Double.compare(that.longitude, longitude) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(latitude, longitude);
|
||||||
|
}
|
||||||
|
}
|
||||||
63
src/main/java/by/prominence/openweather/api/model/Rain.java
Normal file
63
src/main/java/by/prominence/openweather/api/model/Rain.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 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 by.prominence.openweather.api.model;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Rain {
|
||||||
|
|
||||||
|
@JSONField(name = "3h")
|
||||||
|
// Rain volume for the last 3 hours
|
||||||
|
byte rainVolumeLast3Hrs;
|
||||||
|
|
||||||
|
public byte getRainVolumeLast3Hrs() {
|
||||||
|
return rainVolumeLast3Hrs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRainVolumeLast3Hrs(byte rainVolumeLast3Hrs) {
|
||||||
|
this.rainVolumeLast3Hrs = rainVolumeLast3Hrs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Rain{" +
|
||||||
|
"rainVolumeLast3Hrs=" + rainVolumeLast3Hrs +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Rain rain = (Rain) o;
|
||||||
|
return rainVolumeLast3Hrs == rain.rainVolumeLast3Hrs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
|
||||||
|
return Objects.hash(rainVolumeLast3Hrs);
|
||||||
|
}
|
||||||
|
}
|
||||||
63
src/main/java/by/prominence/openweather/api/model/Snow.java
Normal file
63
src/main/java/by/prominence/openweather/api/model/Snow.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 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 by.prominence.openweather.api.model;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Snow {
|
||||||
|
|
||||||
|
@JSONField(name = "all")
|
||||||
|
// Snow volume for the last 3 hours
|
||||||
|
private byte snowVolumeLast3Hrs;
|
||||||
|
|
||||||
|
public byte getSnowVolumeLast3Hrs() {
|
||||||
|
return snowVolumeLast3Hrs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSnowVolumeLast3Hrs(byte snowVolumeLast3Hrs) {
|
||||||
|
this.snowVolumeLast3Hrs = snowVolumeLast3Hrs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Snow{" +
|
||||||
|
"snowVolumeLast3Hrs=" + snowVolumeLast3Hrs +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Snow snow = (Snow) o;
|
||||||
|
return snowVolumeLast3Hrs == snow.snowVolumeLast3Hrs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
|
||||||
|
return Objects.hash(snowVolumeLast3Hrs);
|
||||||
|
}
|
||||||
|
}
|
||||||
117
src/main/java/by/prominence/openweather/api/model/Weather.java
Normal file
117
src/main/java/by/prominence/openweather/api/model/Weather.java
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 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 by.prominence.openweather.api.model;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Weather {
|
||||||
|
|
||||||
|
@JSONField(name = "id")
|
||||||
|
// Weather condition id
|
||||||
|
long conditionId;
|
||||||
|
|
||||||
|
@JSONField(name = "main")
|
||||||
|
// Group of weather parameters (Rain, Snow, Extreme etc.)
|
||||||
|
String weatherGroup;
|
||||||
|
|
||||||
|
@JSONField(name = "description")
|
||||||
|
// Weather condition within the group
|
||||||
|
String description;
|
||||||
|
|
||||||
|
@JSONField(name = "icon")
|
||||||
|
// Weather icon id
|
||||||
|
String iconId;
|
||||||
|
|
||||||
|
public long getConditionId() {
|
||||||
|
return conditionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConditionId(long conditionId) {
|
||||||
|
this.conditionId = conditionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWeatherGroup() {
|
||||||
|
return weatherGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeatherGroup(String weatherGroup) {
|
||||||
|
this.weatherGroup = weatherGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIconId() {
|
||||||
|
return iconId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIconId(String iconId) {
|
||||||
|
this.iconId = iconId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL getWeatherIconUrl() {
|
||||||
|
URL iconUrl = null;
|
||||||
|
try {
|
||||||
|
iconUrl = new URL("http://openweathermap.org/img/w/" + iconId + ".png");
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return iconUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Weather{" +
|
||||||
|
"conditionId=" + conditionId +
|
||||||
|
", weatherGroup='" + weatherGroup + '\'' +
|
||||||
|
", description='" + description + '\'' +
|
||||||
|
", iconId='" + iconId + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Weather weather = (Weather) o;
|
||||||
|
return conditionId == weather.conditionId &&
|
||||||
|
Objects.equals(weatherGroup, weather.weatherGroup) &&
|
||||||
|
Objects.equals(description, weather.description) &&
|
||||||
|
Objects.equals(iconId, weather.iconId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
|
||||||
|
return Objects.hash(conditionId, weatherGroup, description, iconId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,149 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 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 by.prominence.openweather.api.model;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class WeatherInfo {
|
||||||
|
|
||||||
|
@JSONField(name = "temp")
|
||||||
|
// Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||||
|
private float temperature;
|
||||||
|
|
||||||
|
@JSONField(name = "pressure")
|
||||||
|
// Atmospheric pressure (on the sea level, if there is no sea_level or grnd_level data), hPa
|
||||||
|
private short pressure;
|
||||||
|
|
||||||
|
@JSONField(name = "humidity")
|
||||||
|
// Humidity, %
|
||||||
|
private byte humidity;
|
||||||
|
|
||||||
|
@JSONField(name = "temp_min")
|
||||||
|
// Minimum temperature at the moment. This is deviation from current temp that is possible for large cities
|
||||||
|
// and megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||||
|
private float minimumTemperature;
|
||||||
|
|
||||||
|
@JSONField(name = "temp_max")
|
||||||
|
// Maximum temperature at the moment. This is deviation from current temp that is possible for large cities
|
||||||
|
// and megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||||
|
private float maximumTemperature;
|
||||||
|
|
||||||
|
@JSONField(name = "sea_level")
|
||||||
|
// Atmospheric pressure on the sea level, hPa
|
||||||
|
private short seaLevelPressure;
|
||||||
|
|
||||||
|
@JSONField(name = "grnd_level")
|
||||||
|
// Atmospheric pressure on the ground level, hPa
|
||||||
|
private short groundLevelPressure;
|
||||||
|
|
||||||
|
public float getTemperature() {
|
||||||
|
return temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTemperature(float temperature) {
|
||||||
|
this.temperature = temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getPressure() {
|
||||||
|
return pressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPressure(short pressure) {
|
||||||
|
this.pressure = pressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte getHumidity() {
|
||||||
|
return humidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHumidity(byte humidity) {
|
||||||
|
this.humidity = humidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getMinimumTemperature() {
|
||||||
|
return minimumTemperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinimumTemperature(float minimumTemperature) {
|
||||||
|
this.minimumTemperature = minimumTemperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getMaximumTemperature() {
|
||||||
|
return maximumTemperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaximumTemperature(float maximumTemperature) {
|
||||||
|
this.maximumTemperature = maximumTemperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getSeaLevelPressure() {
|
||||||
|
return seaLevelPressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeaLevelPressure(short seaLevelPressure) {
|
||||||
|
this.seaLevelPressure = seaLevelPressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getGroundLevelPressure() {
|
||||||
|
return groundLevelPressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroundLevelPressure(short groundLevelPressure) {
|
||||||
|
this.groundLevelPressure = groundLevelPressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "WeatherInfo{" +
|
||||||
|
"temperature=" + temperature +
|
||||||
|
", pressure=" + pressure +
|
||||||
|
", humidity=" + humidity + "%" +
|
||||||
|
", minimumTemperature=" + minimumTemperature +
|
||||||
|
", maximumTemperature=" + maximumTemperature +
|
||||||
|
", seaLevelPressure=" + seaLevelPressure +
|
||||||
|
", groundLevelPressure=" + groundLevelPressure +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
WeatherInfo that = (WeatherInfo) o;
|
||||||
|
return Float.compare(that.temperature, temperature) == 0 &&
|
||||||
|
pressure == that.pressure &&
|
||||||
|
humidity == that.humidity &&
|
||||||
|
Float.compare(that.minimumTemperature, minimumTemperature) == 0 &&
|
||||||
|
Float.compare(that.maximumTemperature, maximumTemperature) == 0 &&
|
||||||
|
seaLevelPressure == that.seaLevelPressure &&
|
||||||
|
groundLevelPressure == that.groundLevelPressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
|
||||||
|
return Objects.hash(temperature, pressure, humidity, minimumTemperature, maximumTemperature, seaLevelPressure, groundLevelPressure);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,193 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 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 by.prominence.openweather.api.model;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class WeatherResponse {
|
||||||
|
|
||||||
|
@JSONField(name = "id")
|
||||||
|
private long cityId;
|
||||||
|
|
||||||
|
@JSONField(name = "name")
|
||||||
|
private String cityName;
|
||||||
|
|
||||||
|
@JSONField(name = "coord")
|
||||||
|
private Coordinates coordinates;
|
||||||
|
|
||||||
|
@JSONField(name = "weather")
|
||||||
|
private List<Weather> weather;
|
||||||
|
|
||||||
|
@JSONField(name = "base")
|
||||||
|
private String base;
|
||||||
|
|
||||||
|
@JSONField(name = "main")
|
||||||
|
private WeatherInfo weatherInfo;
|
||||||
|
|
||||||
|
@JSONField(name = "wind")
|
||||||
|
private Wind wind;
|
||||||
|
|
||||||
|
@JSONField(name = "clouds")
|
||||||
|
private Clouds clouds;
|
||||||
|
|
||||||
|
@JSONField(name = "rain")
|
||||||
|
private Rain rain;
|
||||||
|
|
||||||
|
@JSONField(name = "snow")
|
||||||
|
private Snow snow;
|
||||||
|
|
||||||
|
@JSONField(name = "dt")
|
||||||
|
private LocalTime dataCalculationTime;
|
||||||
|
|
||||||
|
@JSONField(name = "sys")
|
||||||
|
private WeatherSystemInfo weatherSystemInfo;
|
||||||
|
|
||||||
|
@JSONField(name = "cod")
|
||||||
|
private short responseCode;
|
||||||
|
|
||||||
|
public long getCityId() {
|
||||||
|
return cityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCityId(long cityId) {
|
||||||
|
this.cityId = cityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCityName() {
|
||||||
|
return cityName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCityName(String cityName) {
|
||||||
|
this.cityName = cityName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Coordinates getCoordinates() {
|
||||||
|
return coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoordinates(Coordinates coordinates) {
|
||||||
|
this.coordinates = coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Weather> getWeather() {
|
||||||
|
return weather;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeather(List<Weather> weather) {
|
||||||
|
this.weather = weather;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBase() {
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBase(String base) {
|
||||||
|
this.base = base;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WeatherInfo getWeatherInfo() {
|
||||||
|
return weatherInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeatherInfo(WeatherInfo weatherInfo) {
|
||||||
|
this.weatherInfo = weatherInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Wind getWind() {
|
||||||
|
return wind;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWind(Wind wind) {
|
||||||
|
this.wind = wind;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Clouds getClouds() {
|
||||||
|
return clouds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClouds(Clouds clouds) {
|
||||||
|
this.clouds = clouds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rain getRain() {
|
||||||
|
return rain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRain(Rain rain) {
|
||||||
|
this.rain = rain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Snow getSnow() {
|
||||||
|
return snow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSnow(Snow snow) {
|
||||||
|
this.snow = snow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalTime getDataCalculationTime() {
|
||||||
|
return dataCalculationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDataCalculationTime(LocalTime dataCalculationTime) {
|
||||||
|
this.dataCalculationTime = dataCalculationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WeatherSystemInfo getWeatherSystemInfo() {
|
||||||
|
return weatherSystemInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeatherSystemInfo(WeatherSystemInfo weatherSystemInfo) {
|
||||||
|
this.weatherSystemInfo = weatherSystemInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getResponseCode() {
|
||||||
|
return responseCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResponseCode(short responseCode) {
|
||||||
|
this.responseCode = responseCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "WeatherResponse{" +
|
||||||
|
"cityId=" + cityId +
|
||||||
|
",\n cityName='" + cityName + '\'' +
|
||||||
|
",\n coordinates=" + coordinates +
|
||||||
|
",\n weather=" + weather +
|
||||||
|
",\n base='" + base + '\'' +
|
||||||
|
",\n weatherInfo=" + weatherInfo +
|
||||||
|
",\n wind=" + wind +
|
||||||
|
",\n clouds=" + clouds +
|
||||||
|
",\n rain=" + rain +
|
||||||
|
",\n snow=" + snow +
|
||||||
|
",\n dataCalculationTime=" + dataCalculationTime +
|
||||||
|
",\n weatherSystemInfo=" + weatherSystemInfo +
|
||||||
|
",\n responseCode=" + responseCode +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 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 by.prominence.openweather.api.model;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class WeatherSystemInfo {
|
||||||
|
|
||||||
|
@JSONField(name = "type")
|
||||||
|
// Internal parameter
|
||||||
|
private short type;
|
||||||
|
|
||||||
|
@JSONField(name = "id")
|
||||||
|
// Internal parameter
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
@JSONField(name = "message")
|
||||||
|
// Internal parameter
|
||||||
|
private double message;
|
||||||
|
|
||||||
|
@JSONField(name = "country")
|
||||||
|
// Country code (GB, JP etc.)
|
||||||
|
private String country;
|
||||||
|
|
||||||
|
@JSONField(name = "sunrise")
|
||||||
|
// Sunrise time, unix, UTC
|
||||||
|
private LocalTime sunrise;
|
||||||
|
|
||||||
|
@JSONField(name = "sunset")
|
||||||
|
// Sunset time, unix, UTC
|
||||||
|
private LocalTime sunset;
|
||||||
|
|
||||||
|
public short getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(short type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(double message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCountry() {
|
||||||
|
return country;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCountry(String country) {
|
||||||
|
this.country = country;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalTime getSunrise() {
|
||||||
|
return sunrise;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSunrise(LocalTime sunrise) {
|
||||||
|
this.sunrise = sunrise;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalTime getSunset() {
|
||||||
|
return sunset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSunset(LocalTime sunset) {
|
||||||
|
this.sunset = sunset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "WeatherSystemInfo{" +
|
||||||
|
"type=" + type +
|
||||||
|
", id=" + id +
|
||||||
|
", message=" + message +
|
||||||
|
", country='" + country + '\'' +
|
||||||
|
", sunrise=" + sunrise +
|
||||||
|
", sunset=" + sunset +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
WeatherSystemInfo that = (WeatherSystemInfo) o;
|
||||||
|
return type == that.type &&
|
||||||
|
id == that.id &&
|
||||||
|
Double.compare(that.message, message) == 0 &&
|
||||||
|
Objects.equals(country, that.country) &&
|
||||||
|
Objects.equals(sunrise, that.sunrise) &&
|
||||||
|
Objects.equals(sunset, that.sunset);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
|
||||||
|
return Objects.hash(type, id, message, country, sunrise, sunset);
|
||||||
|
}
|
||||||
|
}
|
||||||
77
src/main/java/by/prominence/openweather/api/model/Wind.java
Normal file
77
src/main/java/by/prominence/openweather/api/model/Wind.java
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 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 by.prominence.openweather.api.model;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Wind {
|
||||||
|
|
||||||
|
@JSONField(name = "speed")
|
||||||
|
// Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour.
|
||||||
|
private float speed;
|
||||||
|
|
||||||
|
@JSONField(name = "deg")
|
||||||
|
// Wind direction, degrees (meteorological)
|
||||||
|
private short degrees;
|
||||||
|
|
||||||
|
public float getSpeed() {
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpeed(float speed) {
|
||||||
|
this.speed = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getDegrees() {
|
||||||
|
return degrees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDegrees(short degrees) {
|
||||||
|
this.degrees = degrees;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Wind{" +
|
||||||
|
"speed=" + speed +
|
||||||
|
", degrees=" + degrees +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Wind wind = (Wind) o;
|
||||||
|
return Float.compare(wind.speed, speed) == 0 &&
|
||||||
|
degrees == wind.degrees;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
|
||||||
|
return Objects.hash(speed, degrees);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 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 by.prominence.openweather.api.provider;
|
||||||
|
|
||||||
|
import by.prominence.openweather.api.model.Coordinates;
|
||||||
|
import by.prominence.openweather.api.model.WeatherResponse;
|
||||||
|
import by.prominence.openweather.api.utils.JsonUtils;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class DefaultWeatherProvider implements WeatherProvider {
|
||||||
|
|
||||||
|
private static final String OPEN_WEATHER_API_VERSION = "2.5";
|
||||||
|
private static final String OPEN_WEATHER_API_URL = "http://api.openweathermap.org/data/" + OPEN_WEATHER_API_VERSION + "/weather";
|
||||||
|
|
||||||
|
private final String authToken;
|
||||||
|
|
||||||
|
public DefaultWeatherProvider(String authToken) {
|
||||||
|
this.authToken = authToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WeatherResponse getByCityId(String id) {
|
||||||
|
return executeRequest("?id=" + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WeatherResponse getByCityName(String name) {
|
||||||
|
return executeRequest("?q=" + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WeatherResponse getByCoordinates(double latitude, double longitude) {
|
||||||
|
return executeRequest("?lat=" + latitude + "&lon=" + longitude);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WeatherResponse getByCoordinates(Coordinates coordinates) {
|
||||||
|
return getByCoordinates(coordinates.getLatitude(), coordinates.getLongitude());
|
||||||
|
}
|
||||||
|
|
||||||
|
public WeatherResponse getByZIPCode(String zipCode, String countryCode) {
|
||||||
|
return executeRequest("?zip=" + zipCode + "," + countryCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
private WeatherResponse executeRequest(String parameterString) {
|
||||||
|
|
||||||
|
String url = OPEN_WEATHER_API_URL + parameterString + "&appid=" + authToken;
|
||||||
|
|
||||||
|
HttpClient httpClient = HttpClientBuilder.create().build();
|
||||||
|
HttpGet request = new HttpGet(url);
|
||||||
|
HttpResponse response = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
response = httpClient.execute(request);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
WeatherResponse weatherResponse = null;
|
||||||
|
if (response != null) {
|
||||||
|
try {
|
||||||
|
weatherResponse = (WeatherResponse)JsonUtils.parseJson(response.getEntity().getContent(), WeatherResponse.class);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return weatherResponse;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 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 by.prominence.openweather.api.provider;
|
||||||
|
|
||||||
|
import by.prominence.openweather.api.model.Coordinates;
|
||||||
|
import by.prominence.openweather.api.model.WeatherResponse;
|
||||||
|
|
||||||
|
public interface WeatherProvider {
|
||||||
|
|
||||||
|
public WeatherResponse getByCityId(String id);
|
||||||
|
public WeatherResponse getByCityName(String name);
|
||||||
|
public WeatherResponse getByCoordinates(double latitude, double longitude);
|
||||||
|
public WeatherResponse getByCoordinates(Coordinates coordinates);
|
||||||
|
public WeatherResponse getByZIPCode(String zipCode, String countryCode);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 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 by.prominence.openweather.api.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
public class JsonUtils {
|
||||||
|
|
||||||
|
public static Object parseJson(InputStream inputStream, Class clazz) throws IOException {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||||
|
|
||||||
|
StringBuffer result = new StringBuffer();
|
||||||
|
String line = "";
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
result.append(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
return JSON.parseObject(result.toString(), clazz);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user