18 Commits

Author SHA1 Message Date
Prominence 44da350e3c Updated version. 2019-05-29 23:38:40 +03:00
Prominence 39ee5aa38c Updated documentation. 2019-05-29 23:36:29 +03:00
Prominence c6bbf7be90 Changed custom exceptions: now they are uncheked. Fixed several API issues. Added tests. 2019-05-29 22:50:07 +03:00
Prominence 340383afc8 Documentation was updated. 2018-08-04 19:20:15 +03:00
Prominence 6ffa524ce7 Documentation was updated. 2018-08-04 19:18:54 +03:00
Prominence 87fb040169 Shifted to SNAPSHOT version. 2018-08-04 19:17:10 +03:00
Prominence d4db442b63 Version was updated to 1.1. 2018-08-04 19:13:09 +03:00
Prominence 39d56b6782 Implemented Air Pollution retrieving. 2018-08-02 21:34:41 +03:00
Prominence 0487e0f2d0 'System' class was removed. 2018-08-01 21:02:42 +03:00
Prominence c288f71826 Useless imports were removed. 2018-08-01 21:00:11 +03:00
Prominence 157959e537 'System' class was removed. 2018-08-01 20:40:17 +03:00
Prominence 126bfc2d56 Updated documentation. Added useful method. 2018-07-31 23:53:45 +03:00
Prominence e5dee248b6 Implemented UltravioletIndex retrieving. Renamed JSON utulity class. 2018-07-29 18:55:05 +03:00
Prominence 20adced4d7 Typo was fixed. 2018-07-25 23:26:08 +03:00
Prominence 86b0d52586 Documentation was moved into separate files according to version. 2018-07-25 23:25:01 +03:00
Prominence d86b228c6e Implemented DailyForecast requesting. Added 'lombok' dependency. Some refactoring... 2018-07-25 00:19:43 +03:00
Prominence 61eea0b8f6 Switched to SNAPSHOT version. 2018-07-22 22:30:25 +03:00
Alexey Zinchenko d1ee732f91 Update README.md 2018-07-22 22:13:51 +03:00
37 changed files with 3055 additions and 1154 deletions
+18 -247
View File
@@ -4,263 +4,34 @@ Java API for OpenWeatherMap services.
### Implemented features:
* Current weather data
* 5 day / 3 hour forecast
* 16 day / daily forecast
* UV Index
* Air pollution(beta)
### Will be implemented later:
* 16 day / daily forecast
* UV Index(beta)
* Air pollution(beta)
Global changes in API and more functionality.
### Maven coordinates:
_Not available yet._
### How to use:
Firstly, you need to create the instance of `OpenWeatherMapManager` class:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
```
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
Currently available methods:
* `getWeatherRequester()`
* `getForecastRequester()`
#### Current weather data
First step is retrieving `WeatherRequester` instance:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
WeatherRequester weatherRequester = openWeatherManager.getWeatherRequester();
```
after you are able to set preferable options(via chain methods) and execute appropriate request:
```
Weather weatherResponse = weatherRequester
.setLanguage(Language.ENGLISH)
.setUnitSystem(Unit.METRIC_SYSTEM)
.setAccuracy(Accuracy.ACCURATE)
.getByCityName("Minsk");
```
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
Available requests:
* `getByCityId(String cityId)`
* `getByCityName(String cityName)`
* `getByCoordinates(double latitude, double longitude)`
* `getByCoordinates(Coordinates coordinates)`
* `getByZIPCode(String zipCode, String countryCode)`
`Weather`'s useful public methods(setters are not listed):
| Method | Description |
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
| `getCityName()` | Returns city name. Example: `Minsk`. |
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
| `getBase()` | Returns `String` with some internal information. Example: `cmc stations` - from official documentation. |
| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, pressure and humidity. |
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
| `getDataCalculationTime()`| Returns `long` value that represents data calculation timestamp. |
| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset time. |
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getWeatherSystemInfo().getCountry()`. |
| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. |
| `getDataCalculationDate()`| Returns data calculation time in `Date` representation. |
| `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. |
| `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. |
| `getPressure()` | An alias for `getWeatherInfo().getPressure()`. |
| `getPressureUnit()` | An alias for `getWeatherInfo().getPressureUnit()`. |
| `getHumidityPercentage()` | An alias for `getWeatherInfo().getHumidity()`. |
| `toString()` | Returns pretty string for the whole available weather information. |
`toString()` output example:
```
City: Minsk(625144). Coordinates: latitude=53.9, longitude=27.56
Country: BY
Sunrise: Sun Jul 15 04:58:27 MSK 2018
Sunset: Sun Jul 15 21:32:19 MSK 2018
Weather: light intensity shower rain
Temperature: 17.0 ℃. Minimum temparature: 17.0 ℃. Maximum temperature: 17.0 ℃
Humidity: 93%
Pressure: 1008 hPa
Wind: 2.0 meter/sec, 20 degrees
Cloudiness: 75%
Data calculation time: Mon Jul 16 00:00:00 MSK 2018
```xml
<dependency>
<groupId>com.github.prominence</groupId>
<artifactId>openweathermap-api</artifactId>
<version>1.2</version>
</dependency>
```
#### 5 day / 3 hour forecast
First step is retrieving `HourlyForecastRequester` instance:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
ForecastRequester forecastRequester = openWeatherManager.getForecastRequester();
```
after you are able to set preferable options(via chain methods) and execute appropriate request:
```
HourlyForecast forecastResponse = forecastRequester
.setLanguage(Language.ENGLISH)
.setUnitSystem(Unit.METRIC_SYSTEM)
.setAccuracy(Accuracy.ACCURATE)
.getByCityName("Pruzhany");
```
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
### Gradle coordinates:
Available requests:
* `getByCityId(String cityId)`
* `getByCityName(String cityName)`
* `getByCoordinates(double latitude, double longitude)`
* `getByCoordinates(Coordinates coordinates)`
* `getByZIPCode(String zipCode, String countryCode)`
`HourlyForecast`'s useful public methods(setters are not listed):
| Method | Description |
|-----------------------------|--------------------------------------------------------------------------------------------|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
| `getCityName()` | Returns city name. Example: `Minsk`. |
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
| `getCityInfo()` | Returns `HourlyForecast.CityInfo` instance that contains information about city. |
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
| `getAverageTemperature()` | Returns average temperature from forecasts. |
| `getMinimumTemperature()` | Returns minimum temperature from forecasts. |
| `getMaximumTemperature()` | Returns maximum temperature from forecasts. |
| `getByMinimumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is minimal. |
| `getByMaximumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is maximal. |
| `getAveragePressure()` | Returns average pressure from forecasts. |
| `getMinimumPressure()` | Returns minimum pressure from forecasts. |
| `getMaximumPressure()` | Returns maximum pressure from forecasts. |
| `getByMinimumPressure()` | Returns `HourlyForecast.Forecast` for the time where pressure is minimal. |
| `getByMaximumPressure()` | Returns `HourlyForecast.Forecast` for the time where pressure is maximal. |
| `toString()` | Returns pretty string for the whole available forecast information. |
`toString()` output example:
```
City: Pruzhany(622997). Coordinates: latitude=52.5582, longitude=24.4567
Country: BY
Forecasts:
Time: Tue Jul 17 00:00:00 MSK 2018. Weather: light rain. Temperature: 16.24 ℃. Minimum temperature: 16.24 ℃. Maximum temperature: 17.36 ℃. Pressure: 997.38 hPa. Sea-level pressure: 1018.59 hPa. Ground-level pressure: 997.38 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 2.85 meter/sec, 324 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 03:00:00 MSK 2018. Weather: moderate rain. Temperature: 16.0 ℃. Minimum temperature: 16.0 ℃. Maximum temperature: 16.83 ℃. Pressure: 996.88 hPa. Sea-level pressure: 1017.86 hPa. Ground-level pressure: 996.88 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 1.86 meter/sec, 349 degrees. Rain(last 3 hrs): 3 mm
Time: Tue Jul 17 06:00:00 MSK 2018. Weather: light rain. Temperature: 15.76 ℃. Minimum temperature: 15.76 ℃. Maximum temperature: 16.31 ℃. Pressure: 996.7 hPa. Sea-level pressure: 1017.72 hPa. Ground-level pressure: 996.7 hPa. Humidity: 94%. Cloudiness: 76%. Wind: 1.62 meter/sec, 113 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 09:00:00 MSK 2018. Weather: light rain. Temperature: 18.23 ℃. Minimum temperature: 18.23 ℃. Maximum temperature: 18.51 ℃. Pressure: 997.17 hPa. Sea-level pressure: 1018.18 hPa. Ground-level pressure: 997.17 hPa. Humidity: 100%. Cloudiness: 76%. Wind: 2.11 meter/sec, 107 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 12:00:00 MSK 2018. Weather: light rain. Temperature: 21.0 ℃. Minimum temperature: 21.0 ℃. Maximum temperature: 21.0 ℃. Pressure: 997.6 hPa. Sea-level pressure: 1018.5 hPa. Ground-level pressure: 997.6 hPa. Humidity: 100%. Cloudiness: 68%. Wind: 2.51 meter/sec, 82 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 15:00:00 MSK 2018. Weather: light rain. Temperature: 21.78 ℃. Minimum temperature: 21.78 ℃. Maximum temperature: 21.78 ℃. Pressure: 997.73 hPa. Sea-level pressure: 1018.66 hPa. Ground-level pressure: 997.73 hPa. Humidity: 92%. Cloudiness: 88%. Wind: 4.05 meter/sec, 78 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 18:00:00 MSK 2018. Weather: light rain. Temperature: 22.9 ℃. Minimum temperature: 22.9 ℃. Maximum temperature: 22.9 ℃. Pressure: 997.66 hPa. Sea-level pressure: 1018.55 hPa. Ground-level pressure: 997.66 hPa. Humidity: 93%. Cloudiness: 68%. Wind: 3.06 meter/sec, 67 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 21:00:00 MSK 2018. Weather: light rain. Temperature: 23.04 ℃. Minimum temperature: 23.04 ℃. Maximum temperature: 23.04 ℃. Pressure: 996.89 hPa. Sea-level pressure: 1017.99 hPa. Ground-level pressure: 996.89 hPa. Humidity: 83%. Cloudiness: 88%. Wind: 3.17 meter/sec, 16 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 00:00:00 MSK 2018. Weather: moderate rain. Temperature: 18.5 ℃. Minimum temperature: 18.5 ℃. Maximum temperature: 18.5 ℃. Pressure: 997.33 hPa. Sea-level pressure: 1018.34 hPa. Ground-level pressure: 997.33 hPa. Humidity: 97%. Cloudiness: 44%. Wind: 3.56 meter/sec, 31 degrees. Rain(last 3 hrs): 7 mm
Time: Wed Jul 18 03:00:00 MSK 2018. Weather: few clouds. Temperature: 18.57 ℃. Minimum temperature: 18.57 ℃. Maximum temperature: 18.57 ℃. Pressure: 996.91 hPa. Sea-level pressure: 1017.87 hPa. Ground-level pressure: 996.91 hPa. Humidity: 95%. Cloudiness: 24%. Wind: 5.26 meter/sec, 44 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 06:00:00 MSK 2018. Weather: few clouds. Temperature: 18.94 ℃. Minimum temperature: 18.94 ℃. Maximum temperature: 18.94 ℃. Pressure: 997.07 hPa. Sea-level pressure: 1018.06 hPa. Ground-level pressure: 997.07 hPa. Humidity: 95%. Cloudiness: 20%. Wind: 4.8 meter/sec, 45 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 09:00:00 MSK 2018. Weather: light rain. Temperature: 20.6 ℃. Minimum temperature: 20.6 ℃. Maximum temperature: 20.6 ℃. Pressure: 997.8 hPa. Sea-level pressure: 1018.66 hPa. Ground-level pressure: 997.8 hPa. Humidity: 97%. Cloudiness: 48%. Wind: 5.56 meter/sec, 54 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 12:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.87 ℃. Minimum temperature: 23.87 ℃. Maximum temperature: 23.87 ℃. Pressure: 998.06 hPa. Sea-level pressure: 1019.05 hPa. Ground-level pressure: 998.06 hPa. Humidity: 88%. Cloudiness: 32%. Wind: 5.86 meter/sec, 52 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 24.67 ℃. Minimum temperature: 24.67 ℃. Maximum temperature: 24.67 ℃. Pressure: 998.51 hPa. Sea-level pressure: 1019.33 hPa. Ground-level pressure: 998.51 hPa. Humidity: 84%. Cloudiness: 36%. Wind: 5.63 meter/sec, 51 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.15 ℃. Minimum temperature: 25.15 ℃. Maximum temperature: 25.15 ℃. Pressure: 998.79 hPa. Sea-level pressure: 1019.64 hPa. Ground-level pressure: 998.79 hPa. Humidity: 78%. Cloudiness: 44%. Wind: 5.47 meter/sec, 38 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.23 ℃. Minimum temperature: 23.23 ℃. Maximum temperature: 23.23 ℃. Pressure: 999.08 hPa. Sea-level pressure: 1020.04 hPa. Ground-level pressure: 999.08 hPa. Humidity: 75%. Cloudiness: 48%. Wind: 4.62 meter/sec, 25 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 20.79 ℃. Minimum temperature: 20.79 ℃. Maximum temperature: 20.79 ℃. Pressure: 999.67 hPa. Sea-level pressure: 1020.68 hPa. Ground-level pressure: 999.67 hPa. Humidity: 76%. Cloudiness: 48%. Wind: 4.29 meter/sec, 13 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 03:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.45 ℃. Minimum temperature: 19.45 ℃. Maximum temperature: 19.45 ℃. Pressure: 999.95 hPa. Sea-level pressure: 1021.02 hPa. Ground-level pressure: 999.95 hPa. Humidity: 80%. Cloudiness: 48%. Wind: 4.22 meter/sec, 17 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 06:00:00 MSK 2018. Weather: light rain. Temperature: 18.9 ℃. Minimum temperature: 18.9 ℃. Maximum temperature: 18.9 ℃. Pressure: 1000.6 hPa. Sea-level pressure: 1021.62 hPa. Ground-level pressure: 1000.6 hPa. Humidity: 83%. Cloudiness: 92%. Wind: 4.43 meter/sec, 10 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 09:00:00 MSK 2018. Weather: light rain. Temperature: 21.37 ℃. Minimum temperature: 21.37 ℃. Maximum temperature: 21.37 ℃. Pressure: 1000.95 hPa. Sea-level pressure: 1022.01 hPa. Ground-level pressure: 1000.95 hPa. Humidity: 87%. Cloudiness: 0%. Wind: 4.36 meter/sec, 6 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.92 ℃. Minimum temperature: 23.92 ℃. Maximum temperature: 23.92 ℃. Pressure: 1001.5 hPa. Sea-level pressure: 1022.43 hPa. Ground-level pressure: 1001.5 hPa. Humidity: 77%. Cloudiness: 0%. Wind: 5.66 meter/sec, 12 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 15:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.7 ℃. Minimum temperature: 23.7 ℃. Maximum temperature: 23.7 ℃. Pressure: 1001.75 hPa. Sea-level pressure: 1022.72 hPa. Ground-level pressure: 1001.75 hPa. Humidity: 72%. Cloudiness: 56%. Wind: 5.87 meter/sec, 349 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 18:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.82 ℃. Minimum temperature: 23.82 ℃. Maximum temperature: 23.82 ℃. Pressure: 1001.55 hPa. Sea-level pressure: 1022.59 hPa. Ground-level pressure: 1001.55 hPa. Humidity: 72%. Cloudiness: 68%. Wind: 5.47 meter/sec, 340 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.22 ℃. Minimum temperature: 22.22 ℃. Maximum temperature: 22.22 ℃. Pressure: 1001.82 hPa. Sea-level pressure: 1022.93 hPa. Ground-level pressure: 1001.82 hPa. Humidity: 67%. Cloudiness: 76%. Wind: 4.12 meter/sec, 333 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.76 ℃. Minimum temperature: 19.76 ℃. Maximum temperature: 19.76 ℃. Pressure: 1001.98 hPa. Sea-level pressure: 1023.13 hPa. Ground-level pressure: 1001.98 hPa. Humidity: 76%. Cloudiness: 32%. Wind: 4.11 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 03:00:00 MSK 2018. Weather: clear sky. Temperature: 17.53 ℃. Minimum temperature: 17.53 ℃. Maximum temperature: 17.53 ℃. Pressure: 1001.93 hPa. Sea-level pressure: 1023.13 hPa. Ground-level pressure: 1001.93 hPa. Humidity: 87%. Cloudiness: 8%. Wind: 4.21 meter/sec, 309 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 16.83 ℃. Minimum temperature: 16.83 ℃. Maximum temperature: 16.83 ℃. Pressure: 1001.79 hPa. Sea-level pressure: 1022.99 hPa. Ground-level pressure: 1001.79 hPa. Humidity: 91%. Cloudiness: 44%. Wind: 3.65 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 09:00:00 MSK 2018. Weather: light rain. Temperature: 19.57 ℃. Minimum temperature: 19.57 ℃. Maximum temperature: 19.57 ℃. Pressure: 1001.34 hPa. Sea-level pressure: 1022.41 hPa. Ground-level pressure: 1001.34 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 4.38 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.5 ℃. Minimum temperature: 23.5 ℃. Maximum temperature: 23.5 ℃. Pressure: 1001.0 hPa. Sea-level pressure: 1021.99 hPa. Ground-level pressure: 1001.0 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 5.36 meter/sec, 299 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.14 ℃. Minimum temperature: 25.14 ℃. Maximum temperature: 25.14 ℃. Pressure: 1000.5 hPa. Sea-level pressure: 1021.51 hPa. Ground-level pressure: 1000.5 hPa. Humidity: 73%. Cloudiness: 32%. Wind: 6.72 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 18:00:00 MSK 2018. Weather: overcast clouds. Temperature: 23.56 ℃. Minimum temperature: 23.56 ℃. Maximum temperature: 23.56 ℃. Pressure: 1000.7 hPa. Sea-level pressure: 1021.58 hPa. Ground-level pressure: 1000.7 hPa. Humidity: 66%. Cloudiness: 88%. Wind: 6.57 meter/sec, 317 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.41 ℃. Minimum temperature: 22.41 ℃. Maximum temperature: 22.41 ℃. Pressure: 1000.64 hPa. Sea-level pressure: 1021.67 hPa. Ground-level pressure: 1000.64 hPa. Humidity: 68%. Cloudiness: 64%. Wind: 4.31 meter/sec, 326 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 00:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.92 ℃. Minimum temperature: 20.92 ℃. Maximum temperature: 20.92 ℃. Pressure: 1001.06 hPa. Sea-level pressure: 1022.14 hPa. Ground-level pressure: 1001.06 hPa. Humidity: 78%. Cloudiness: 68%. Wind: 3.42 meter/sec, 327 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 03:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.28 ℃. Minimum temperature: 20.28 ℃. Maximum temperature: 20.28 ℃. Pressure: 1001.04 hPa. Sea-level pressure: 1022.13 hPa. Ground-level pressure: 1001.04 hPa. Humidity: 78%. Cloudiness: 76%. Wind: 4.27 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.11 ℃. Minimum temperature: 19.11 ℃. Maximum temperature: 19.11 ℃. Pressure: 1001.13 hPa. Sea-level pressure: 1022.28 hPa. Ground-level pressure: 1001.13 hPa. Humidity: 74%. Cloudiness: 32%. Wind: 4.96 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 09:00:00 MSK 2018. Weather: few clouds. Temperature: 20.16 ℃. Minimum temperature: 20.16 ℃. Maximum temperature: 20.16 ℃. Pressure: 1001.43 hPa. Sea-level pressure: 1022.62 hPa. Ground-level pressure: 1001.43 hPa. Humidity: 86%. Cloudiness: 20%. Wind: 5.16 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 12:00:00 MSK 2018. Weather: few clouds. Temperature: 22.37 ℃. Minimum temperature: 22.37 ℃. Maximum temperature: 22.37 ℃. Pressure: 1001.53 hPa. Sea-level pressure: 1022.62 hPa. Ground-level pressure: 1001.53 hPa. Humidity: 88%. Cloudiness: 20%. Wind: 5.56 meter/sec, 307 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.85 ℃. Minimum temperature: 22.85 ℃. Maximum temperature: 22.85 ℃. Pressure: 1001.63 hPa. Sea-level pressure: 1022.65 hPa. Ground-level pressure: 1001.63 hPa. Humidity: 81%. Cloudiness: 44%. Wind: 5.46 meter/sec, 314 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.79 ℃. Minimum temperature: 23.79 ℃. Maximum temperature: 23.79 ℃. Pressure: 1001.53 hPa. Sea-level pressure: 1022.53 hPa. Ground-level pressure: 1001.53 hPa. Humidity: 72%. Cloudiness: 32%. Wind: 5.56 meter/sec, 313 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.56 ℃. Minimum temperature: 22.56 ℃. Maximum temperature: 22.56 ℃. Pressure: 1001.72 hPa. Sea-level pressure: 1022.7 hPa. Ground-level pressure: 1001.72 hPa. Humidity: 66%. Cloudiness: 48%. Wind: 3.96 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
```groovy
compile('com.github.prominence:openweathermap-api:1.2')
```
`Forecast`'s useful public methods(setters are not listed):
| Method | Description |
|-----------------------------|------------------------------------------------------------------------------------------------------------------|
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
| `getWeatherInfo()` | Returns `HourlyForecast.WeatherInfo` instance that contains information about temperature, pressure and humidity.|
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. |
| `getDt_txt()` | Returns `String` value that represents data calculation time. |
| `toString()` | Returns pretty string for the whole available weather information. |
### Constants and options
#### Accuracy
| Constant | Description |
|--------------------|------------------|
| Accuracy.LIKE | Close result. |
| Accuracy.ACCURATE | Accurate result. |
#### Language
| Constant | Description |
|-----------------------------------|-------------------------------|
| Language.ARABIC | Arabic language. |
| Language.BULGARIAN | Bulgarian language. |
| Language.CATALAN | Catalan language. |
| Language.CZECH | Czech language. |
| Language.GERMAN | German language. |
| Language.GREEK | Greek language. |
| Language.ENGLISH | English language. |
| Language.PERSIAN | Persian (Farsi) language. |
| Language.FINNISH | Finnish language. |
| Language.FRENCH | French language. |
| Language.GALICIAN | Galician language. |
| Language.CROATIAN | Croatian language. |
| Language.HUNGARIAN | Hungarian language. |
| Language.ITALIAN | Italian language. |
| Language.JAPANESE | Japanese language. |
| Language.KOREAN | Korean language. |
| Language.LATVIAN | Latvian language. |
| Language.LITHUANIAN | Lithuanian language. |
| Language.MACEDONIAN | Macedonian language. |
| Language.DUTCH | Dutch language. |
| Language.POLISH | Polish language. |
| Language.PORTUGUESE | Portuguese language. |
| Language.ROMANIAN | Romanian language. |
| Language.RUSSIAN | Russian language. |
| Language.SWEDISH | Swedish language. |
| Language.SLOVAK | Slovak language. |
| Language.SLOVENIAN | Slovenian language. |
| Language.SPANISH | Spanish language. |
| Language.TURKISH | Turkish language. |
| Language.UKRANIAN | Ukrainian language. |
| Language.VIETNAMESE | Vietnamese language. |
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
#### System
| Constant | Description |
|-------------------------------|-----------------------|
|System.OPEN_WEATHER_API_URL | Basic API url. |
|System.OPEN_WEATHER_API_VERSION| Current API version. |
#### Unit
| Constant | Description |
|----------------------|------------------------------------------------|
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow) |
### Dependencies
* com.alibaba:fastjson:1.2.44
### Documentation
* [OpenWeatherMap Java API - 1.0](docs/Release_1.0.md)
* [OpenWeatherMap Java API - 1.1](docs/Release_1.1.md)
* [OpenWeatherMap Java API - 1.2](docs/Release_1.2.md)
* [OpenWeatherMap Java API - SNAPSHOT](docs/SNAPSHOT.md)
### License
MIT
+267
View File
@@ -0,0 +1,267 @@
### Implemented features:
* Current weather data
* 5 day / 3 hour forecast
### Maven coordinates:
```xml
<dependency>
<groupId>com.github.prominence</groupId>
<artifactId>openweathermap-api</artifactId>
<version>1.0</version>
</dependency>
```
### Gradle coordinates:
```groovy
compile('com.github.prominence:openweathermap-api:1.0')
```
### How to use:
Firstly, you need to create the instance of `OpenWeatherMapManager` class:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
```
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
Currently available methods:
* `getWeatherRequester()`
* `getForecastRequester()`
#### Current weather data
First step is retrieving `WeatherRequester` instance:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
WeatherRequester weatherRequester = openWeatherManager.getWeatherRequester();
```
after you are able to set preferable options(via chain methods) and execute appropriate request:
```
Weather weatherResponse = weatherRequester
.setLanguage(Language.ENGLISH)
.setUnitSystem(Unit.METRIC_SYSTEM)
.setAccuracy(Accuracy.ACCURATE)
.getByCityName("Minsk");
```
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
Available requests:
* `getByCityId(String cityId)`
* `getByCityName(String cityName)`
* `getByCoordinates(double latitude, double longitude)`
* `getByCoordinates(Coordinates coordinates)`
* `getByZIPCode(String zipCode, String countryCode)`
`Weather`'s useful public methods(setters are not listed):
| Method | Description |
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
| `getCityName()` | Returns city name. Example: `Minsk`. |
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
| `getBase()` | Returns `String` with some internal information. Example: `cmc stations` - from official documentation. |
| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, pressure and humidity. |
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
| `getDataCalculationTime()`| Returns `long` value that represents data calculation timestamp. |
| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset time. |
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getWeatherSystemInfo().getCountry()`. |
| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. |
| `getDataCalculationDate()`| Returns data calculation time in `Date` representation. |
| `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. |
| `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. |
| `getPressure()` | An alias for `getWeatherInfo().getPressure()`. |
| `getPressureUnit()` | An alias for `getWeatherInfo().getPressureUnit()`. |
| `getHumidityPercentage()` | An alias for `getWeatherInfo().getHumidity()`. |
| `toString()` | Returns pretty string for the whole available weather information. |
`toString()` output example:
```
City: Minsk(625144). Coordinates: latitude=53.9, longitude=27.56
Country: BY
Sunrise: Sun Jul 15 04:58:27 MSK 2018
Sunset: Sun Jul 15 21:32:19 MSK 2018
Weather: light intensity shower rain
Temperature: 17.0 ℃. Minimum temparature: 17.0 ℃. Maximum temperature: 17.0 ℃
Humidity: 93%
Pressure: 1008 hPa
Wind: 2.0 meter/sec, 20 degrees
Cloudiness: 75%
Data calculation time: Mon Jul 16 00:00:00 MSK 2018
```
#### 5 day / 3 hour forecast
First step is retrieving `HourlyForecastRequester` instance:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
ForecastRequester forecastRequester = openWeatherManager.getForecastRequester();
```
after you are able to set preferable options(via chain methods) and execute appropriate request:
```
HourlyForecast forecastResponse = forecastRequester
.setLanguage(Language.ENGLISH)
.setUnitSystem(Unit.METRIC_SYSTEM)
.setAccuracy(Accuracy.ACCURATE)
.getByCityName("Pruzhany");
```
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
Available requests:
* `getByCityId(String cityId)`
* `getByCityName(String cityName)`
* `getByCoordinates(double latitude, double longitude)`
* `getByCoordinates(Coordinates coordinates)`
* `getByZIPCode(String zipCode, String countryCode)`
`HourlyForecast`'s useful public methods(setters are not listed):
| Method | Description |
|-----------------------------|--------------------------------------------------------------------------------------------|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
| `getCityName()` | Returns city name. Example: `Minsk`. |
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
| `getCityInfo()` | Returns `HourlyForecast.CityInfo` instance that contains information about city. |
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
| `getAverageTemperature()` | Returns average temperature from forecasts. |
| `getMinimumTemperature()` | Returns minimum temperature from forecasts. |
| `getMaximumTemperature()` | Returns maximum temperature from forecasts. |
| `getByMinimumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is minimal. |
| `getByMaximumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is maximal. |
| `getAveragePressure()` | Returns average pressure from forecasts. |
| `getMinimumPressure()` | Returns minimum pressure from forecasts. |
| `getMaximumPressure()` | Returns maximum pressure from forecasts. |
| `getByMinimumPressure()` | Returns `HourlyForecast.Forecast` for the time where pressure is minimal. |
| `getByMaximumPressure()` | Returns `HourlyForecast.Forecast` for the time where pressure is maximal. |
| `toString()` | Returns pretty string for the whole available forecast information. |
`toString()` output example:
```
City: Pruzhany(622997). Coordinates: latitude=52.5582, longitude=24.4567
Country: BY
Forecasts:
Time: Tue Jul 17 00:00:00 MSK 2018. Weather: light rain. Temperature: 16.24 ℃. Minimum temperature: 16.24 ℃. Maximum temperature: 17.36 ℃. Pressure: 997.38 hPa. Sea-level pressure: 1018.59 hPa. Ground-level pressure: 997.38 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 2.85 meter/sec, 324 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 03:00:00 MSK 2018. Weather: moderate rain. Temperature: 16.0 ℃. Minimum temperature: 16.0 ℃. Maximum temperature: 16.83 ℃. Pressure: 996.88 hPa. Sea-level pressure: 1017.86 hPa. Ground-level pressure: 996.88 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 1.86 meter/sec, 349 degrees. Rain(last 3 hrs): 3 mm
Time: Tue Jul 17 06:00:00 MSK 2018. Weather: light rain. Temperature: 15.76 ℃. Minimum temperature: 15.76 ℃. Maximum temperature: 16.31 ℃. Pressure: 996.7 hPa. Sea-level pressure: 1017.72 hPa. Ground-level pressure: 996.7 hPa. Humidity: 94%. Cloudiness: 76%. Wind: 1.62 meter/sec, 113 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 09:00:00 MSK 2018. Weather: light rain. Temperature: 18.23 ℃. Minimum temperature: 18.23 ℃. Maximum temperature: 18.51 ℃. Pressure: 997.17 hPa. Sea-level pressure: 1018.18 hPa. Ground-level pressure: 997.17 hPa. Humidity: 100%. Cloudiness: 76%. Wind: 2.11 meter/sec, 107 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 12:00:00 MSK 2018. Weather: light rain. Temperature: 21.0 ℃. Minimum temperature: 21.0 ℃. Maximum temperature: 21.0 ℃. Pressure: 997.6 hPa. Sea-level pressure: 1018.5 hPa. Ground-level pressure: 997.6 hPa. Humidity: 100%. Cloudiness: 68%. Wind: 2.51 meter/sec, 82 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 15:00:00 MSK 2018. Weather: light rain. Temperature: 21.78 ℃. Minimum temperature: 21.78 ℃. Maximum temperature: 21.78 ℃. Pressure: 997.73 hPa. Sea-level pressure: 1018.66 hPa. Ground-level pressure: 997.73 hPa. Humidity: 92%. Cloudiness: 88%. Wind: 4.05 meter/sec, 78 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 18:00:00 MSK 2018. Weather: light rain. Temperature: 22.9 ℃. Minimum temperature: 22.9 ℃. Maximum temperature: 22.9 ℃. Pressure: 997.66 hPa. Sea-level pressure: 1018.55 hPa. Ground-level pressure: 997.66 hPa. Humidity: 93%. Cloudiness: 68%. Wind: 3.06 meter/sec, 67 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 21:00:00 MSK 2018. Weather: light rain. Temperature: 23.04 ℃. Minimum temperature: 23.04 ℃. Maximum temperature: 23.04 ℃. Pressure: 996.89 hPa. Sea-level pressure: 1017.99 hPa. Ground-level pressure: 996.89 hPa. Humidity: 83%. Cloudiness: 88%. Wind: 3.17 meter/sec, 16 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 00:00:00 MSK 2018. Weather: moderate rain. Temperature: 18.5 ℃. Minimum temperature: 18.5 ℃. Maximum temperature: 18.5 ℃. Pressure: 997.33 hPa. Sea-level pressure: 1018.34 hPa. Ground-level pressure: 997.33 hPa. Humidity: 97%. Cloudiness: 44%. Wind: 3.56 meter/sec, 31 degrees. Rain(last 3 hrs): 7 mm
Time: Wed Jul 18 03:00:00 MSK 2018. Weather: few clouds. Temperature: 18.57 ℃. Minimum temperature: 18.57 ℃. Maximum temperature: 18.57 ℃. Pressure: 996.91 hPa. Sea-level pressure: 1017.87 hPa. Ground-level pressure: 996.91 hPa. Humidity: 95%. Cloudiness: 24%. Wind: 5.26 meter/sec, 44 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 06:00:00 MSK 2018. Weather: few clouds. Temperature: 18.94 ℃. Minimum temperature: 18.94 ℃. Maximum temperature: 18.94 ℃. Pressure: 997.07 hPa. Sea-level pressure: 1018.06 hPa. Ground-level pressure: 997.07 hPa. Humidity: 95%. Cloudiness: 20%. Wind: 4.8 meter/sec, 45 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 09:00:00 MSK 2018. Weather: light rain. Temperature: 20.6 ℃. Minimum temperature: 20.6 ℃. Maximum temperature: 20.6 ℃. Pressure: 997.8 hPa. Sea-level pressure: 1018.66 hPa. Ground-level pressure: 997.8 hPa. Humidity: 97%. Cloudiness: 48%. Wind: 5.56 meter/sec, 54 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 12:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.87 ℃. Minimum temperature: 23.87 ℃. Maximum temperature: 23.87 ℃. Pressure: 998.06 hPa. Sea-level pressure: 1019.05 hPa. Ground-level pressure: 998.06 hPa. Humidity: 88%. Cloudiness: 32%. Wind: 5.86 meter/sec, 52 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 24.67 ℃. Minimum temperature: 24.67 ℃. Maximum temperature: 24.67 ℃. Pressure: 998.51 hPa. Sea-level pressure: 1019.33 hPa. Ground-level pressure: 998.51 hPa. Humidity: 84%. Cloudiness: 36%. Wind: 5.63 meter/sec, 51 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.15 ℃. Minimum temperature: 25.15 ℃. Maximum temperature: 25.15 ℃. Pressure: 998.79 hPa. Sea-level pressure: 1019.64 hPa. Ground-level pressure: 998.79 hPa. Humidity: 78%. Cloudiness: 44%. Wind: 5.47 meter/sec, 38 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.23 ℃. Minimum temperature: 23.23 ℃. Maximum temperature: 23.23 ℃. Pressure: 999.08 hPa. Sea-level pressure: 1020.04 hPa. Ground-level pressure: 999.08 hPa. Humidity: 75%. Cloudiness: 48%. Wind: 4.62 meter/sec, 25 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 20.79 ℃. Minimum temperature: 20.79 ℃. Maximum temperature: 20.79 ℃. Pressure: 999.67 hPa. Sea-level pressure: 1020.68 hPa. Ground-level pressure: 999.67 hPa. Humidity: 76%. Cloudiness: 48%. Wind: 4.29 meter/sec, 13 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 03:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.45 ℃. Minimum temperature: 19.45 ℃. Maximum temperature: 19.45 ℃. Pressure: 999.95 hPa. Sea-level pressure: 1021.02 hPa. Ground-level pressure: 999.95 hPa. Humidity: 80%. Cloudiness: 48%. Wind: 4.22 meter/sec, 17 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 06:00:00 MSK 2018. Weather: light rain. Temperature: 18.9 ℃. Minimum temperature: 18.9 ℃. Maximum temperature: 18.9 ℃. Pressure: 1000.6 hPa. Sea-level pressure: 1021.62 hPa. Ground-level pressure: 1000.6 hPa. Humidity: 83%. Cloudiness: 92%. Wind: 4.43 meter/sec, 10 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 09:00:00 MSK 2018. Weather: light rain. Temperature: 21.37 ℃. Minimum temperature: 21.37 ℃. Maximum temperature: 21.37 ℃. Pressure: 1000.95 hPa. Sea-level pressure: 1022.01 hPa. Ground-level pressure: 1000.95 hPa. Humidity: 87%. Cloudiness: 0%. Wind: 4.36 meter/sec, 6 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.92 ℃. Minimum temperature: 23.92 ℃. Maximum temperature: 23.92 ℃. Pressure: 1001.5 hPa. Sea-level pressure: 1022.43 hPa. Ground-level pressure: 1001.5 hPa. Humidity: 77%. Cloudiness: 0%. Wind: 5.66 meter/sec, 12 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 15:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.7 ℃. Minimum temperature: 23.7 ℃. Maximum temperature: 23.7 ℃. Pressure: 1001.75 hPa. Sea-level pressure: 1022.72 hPa. Ground-level pressure: 1001.75 hPa. Humidity: 72%. Cloudiness: 56%. Wind: 5.87 meter/sec, 349 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 18:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.82 ℃. Minimum temperature: 23.82 ℃. Maximum temperature: 23.82 ℃. Pressure: 1001.55 hPa. Sea-level pressure: 1022.59 hPa. Ground-level pressure: 1001.55 hPa. Humidity: 72%. Cloudiness: 68%. Wind: 5.47 meter/sec, 340 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.22 ℃. Minimum temperature: 22.22 ℃. Maximum temperature: 22.22 ℃. Pressure: 1001.82 hPa. Sea-level pressure: 1022.93 hPa. Ground-level pressure: 1001.82 hPa. Humidity: 67%. Cloudiness: 76%. Wind: 4.12 meter/sec, 333 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.76 ℃. Minimum temperature: 19.76 ℃. Maximum temperature: 19.76 ℃. Pressure: 1001.98 hPa. Sea-level pressure: 1023.13 hPa. Ground-level pressure: 1001.98 hPa. Humidity: 76%. Cloudiness: 32%. Wind: 4.11 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 03:00:00 MSK 2018. Weather: clear sky. Temperature: 17.53 ℃. Minimum temperature: 17.53 ℃. Maximum temperature: 17.53 ℃. Pressure: 1001.93 hPa. Sea-level pressure: 1023.13 hPa. Ground-level pressure: 1001.93 hPa. Humidity: 87%. Cloudiness: 8%. Wind: 4.21 meter/sec, 309 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 16.83 ℃. Minimum temperature: 16.83 ℃. Maximum temperature: 16.83 ℃. Pressure: 1001.79 hPa. Sea-level pressure: 1022.99 hPa. Ground-level pressure: 1001.79 hPa. Humidity: 91%. Cloudiness: 44%. Wind: 3.65 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 09:00:00 MSK 2018. Weather: light rain. Temperature: 19.57 ℃. Minimum temperature: 19.57 ℃. Maximum temperature: 19.57 ℃. Pressure: 1001.34 hPa. Sea-level pressure: 1022.41 hPa. Ground-level pressure: 1001.34 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 4.38 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.5 ℃. Minimum temperature: 23.5 ℃. Maximum temperature: 23.5 ℃. Pressure: 1001.0 hPa. Sea-level pressure: 1021.99 hPa. Ground-level pressure: 1001.0 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 5.36 meter/sec, 299 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.14 ℃. Minimum temperature: 25.14 ℃. Maximum temperature: 25.14 ℃. Pressure: 1000.5 hPa. Sea-level pressure: 1021.51 hPa. Ground-level pressure: 1000.5 hPa. Humidity: 73%. Cloudiness: 32%. Wind: 6.72 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 18:00:00 MSK 2018. Weather: overcast clouds. Temperature: 23.56 ℃. Minimum temperature: 23.56 ℃. Maximum temperature: 23.56 ℃. Pressure: 1000.7 hPa. Sea-level pressure: 1021.58 hPa. Ground-level pressure: 1000.7 hPa. Humidity: 66%. Cloudiness: 88%. Wind: 6.57 meter/sec, 317 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.41 ℃. Minimum temperature: 22.41 ℃. Maximum temperature: 22.41 ℃. Pressure: 1000.64 hPa. Sea-level pressure: 1021.67 hPa. Ground-level pressure: 1000.64 hPa. Humidity: 68%. Cloudiness: 64%. Wind: 4.31 meter/sec, 326 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 00:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.92 ℃. Minimum temperature: 20.92 ℃. Maximum temperature: 20.92 ℃. Pressure: 1001.06 hPa. Sea-level pressure: 1022.14 hPa. Ground-level pressure: 1001.06 hPa. Humidity: 78%. Cloudiness: 68%. Wind: 3.42 meter/sec, 327 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 03:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.28 ℃. Minimum temperature: 20.28 ℃. Maximum temperature: 20.28 ℃. Pressure: 1001.04 hPa. Sea-level pressure: 1022.13 hPa. Ground-level pressure: 1001.04 hPa. Humidity: 78%. Cloudiness: 76%. Wind: 4.27 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.11 ℃. Minimum temperature: 19.11 ℃. Maximum temperature: 19.11 ℃. Pressure: 1001.13 hPa. Sea-level pressure: 1022.28 hPa. Ground-level pressure: 1001.13 hPa. Humidity: 74%. Cloudiness: 32%. Wind: 4.96 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 09:00:00 MSK 2018. Weather: few clouds. Temperature: 20.16 ℃. Minimum temperature: 20.16 ℃. Maximum temperature: 20.16 ℃. Pressure: 1001.43 hPa. Sea-level pressure: 1022.62 hPa. Ground-level pressure: 1001.43 hPa. Humidity: 86%. Cloudiness: 20%. Wind: 5.16 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 12:00:00 MSK 2018. Weather: few clouds. Temperature: 22.37 ℃. Minimum temperature: 22.37 ℃. Maximum temperature: 22.37 ℃. Pressure: 1001.53 hPa. Sea-level pressure: 1022.62 hPa. Ground-level pressure: 1001.53 hPa. Humidity: 88%. Cloudiness: 20%. Wind: 5.56 meter/sec, 307 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.85 ℃. Minimum temperature: 22.85 ℃. Maximum temperature: 22.85 ℃. Pressure: 1001.63 hPa. Sea-level pressure: 1022.65 hPa. Ground-level pressure: 1001.63 hPa. Humidity: 81%. Cloudiness: 44%. Wind: 5.46 meter/sec, 314 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.79 ℃. Minimum temperature: 23.79 ℃. Maximum temperature: 23.79 ℃. Pressure: 1001.53 hPa. Sea-level pressure: 1022.53 hPa. Ground-level pressure: 1001.53 hPa. Humidity: 72%. Cloudiness: 32%. Wind: 5.56 meter/sec, 313 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.56 ℃. Minimum temperature: 22.56 ℃. Maximum temperature: 22.56 ℃. Pressure: 1001.72 hPa. Sea-level pressure: 1022.7 hPa. Ground-level pressure: 1001.72 hPa. Humidity: 66%. Cloudiness: 48%. Wind: 3.96 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
```
`Forecast`'s useful public methods(setters are not listed):
| Method | Description |
|-----------------------------|------------------------------------------------------------------------------------------------------------------|
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
| `getWeatherInfo()` | Returns `HourlyForecast.WeatherInfo` instance that contains information about temperature, pressure and humidity.|
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. |
| `getDt_txt()` | Returns `String` value that represents data calculation time. |
| `toString()` | Returns pretty string for the whole available weather information. |
### Constants and options
#### Accuracy
| Constant | Description |
|--------------------|------------------|
| Accuracy.LIKE | Close result. |
| Accuracy.ACCURATE | Accurate result. |
#### Language
| Constant | Description |
|-----------------------------------|-------------------------------|
| Language.ARABIC | Arabic language. |
| Language.BULGARIAN | Bulgarian language. |
| Language.CATALAN | Catalan language. |
| Language.CZECH | Czech language. |
| Language.GERMAN | German language. |
| Language.GREEK | Greek language. |
| Language.ENGLISH | English language. |
| Language.PERSIAN | Persian (Farsi) language. |
| Language.FINNISH | Finnish language. |
| Language.FRENCH | French language. |
| Language.GALICIAN | Galician language. |
| Language.CROATIAN | Croatian language. |
| Language.HUNGARIAN | Hungarian language. |
| Language.ITALIAN | Italian language. |
| Language.JAPANESE | Japanese language. |
| Language.KOREAN | Korean language. |
| Language.LATVIAN | Latvian language. |
| Language.LITHUANIAN | Lithuanian language. |
| Language.MACEDONIAN | Macedonian language. |
| Language.DUTCH | Dutch language. |
| Language.POLISH | Polish language. |
| Language.PORTUGUESE | Portuguese language. |
| Language.ROMANIAN | Romanian language. |
| Language.RUSSIAN | Russian language. |
| Language.SWEDISH | Swedish language. |
| Language.SLOVAK | Slovak language. |
| Language.SLOVENIAN | Slovenian language. |
| Language.SPANISH | Spanish language. |
| Language.TURKISH | Turkish language. |
| Language.UKRANIAN | Ukrainian language. |
| Language.VIETNAMESE | Vietnamese language. |
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
#### System
| Constant | Description |
|-------------------------------|-----------------------|
|System.OPEN_WEATHER_API_URL | Basic API url. |
|System.OPEN_WEATHER_API_VERSION| Current API version. |
#### Unit
| Constant | Description |
|----------------------|------------------------------------------------|
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow) |
### Dependencies
* com.alibaba:fastjson:1.2.44
+390
View File
@@ -0,0 +1,390 @@
### Implemented features:
* Current weather data
* 5 day / 3 hour forecast
* 16 day / daily forecast
* UV Index
* Air Pollution
### Maven coordinates:
```xml
<dependency>
<groupId>com.github.prominence</groupId>
<artifactId>openweathermap-api</artifactId>
<version>1.1</version>
</dependency>
```
### Gradle coordinates:
```groovy
compile('com.github.prominence:openweathermap-api:1.1')
```
### How to use:
Firstly, you need to create the instance of `OpenWeatherMapManager` class:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
```
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
Currently available methods:
* `getWeatherRequester()`
* `getHourlyForecastRequester()`
* `getDailyForecastRequester()`
* `getUltravioletIndexRequester()`
* `getAirPollutionRequester()`
#### Current weather data
First step is retrieving `WeatherRequester` instance:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
WeatherRequester weatherRequester = openWeatherManager.getWeatherRequester();
```
after you are able to set preferable options(via chain methods) and execute appropriate request:
```
Weather weatherResponse = weatherRequester
.setLanguage(Language.ENGLISH)
.setUnitSystem(Unit.METRIC_SYSTEM)
.setAccuracy(Accuracy.ACCURATE)
.getByCityName("Minsk");
```
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
Available requests:
* `getByCityId(String cityId)`
* `getByCityName(String cityName)`
* `getByCoordinates(double latitude, double longitude)`
* `getByCoordinates(Coordinates coordinates)`
* `getByZIPCode(String zipCode, String countryCode)`
`Weather`'s useful public methods(setters are not listed):
| Method | Description |
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
| `getCityName()` | Returns city name. Example: `Minsk`. |
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
| `getBase()` | Returns `String` with some internal information. Example: `cmc stations` - from official documentation. |
| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, pressure and humidity. |
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
| `getDataCalculationTime()`| Returns `long` value that represents data calculation timestamp. |
| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset time. |
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getWeatherSystemInfo().getCountry()`. |
| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. |
| `getDataCalculationDate()`| Returns data calculation time in `Date` representation. |
| `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. |
| `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. |
| `getPressure()` | An alias for `getWeatherInfo().getPressure()`. |
| `getPressureUnit()` | An alias for `getWeatherInfo().getPressureUnit()`. |
| `getHumidityPercentage()` | An alias for `getWeatherInfo().getHumidity()`. |
| `toString()` | Returns pretty string for the whole available weather information. |
`toString()` output example:
```
City: Minsk(625144). Coordinates: latitude=53.9, longitude=27.56
Country: BY
Sunrise: Sun Jul 15 04:58:27 MSK 2018
Sunset: Sun Jul 15 21:32:19 MSK 2018
Weather: light intensity shower rain
Temperature: 17.0 ℃. Minimum temparature: 17.0 ℃. Maximum temperature: 17.0 ℃
Humidity: 93%
Pressure: 1008 hPa
Wind: 2.0 meter/sec, 20 degrees
Cloudiness: 75%
Data calculation time: Mon Jul 16 00:00:00 MSK 2018
```
#### 5 day / 3 hour forecast
First step is retrieving `HourlyForecastRequester` instance:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
HourlyForecastRequester forecastRequester = openWeatherManager.getHourlyForecastRequester();
```
after you are able to set preferable options(via chain methods) and execute appropriate request:
```
HourlyForecast forecastResponse = forecastRequester
.setLanguage(Language.ENGLISH)
.setUnitSystem(Unit.METRIC_SYSTEM)
.setAccuracy(Accuracy.ACCURATE)
.getByCityName("Pruzhany");
```
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
Available requests:
* `getByCityId(String cityId)`
* `getByCityName(String cityName)`
* `getByCoordinates(double latitude, double longitude)`
* `getByCoordinates(Coordinates coordinates)`
* `getByZIPCode(String zipCode, String countryCode)`
`HourlyForecast`'s useful public methods(setters are not listed):
| Method | Description |
|-----------------------------|--------------------------------------------------------------------------------------------|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
| `getCityName()` | Returns city name. Example: `Minsk`. |
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
| `getCityInfo()` | Returns `CityInfo` instance that contains information about city. |
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
| `getAverageTemperature()` | Returns average temperature from forecasts. |
| `getMinimumTemperature()` | Returns minimum temperature from forecasts. |
| `getMaximumTemperature()` | Returns maximum temperature from forecasts. |
| `getByMinimumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is minimal. |
| `getByMaximumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is maximal. |
| `getAveragePressure()` | Returns average pressure from forecasts. |
| `getMinimumPressure()` | Returns minimum pressure from forecasts. |
| `getMaximumPressure()` | Returns maximum pressure from forecasts. |
| `getByMinimumPressure()` | Returns `HourlyForecast.Forecast` for the time where pressure is minimal. |
| `getByMaximumPressure()` | Returns `HourlyForecast.Forecast` for the time where pressure is maximal. |
| `toString()` | Returns pretty string for the whole available forecast information. |
`toString()` output example:
```
City: Pruzhany(622997). Coordinates: latitude=52.5582, longitude=24.4567
Country: BY
Forecasts:
Time: Tue Jul 17 00:00:00 MSK 2018. Weather: light rain. Temperature: 16.24 ℃. Minimum temperature: 16.24 ℃. Maximum temperature: 17.36 ℃. Pressure: 997.38 hPa. Sea-level pressure: 1018.59 hPa. Ground-level pressure: 997.38 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 2.85 meter/sec, 324 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 03:00:00 MSK 2018. Weather: moderate rain. Temperature: 16.0 ℃. Minimum temperature: 16.0 ℃. Maximum temperature: 16.83 ℃. Pressure: 996.88 hPa. Sea-level pressure: 1017.86 hPa. Ground-level pressure: 996.88 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 1.86 meter/sec, 349 degrees. Rain(last 3 hrs): 3 mm
Time: Tue Jul 17 06:00:00 MSK 2018. Weather: light rain. Temperature: 15.76 ℃. Minimum temperature: 15.76 ℃. Maximum temperature: 16.31 ℃. Pressure: 996.7 hPa. Sea-level pressure: 1017.72 hPa. Ground-level pressure: 996.7 hPa. Humidity: 94%. Cloudiness: 76%. Wind: 1.62 meter/sec, 113 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 09:00:00 MSK 2018. Weather: light rain. Temperature: 18.23 ℃. Minimum temperature: 18.23 ℃. Maximum temperature: 18.51 ℃. Pressure: 997.17 hPa. Sea-level pressure: 1018.18 hPa. Ground-level pressure: 997.17 hPa. Humidity: 100%. Cloudiness: 76%. Wind: 2.11 meter/sec, 107 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 12:00:00 MSK 2018. Weather: light rain. Temperature: 21.0 ℃. Minimum temperature: 21.0 ℃. Maximum temperature: 21.0 ℃. Pressure: 997.6 hPa. Sea-level pressure: 1018.5 hPa. Ground-level pressure: 997.6 hPa. Humidity: 100%. Cloudiness: 68%. Wind: 2.51 meter/sec, 82 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 15:00:00 MSK 2018. Weather: light rain. Temperature: 21.78 ℃. Minimum temperature: 21.78 ℃. Maximum temperature: 21.78 ℃. Pressure: 997.73 hPa. Sea-level pressure: 1018.66 hPa. Ground-level pressure: 997.73 hPa. Humidity: 92%. Cloudiness: 88%. Wind: 4.05 meter/sec, 78 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 18:00:00 MSK 2018. Weather: light rain. Temperature: 22.9 ℃. Minimum temperature: 22.9 ℃. Maximum temperature: 22.9 ℃. Pressure: 997.66 hPa. Sea-level pressure: 1018.55 hPa. Ground-level pressure: 997.66 hPa. Humidity: 93%. Cloudiness: 68%. Wind: 3.06 meter/sec, 67 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 21:00:00 MSK 2018. Weather: light rain. Temperature: 23.04 ℃. Minimum temperature: 23.04 ℃. Maximum temperature: 23.04 ℃. Pressure: 996.89 hPa. Sea-level pressure: 1017.99 hPa. Ground-level pressure: 996.89 hPa. Humidity: 83%. Cloudiness: 88%. Wind: 3.17 meter/sec, 16 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 00:00:00 MSK 2018. Weather: moderate rain. Temperature: 18.5 ℃. Minimum temperature: 18.5 ℃. Maximum temperature: 18.5 ℃. Pressure: 997.33 hPa. Sea-level pressure: 1018.34 hPa. Ground-level pressure: 997.33 hPa. Humidity: 97%. Cloudiness: 44%. Wind: 3.56 meter/sec, 31 degrees. Rain(last 3 hrs): 7 mm
Time: Wed Jul 18 03:00:00 MSK 2018. Weather: few clouds. Temperature: 18.57 ℃. Minimum temperature: 18.57 ℃. Maximum temperature: 18.57 ℃. Pressure: 996.91 hPa. Sea-level pressure: 1017.87 hPa. Ground-level pressure: 996.91 hPa. Humidity: 95%. Cloudiness: 24%. Wind: 5.26 meter/sec, 44 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 06:00:00 MSK 2018. Weather: few clouds. Temperature: 18.94 ℃. Minimum temperature: 18.94 ℃. Maximum temperature: 18.94 ℃. Pressure: 997.07 hPa. Sea-level pressure: 1018.06 hPa. Ground-level pressure: 997.07 hPa. Humidity: 95%. Cloudiness: 20%. Wind: 4.8 meter/sec, 45 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 09:00:00 MSK 2018. Weather: light rain. Temperature: 20.6 ℃. Minimum temperature: 20.6 ℃. Maximum temperature: 20.6 ℃. Pressure: 997.8 hPa. Sea-level pressure: 1018.66 hPa. Ground-level pressure: 997.8 hPa. Humidity: 97%. Cloudiness: 48%. Wind: 5.56 meter/sec, 54 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 12:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.87 ℃. Minimum temperature: 23.87 ℃. Maximum temperature: 23.87 ℃. Pressure: 998.06 hPa. Sea-level pressure: 1019.05 hPa. Ground-level pressure: 998.06 hPa. Humidity: 88%. Cloudiness: 32%. Wind: 5.86 meter/sec, 52 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 24.67 ℃. Minimum temperature: 24.67 ℃. Maximum temperature: 24.67 ℃. Pressure: 998.51 hPa. Sea-level pressure: 1019.33 hPa. Ground-level pressure: 998.51 hPa. Humidity: 84%. Cloudiness: 36%. Wind: 5.63 meter/sec, 51 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.15 ℃. Minimum temperature: 25.15 ℃. Maximum temperature: 25.15 ℃. Pressure: 998.79 hPa. Sea-level pressure: 1019.64 hPa. Ground-level pressure: 998.79 hPa. Humidity: 78%. Cloudiness: 44%. Wind: 5.47 meter/sec, 38 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.23 ℃. Minimum temperature: 23.23 ℃. Maximum temperature: 23.23 ℃. Pressure: 999.08 hPa. Sea-level pressure: 1020.04 hPa. Ground-level pressure: 999.08 hPa. Humidity: 75%. Cloudiness: 48%. Wind: 4.62 meter/sec, 25 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 20.79 ℃. Minimum temperature: 20.79 ℃. Maximum temperature: 20.79 ℃. Pressure: 999.67 hPa. Sea-level pressure: 1020.68 hPa. Ground-level pressure: 999.67 hPa. Humidity: 76%. Cloudiness: 48%. Wind: 4.29 meter/sec, 13 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 03:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.45 ℃. Minimum temperature: 19.45 ℃. Maximum temperature: 19.45 ℃. Pressure: 999.95 hPa. Sea-level pressure: 1021.02 hPa. Ground-level pressure: 999.95 hPa. Humidity: 80%. Cloudiness: 48%. Wind: 4.22 meter/sec, 17 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 06:00:00 MSK 2018. Weather: light rain. Temperature: 18.9 ℃. Minimum temperature: 18.9 ℃. Maximum temperature: 18.9 ℃. Pressure: 1000.6 hPa. Sea-level pressure: 1021.62 hPa. Ground-level pressure: 1000.6 hPa. Humidity: 83%. Cloudiness: 92%. Wind: 4.43 meter/sec, 10 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 09:00:00 MSK 2018. Weather: light rain. Temperature: 21.37 ℃. Minimum temperature: 21.37 ℃. Maximum temperature: 21.37 ℃. Pressure: 1000.95 hPa. Sea-level pressure: 1022.01 hPa. Ground-level pressure: 1000.95 hPa. Humidity: 87%. Cloudiness: 0%. Wind: 4.36 meter/sec, 6 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.92 ℃. Minimum temperature: 23.92 ℃. Maximum temperature: 23.92 ℃. Pressure: 1001.5 hPa. Sea-level pressure: 1022.43 hPa. Ground-level pressure: 1001.5 hPa. Humidity: 77%. Cloudiness: 0%. Wind: 5.66 meter/sec, 12 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 15:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.7 ℃. Minimum temperature: 23.7 ℃. Maximum temperature: 23.7 ℃. Pressure: 1001.75 hPa. Sea-level pressure: 1022.72 hPa. Ground-level pressure: 1001.75 hPa. Humidity: 72%. Cloudiness: 56%. Wind: 5.87 meter/sec, 349 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 18:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.82 ℃. Minimum temperature: 23.82 ℃. Maximum temperature: 23.82 ℃. Pressure: 1001.55 hPa. Sea-level pressure: 1022.59 hPa. Ground-level pressure: 1001.55 hPa. Humidity: 72%. Cloudiness: 68%. Wind: 5.47 meter/sec, 340 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.22 ℃. Minimum temperature: 22.22 ℃. Maximum temperature: 22.22 ℃. Pressure: 1001.82 hPa. Sea-level pressure: 1022.93 hPa. Ground-level pressure: 1001.82 hPa. Humidity: 67%. Cloudiness: 76%. Wind: 4.12 meter/sec, 333 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.76 ℃. Minimum temperature: 19.76 ℃. Maximum temperature: 19.76 ℃. Pressure: 1001.98 hPa. Sea-level pressure: 1023.13 hPa. Ground-level pressure: 1001.98 hPa. Humidity: 76%. Cloudiness: 32%. Wind: 4.11 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 03:00:00 MSK 2018. Weather: clear sky. Temperature: 17.53 ℃. Minimum temperature: 17.53 ℃. Maximum temperature: 17.53 ℃. Pressure: 1001.93 hPa. Sea-level pressure: 1023.13 hPa. Ground-level pressure: 1001.93 hPa. Humidity: 87%. Cloudiness: 8%. Wind: 4.21 meter/sec, 309 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 16.83 ℃. Minimum temperature: 16.83 ℃. Maximum temperature: 16.83 ℃. Pressure: 1001.79 hPa. Sea-level pressure: 1022.99 hPa. Ground-level pressure: 1001.79 hPa. Humidity: 91%. Cloudiness: 44%. Wind: 3.65 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 09:00:00 MSK 2018. Weather: light rain. Temperature: 19.57 ℃. Minimum temperature: 19.57 ℃. Maximum temperature: 19.57 ℃. Pressure: 1001.34 hPa. Sea-level pressure: 1022.41 hPa. Ground-level pressure: 1001.34 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 4.38 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.5 ℃. Minimum temperature: 23.5 ℃. Maximum temperature: 23.5 ℃. Pressure: 1001.0 hPa. Sea-level pressure: 1021.99 hPa. Ground-level pressure: 1001.0 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 5.36 meter/sec, 299 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.14 ℃. Minimum temperature: 25.14 ℃. Maximum temperature: 25.14 ℃. Pressure: 1000.5 hPa. Sea-level pressure: 1021.51 hPa. Ground-level pressure: 1000.5 hPa. Humidity: 73%. Cloudiness: 32%. Wind: 6.72 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 18:00:00 MSK 2018. Weather: overcast clouds. Temperature: 23.56 ℃. Minimum temperature: 23.56 ℃. Maximum temperature: 23.56 ℃. Pressure: 1000.7 hPa. Sea-level pressure: 1021.58 hPa. Ground-level pressure: 1000.7 hPa. Humidity: 66%. Cloudiness: 88%. Wind: 6.57 meter/sec, 317 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.41 ℃. Minimum temperature: 22.41 ℃. Maximum temperature: 22.41 ℃. Pressure: 1000.64 hPa. Sea-level pressure: 1021.67 hPa. Ground-level pressure: 1000.64 hPa. Humidity: 68%. Cloudiness: 64%. Wind: 4.31 meter/sec, 326 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 00:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.92 ℃. Minimum temperature: 20.92 ℃. Maximum temperature: 20.92 ℃. Pressure: 1001.06 hPa. Sea-level pressure: 1022.14 hPa. Ground-level pressure: 1001.06 hPa. Humidity: 78%. Cloudiness: 68%. Wind: 3.42 meter/sec, 327 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 03:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.28 ℃. Minimum temperature: 20.28 ℃. Maximum temperature: 20.28 ℃. Pressure: 1001.04 hPa. Sea-level pressure: 1022.13 hPa. Ground-level pressure: 1001.04 hPa. Humidity: 78%. Cloudiness: 76%. Wind: 4.27 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.11 ℃. Minimum temperature: 19.11 ℃. Maximum temperature: 19.11 ℃. Pressure: 1001.13 hPa. Sea-level pressure: 1022.28 hPa. Ground-level pressure: 1001.13 hPa. Humidity: 74%. Cloudiness: 32%. Wind: 4.96 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 09:00:00 MSK 2018. Weather: few clouds. Temperature: 20.16 ℃. Minimum temperature: 20.16 ℃. Maximum temperature: 20.16 ℃. Pressure: 1001.43 hPa. Sea-level pressure: 1022.62 hPa. Ground-level pressure: 1001.43 hPa. Humidity: 86%. Cloudiness: 20%. Wind: 5.16 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 12:00:00 MSK 2018. Weather: few clouds. Temperature: 22.37 ℃. Minimum temperature: 22.37 ℃. Maximum temperature: 22.37 ℃. Pressure: 1001.53 hPa. Sea-level pressure: 1022.62 hPa. Ground-level pressure: 1001.53 hPa. Humidity: 88%. Cloudiness: 20%. Wind: 5.56 meter/sec, 307 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.85 ℃. Minimum temperature: 22.85 ℃. Maximum temperature: 22.85 ℃. Pressure: 1001.63 hPa. Sea-level pressure: 1022.65 hPa. Ground-level pressure: 1001.63 hPa. Humidity: 81%. Cloudiness: 44%. Wind: 5.46 meter/sec, 314 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.79 ℃. Minimum temperature: 23.79 ℃. Maximum temperature: 23.79 ℃. Pressure: 1001.53 hPa. Sea-level pressure: 1022.53 hPa. Ground-level pressure: 1001.53 hPa. Humidity: 72%. Cloudiness: 32%. Wind: 5.56 meter/sec, 313 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.56 ℃. Minimum temperature: 22.56 ℃. Maximum temperature: 22.56 ℃. Pressure: 1001.72 hPa. Sea-level pressure: 1022.7 hPa. Ground-level pressure: 1001.72 hPa. Humidity: 66%. Cloudiness: 48%. Wind: 3.96 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
```
`HourlyForecast.Forecast`'s useful public methods(setters are not listed):
| Method | Description |
|-----------------------------|------------------------------------------------------------------------------------------------------------------|
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
| `getWeatherInfo()` | Returns `HourlyForecast.WeatherInfo` instance that contains information about temperature, pressure and humidity.|
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. |
| `getDt_txt()` | Returns `String` value that represents data calculation time. |
| `toString()` | Returns pretty string for the whole available forecast information. |
#### 16 day / daily forecast
First step is retrieving `DailyForecastRequester` instance:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
DailyForecastRequester forecastRequester = openWeatherManager.getDailyForecastRequester();
```
after you are able to set preferable options(via chain methods) and execute appropriate request:
```
DailyForecast forecastResponse = forecastRequester
.setLanguage(Language.ENGLISH)
.setUnitSystem(Unit.METRIC_SYSTEM)
.setAccuracy(Accuracy.ACCURATE)
.getByCityName("Pruzhany");
```
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
Available requests:
* `getByCityId(String cityId)`
* `getByCityName(String cityName)`
* `getByCoordinates(double latitude, double longitude)`
* `getByCoordinates(Coordinates coordinates)`
* `getByZIPCode(String zipCode, String countryCode)`
`DailyForecast`'s useful public methods(setters are not listed):
| Method | Description |
|-----------------------------|--------------------------------------------------------------------------------------------|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
| `getCityName()` | Returns city name. Example: `Minsk`. |
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
| `getCityInfo()` | Returns `CityInfo` instance that contains information about city. |
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
| `toString()` | Returns pretty string for the whole available forecast information. |
`DailyForecast.Forecast`'s useful public methods(setters are not listed):
| Method | Description |
|-----------------------------|------------------------------------------------------------------------------------------------------------------|
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
| `getTemperature()` | Returns `DailyForecast.Forecast.Temperature` instance that contains information about temperature(avg, min, max).|
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
| `getCloudiness()` | Returns *cloudiness* percentage information. |
| `getHumidity()` | Returns *humidity* percentage information. |
| `getWindSpeed()` | Returns wind's speed. |
| `getWindDegrees()` | Returns wind's degree. |
| `getWindUnit()` | Returns wind's unit. |
| `getPressure()` | Returns pressure value. |
| `getPressureUnit()` | Returns pressure's unit. |
| `toString()` | Returns pretty string for the whole available forecast information. |
#### UV Index
First step is retrieving `UltravioletIndexRequester` instance:
```java
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
UltravioletIndexRequester requester = openWeatherMapManager.getUltravioletIndexRequester();
```
after you need to set coordinates and execute appropriate request:
```
UltravioletIndex uvResponse = requester
.setCoodrinates(55.33f, 24.27f)
.getCurrentUVIndex();
```
Available requests:
* `getCurrentUVIndex()`
* `getUVIndexForecast(int amountOfDays)`
* `getUVIndexByPeriod(Date from, Date to)`
`UltravioletIndex`'s useful public methods(setters are not listed):
| Method | Description |
|---------------------------|---------------------------------------------------------------|
| `getLatitude()` | Returns latitude. |
| `getLongitude()` | Returns longitude. |
| `getDateISO()` | Returns ISO date in String representation. |
| `getDateTimestamp()` | Returns date timestamp. |
| `getValue()` | Returns UV value. |
| `getCalculationDate()` | Returns date in Date representation`. |
| `toString()` | Returns pretty string for the whole available UV information. |
`toString()` output example:
```
Date: Tue Jul 31 15:00:00 MSK 2018, Ultraviolet value: 6.230000
```
#### Air pollution
First step is retrieving `AirPollutionRequester` instance:
```java
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
AirPollutionRequester requester = openWeatherMapManager.getAirPollutionRequester();
```
after you need to set coordinates, time frame, date and execute appropriate request:
```
AirPollution airPollutionResponse = forecastRequester
.setCoordinates(0.0f, 10.0f)
.setTimeFrame(TimeFrame.YEAR)
.setDate(new Date())
.retrieve();
```
Available requests:
* `retrieve()`
`AirPollution`'s useful public methods(setters are not listed):
| Method | Description |
|---------------------------|---------------------------------------------------------------------------|
| `getCoordinates()` | Returns `Coordinates` instance. |
| `getLongitude()` | Returns longitude. |
| `airPollutionInfo()` | Returns list of `AirPollution.AirPollutionInfo` instances. |
| `toString()` | Returns pretty string for the whole available air pollution information. |
`toString()` output example:
```
AirPollution[Date: Tue Jul 24 01:04:40 MSK 2018; Coordinates: latitude=0.0, longitude=9.9955]
[Value: 8.0347114E-8, Value: 9.5041536E-8, Value: 7.7667146E-8, Value: 7.251491E-8, Value: 5.899763E-8, Value: 1.9186361E-8, Value: 1.729535E-8, Value: 1.25645805E-8, Value: 3.0852514E-9]
```
### Constants and options
#### Accuracy
| Constant | Description |
|--------------------|------------------|
| Accuracy.LIKE | Close result. |
| Accuracy.ACCURATE | Accurate result. |
#### Language
| Constant | Description |
|-----------------------------------|-------------------------------|
| Language.ARABIC | Arabic language. |
| Language.BULGARIAN | Bulgarian language. |
| Language.CATALAN | Catalan language. |
| Language.CZECH | Czech language. |
| Language.GERMAN | German language. |
| Language.GREEK | Greek language. |
| Language.ENGLISH | English language. |
| Language.PERSIAN | Persian (Farsi) language. |
| Language.FINNISH | Finnish language. |
| Language.FRENCH | French language. |
| Language.GALICIAN | Galician language. |
| Language.CROATIAN | Croatian language. |
| Language.HUNGARIAN | Hungarian language. |
| Language.ITALIAN | Italian language. |
| Language.JAPANESE | Japanese language. |
| Language.KOREAN | Korean language. |
| Language.LATVIAN | Latvian language. |
| Language.LITHUANIAN | Lithuanian language. |
| Language.MACEDONIAN | Macedonian language. |
| Language.DUTCH | Dutch language. |
| Language.POLISH | Polish language. |
| Language.PORTUGUESE | Portuguese language. |
| Language.ROMANIAN | Romanian language. |
| Language.RUSSIAN | Russian language. |
| Language.SWEDISH | Swedish language. |
| Language.SLOVAK | Slovak language. |
| Language.SLOVENIAN | Slovenian language. |
| Language.SPANISH | Spanish language. |
| Language.TURKISH | Turkish language. |
| Language.UKRANIAN | Ukrainian language. |
| Language.VIETNAMESE | Vietnamese language. |
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
#### Unit
| Constant | Description |
|----------------------|------------------------------------------------|
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow) |
### Dependencies
* com.alibaba:fastjson:1.2.44
* org.projectlombok:lombok:1.18.0 (*provided*)
+402
View File
@@ -0,0 +1,402 @@
### Implemented features:
* Current weather data
* 5 day / 3 hour forecast
* 16 day / daily forecast
* UV Index
* Air Pollution
### Maven coordinates:
```xml
<dependency>
<groupId>com.github.prominence</groupId>
<artifactId>openweathermap-api</artifactId>
<version>1.2</version>
</dependency>
```
### Gradle coordinates:
```groovy
compile('com.github.prominence:openweathermap-api:1.2')
```
### How to use:
Firstly, you need to create the instance of `OpenWeatherMapManager` class:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
```
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
Currently available methods:
* `getWeatherRequester()`
* `getHourlyForecastRequester()`
* `getDailyForecastRequester()`
* `getUltravioletIndexRequester(...)`
* `getAirPollutionRequester(...)`
#### Current weather data
First step is retrieving `WeatherRequester` instance:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
WeatherRequester weatherRequester = openWeatherManager.getWeatherRequester();
```
after you are able to set preferable options(via chain methods) and execute appropriate request:
```
Weather weatherResponse = weatherRequester
.setLanguage(Language.ENGLISH)
.setUnitSystem(Unit.METRIC_SYSTEM)
.setAccuracy(Accuracy.ACCURATE)
.getByCityName("Minsk");
```
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
Available requests:
* `getByCityId(String cityId)`
* `getByCityName(String cityName)`
* `getByCoordinates(double latitude, double longitude)`
* `getByCoordinates(Coordinates coordinates)`
* `getByZIPCode(String zipCode, String countryCode)`
`Weather`'s useful public methods(setters are not listed):
| Method | Description |
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
| `getCityName()` | Returns city name. Example: `Minsk`. |
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
| `getBase()` | Returns `String` with some internal information. Example: `cmc stations` - from official documentation. |
| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, pressure and humidity. |
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
| `getDataCalculationTime()`| Returns `long` value that represents data calculation timestamp. |
| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset time. |
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getWeatherSystemInfo().getCountry()`. |
| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. |
| `getDataCalculationDate()`| Returns data calculation time in `Date` representation. |
| `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. |
| `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. |
| `getPressure()` | An alias for `getWeatherInfo().getPressure()`. |
| `getPressureUnit()` | An alias for `getWeatherInfo().getPressureUnit()`. |
| `getHumidityPercentage()` | An alias for `getWeatherInfo().getHumidity()`. |
| `toString()` | Returns pretty string for the whole available weather information. |
`toString()` output example:
```
City: Minsk(625144). Coordinates: latitude=53.9, longitude=27.56
Country: BY
Sunrise: Sun Jul 15 04:58:27 MSK 2018
Sunset: Sun Jul 15 21:32:19 MSK 2018
Weather: light intensity shower rain
Temperature: 17.0 ℃. Minimum temparature: 17.0 ℃. Maximum temperature: 17.0 ℃
Humidity: 93%
Pressure: 1008 hPa
Wind: 2.0 meter/sec, 20 degrees
Cloudiness: 75%
Data calculation time: Mon Jul 16 00:00:00 MSK 2018
```
#### 5 day / 3 hour forecast
First step is retrieving `HourlyForecastRequester` instance:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
HourlyForecastRequester forecastRequester = openWeatherManager.getHourlyForecastRequester();
```
after you are able to set preferable options(via chain methods) and execute appropriate request:
```
HourlyForecast forecastResponse = forecastRequester
.setLanguage(Language.ENGLISH)
.setUnitSystem(Unit.METRIC_SYSTEM)
.setAccuracy(Accuracy.ACCURATE)
.getByCityName("Pruzhany");
```
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
Available requests:
* `getByCityId(String cityId)`
* `getByCityName(String cityName)`
* `getByCoordinates(double latitude, double longitude)`
* `getByCoordinates(Coordinates coordinates)`
* `getByZIPCode(String zipCode, String countryCode)`
`HourlyForecast`'s useful public methods(setters are not listed):
| Method | Description |
|-----------------------------|--------------------------------------------------------------------------------------------|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
| `getCityName()` | Returns city name. Example: `Minsk`. |
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
| `getCityInfo()` | Returns `CityInfo` instance that contains information about city. |
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
| `getAverageTemperature()` | Returns average temperature from forecasts. |
| `getMinimumTemperature()` | Returns minimum temperature from forecasts. |
| `getMaximumTemperature()` | Returns maximum temperature from forecasts. |
| `getByMinimumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is minimal. |
| `getByMaximumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is maximal. |
| `getAveragePressure()` | Returns average pressure from forecasts. |
| `getMinimumPressure()` | Returns minimum pressure from forecasts. |
| `getMaximumPressure()` | Returns maximum pressure from forecasts. |
| `getByMinimumPressure()` | Returns `HourlyForecast.Forecast` for the time where pressure is minimal. |
| `getByMaximumPressure()` | Returns `HourlyForecast.Forecast` for the time where pressure is maximal. |
| `toString()` | Returns pretty string for the whole available forecast information. |
`toString()` output example:
```
City: Pruzhany(622997). Coordinates: latitude=52.5582, longitude=24.4567
Country: BY
Forecasts:
Time: Tue Jul 17 00:00:00 MSK 2018. Weather: light rain. Temperature: 16.24 ℃. Minimum temperature: 16.24 ℃. Maximum temperature: 17.36 ℃. Pressure: 997.38 hPa. Sea-level pressure: 1018.59 hPa. Ground-level pressure: 997.38 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 2.85 meter/sec, 324 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 03:00:00 MSK 2018. Weather: moderate rain. Temperature: 16.0 ℃. Minimum temperature: 16.0 ℃. Maximum temperature: 16.83 ℃. Pressure: 996.88 hPa. Sea-level pressure: 1017.86 hPa. Ground-level pressure: 996.88 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 1.86 meter/sec, 349 degrees. Rain(last 3 hrs): 3 mm
Time: Tue Jul 17 06:00:00 MSK 2018. Weather: light rain. Temperature: 15.76 ℃. Minimum temperature: 15.76 ℃. Maximum temperature: 16.31 ℃. Pressure: 996.7 hPa. Sea-level pressure: 1017.72 hPa. Ground-level pressure: 996.7 hPa. Humidity: 94%. Cloudiness: 76%. Wind: 1.62 meter/sec, 113 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 09:00:00 MSK 2018. Weather: light rain. Temperature: 18.23 ℃. Minimum temperature: 18.23 ℃. Maximum temperature: 18.51 ℃. Pressure: 997.17 hPa. Sea-level pressure: 1018.18 hPa. Ground-level pressure: 997.17 hPa. Humidity: 100%. Cloudiness: 76%. Wind: 2.11 meter/sec, 107 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 12:00:00 MSK 2018. Weather: light rain. Temperature: 21.0 ℃. Minimum temperature: 21.0 ℃. Maximum temperature: 21.0 ℃. Pressure: 997.6 hPa. Sea-level pressure: 1018.5 hPa. Ground-level pressure: 997.6 hPa. Humidity: 100%. Cloudiness: 68%. Wind: 2.51 meter/sec, 82 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 15:00:00 MSK 2018. Weather: light rain. Temperature: 21.78 ℃. Minimum temperature: 21.78 ℃. Maximum temperature: 21.78 ℃. Pressure: 997.73 hPa. Sea-level pressure: 1018.66 hPa. Ground-level pressure: 997.73 hPa. Humidity: 92%. Cloudiness: 88%. Wind: 4.05 meter/sec, 78 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 18:00:00 MSK 2018. Weather: light rain. Temperature: 22.9 ℃. Minimum temperature: 22.9 ℃. Maximum temperature: 22.9 ℃. Pressure: 997.66 hPa. Sea-level pressure: 1018.55 hPa. Ground-level pressure: 997.66 hPa. Humidity: 93%. Cloudiness: 68%. Wind: 3.06 meter/sec, 67 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 21:00:00 MSK 2018. Weather: light rain. Temperature: 23.04 ℃. Minimum temperature: 23.04 ℃. Maximum temperature: 23.04 ℃. Pressure: 996.89 hPa. Sea-level pressure: 1017.99 hPa. Ground-level pressure: 996.89 hPa. Humidity: 83%. Cloudiness: 88%. Wind: 3.17 meter/sec, 16 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 00:00:00 MSK 2018. Weather: moderate rain. Temperature: 18.5 ℃. Minimum temperature: 18.5 ℃. Maximum temperature: 18.5 ℃. Pressure: 997.33 hPa. Sea-level pressure: 1018.34 hPa. Ground-level pressure: 997.33 hPa. Humidity: 97%. Cloudiness: 44%. Wind: 3.56 meter/sec, 31 degrees. Rain(last 3 hrs): 7 mm
Time: Wed Jul 18 03:00:00 MSK 2018. Weather: few clouds. Temperature: 18.57 ℃. Minimum temperature: 18.57 ℃. Maximum temperature: 18.57 ℃. Pressure: 996.91 hPa. Sea-level pressure: 1017.87 hPa. Ground-level pressure: 996.91 hPa. Humidity: 95%. Cloudiness: 24%. Wind: 5.26 meter/sec, 44 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 06:00:00 MSK 2018. Weather: few clouds. Temperature: 18.94 ℃. Minimum temperature: 18.94 ℃. Maximum temperature: 18.94 ℃. Pressure: 997.07 hPa. Sea-level pressure: 1018.06 hPa. Ground-level pressure: 997.07 hPa. Humidity: 95%. Cloudiness: 20%. Wind: 4.8 meter/sec, 45 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 09:00:00 MSK 2018. Weather: light rain. Temperature: 20.6 ℃. Minimum temperature: 20.6 ℃. Maximum temperature: 20.6 ℃. Pressure: 997.8 hPa. Sea-level pressure: 1018.66 hPa. Ground-level pressure: 997.8 hPa. Humidity: 97%. Cloudiness: 48%. Wind: 5.56 meter/sec, 54 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 12:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.87 ℃. Minimum temperature: 23.87 ℃. Maximum temperature: 23.87 ℃. Pressure: 998.06 hPa. Sea-level pressure: 1019.05 hPa. Ground-level pressure: 998.06 hPa. Humidity: 88%. Cloudiness: 32%. Wind: 5.86 meter/sec, 52 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 24.67 ℃. Minimum temperature: 24.67 ℃. Maximum temperature: 24.67 ℃. Pressure: 998.51 hPa. Sea-level pressure: 1019.33 hPa. Ground-level pressure: 998.51 hPa. Humidity: 84%. Cloudiness: 36%. Wind: 5.63 meter/sec, 51 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.15 ℃. Minimum temperature: 25.15 ℃. Maximum temperature: 25.15 ℃. Pressure: 998.79 hPa. Sea-level pressure: 1019.64 hPa. Ground-level pressure: 998.79 hPa. Humidity: 78%. Cloudiness: 44%. Wind: 5.47 meter/sec, 38 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.23 ℃. Minimum temperature: 23.23 ℃. Maximum temperature: 23.23 ℃. Pressure: 999.08 hPa. Sea-level pressure: 1020.04 hPa. Ground-level pressure: 999.08 hPa. Humidity: 75%. Cloudiness: 48%. Wind: 4.62 meter/sec, 25 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 20.79 ℃. Minimum temperature: 20.79 ℃. Maximum temperature: 20.79 ℃. Pressure: 999.67 hPa. Sea-level pressure: 1020.68 hPa. Ground-level pressure: 999.67 hPa. Humidity: 76%. Cloudiness: 48%. Wind: 4.29 meter/sec, 13 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 03:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.45 ℃. Minimum temperature: 19.45 ℃. Maximum temperature: 19.45 ℃. Pressure: 999.95 hPa. Sea-level pressure: 1021.02 hPa. Ground-level pressure: 999.95 hPa. Humidity: 80%. Cloudiness: 48%. Wind: 4.22 meter/sec, 17 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 06:00:00 MSK 2018. Weather: light rain. Temperature: 18.9 ℃. Minimum temperature: 18.9 ℃. Maximum temperature: 18.9 ℃. Pressure: 1000.6 hPa. Sea-level pressure: 1021.62 hPa. Ground-level pressure: 1000.6 hPa. Humidity: 83%. Cloudiness: 92%. Wind: 4.43 meter/sec, 10 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 09:00:00 MSK 2018. Weather: light rain. Temperature: 21.37 ℃. Minimum temperature: 21.37 ℃. Maximum temperature: 21.37 ℃. Pressure: 1000.95 hPa. Sea-level pressure: 1022.01 hPa. Ground-level pressure: 1000.95 hPa. Humidity: 87%. Cloudiness: 0%. Wind: 4.36 meter/sec, 6 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.92 ℃. Minimum temperature: 23.92 ℃. Maximum temperature: 23.92 ℃. Pressure: 1001.5 hPa. Sea-level pressure: 1022.43 hPa. Ground-level pressure: 1001.5 hPa. Humidity: 77%. Cloudiness: 0%. Wind: 5.66 meter/sec, 12 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 15:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.7 ℃. Minimum temperature: 23.7 ℃. Maximum temperature: 23.7 ℃. Pressure: 1001.75 hPa. Sea-level pressure: 1022.72 hPa. Ground-level pressure: 1001.75 hPa. Humidity: 72%. Cloudiness: 56%. Wind: 5.87 meter/sec, 349 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 18:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.82 ℃. Minimum temperature: 23.82 ℃. Maximum temperature: 23.82 ℃. Pressure: 1001.55 hPa. Sea-level pressure: 1022.59 hPa. Ground-level pressure: 1001.55 hPa. Humidity: 72%. Cloudiness: 68%. Wind: 5.47 meter/sec, 340 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.22 ℃. Minimum temperature: 22.22 ℃. Maximum temperature: 22.22 ℃. Pressure: 1001.82 hPa. Sea-level pressure: 1022.93 hPa. Ground-level pressure: 1001.82 hPa. Humidity: 67%. Cloudiness: 76%. Wind: 4.12 meter/sec, 333 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.76 ℃. Minimum temperature: 19.76 ℃. Maximum temperature: 19.76 ℃. Pressure: 1001.98 hPa. Sea-level pressure: 1023.13 hPa. Ground-level pressure: 1001.98 hPa. Humidity: 76%. Cloudiness: 32%. Wind: 4.11 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 03:00:00 MSK 2018. Weather: clear sky. Temperature: 17.53 ℃. Minimum temperature: 17.53 ℃. Maximum temperature: 17.53 ℃. Pressure: 1001.93 hPa. Sea-level pressure: 1023.13 hPa. Ground-level pressure: 1001.93 hPa. Humidity: 87%. Cloudiness: 8%. Wind: 4.21 meter/sec, 309 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 16.83 ℃. Minimum temperature: 16.83 ℃. Maximum temperature: 16.83 ℃. Pressure: 1001.79 hPa. Sea-level pressure: 1022.99 hPa. Ground-level pressure: 1001.79 hPa. Humidity: 91%. Cloudiness: 44%. Wind: 3.65 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 09:00:00 MSK 2018. Weather: light rain. Temperature: 19.57 ℃. Minimum temperature: 19.57 ℃. Maximum temperature: 19.57 ℃. Pressure: 1001.34 hPa. Sea-level pressure: 1022.41 hPa. Ground-level pressure: 1001.34 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 4.38 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.5 ℃. Minimum temperature: 23.5 ℃. Maximum temperature: 23.5 ℃. Pressure: 1001.0 hPa. Sea-level pressure: 1021.99 hPa. Ground-level pressure: 1001.0 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 5.36 meter/sec, 299 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.14 ℃. Minimum temperature: 25.14 ℃. Maximum temperature: 25.14 ℃. Pressure: 1000.5 hPa. Sea-level pressure: 1021.51 hPa. Ground-level pressure: 1000.5 hPa. Humidity: 73%. Cloudiness: 32%. Wind: 6.72 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 18:00:00 MSK 2018. Weather: overcast clouds. Temperature: 23.56 ℃. Minimum temperature: 23.56 ℃. Maximum temperature: 23.56 ℃. Pressure: 1000.7 hPa. Sea-level pressure: 1021.58 hPa. Ground-level pressure: 1000.7 hPa. Humidity: 66%. Cloudiness: 88%. Wind: 6.57 meter/sec, 317 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.41 ℃. Minimum temperature: 22.41 ℃. Maximum temperature: 22.41 ℃. Pressure: 1000.64 hPa. Sea-level pressure: 1021.67 hPa. Ground-level pressure: 1000.64 hPa. Humidity: 68%. Cloudiness: 64%. Wind: 4.31 meter/sec, 326 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 00:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.92 ℃. Minimum temperature: 20.92 ℃. Maximum temperature: 20.92 ℃. Pressure: 1001.06 hPa. Sea-level pressure: 1022.14 hPa. Ground-level pressure: 1001.06 hPa. Humidity: 78%. Cloudiness: 68%. Wind: 3.42 meter/sec, 327 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 03:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.28 ℃. Minimum temperature: 20.28 ℃. Maximum temperature: 20.28 ℃. Pressure: 1001.04 hPa. Sea-level pressure: 1022.13 hPa. Ground-level pressure: 1001.04 hPa. Humidity: 78%. Cloudiness: 76%. Wind: 4.27 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.11 ℃. Minimum temperature: 19.11 ℃. Maximum temperature: 19.11 ℃. Pressure: 1001.13 hPa. Sea-level pressure: 1022.28 hPa. Ground-level pressure: 1001.13 hPa. Humidity: 74%. Cloudiness: 32%. Wind: 4.96 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 09:00:00 MSK 2018. Weather: few clouds. Temperature: 20.16 ℃. Minimum temperature: 20.16 ℃. Maximum temperature: 20.16 ℃. Pressure: 1001.43 hPa. Sea-level pressure: 1022.62 hPa. Ground-level pressure: 1001.43 hPa. Humidity: 86%. Cloudiness: 20%. Wind: 5.16 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 12:00:00 MSK 2018. Weather: few clouds. Temperature: 22.37 ℃. Minimum temperature: 22.37 ℃. Maximum temperature: 22.37 ℃. Pressure: 1001.53 hPa. Sea-level pressure: 1022.62 hPa. Ground-level pressure: 1001.53 hPa. Humidity: 88%. Cloudiness: 20%. Wind: 5.56 meter/sec, 307 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.85 ℃. Minimum temperature: 22.85 ℃. Maximum temperature: 22.85 ℃. Pressure: 1001.63 hPa. Sea-level pressure: 1022.65 hPa. Ground-level pressure: 1001.63 hPa. Humidity: 81%. Cloudiness: 44%. Wind: 5.46 meter/sec, 314 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.79 ℃. Minimum temperature: 23.79 ℃. Maximum temperature: 23.79 ℃. Pressure: 1001.53 hPa. Sea-level pressure: 1022.53 hPa. Ground-level pressure: 1001.53 hPa. Humidity: 72%. Cloudiness: 32%. Wind: 5.56 meter/sec, 313 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.56 ℃. Minimum temperature: 22.56 ℃. Maximum temperature: 22.56 ℃. Pressure: 1001.72 hPa. Sea-level pressure: 1022.7 hPa. Ground-level pressure: 1001.72 hPa. Humidity: 66%. Cloudiness: 48%. Wind: 3.96 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
```
`HourlyForecast.Forecast`'s useful public methods(setters are not listed):
| Method | Description |
|-----------------------------|------------------------------------------------------------------------------------------------------------------|
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
| `getWeatherInfo()` | Returns `HourlyForecast.WeatherInfo` instance that contains information about temperature, pressure and humidity.|
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. |
| `getDt_txt()` | Returns `String` value that represents data calculation time. |
| `toString()` | Returns pretty string for the whole available forecast information. |
#### 16 day / daily forecast
First step is retrieving `DailyForecastRequester` instance:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
DailyForecastRequester forecastRequester = openWeatherManager.getDailyForecastRequester();
```
after you are able to set preferable options(via chain methods) and execute appropriate request:
```
DailyForecast forecastResponse = forecastRequester
.setLanguage(Language.ENGLISH)
.setUnitSystem(Unit.METRIC_SYSTEM)
.setAccuracy(Accuracy.ACCURATE)
.getByCityName("Pruzhany");
```
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
Available requests:
* `getByCityId(String cityId)`
* `getByCityName(String cityName)`
* `getByCoordinates(double latitude, double longitude)`
* `getByCoordinates(Coordinates coordinates)`
* `getByZIPCode(String zipCode, String countryCode)`
`DailyForecast`'s useful public methods(setters are not listed):
| Method | Description |
|-----------------------------|--------------------------------------------------------------------------------------------|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
| `getCityName()` | Returns city name. Example: `Minsk`. |
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
| `getCityInfo()` | Returns `CityInfo` instance that contains information about city. |
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
| `toString()` | Returns pretty string for the whole available forecast information. |
`DailyForecast.Forecast`'s useful public methods(setters are not listed):
| Method | Description |
|-----------------------------|------------------------------------------------------------------------------------------------------------------|
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
| `getTemperature()` | Returns `DailyForecast.Forecast.Temperature` instance that contains information about temperature(avg, min, max).|
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
| `getCloudiness()` | Returns *cloudiness* percentage information. |
| `getHumidity()` | Returns *humidity* percentage information. |
| `getWindSpeed()` | Returns wind's speed. |
| `getWindDegrees()` | Returns wind's degree. |
| `getWindUnit()` | Returns wind's unit. |
| `getPressure()` | Returns pressure value. |
| `getPressureUnit()` | Returns pressure's unit. |
| `toString()` | Returns pretty string for the whole available forecast information. |
#### UV Index
First step is retrieving `UltravioletIndexRequester` instance:
```java
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
UltravioletIndexRequester requester = openWeatherMapManager.getUltravioletIndexRequester(34.23f, -22.45f);
```
or
```java
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
Coordinates coordinates = new Coordinates(34.23f, -22.45f);
UltravioletIndexRequester requester = openWeatherMapManager.getUltravioletIndexRequester(coordinates);
```
after you need to execute appropriate request:
```
UltravioletIndex uvResponse = requester.getCurrentUVIndex();
```
You can change required coordinates via: `requester.setCoordinates(Coordinates coordinates);` or `requester.setCoordinates(float latitude, float longitude);`
Available requests:
* `getCurrentUVIndex()`
* `getUVIndexForecast(int amountOfDays)`
* `getUVIndexByPeriod(Date from, Date to)`
`UltravioletIndex`'s useful public methods(setters are not listed):
| Method | Description |
|---------------------------|---------------------------------------------------------------|
| `getLatitude()` | Returns latitude. |
| `getLongitude()` | Returns longitude. |
| `getDateISO()` | Returns ISO date in String representation. |
| `getDateTimestamp()` | Returns date timestamp. |
| `getValue()` | Returns UV value. |
| `getCalculationDate()` | Returns date in Date representation`. |
| `toString()` | Returns pretty string for the whole available UV information. |
`toString()` output example:
```
Date: Tue Jul 31 15:00:00 MSK 2018, Ultraviolet value: 6.230000
```
#### Air pollution
First step is retrieving `AirPollutionRequester` instance:
```java
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
AirPollutionRequester requester = openWeatherMapManager.getAirPollutionRequester(0f, 10f, new Date(), TimeFrame.DAY);
```
after you need to execute appropriate request:
```
AirPollution airPolutionResponse = requester.retrieve();
```
You can modify parameters anytime:
```java
requester.setCoordinates(Coordinates coordinates);
requester.setCoordinates(float latitude, float longitude);
requester.setTimeFrame(TimeFrame timeFrame);
requester.setDate(Date date);
```
Available requests:
* `retrieve()`
`AirPollution`'s useful public methods(setters are not listed):
| Method | Description |
|---------------------------|---------------------------------------------------------------------------|
| `getCoordinates()` | Returns `Coordinates` instance. |
| `getLongitude()` | Returns longitude. |
| `airPollutionInfo()` | Returns list of `AirPollution.AirPollutionInfo` instances. |
| `toString()` | Returns pretty string for the whole available air pollution information. |
`toString()` output example:
```
AirPollution[Date: Tue Jul 24 01:04:40 MSK 2018; Coordinates: latitude=0.0, longitude=9.9955]
[Value: 8.0347114E-8, Value: 9.5041536E-8, Value: 7.7667146E-8, Value: 7.251491E-8, Value: 5.899763E-8, Value: 1.9186361E-8, Value: 1.729535E-8, Value: 1.25645805E-8, Value: 3.0852514E-9]
```
### Constants and options
#### Accuracy
| Constant | Description |
|--------------------|------------------|
| Accuracy.LIKE | Close result. |
| Accuracy.ACCURATE | Accurate result. |
#### Language
| Constant | Description |
|-----------------------------------|-------------------------------|
| Language.ARABIC | Arabic language. |
| Language.BULGARIAN | Bulgarian language. |
| Language.CATALAN | Catalan language. |
| Language.CZECH | Czech language. |
| Language.GERMAN | German language. |
| Language.GREEK | Greek language. |
| Language.ENGLISH | English language. |
| Language.PERSIAN | Persian (Farsi) language. |
| Language.FINNISH | Finnish language. |
| Language.FRENCH | French language. |
| Language.GALICIAN | Galician language. |
| Language.CROATIAN | Croatian language. |
| Language.HUNGARIAN | Hungarian language. |
| Language.ITALIAN | Italian language. |
| Language.JAPANESE | Japanese language. |
| Language.KOREAN | Korean language. |
| Language.LATVIAN | Latvian language. |
| Language.LITHUANIAN | Lithuanian language. |
| Language.MACEDONIAN | Macedonian language. |
| Language.DUTCH | Dutch language. |
| Language.POLISH | Polish language. |
| Language.PORTUGUESE | Portuguese language. |
| Language.ROMANIAN | Romanian language. |
| Language.RUSSIAN | Russian language. |
| Language.SWEDISH | Swedish language. |
| Language.SLOVAK | Slovak language. |
| Language.SLOVENIAN | Slovenian language. |
| Language.SPANISH | Spanish language. |
| Language.TURKISH | Turkish language. |
| Language.UKRANIAN | Ukrainian language. |
| Language.VIETNAMESE | Vietnamese language. |
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
#### Unit
| Constant | Description |
|----------------------|------------------------------------------------|
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow) |
### Dependencies
* com.alibaba:fastjson:1.2.44
* org.projectlombok:lombok:1.18.0 (*provided*)
* junit:junit:4.12 (*test*)
+389
View File
@@ -0,0 +1,389 @@
### Implemented features:
* Current weather data
* 5 day / 3 hour forecast
* 16 day / daily forecast
* UV Index
* Air Pollution
### Maven coordinates:
```xml
<dependency>
<groupId>com.github.prominence</groupId>
<artifactId>openweathermap-api</artifactId>
<version>1.1-SNAPSHOT</version>
</dependency>
```
### Gradle coordinates:
```groovy
compile('com.github.prominence:openweathermap-api:1.1-SNAPSHOT')
```
### How to use:
Firstly, you need to create the instance of `OpenWeatherMapManager` class:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
```
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
Currently available methods:
* `getWeatherRequester()`
* `getHourlyForecastRequester()`
* `getDailyForecastRequester()`
* `getUltravioletIndexRequester()`
#### Current weather data
First step is retrieving `WeatherRequester` instance:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
WeatherRequester weatherRequester = openWeatherManager.getWeatherRequester();
```
after you are able to set preferable options(via chain methods) and execute appropriate request:
```
Weather weatherResponse = weatherRequester
.setLanguage(Language.ENGLISH)
.setUnitSystem(Unit.METRIC_SYSTEM)
.setAccuracy(Accuracy.ACCURATE)
.getByCityName("Minsk");
```
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
Available requests:
* `getByCityId(String cityId)`
* `getByCityName(String cityName)`
* `getByCoordinates(double latitude, double longitude)`
* `getByCoordinates(Coordinates coordinates)`
* `getByZIPCode(String zipCode, String countryCode)`
`Weather`'s useful public methods(setters are not listed):
| Method | Description |
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
| `getCityName()` | Returns city name. Example: `Minsk`. |
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
| `getBase()` | Returns `String` with some internal information. Example: `cmc stations` - from official documentation. |
| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, pressure and humidity. |
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
| `getDataCalculationTime()`| Returns `long` value that represents data calculation timestamp. |
| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset time. |
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getWeatherSystemInfo().getCountry()`. |
| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. |
| `getDataCalculationDate()`| Returns data calculation time in `Date` representation. |
| `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. |
| `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. |
| `getPressure()` | An alias for `getWeatherInfo().getPressure()`. |
| `getPressureUnit()` | An alias for `getWeatherInfo().getPressureUnit()`. |
| `getHumidityPercentage()` | An alias for `getWeatherInfo().getHumidity()`. |
| `toString()` | Returns pretty string for the whole available weather information. |
`toString()` output example:
```
City: Minsk(625144). Coordinates: latitude=53.9, longitude=27.56
Country: BY
Sunrise: Sun Jul 15 04:58:27 MSK 2018
Sunset: Sun Jul 15 21:32:19 MSK 2018
Weather: light intensity shower rain
Temperature: 17.0 ℃. Minimum temparature: 17.0 ℃. Maximum temperature: 17.0 ℃
Humidity: 93%
Pressure: 1008 hPa
Wind: 2.0 meter/sec, 20 degrees
Cloudiness: 75%
Data calculation time: Mon Jul 16 00:00:00 MSK 2018
```
#### 5 day / 3 hour forecast
First step is retrieving `HourlyForecastRequester` instance:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
HourlyForecastRequester forecastRequester = openWeatherManager.getHourlyForecastRequester();
```
after you are able to set preferable options(via chain methods) and execute appropriate request:
```
HourlyForecast forecastResponse = forecastRequester
.setLanguage(Language.ENGLISH)
.setUnitSystem(Unit.METRIC_SYSTEM)
.setAccuracy(Accuracy.ACCURATE)
.getByCityName("Pruzhany");
```
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
Available requests:
* `getByCityId(String cityId)`
* `getByCityName(String cityName)`
* `getByCoordinates(double latitude, double longitude)`
* `getByCoordinates(Coordinates coordinates)`
* `getByZIPCode(String zipCode, String countryCode)`
`HourlyForecast`'s useful public methods(setters are not listed):
| Method | Description |
|-----------------------------|--------------------------------------------------------------------------------------------|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
| `getCityName()` | Returns city name. Example: `Minsk`. |
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
| `getCityInfo()` | Returns `CityInfo` instance that contains information about city. |
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
| `getAverageTemperature()` | Returns average temperature from forecasts. |
| `getMinimumTemperature()` | Returns minimum temperature from forecasts. |
| `getMaximumTemperature()` | Returns maximum temperature from forecasts. |
| `getByMinimumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is minimal. |
| `getByMaximumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is maximal. |
| `getAveragePressure()` | Returns average pressure from forecasts. |
| `getMinimumPressure()` | Returns minimum pressure from forecasts. |
| `getMaximumPressure()` | Returns maximum pressure from forecasts. |
| `getByMinimumPressure()` | Returns `HourlyForecast.Forecast` for the time where pressure is minimal. |
| `getByMaximumPressure()` | Returns `HourlyForecast.Forecast` for the time where pressure is maximal. |
| `toString()` | Returns pretty string for the whole available forecast information. |
`toString()` output example:
```
City: Pruzhany(622997). Coordinates: latitude=52.5582, longitude=24.4567
Country: BY
Forecasts:
Time: Tue Jul 17 00:00:00 MSK 2018. Weather: light rain. Temperature: 16.24 ℃. Minimum temperature: 16.24 ℃. Maximum temperature: 17.36 ℃. Pressure: 997.38 hPa. Sea-level pressure: 1018.59 hPa. Ground-level pressure: 997.38 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 2.85 meter/sec, 324 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 03:00:00 MSK 2018. Weather: moderate rain. Temperature: 16.0 ℃. Minimum temperature: 16.0 ℃. Maximum temperature: 16.83 ℃. Pressure: 996.88 hPa. Sea-level pressure: 1017.86 hPa. Ground-level pressure: 996.88 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 1.86 meter/sec, 349 degrees. Rain(last 3 hrs): 3 mm
Time: Tue Jul 17 06:00:00 MSK 2018. Weather: light rain. Temperature: 15.76 ℃. Minimum temperature: 15.76 ℃. Maximum temperature: 16.31 ℃. Pressure: 996.7 hPa. Sea-level pressure: 1017.72 hPa. Ground-level pressure: 996.7 hPa. Humidity: 94%. Cloudiness: 76%. Wind: 1.62 meter/sec, 113 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 09:00:00 MSK 2018. Weather: light rain. Temperature: 18.23 ℃. Minimum temperature: 18.23 ℃. Maximum temperature: 18.51 ℃. Pressure: 997.17 hPa. Sea-level pressure: 1018.18 hPa. Ground-level pressure: 997.17 hPa. Humidity: 100%. Cloudiness: 76%. Wind: 2.11 meter/sec, 107 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 12:00:00 MSK 2018. Weather: light rain. Temperature: 21.0 ℃. Minimum temperature: 21.0 ℃. Maximum temperature: 21.0 ℃. Pressure: 997.6 hPa. Sea-level pressure: 1018.5 hPa. Ground-level pressure: 997.6 hPa. Humidity: 100%. Cloudiness: 68%. Wind: 2.51 meter/sec, 82 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 15:00:00 MSK 2018. Weather: light rain. Temperature: 21.78 ℃. Minimum temperature: 21.78 ℃. Maximum temperature: 21.78 ℃. Pressure: 997.73 hPa. Sea-level pressure: 1018.66 hPa. Ground-level pressure: 997.73 hPa. Humidity: 92%. Cloudiness: 88%. Wind: 4.05 meter/sec, 78 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 18:00:00 MSK 2018. Weather: light rain. Temperature: 22.9 ℃. Minimum temperature: 22.9 ℃. Maximum temperature: 22.9 ℃. Pressure: 997.66 hPa. Sea-level pressure: 1018.55 hPa. Ground-level pressure: 997.66 hPa. Humidity: 93%. Cloudiness: 68%. Wind: 3.06 meter/sec, 67 degrees. Rain(last 3 hrs): 0 mm
Time: Tue Jul 17 21:00:00 MSK 2018. Weather: light rain. Temperature: 23.04 ℃. Minimum temperature: 23.04 ℃. Maximum temperature: 23.04 ℃. Pressure: 996.89 hPa. Sea-level pressure: 1017.99 hPa. Ground-level pressure: 996.89 hPa. Humidity: 83%. Cloudiness: 88%. Wind: 3.17 meter/sec, 16 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 00:00:00 MSK 2018. Weather: moderate rain. Temperature: 18.5 ℃. Minimum temperature: 18.5 ℃. Maximum temperature: 18.5 ℃. Pressure: 997.33 hPa. Sea-level pressure: 1018.34 hPa. Ground-level pressure: 997.33 hPa. Humidity: 97%. Cloudiness: 44%. Wind: 3.56 meter/sec, 31 degrees. Rain(last 3 hrs): 7 mm
Time: Wed Jul 18 03:00:00 MSK 2018. Weather: few clouds. Temperature: 18.57 ℃. Minimum temperature: 18.57 ℃. Maximum temperature: 18.57 ℃. Pressure: 996.91 hPa. Sea-level pressure: 1017.87 hPa. Ground-level pressure: 996.91 hPa. Humidity: 95%. Cloudiness: 24%. Wind: 5.26 meter/sec, 44 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 06:00:00 MSK 2018. Weather: few clouds. Temperature: 18.94 ℃. Minimum temperature: 18.94 ℃. Maximum temperature: 18.94 ℃. Pressure: 997.07 hPa. Sea-level pressure: 1018.06 hPa. Ground-level pressure: 997.07 hPa. Humidity: 95%. Cloudiness: 20%. Wind: 4.8 meter/sec, 45 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 09:00:00 MSK 2018. Weather: light rain. Temperature: 20.6 ℃. Minimum temperature: 20.6 ℃. Maximum temperature: 20.6 ℃. Pressure: 997.8 hPa. Sea-level pressure: 1018.66 hPa. Ground-level pressure: 997.8 hPa. Humidity: 97%. Cloudiness: 48%. Wind: 5.56 meter/sec, 54 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 12:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.87 ℃. Minimum temperature: 23.87 ℃. Maximum temperature: 23.87 ℃. Pressure: 998.06 hPa. Sea-level pressure: 1019.05 hPa. Ground-level pressure: 998.06 hPa. Humidity: 88%. Cloudiness: 32%. Wind: 5.86 meter/sec, 52 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 24.67 ℃. Minimum temperature: 24.67 ℃. Maximum temperature: 24.67 ℃. Pressure: 998.51 hPa. Sea-level pressure: 1019.33 hPa. Ground-level pressure: 998.51 hPa. Humidity: 84%. Cloudiness: 36%. Wind: 5.63 meter/sec, 51 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.15 ℃. Minimum temperature: 25.15 ℃. Maximum temperature: 25.15 ℃. Pressure: 998.79 hPa. Sea-level pressure: 1019.64 hPa. Ground-level pressure: 998.79 hPa. Humidity: 78%. Cloudiness: 44%. Wind: 5.47 meter/sec, 38 degrees. Rain(last 3 hrs): 0 mm
Time: Wed Jul 18 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.23 ℃. Minimum temperature: 23.23 ℃. Maximum temperature: 23.23 ℃. Pressure: 999.08 hPa. Sea-level pressure: 1020.04 hPa. Ground-level pressure: 999.08 hPa. Humidity: 75%. Cloudiness: 48%. Wind: 4.62 meter/sec, 25 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 20.79 ℃. Minimum temperature: 20.79 ℃. Maximum temperature: 20.79 ℃. Pressure: 999.67 hPa. Sea-level pressure: 1020.68 hPa. Ground-level pressure: 999.67 hPa. Humidity: 76%. Cloudiness: 48%. Wind: 4.29 meter/sec, 13 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 03:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.45 ℃. Minimum temperature: 19.45 ℃. Maximum temperature: 19.45 ℃. Pressure: 999.95 hPa. Sea-level pressure: 1021.02 hPa. Ground-level pressure: 999.95 hPa. Humidity: 80%. Cloudiness: 48%. Wind: 4.22 meter/sec, 17 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 06:00:00 MSK 2018. Weather: light rain. Temperature: 18.9 ℃. Minimum temperature: 18.9 ℃. Maximum temperature: 18.9 ℃. Pressure: 1000.6 hPa. Sea-level pressure: 1021.62 hPa. Ground-level pressure: 1000.6 hPa. Humidity: 83%. Cloudiness: 92%. Wind: 4.43 meter/sec, 10 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 09:00:00 MSK 2018. Weather: light rain. Temperature: 21.37 ℃. Minimum temperature: 21.37 ℃. Maximum temperature: 21.37 ℃. Pressure: 1000.95 hPa. Sea-level pressure: 1022.01 hPa. Ground-level pressure: 1000.95 hPa. Humidity: 87%. Cloudiness: 0%. Wind: 4.36 meter/sec, 6 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.92 ℃. Minimum temperature: 23.92 ℃. Maximum temperature: 23.92 ℃. Pressure: 1001.5 hPa. Sea-level pressure: 1022.43 hPa. Ground-level pressure: 1001.5 hPa. Humidity: 77%. Cloudiness: 0%. Wind: 5.66 meter/sec, 12 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 15:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.7 ℃. Minimum temperature: 23.7 ℃. Maximum temperature: 23.7 ℃. Pressure: 1001.75 hPa. Sea-level pressure: 1022.72 hPa. Ground-level pressure: 1001.75 hPa. Humidity: 72%. Cloudiness: 56%. Wind: 5.87 meter/sec, 349 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 18:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.82 ℃. Minimum temperature: 23.82 ℃. Maximum temperature: 23.82 ℃. Pressure: 1001.55 hPa. Sea-level pressure: 1022.59 hPa. Ground-level pressure: 1001.55 hPa. Humidity: 72%. Cloudiness: 68%. Wind: 5.47 meter/sec, 340 degrees. Rain(last 3 hrs): 0 mm
Time: Thu Jul 19 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.22 ℃. Minimum temperature: 22.22 ℃. Maximum temperature: 22.22 ℃. Pressure: 1001.82 hPa. Sea-level pressure: 1022.93 hPa. Ground-level pressure: 1001.82 hPa. Humidity: 67%. Cloudiness: 76%. Wind: 4.12 meter/sec, 333 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.76 ℃. Minimum temperature: 19.76 ℃. Maximum temperature: 19.76 ℃. Pressure: 1001.98 hPa. Sea-level pressure: 1023.13 hPa. Ground-level pressure: 1001.98 hPa. Humidity: 76%. Cloudiness: 32%. Wind: 4.11 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 03:00:00 MSK 2018. Weather: clear sky. Temperature: 17.53 ℃. Minimum temperature: 17.53 ℃. Maximum temperature: 17.53 ℃. Pressure: 1001.93 hPa. Sea-level pressure: 1023.13 hPa. Ground-level pressure: 1001.93 hPa. Humidity: 87%. Cloudiness: 8%. Wind: 4.21 meter/sec, 309 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 16.83 ℃. Minimum temperature: 16.83 ℃. Maximum temperature: 16.83 ℃. Pressure: 1001.79 hPa. Sea-level pressure: 1022.99 hPa. Ground-level pressure: 1001.79 hPa. Humidity: 91%. Cloudiness: 44%. Wind: 3.65 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 09:00:00 MSK 2018. Weather: light rain. Temperature: 19.57 ℃. Minimum temperature: 19.57 ℃. Maximum temperature: 19.57 ℃. Pressure: 1001.34 hPa. Sea-level pressure: 1022.41 hPa. Ground-level pressure: 1001.34 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 4.38 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.5 ℃. Minimum temperature: 23.5 ℃. Maximum temperature: 23.5 ℃. Pressure: 1001.0 hPa. Sea-level pressure: 1021.99 hPa. Ground-level pressure: 1001.0 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 5.36 meter/sec, 299 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.14 ℃. Minimum temperature: 25.14 ℃. Maximum temperature: 25.14 ℃. Pressure: 1000.5 hPa. Sea-level pressure: 1021.51 hPa. Ground-level pressure: 1000.5 hPa. Humidity: 73%. Cloudiness: 32%. Wind: 6.72 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 18:00:00 MSK 2018. Weather: overcast clouds. Temperature: 23.56 ℃. Minimum temperature: 23.56 ℃. Maximum temperature: 23.56 ℃. Pressure: 1000.7 hPa. Sea-level pressure: 1021.58 hPa. Ground-level pressure: 1000.7 hPa. Humidity: 66%. Cloudiness: 88%. Wind: 6.57 meter/sec, 317 degrees. Rain(last 3 hrs): 0 mm
Time: Fri Jul 20 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.41 ℃. Minimum temperature: 22.41 ℃. Maximum temperature: 22.41 ℃. Pressure: 1000.64 hPa. Sea-level pressure: 1021.67 hPa. Ground-level pressure: 1000.64 hPa. Humidity: 68%. Cloudiness: 64%. Wind: 4.31 meter/sec, 326 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 00:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.92 ℃. Minimum temperature: 20.92 ℃. Maximum temperature: 20.92 ℃. Pressure: 1001.06 hPa. Sea-level pressure: 1022.14 hPa. Ground-level pressure: 1001.06 hPa. Humidity: 78%. Cloudiness: 68%. Wind: 3.42 meter/sec, 327 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 03:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.28 ℃. Minimum temperature: 20.28 ℃. Maximum temperature: 20.28 ℃. Pressure: 1001.04 hPa. Sea-level pressure: 1022.13 hPa. Ground-level pressure: 1001.04 hPa. Humidity: 78%. Cloudiness: 76%. Wind: 4.27 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.11 ℃. Minimum temperature: 19.11 ℃. Maximum temperature: 19.11 ℃. Pressure: 1001.13 hPa. Sea-level pressure: 1022.28 hPa. Ground-level pressure: 1001.13 hPa. Humidity: 74%. Cloudiness: 32%. Wind: 4.96 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 09:00:00 MSK 2018. Weather: few clouds. Temperature: 20.16 ℃. Minimum temperature: 20.16 ℃. Maximum temperature: 20.16 ℃. Pressure: 1001.43 hPa. Sea-level pressure: 1022.62 hPa. Ground-level pressure: 1001.43 hPa. Humidity: 86%. Cloudiness: 20%. Wind: 5.16 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 12:00:00 MSK 2018. Weather: few clouds. Temperature: 22.37 ℃. Minimum temperature: 22.37 ℃. Maximum temperature: 22.37 ℃. Pressure: 1001.53 hPa. Sea-level pressure: 1022.62 hPa. Ground-level pressure: 1001.53 hPa. Humidity: 88%. Cloudiness: 20%. Wind: 5.56 meter/sec, 307 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.85 ℃. Minimum temperature: 22.85 ℃. Maximum temperature: 22.85 ℃. Pressure: 1001.63 hPa. Sea-level pressure: 1022.65 hPa. Ground-level pressure: 1001.63 hPa. Humidity: 81%. Cloudiness: 44%. Wind: 5.46 meter/sec, 314 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.79 ℃. Minimum temperature: 23.79 ℃. Maximum temperature: 23.79 ℃. Pressure: 1001.53 hPa. Sea-level pressure: 1022.53 hPa. Ground-level pressure: 1001.53 hPa. Humidity: 72%. Cloudiness: 32%. Wind: 5.56 meter/sec, 313 degrees. Rain(last 3 hrs): 0 mm
Time: Sat Jul 21 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.56 ℃. Minimum temperature: 22.56 ℃. Maximum temperature: 22.56 ℃. Pressure: 1001.72 hPa. Sea-level pressure: 1022.7 hPa. Ground-level pressure: 1001.72 hPa. Humidity: 66%. Cloudiness: 48%. Wind: 3.96 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
```
`HourlyForecast.Forecast`'s useful public methods(setters are not listed):
| Method | Description |
|-----------------------------|------------------------------------------------------------------------------------------------------------------|
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
| `getWeatherInfo()` | Returns `HourlyForecast.WeatherInfo` instance that contains information about temperature, pressure and humidity.|
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. |
| `getDt_txt()` | Returns `String` value that represents data calculation time. |
| `toString()` | Returns pretty string for the whole available forecast information. |
#### 16 day / daily forecast
First step is retrieving `DailyForecastRequester` instance:
```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
DailyForecastRequester forecastRequester = openWeatherManager.getDailyForecastRequester();
```
after you are able to set preferable options(via chain methods) and execute appropriate request:
```
DailyForecast forecastResponse = forecastRequester
.setLanguage(Language.ENGLISH)
.setUnitSystem(Unit.METRIC_SYSTEM)
.setAccuracy(Accuracy.ACCURATE)
.getByCityName("Pruzhany");
```
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
Available requests:
* `getByCityId(String cityId)`
* `getByCityName(String cityName)`
* `getByCoordinates(double latitude, double longitude)`
* `getByCoordinates(Coordinates coordinates)`
* `getByZIPCode(String zipCode, String countryCode)`
`DailyForecast`'s useful public methods(setters are not listed):
| Method | Description |
|-----------------------------|--------------------------------------------------------------------------------------------|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
| `getCityName()` | Returns city name. Example: `Minsk`. |
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
| `getCityInfo()` | Returns `CityInfo` instance that contains information about city. |
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
| `toString()` | Returns pretty string for the whole available forecast information. |
`DailyForecast.Forecast`'s useful public methods(setters are not listed):
| Method | Description |
|-----------------------------|------------------------------------------------------------------------------------------------------------------|
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
| `getTemperature()` | Returns `DailyForecast.Forecast.Temperature` instance that contains information about temperature(avg, min, max).|
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
| `getCloudiness()` | Returns *cloudiness* percentage information. |
| `getHumidity()` | Returns *humidity* percentage information. |
| `getWindSpeed()` | Returns wind's speed. |
| `getWindDegrees()` | Returns wind's degree. |
| `getWindUnit()` | Returns wind's unit. |
| `getPressure()` | Returns pressure value. |
| `getPressureUnit()` | Returns pressure's unit. |
| `toString()` | Returns pretty string for the whole available forecast information. |
#### UV Index
First step is retrieving `UltravioletIndexRequester` instance:
```java
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
UltravioletIndexRequester requester = openWeatherMapManager.getUltravioletIndexRequester();
```
after you need to set coordinates and execute appropriate request:
```
DailyForecast forecastResponse = forecastRequester
.setCoodrinates(55.33f, 24.27f)
.getCurrentUVIndex();
```
Available requests:
* `getCurrentUVIndex()`
* `getUVIndexForecast(int amountOfDays)`
* `getUVIndexByPeriod(Date from, Date to)`
`UltravioletIndex`'s useful public methods(setters are not listed):
| Method | Description |
|---------------------------|---------------------------------------------------------------|
| `getLatitude()` | Returns latitude. |
| `getLongitude()` | Returns longitude. |
| `getDateISO()` | Returns ISO date in String representation. |
| `getDateTimestamp()` | Returns date timestamp. |
| `getValue()` | Returns UV value. |
| `getCalculationDate()` | Returns date in Date representation`. |
| `toString()` | Returns pretty string for the whole available UV information. |
`toString()` output example:
```
Date: Tue Jul 31 15:00:00 MSK 2018, Ultraviolet value: 6.230000
```
#### Air pollution
First step is retrieving `AirPollutionRequester` instance:
```java
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
AirPollutionRequester requester = openWeatherMapManager.getAirPollutionRequester();
```
after you need to set coordinates, time frame, date and execute appropriate request:
```
DailyForecast forecastResponse = forecastRequester
.setCoordinates(0.0f, 10.0f)
.setTimeFrame(TimeFrame.YEAR)
.setDate(new Date())
.retrieve();
```
Available requests:
* `retrieve()`
`AirPollution`'s useful public methods(setters are not listed):
| Method | Description |
|---------------------------|---------------------------------------------------------------------------|
| `getCoordinates()` | Returns `Coordinates` instance. |
| `getLongitude()` | Returns longitude. |
| `airPollutionInfo()` | Returns list of `AirPollution.AirPollutionInfo` instances. |
| `toString()` | Returns pretty string for the whole available air pollution information. |
`toString()` output example:
```
AirPollution[Date: Tue Jul 24 01:04:40 MSK 2018; Coordinates: latitude=0.0, longitude=9.9955]
[Value: 8.0347114E-8, Value: 9.5041536E-8, Value: 7.7667146E-8, Value: 7.251491E-8, Value: 5.899763E-8, Value: 1.9186361E-8, Value: 1.729535E-8, Value: 1.25645805E-8, Value: 3.0852514E-9]
```
### Constants and options
#### Accuracy
| Constant | Description |
|--------------------|------------------|
| Accuracy.LIKE | Close result. |
| Accuracy.ACCURATE | Accurate result. |
#### Language
| Constant | Description |
|-----------------------------------|-------------------------------|
| Language.ARABIC | Arabic language. |
| Language.BULGARIAN | Bulgarian language. |
| Language.CATALAN | Catalan language. |
| Language.CZECH | Czech language. |
| Language.GERMAN | German language. |
| Language.GREEK | Greek language. |
| Language.ENGLISH | English language. |
| Language.PERSIAN | Persian (Farsi) language. |
| Language.FINNISH | Finnish language. |
| Language.FRENCH | French language. |
| Language.GALICIAN | Galician language. |
| Language.CROATIAN | Croatian language. |
| Language.HUNGARIAN | Hungarian language. |
| Language.ITALIAN | Italian language. |
| Language.JAPANESE | Japanese language. |
| Language.KOREAN | Korean language. |
| Language.LATVIAN | Latvian language. |
| Language.LITHUANIAN | Lithuanian language. |
| Language.MACEDONIAN | Macedonian language. |
| Language.DUTCH | Dutch language. |
| Language.POLISH | Polish language. |
| Language.PORTUGUESE | Portuguese language. |
| Language.ROMANIAN | Romanian language. |
| Language.RUSSIAN | Russian language. |
| Language.SWEDISH | Swedish language. |
| Language.SLOVAK | Slovak language. |
| Language.SLOVENIAN | Slovenian language. |
| Language.SPANISH | Spanish language. |
| Language.TURKISH | Turkish language. |
| Language.UKRANIAN | Ukrainian language. |
| Language.VIETNAMESE | Vietnamese language. |
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
#### Unit
| Constant | Description |
|----------------------|------------------------------------------------|
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow) |
### Dependencies
* com.alibaba:fastjson:1.2.44
* org.projectlombok:lombok:1.18.0 (*provided*)
+16 -3
View File
@@ -6,7 +6,7 @@
<groupId>com.github.prominence</groupId>
<artifactId>openweathermap-api</artifactId>
<version>1.0</version>
<version>1.2</version>
<packaging>jar</packaging>
<name>Java OpenWeatherMap API</name>
@@ -72,7 +72,7 @@
<version>3.1.0</version>
<configuration>
<excludes>
<exclude>ApplicationTest.class</exclude>
<exclude>**/test/*</exclude>
</excludes>
</configuration>
</plugin>
@@ -136,6 +136,19 @@
<artifactId>fastjson</artifactId>
<version>1.2.44</version>
</dependency>
</dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,107 @@
/*
* 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 com.github.prominence.openweathermap.api;
import com.github.prominence.openweathermap.api.constants.TimeFrame;
import com.github.prominence.openweathermap.api.model.response.AirPollution;
import com.github.prominence.openweathermap.api.model.Coordinates;
import com.github.prominence.openweathermap.api.utils.TimeFrameUtils;
import com.github.prominence.openweathermap.api.utils.JSONUtils;
import com.github.prominence.openweathermap.api.utils.RequestUtils;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
public class AirPollutionRequester extends AuthenticationTokenBasedRequester {
private Coordinates coordinates;
private TimeFrame timeFrame;
private Date date;
AirPollutionRequester(String authToken, float latitude, float longitude, Date date, TimeFrame timeFrame) {
super(authToken);
this.coordinates = new Coordinates(latitude, longitude);
this.date = date;
this.timeFrame = timeFrame;
}
public AirPollutionRequester setCoordinates(Coordinates coordinates) {
this.coordinates = coordinates;
return this;
}
public AirPollutionRequester setCoordinates(float latitude, float longitude) {
this.coordinates = new Coordinates(latitude, longitude);
return this;
}
public AirPollutionRequester setTimeFrame(TimeFrame timeFrame) {
this.timeFrame = timeFrame;
return this;
}
public AirPollutionRequester setDate(Date date) {
this.date = date;
return this;
}
public AirPollution retrieve() {
if (coordinates == null || timeFrame == null || date == null) {
throw new IllegalArgumentException("Coordinates, date or time frame weren't set.");
}
String requestParameters = String.format("%s,%s/%s.json", coordinates.getLatitude(), coordinates.getLongitude(), TimeFrameUtils.formatDate(date, timeFrame));
AirPollution airPollution = null;
// currently only CO
try (InputStream response = executeRequest("pollution/v1/co/", requestParameters)) {
airPollution = (AirPollution) JSONUtils.parseJSON(response, AirPollution.class);
} catch (IOException ex) {
ex.printStackTrace();
}
return airPollution;
}
private InputStream executeRequest(String requestType, String requestSpecificParameters) {
String url = OPEN_WEATHER_BASE_URL + requestType +
requestSpecificParameters +
"?appid=" +
authToken;
InputStream getRequest = null;
try {
getRequest = RequestUtils.executeGetRequest(new URL(url));
} catch (MalformedURLException e) {
e.printStackTrace();
}
return getRequest;
}
}
@@ -24,6 +24,10 @@ package com.github.prominence.openweathermap.api;
abstract class AuthenticationTokenBasedRequester {
protected static final String OPEN_WEATHER_API_VERSION = "2.5";
protected static final String OPEN_WEATHER_BASE_URL = "http://api.openweathermap.org/";
protected static final String OPEN_WEATHER_API_URL = OPEN_WEATHER_BASE_URL + "data/" + OPEN_WEATHER_API_VERSION + "/";
protected String authToken;
protected AuthenticationTokenBasedRequester(String authToken) {
@@ -22,14 +22,12 @@
package com.github.prominence.openweathermap.api;
import com.github.prominence.openweathermap.api.constants.System;
import com.github.prominence.openweathermap.api.constants.Unit;
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
import com.github.prominence.openweathermap.api.model.Coordinates;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
abstract class BasicRequester<T> extends AuthenticationTokenBasedRequester {
@@ -41,29 +39,29 @@ abstract class BasicRequester<T> extends AuthenticationTokenBasedRequester {
super(authToken);
}
public T getByCityId(String id) throws InvalidAuthTokenException, DataNotFoundException {
public T getByCityId(String id) {
return executeRequest("?id=" + id);
}
public T getByCityName(String name) throws InvalidAuthTokenException, DataNotFoundException {
public T getByCityName(String name) {
return executeRequest("?q=" + name);
}
public T getByCoordinates(double latitude, double longitude) throws InvalidAuthTokenException, DataNotFoundException {
public T getByCoordinates(double latitude, double longitude) {
return executeRequest("?lat=" + latitude + "&lon=" + longitude);
}
public T getByCoordinates(Coordinates coordinates) throws InvalidAuthTokenException, DataNotFoundException {
public T getByCoordinates(Coordinates coordinates) {
return getByCoordinates(coordinates.getLatitude(), coordinates.getLongitude());
}
public T getByZIPCode(String zipCode, String countryCode) throws InvalidAuthTokenException, DataNotFoundException {
public T getByZIPCode(String zipCode, String countryCode) {
return executeRequest("?zip=" + zipCode + "," + countryCode);
}
protected URL buildURL(String requestSpecificParameters) throws MalformedURLException {
protected URL buildURL(String requestSpecificParameters) {
StringBuilder urlBuilder = new StringBuilder(System.OPEN_WEATHER_API_URL);
StringBuilder urlBuilder = new StringBuilder(OPEN_WEATHER_API_URL);
urlBuilder.append(getRequestType());
urlBuilder.append(requestSpecificParameters);
@@ -86,10 +84,32 @@ abstract class BasicRequester<T> extends AuthenticationTokenBasedRequester {
urlBuilder.append(accuracy);
}
return new URL(urlBuilder.toString());
Map<String, String> additionalParameters = getAdditionalParameters();
if (additionalParameters != null) {
additionalParameters.forEach((key, value) -> {
urlBuilder.append("&");
urlBuilder.append(key);
urlBuilder.append("=");
urlBuilder.append(value);
});
}
URL url = null;
try {
url = new URL(urlBuilder.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
}
return url;
}
protected Map<String, String> getAdditionalParameters() {
return null;
}
protected abstract String getRequestType();
protected abstract T executeRequest(String requestSpecificParamsString) throws InvalidAuthTokenException, DataNotFoundException;
protected abstract T executeRequest(String requestSpecificParameters);
}
@@ -0,0 +1,85 @@
/*
* 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 com.github.prominence.openweathermap.api;
import com.github.prominence.openweathermap.api.constants.Unit;
import com.github.prominence.openweathermap.api.model.response.DailyForecast;
import com.github.prominence.openweathermap.api.utils.JSONUtils;
import com.github.prominence.openweathermap.api.utils.RequestUtils;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
public class DailyForecastRequester extends BasicRequester<DailyForecast> {
int amountOfDays = -1;
protected DailyForecastRequester(String authToken) {
super(authToken);
}
public DailyForecastRequester setAmountOfDays(int amountOfDays) {
this.amountOfDays = amountOfDays;
return this;
}
@Override
protected String getRequestType() {
return "forecast/daily";
}
@Override
protected Map<String, String> getAdditionalParameters() {
Map<String, String> additionalParameters = null;
if (amountOfDays != -1) {
additionalParameters = new HashMap<>();
additionalParameters.put("cnt", String.valueOf(amountOfDays));
}
return additionalParameters;
}
@Override
protected DailyForecast executeRequest(String requestSpecificParameters) {
DailyForecast forecastResponse = null;
try {
InputStream requestResult = RequestUtils.executeGetRequest(buildURL(requestSpecificParameters));
forecastResponse = (DailyForecast) JSONUtils.parseJSON(requestResult, DailyForecast.class);
char temperatureUnit = Unit.getTemperatureUnit(unitSystem);
String windUnit = Unit.getWindUnit(unitSystem);
forecastResponse.getForecasts().forEach(forecastInfo -> {
forecastInfo.setWindUnit(windUnit);
forecastInfo.getTemperature().setTemperatureUnit(temperatureUnit);
});
} catch (IOException ex) {
ex.printStackTrace();
}
return forecastResponse;
}
}
@@ -23,10 +23,8 @@
package com.github.prominence.openweathermap.api;
import com.github.prominence.openweathermap.api.constants.Unit;
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
import com.github.prominence.openweathermap.api.model.response.HourlyForecast;
import com.github.prominence.openweathermap.api.utils.JsonUtils;
import com.github.prominence.openweathermap.api.utils.JSONUtils;
import com.github.prominence.openweathermap.api.utils.RequestUtils;
import java.io.IOException;
@@ -57,13 +55,13 @@ public class HourlyForecastRequester extends BasicRequester<HourlyForecast> {
return "forecast";
}
protected HourlyForecast executeRequest(String requestSpecificParameters) throws InvalidAuthTokenException, DataNotFoundException {
protected HourlyForecast executeRequest(String requestSpecificParameters) {
HourlyForecast forecastResponse = null;
try {
InputStream requestResult = RequestUtils.executeGetRequest(buildURL(requestSpecificParameters));
forecastResponse = (HourlyForecast)JsonUtils.parseJson(requestResult, HourlyForecast.class);
forecastResponse = (HourlyForecast) JSONUtils.parseJSON(requestResult, HourlyForecast.class);
char temperatureUnit = Unit.getTemperatureUnit(unitSystem);
String windUnit = Unit.getWindUnit(unitSystem);
@@ -22,6 +22,11 @@
package com.github.prominence.openweathermap.api;
import com.github.prominence.openweathermap.api.constants.TimeFrame;
import com.github.prominence.openweathermap.api.model.Coordinates;
import java.util.Date;
public class OpenWeatherMapManager {
private String authToken;
@@ -34,7 +39,27 @@ public class OpenWeatherMapManager {
return new WeatherRequester(authToken);
}
public HourlyForecastRequester getForecastRequester() {
public HourlyForecastRequester getHourlyForecastRequester() {
return new HourlyForecastRequester(authToken);
}
public DailyForecastRequester getDailyForecastRequester() {
return new DailyForecastRequester(authToken);
}
public UltravioletIndexRequester getUltravioletIndexRequester(float latitude, float longitude) {
return new UltravioletIndexRequester(authToken, latitude, longitude);
}
public UltravioletIndexRequester getUltravioletIndexRequester(Coordinates coordinates) {
return new UltravioletIndexRequester(authToken, coordinates.getLatitude(), coordinates.getLongitude());
}
public AirPollutionRequester getAirPollutionRequester(float latitude, float longitude, Date date, TimeFrame timeFrame) {
return new AirPollutionRequester(authToken, latitude, longitude, date, timeFrame);
}
public AirPollutionRequester getAirPollutionRequester(Coordinates coordinates, Date date, TimeFrame timeFrame) {
return new AirPollutionRequester(authToken, coordinates.getLatitude(), coordinates.getLongitude(), date, timeFrame);
}
}
@@ -0,0 +1,119 @@
/*
* 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 com.github.prominence.openweathermap.api;
import com.alibaba.fastjson.TypeReference;
import com.github.prominence.openweathermap.api.model.response.UltravioletIndex;
import com.github.prominence.openweathermap.api.model.Coordinates;
import com.github.prominence.openweathermap.api.utils.JSONUtils;
import com.github.prominence.openweathermap.api.utils.RequestUtils;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.List;
public class UltravioletIndexRequester extends AuthenticationTokenBasedRequester {
private Coordinates coordinates;
UltravioletIndexRequester(String authToken, float latitude, float longitude) {
super(authToken);
this.coordinates = new Coordinates(latitude, longitude);
}
public UltravioletIndexRequester setCoordinates(Coordinates coordinates) {
this.coordinates = coordinates;
return this;
}
public UltravioletIndexRequester setCoordinates(float latitude, float longitude) {
this.coordinates = new Coordinates(latitude, longitude);
return this;
}
public UltravioletIndex getCurrentUVIndex() {
String requestParameters = String.format("lat=%f&lon=%f", coordinates.getLatitude(), coordinates.getLongitude());
return getSingleObject(requestParameters);
}
public List<UltravioletIndex> getUVIndexForecast(int amountOfDays) {
String requestParameters = String.format("lat=%f&lon=%f&cnt=%d", coordinates.getLatitude(), coordinates.getLongitude(), amountOfDays);
return getListOfObjects(requestParameters);
}
public List<UltravioletIndex> getUVIndexByPeriod(Date from, Date to) {
String requestParameters = String.format("lat=%f&lon=%f&start=%d&end=%d", coordinates.getLatitude(), coordinates.getLongitude(), from.getTime() / 1000, to.getTime() / 1000);
return getListOfObjects(requestParameters);
}
private UltravioletIndex getSingleObject(String requestParameters) {
UltravioletIndex ultravioletIndex = null;
try (InputStream response = executeRequest("uvi", requestParameters)) {
ultravioletIndex = (UltravioletIndex) JSONUtils.parseJSON(response, UltravioletIndex.class);
} catch (IOException ex) {
ex.printStackTrace();
}
return ultravioletIndex;
}
private List<UltravioletIndex> getListOfObjects(String requestParameters) {
List<UltravioletIndex> ultravioletIndex = null;
TypeReference<List<UltravioletIndex>> typeRef = new TypeReference<List<UltravioletIndex>>() {
};
try (InputStream response = executeRequest("uvi/forecast", requestParameters)) {
ultravioletIndex = (List<UltravioletIndex>) JSONUtils.parseJSON(response, typeRef);
} catch (IOException ex) {
ex.printStackTrace();
}
return ultravioletIndex;
}
private InputStream executeRequest(String requestType, String requestSpecificParameters) {
StringBuilder urlBuilder = new StringBuilder(OPEN_WEATHER_API_URL);
urlBuilder.append(requestType);
urlBuilder.append('?');
urlBuilder.append(requestSpecificParameters);
urlBuilder.append("&appid=");
urlBuilder.append(authToken);
InputStream getRequest = null;
try {
getRequest = RequestUtils.executeGetRequest(new URL(urlBuilder.toString()));
} catch (MalformedURLException e) {
e.printStackTrace();
}
return getRequest;
}
}
@@ -23,10 +23,8 @@
package com.github.prominence.openweathermap.api;
import com.github.prominence.openweathermap.api.constants.Unit;
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
import com.github.prominence.openweathermap.api.model.response.Weather;
import com.github.prominence.openweathermap.api.utils.JsonUtils;
import com.github.prominence.openweathermap.api.utils.JSONUtils;
import com.github.prominence.openweathermap.api.utils.RequestUtils;
import java.io.IOException;
@@ -57,13 +55,13 @@ public class WeatherRequester extends BasicRequester<Weather> {
return "weather";
}
protected Weather executeRequest(String requestSpecificParameters) throws InvalidAuthTokenException, DataNotFoundException {
protected Weather executeRequest(String requestSpecificParameters) {
Weather weather = null;
try {
InputStream requestResult = RequestUtils.executeGetRequest(buildURL(requestSpecificParameters));
weather = (Weather)JsonUtils.parseJson(requestResult, Weather.class);
weather = (Weather) JSONUtils.parseJSON(requestResult, Weather.class);
weather.getWind().setUnit(Unit.getWindUnit(unitSystem));
weather.getWeatherInfo().setTemperatureUnit(Unit.getTemperatureUnit(unitSystem));
@@ -18,14 +18,16 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
package com.github.prominence.openweathermap.api.constants;
public final class System {
private System() {}
public static final String OPEN_WEATHER_API_VERSION = "2.5";
public static final String OPEN_WEATHER_API_URL = "http://api.openweathermap.org/data/" + OPEN_WEATHER_API_VERSION + "/";
public enum TimeFrame {
YEAR,
MONTH,
DAY,
HOUR,
MINUTE,
SECOND
}
@@ -22,7 +22,7 @@
package com.github.prominence.openweathermap.api.exception;
public class DataNotFoundException extends Exception {
public class DataNotFoundException extends RuntimeException {
public DataNotFoundException() {
super("Data for provided parameters wasn't found. Please, check your request.");
@@ -22,10 +22,10 @@
package com.github.prominence.openweathermap.api.exception;
public class InvalidAuthTokenException extends Exception {
public class InvalidAuthTokenException extends RuntimeException {
public InvalidAuthTokenException() {
super("Check you authentication token! You can get it here: https://home.openweathermap.org/api_keys/.");
super("Check your authentication token! You can get it here: https://home.openweathermap.org/api_keys/.");
}
}
@@ -0,0 +1,58 @@
/*
* 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 com.github.prominence.openweathermap.api.model;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@EqualsAndHashCode
public class CityInfo {
// City ID
@Getter
@Setter
private long id;
// City name
@Getter
@Setter
private String name;
@JSONField(name = "coord")
@Getter
@Setter
private Coordinates coordinates;
// Country code (GB, JP etc.)
@Getter
@Setter
private String country;
@Override
public String toString() {
return "City: " + name + "(" + id + "). Coordinates: " + coordinates + '\n' + "Country: " + country;
}
}
@@ -23,39 +23,21 @@
package com.github.prominence.openweathermap.api.model;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.util.Objects;
@EqualsAndHashCode
public class Clouds {
@JSONField(name = "all")
// Cloudiness, %
@Getter
@Setter
private byte cloudiness;
public byte getCloudiness() {
return cloudiness;
}
public void setCloudiness(byte cloudiness) {
this.cloudiness = cloudiness;
}
@Override
public String toString() {
return "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);
}
}
@@ -23,55 +23,29 @@
package com.github.prominence.openweathermap.api.model;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.util.Objects;
@EqualsAndHashCode
@AllArgsConstructor
public class Coordinates {
@JSONField(name = "lat")
// City geo location, latitude
// City geo location, latitude. Valid range: [-90, 90]
@Getter
@Setter
private float latitude;
@JSONField(name = "lon")
// City geo location, longitude
// City geo location, longitude. Valid range: [-180, 180]
@Getter
@Setter
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 "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);
}
}
@@ -23,23 +23,19 @@
package com.github.prominence.openweathermap.api.model;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.util.Objects;
@EqualsAndHashCode
public class Rain {
@JSONField(name = "3h")
// Rain volume for the last 3 hours
@Getter
@Setter
private byte rainVolumeLast3Hrs;
public byte getRainVolumeLast3Hrs() {
return rainVolumeLast3Hrs;
}
public void setRainVolumeLast3Hrs(byte rainVolumeLast3Hrs) {
this.rainVolumeLast3Hrs = rainVolumeLast3Hrs;
}
public String getUnit() {
return "mm";
}
@@ -48,18 +44,4 @@ public class Rain {
public String toString() {
return "Rain(last 3 hrs): " + rainVolumeLast3Hrs + ' ' + getUnit();
}
@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);
}
}
@@ -23,23 +23,19 @@
package com.github.prominence.openweathermap.api.model;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.util.Objects;
@EqualsAndHashCode
public class Snow {
@JSONField(name = "all")
// Snow volume for the last 3 hours
@Getter
@Setter
private byte snowVolumeLast3Hrs;
public byte getSnowVolumeLast3Hrs() {
return snowVolumeLast3Hrs;
}
public void setSnowVolumeLast3Hrs(byte snowVolumeLast3Hrs) {
this.snowVolumeLast3Hrs = snowVolumeLast3Hrs;
}
public String getUnit() {
return "mm";
}
@@ -48,18 +44,4 @@ public class Snow {
public String toString() {
return "Snow(last 3 hrs): " + snowVolumeLast3Hrs + ' ' + getUnit();
}
@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);
}
}
@@ -23,61 +23,40 @@
package com.github.prominence.openweathermap.api.model;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Objects;
@EqualsAndHashCode
public class WeatherState {
@JSONField(name = "id")
// Weather condition id
@Getter
@Setter
long conditionId;
@JSONField(name = "main")
// Group of weather parameters (Rain, Snow, Extreme etc.)
@Getter
@Setter
String weatherGroup;
@JSONField(name = "description")
// Weather condition within the group
@Getter
@Setter
String description;
@JSONField(name = "icon")
// Weather icon id
@Getter
@Setter
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 {
@@ -92,21 +71,4 @@ public class WeatherState {
public String toString() {
return "Weather: " + description;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
WeatherState weatherState = (WeatherState) o;
return conditionId == weatherState.conditionId &&
Objects.equals(weatherGroup, weatherState.weatherGroup) &&
Objects.equals(description, weatherState.description) &&
Objects.equals(iconId, weatherState.iconId);
}
@Override
public int hashCode() {
return Objects.hash(conditionId, weatherGroup, description, iconId);
}
}
@@ -23,62 +23,31 @@
package com.github.prominence.openweathermap.api.model;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.util.Objects;
@EqualsAndHashCode
public class Wind {
@JSONField(name = "speed")
// Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour.
@Getter
@Setter
private float speed;
@Getter
@Setter
private String unit;
@JSONField(name = "deg")
// Wind direction, degrees (meteorological)
@Getter
@Setter
private short degrees;
public float getSpeed() {
return speed;
}
public void setSpeed(float speed) {
this.speed = speed;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public short getDegrees() {
return degrees;
}
public void setDegrees(short degrees) {
this.degrees = degrees;
}
@Override
public String toString() {
return "Wind: " + speed + ' ' + unit + ", " + 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,105 @@
/*
* 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 com.github.prominence.openweathermap.api.model.response;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@EqualsAndHashCode
public class AirPollution {
@Getter
@Setter
private String time;
@Getter
@Setter
@JSONField(name = "location")
private Coordinates coordinates;
@JSONField(name = "data")
@Getter
@Setter
private List<AirPollutionInfo> airPollutionInfo;
public Date getCalculationDate() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
try {
return format.parse(time);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
@Override
public String toString() {
return "AirPollution[Date: " + getCalculationDate() + "; Coordinates: " + coordinates + "]" + "\n" + airPollutionInfo;
}
@EqualsAndHashCode
public static class AirPollutionInfo {
@Getter
@Setter
private float precision;
@Getter
@Setter
private short pressure;
@Getter
@Setter
private float value;
@Override
public String toString() {
return "Value: " + value;
}
}
@EqualsAndHashCode
public static class Coordinates {
@Getter
@Setter
private float latitude;
@Getter
@Setter
private float longitude;
@Override
public String toString() {
return "latitude=" + latitude + ", longitude=" + longitude;
}
}
}
@@ -0,0 +1,256 @@
/*
* 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 com.github.prominence.openweathermap.api.model.response;
import com.alibaba.fastjson.annotation.JSONField;
import com.github.prominence.openweathermap.api.model.CityInfo;
import com.github.prominence.openweathermap.api.model.Coordinates;
import com.github.prominence.openweathermap.api.model.OpenWeatherResponse;
import com.github.prominence.openweathermap.api.model.WeatherState;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.time.Instant;
import java.util.Date;
import java.util.List;
@EqualsAndHashCode
public class DailyForecast implements OpenWeatherResponse {
@JSONField(name = "city")
@Getter
@Setter
private CityInfo cityInfo;
// Internal parameter
@Getter
@Setter
private String cod;
// Internal parameter
@Getter
@Setter
private double message;
// Number of lines returned by this API call
@Getter
@Setter
private byte cnt;
@JSONField(name = "list")
@Getter
@Setter
private List<Forecast> forecasts;
public String getCityName() {
return cityInfo.getName();
}
public long getCityId() {
return cityInfo.getId();
}
public String getCountry() {
return cityInfo.getCountry();
}
public Coordinates getCoordinates() {
return cityInfo.getCoordinates();
}
public short getResponseCode() {
return Short.parseShort(cod);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(cityInfo);
builder.append("\nForecasts: ");
forecasts.forEach(forecast -> {
builder.append("\n\t");
builder.append(forecast);
});
return builder.toString();
}
@EqualsAndHashCode
public static class Forecast {
@JSONField(name = "dt")
// Time of data calculation, unix, UTC
@Getter
@Setter
private long dataCalculationTime;
@JSONField(name = "temp")
@Getter
@Setter
private Temperature temperature;
@Getter
@Setter
private float pressure;
@Getter
@Setter
private byte humidity;
@JSONField(name = "weather")
@Getter
@Setter
private List<WeatherState> weatherStates;
@JSONField(name = "speed")
@Getter
@Setter
private float windSpeed;
@JSONField(name = "deg")
// Wind direction, degrees (meteorological)
@Getter
@Setter
private short windDegrees;
@Getter
@Setter
private String windUnit;
@JSONField(name = "clouds")
@Getter
@Setter
private byte cloudiness;
public String getPressureUnit() {
return "hPa";
}
public Date getDataCalculationDate() {
return Date.from(Instant.ofEpochSecond(dataCalculationTime));
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(temperature);
builder.append(", Pressure: ");
builder.append(pressure);
builder.append(' ');
builder.append(getPressureUnit());
builder.append("; Humidity: ");
builder.append(humidity);
builder.append("%; Weather: ");
if (weatherStates.size() == 1) {
builder.append(weatherStates.get(0));
} else {
builder.append(weatherStates);
}
builder.append("; Wind: ");
builder.append(windSpeed);
builder.append(' ');
builder.append(windUnit);
builder.append(", ");
builder.append(windDegrees);
builder.append(" degrees; Cloudiness: ");
builder.append(cloudiness);
builder.append('%');
return builder.toString();
}
@EqualsAndHashCode
public static class Temperature {
@JSONField(name = "day")
@Getter
@Setter
private float dayTemperature;
@JSONField(name = "min")
@Getter
@Setter
private float minTemperature;
@JSONField(name = "max")
@Getter
@Setter
private float maxTemperature;
@JSONField(name = "night")
@Getter
@Setter
private float nightTemperature;
@JSONField(name = "eve")
@Getter
@Setter
private float eveningTemperature;
@JSONField(name = "morn")
@Getter
@Setter
private float morningTemperature;
@Getter
@Setter
private char temperatureUnit;
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Temperature: [");
builder.append("Day temperature: ");
builder.append(dayTemperature);
builder.append(' ');
builder.append(getTemperatureUnit());
builder.append("; Night temperature: ");
builder.append(nightTemperature);
builder.append(' ');
builder.append(getTemperatureUnit());
builder.append("; Morning temperature: ");
builder.append(morningTemperature);
builder.append(' ');
builder.append(getTemperatureUnit());
builder.append("; Evening temperature: ");
builder.append(eveningTemperature);
builder.append(' ');
builder.append(getTemperatureUnit());
builder.append("; Minimum temperature: ");
builder.append(minTemperature);
builder.append(' ');
builder.append(getTemperatureUnit());
builder.append("; Maximum temperature: ");
builder.append(maxTemperature);
builder.append(' ');
builder.append(getTemperatureUnit());
builder.append("]");
return builder.toString();
}
}
}
}
@@ -24,82 +24,56 @@ package com.github.prominence.openweathermap.api.model.response;
import com.alibaba.fastjson.annotation.JSONField;
import com.github.prominence.openweathermap.api.model.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@EqualsAndHashCode
public class HourlyForecast implements OpenWeatherResponse {
@JSONField(name = "cod")
@Getter
@Setter
private short responseCode;
@Getter
@Setter
private double message;
// Number of lines returned by this API call
@Getter
@Setter
private short cnt;
@JSONField(name = "list")
@Getter
@Setter
private List<Forecast> forecasts;
@JSONField(name = "city")
@Getter
@Setter
private CityInfo cityInfo;
public short getResponseCode() {
return responseCode;
}
public void setResponseCode(short responseCode) {
this.responseCode = responseCode;
}
public double getMessage() {
return message;
}
public void setMessage(double message) {
this.message = message;
}
public short getCnt() {
return cnt;
}
public void setCnt(short cnt) {
this.cnt = cnt;
}
public List<Forecast> getForecasts() {
return forecasts;
}
public void setForecasts(List<Forecast> forecasts) {
this.forecasts = forecasts;
}
public CityInfo getCityInfo() {
return cityInfo;
}
public void setCityInfo(CityInfo cityInfo) {
this.cityInfo = cityInfo;
}
public String getCityName() {
return cityInfo.name;
return cityInfo.getName();
}
public long getCityId() {
return cityInfo.id;
return cityInfo.getId();
}
public String getCountry() {
return cityInfo.country;
return cityInfo.getCountry();
}
public Coordinates getCoordinates() {
return cityInfo.coordinates;
return cityInfo.getCoordinates();
}
public float getAverageTemperature() {
@@ -144,464 +118,199 @@ public class HourlyForecast implements OpenWeatherResponse {
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(cityInfo);
stringBuilder.append("\nForecasts: ");
StringBuilder builder = new StringBuilder();
builder.append(cityInfo);
builder.append("\nForecasts: ");
forecasts.forEach(forecast -> {
stringBuilder.append("\n\t");
stringBuilder.append(forecast);
builder.append("\n\t");
builder.append(forecast);
});
return stringBuilder.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
HourlyForecast that = (HourlyForecast) o;
return responseCode == that.responseCode &&
Double.compare(that.message, message) == 0 &&
cnt == that.cnt &&
Objects.equals(forecasts, that.forecasts) &&
Objects.equals(cityInfo, that.cityInfo);
}
@Override
public int hashCode() {
return Objects.hash(responseCode, message, cnt, forecasts, cityInfo);
}
public static class CityInfo {
// City ID
private long id;
// City name
private String name;
@JSONField(name = "coord")
private Coordinates coordinates;
// Country code (GB, JP etc.)
private String country;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Coordinates getCoordinates() {
return coordinates;
}
public void setCoordinates(Coordinates coordinates) {
this.coordinates = coordinates;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
@Override
public String toString() {
return "City: " + name + "(" + id + "). Coordinates: " + coordinates + '\n' + "Country: " + country;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CityInfo cityInfo = (CityInfo) o;
return id == cityInfo.id &&
Objects.equals(name, cityInfo.name) &&
Objects.equals(coordinates, cityInfo.coordinates) &&
Objects.equals(country, cityInfo.country);
}
@Override
public int hashCode() {
return Objects.hash(id, name, coordinates, country);
}
return builder.toString();
}
@EqualsAndHashCode
public static class Forecast {
@JSONField(name = "dt")
// Time of data calculation, unix, UTC
@Getter
@Setter
private long dataCalculationTime;
@JSONField(name = "main")
@Getter
@Setter
private WeatherInfo weatherInfo;
@JSONField(name = "weather")
@Getter
@Setter
private List<WeatherState> weatherStates;
@Getter
@Setter
private Clouds clouds;
@Getter
@Setter
private Wind wind;
@Getter
@Setter
private Snow snow;
@Getter
@Setter
private Rain rain;
@JSONField(name = "sys")
@Getter
@Setter
private ForecastSystemInfo systemInfo;
// Data/time of calculation, UTC
@Getter
@Setter
private String dt_txt;
public long getDataCalculationTime() {
return dataCalculationTime;
}
public void setDataCalculationTime(long dataCalculationTime) {
this.dataCalculationTime = dataCalculationTime;
}
public Date getDataCalculationDate() {
return new Date(dataCalculationTime * 1000);
}
public WeatherInfo getWeatherInfo() {
return weatherInfo;
}
public void setWeatherInfo(WeatherInfo weatherInfo) {
this.weatherInfo = weatherInfo;
}
public List<WeatherState> getWeatherStates() {
return weatherStates;
}
public void setWeatherStates(List<WeatherState> weatherStates) {
this.weatherStates = weatherStates;
}
public Clouds getClouds() {
return clouds;
}
public void setClouds(Clouds clouds) {
this.clouds = clouds;
}
public Wind getWind() {
return wind;
}
public void setWind(Wind wind) {
this.wind = wind;
}
public Snow getSnow() {
return snow;
}
public void setSnow(Snow snow) {
this.snow = snow;
}
public Rain getRain() {
return rain;
}
public void setRain(Rain rain) {
this.rain = rain;
}
public ForecastSystemInfo getSystemInfo() {
return systemInfo;
}
public void setSystemInfo(ForecastSystemInfo systemInfo) {
this.systemInfo = systemInfo;
}
public String getDt_txt() {
return dt_txt;
}
public void setDt_txt(String dt_txt) {
this.dt_txt = dt_txt;
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Time: ");
stringBuilder.append(new Date(dataCalculationTime * 1000));
stringBuilder.append(". ");
StringBuilder builder = new StringBuilder();
builder.append("Time: ");
builder.append(new Date(dataCalculationTime * 1000));
builder.append("; ");
if (weatherStates.size() == 1) {
stringBuilder.append(weatherStates.get(0));
builder.append(weatherStates.get(0));
} else {
stringBuilder.append(weatherStates);
builder.append(weatherStates);
}
stringBuilder.append(". ");
stringBuilder.append(weatherInfo);
builder.append("; ");
builder.append(weatherInfo);
if (clouds != null) {
stringBuilder.append(". ");
stringBuilder.append(clouds);
builder.append("; ");
builder.append(clouds);
}
if (wind != null) {
stringBuilder.append(". ");
stringBuilder.append(wind);
builder.append("; ");
builder.append(wind);
}
if (snow != null) {
stringBuilder.append(". ");
stringBuilder.append(snow);
builder.append("; ");
builder.append(snow);
}
if (rain != null) {
stringBuilder.append(". ");
stringBuilder.append(rain);
builder.append("; ");
builder.append(rain);
}
return stringBuilder.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Forecast that = (Forecast) o;
return dataCalculationTime == that.dataCalculationTime &&
Objects.equals(weatherInfo, that.weatherInfo) &&
Objects.equals(weatherStates, that.weatherStates) &&
Objects.equals(clouds, that.clouds) &&
Objects.equals(wind, that.wind) &&
Objects.equals(snow, that.snow) &&
Objects.equals(rain, that.rain) &&
Objects.equals(systemInfo, that.systemInfo) &&
Objects.equals(dt_txt, that.dt_txt);
}
@Override
public int hashCode() {
return Objects.hash(dataCalculationTime, weatherInfo, weatherStates, clouds, wind, snow, rain, systemInfo, dt_txt);
return builder.toString();
}
@Data
public static class ForecastSystemInfo {
private String pod;
public String getPod() {
return pod;
}
public void setPod(String pod) {
this.pod = pod;
}
@Override
public String toString() {
return "ForecastSystemInfo{" +
"pod='" + pod + '\'' +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ForecastSystemInfo that = (ForecastSystemInfo) o;
return Objects.equals(pod, that.pod);
}
@Override
public int hashCode() {
return Objects.hash(pod);
}
}
@EqualsAndHashCode
public static class WeatherInfo {
@JSONField(name = "temp")
// Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
@Getter
@Setter
private float temperature;
@JSONField(name = "temp_min")
// Minimum temperature at the moment of calculation. This is deviation from 'temp' that is possible for large cities and
// megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
@Getter
@Setter
private float minimumTemperature;
@JSONField(name = "temp_max")
// Maximum temperature at the moment of calculation. This is deviation from 'temp' that is possible for large cities and
// megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
@Getter
@Setter
private float maximumTemperature;
// Atmospheric pressure on the sea level by default, hPa
@Getter
@Setter
private float pressure;
@JSONField(name = "sea_level")
// Atmospheric pressure on the sea level, hPa
@Getter
@Setter
private float seaLevelPressure;
@JSONField(name = "grnd_level")
// Atmospheric pressure on the ground level, hPa
@Getter
@Setter
private float groundLevelPressure;
// Humidity, %
@Getter
@Setter
private byte humidity;
@JSONField(name = "temp_kf")
// Internal parameter
@Getter
@Setter
private float temperatureCoefficient;
@Getter
@Setter
private char temperatureUnit;
public float getTemperature() {
return temperature;
}
public void setTemperature(float temperature) {
this.temperature = temperature;
}
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 float getPressure() {
return pressure;
}
public void setPressure(float pressure) {
this.pressure = pressure;
}
public float getSeaLevelPressure() {
return seaLevelPressure;
}
public void setSeaLevelPressure(float seaLevelPressure) {
this.seaLevelPressure = seaLevelPressure;
}
public float getGroundLevelPressure() {
return groundLevelPressure;
}
public void setGroundLevelPressure(float groundLevelPressure) {
this.groundLevelPressure = groundLevelPressure;
}
public byte getHumidity() {
return humidity;
}
public void setHumidity(byte humidity) {
this.humidity = humidity;
}
public float getTemperatureCoefficient() {
return temperatureCoefficient;
}
public void setTemperatureCoefficient(float temperatureCoefficient) {
this.temperatureCoefficient = temperatureCoefficient;
}
public char getTemperatureUnit() {
return temperatureUnit;
}
public void setTemperatureUnit(char temperatureUnit) {
this.temperatureUnit = temperatureUnit;
}
public String getPressureUnit() {
return "hPa";
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Temperature: ");
stringBuilder.append(temperature);
stringBuilder.append(' ');
stringBuilder.append(temperatureUnit);
stringBuilder.append(". Minimum temperature: ");
stringBuilder.append(minimumTemperature);
stringBuilder.append(' ');
stringBuilder.append(temperatureUnit);
stringBuilder.append(". Maximum temperature: ");
stringBuilder.append(maximumTemperature);
stringBuilder.append(' ');
stringBuilder.append(temperatureUnit);
stringBuilder.append(". Pressure: ");
stringBuilder.append(pressure);
stringBuilder.append(' ');
stringBuilder.append(getPressureUnit());
StringBuilder builder = new StringBuilder();
builder.append("Temperature: ");
builder.append(temperature);
builder.append(' ');
builder.append(temperatureUnit);
builder.append("; Minimum temperature: ");
builder.append(minimumTemperature);
builder.append(' ');
builder.append(temperatureUnit);
builder.append("; Maximum temperature: ");
builder.append(maximumTemperature);
builder.append(' ');
builder.append(temperatureUnit);
builder.append("; Pressure: ");
builder.append(pressure);
builder.append(' ');
builder.append(getPressureUnit());
if (seaLevelPressure > 0) {
stringBuilder.append(". Sea-level pressure: ");
stringBuilder.append(seaLevelPressure);
stringBuilder.append(' ');
stringBuilder.append(getPressureUnit());
builder.append("; Sea-level pressure: ");
builder.append(seaLevelPressure);
builder.append(' ');
builder.append(getPressureUnit());
}
if (groundLevelPressure > 0) {
stringBuilder.append(". Ground-level pressure: ");
stringBuilder.append(groundLevelPressure);
stringBuilder.append(' ');
stringBuilder.append(getPressureUnit());
builder.append("; Ground-level pressure: ");
builder.append(groundLevelPressure);
builder.append(' ');
builder.append(getPressureUnit());
}
stringBuilder.append(". Humidity: ");
stringBuilder.append(humidity);
stringBuilder.append('%');
builder.append("; Humidity: ");
builder.append(humidity);
builder.append('%');
return stringBuilder.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
WeatherInfo weatherInfo = (WeatherInfo) o;
return Float.compare(weatherInfo.temperature, temperature) == 0 &&
Float.compare(weatherInfo.minimumTemperature, minimumTemperature) == 0 &&
Float.compare(weatherInfo.maximumTemperature, maximumTemperature) == 0 &&
Float.compare(weatherInfo.pressure, pressure) == 0 &&
Float.compare(weatherInfo.seaLevelPressure, seaLevelPressure) == 0 &&
Float.compare(weatherInfo.groundLevelPressure, groundLevelPressure) == 0 &&
humidity == weatherInfo.humidity &&
Float.compare(weatherInfo.temperatureCoefficient, temperatureCoefficient) == 0;
}
@Override
public int hashCode() {
return Objects.hash(temperature, minimumTemperature, maximumTemperature, pressure, seaLevelPressure, groundLevelPressure, humidity, temperatureCoefficient);
return builder.toString();
}
}
}
@@ -0,0 +1,67 @@
/*
* 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 com.github.prominence.openweathermap.api.model.response;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.time.Instant;
import java.util.Date;
@EqualsAndHashCode
public class UltravioletIndex {
@JSONField(name = "lat")
@Getter
@Setter
float latitude;
@JSONField(name = "lon")
@Getter
@Setter
float longitude;
@JSONField(name = "date_iso")
@Getter
@Setter
String dateISO;
@JSONField(name = "date")
@Getter
@Setter
int dateTimestamp;
@Getter
@Setter
float value;
public Date getCalculationDate() {
return Date.from(Instant.ofEpochSecond(dateTimestamp));
}
public String toString() {
return String.format("Date: %s, Ultraviolet value: %f", getCalculationDate(), value);
}
}
@@ -24,151 +24,76 @@ package com.github.prominence.openweathermap.api.model.response;
import com.alibaba.fastjson.annotation.JSONField;
import com.github.prominence.openweathermap.api.model.*;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@EqualsAndHashCode
public class Weather implements OpenWeatherResponse {
@JSONField(name = "id")
@Getter
@Setter
private long cityId;
@JSONField(name = "name")
@Getter
@Setter
private String cityName;
@JSONField(name = "coord")
@Getter
@Setter
private Coordinates coordinates;
@JSONField(name = "weather")
@Getter
@Setter
private List<WeatherState> weatherStates;
@Getter
@Setter
private String base;
@JSONField(name = "main")
@Getter
@Setter
private WeatherInfo weatherInfo;
@Getter
@Setter
private Wind wind;
@Getter
@Setter
private Clouds clouds;
@Getter
@Setter
private Rain rain;
@Getter
@Setter
private Snow snow;
@JSONField(name = "dt")
@Getter
@Setter
private long dataCalculationTime;
@JSONField(name = "sys")
@Getter
@Setter
private WeatherSystemInfo weatherSystemInfo;
@JSONField(name = "cod")
@Getter
@Setter
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<WeatherState> getWeatherStates() {
return weatherStates;
}
public void setWeatherStates(List<WeatherState> weatherStates) {
this.weatherStates = weatherStates;
}
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 long getDataCalculationTime() {
return dataCalculationTime;
}
public void setDataCalculationTime(long 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;
}
public String getCountry() {
return weatherSystemInfo.country;
}
@@ -211,8 +136,7 @@ public class Weather implements OpenWeatherResponse {
stringBuilder.append(cityName);
stringBuilder.append('(');
stringBuilder.append(cityId);
stringBuilder.append("). ");
stringBuilder.append("Coordinates: ");
stringBuilder.append("); Coordinates: ");
stringBuilder.append(coordinates);
stringBuilder.append('\n');
stringBuilder.append(weatherSystemInfo);
@@ -243,103 +167,56 @@ public class Weather implements OpenWeatherResponse {
return stringBuilder.toString();
}
@EqualsAndHashCode
public static class WeatherInfo {
@JSONField(name = "temp")
// Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
@Getter
@Setter
private float temperature;
@JSONField(name = "pressure")
// Atmospheric pressure (on the sea level, if there is no sea_level or grnd_level data), hPa
@Getter
@Setter
private short pressure;
@JSONField(name = "humidity")
// Humidity, %
@Getter
@Setter
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.
@Getter
@Setter
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.
@Getter
@Setter
private float maximumTemperature;
@JSONField(name = "sea_level")
// Atmospheric pressure on the sea level, hPa
@Getter
@Setter
private short seaLevelPressure;
@JSONField(name = "grnd_level")
// Atmospheric pressure on the ground level, hPa
@Getter
@Setter
private short groundLevelPressure;
@Getter
@Setter
private char temperatureUnit;
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;
}
public char getTemperatureUnit() {
return temperatureUnit;
}
public void setTemperatureUnit(char temperatureUnit) {
this.temperatureUnit = temperatureUnit;
}
public String getPressureUnit() {
return "hPa";
}
@@ -351,11 +228,11 @@ public class Weather implements OpenWeatherResponse {
stringBuilder.append(temperature);
stringBuilder.append(' ');
stringBuilder.append(temperatureUnit);
stringBuilder.append(". Minimum temparature: ");
stringBuilder.append("; Minimum temparature: ");
stringBuilder.append(minimumTemperature);
stringBuilder.append(' ');
stringBuilder.append(temperatureUnit);
stringBuilder.append(". Maximum temperature: ");
stringBuilder.append("; Maximum temperature: ");
stringBuilder.append(maximumTemperature);
stringBuilder.append(' ');
stringBuilder.append(temperatureUnit);
@@ -369,13 +246,13 @@ public class Weather implements OpenWeatherResponse {
stringBuilder.append(' ');
stringBuilder.append(getPressureUnit());
if (seaLevelPressure > 0) {
stringBuilder.append(". Sea-level pressure: ");
stringBuilder.append("; Sea-level pressure: ");
stringBuilder.append(seaLevelPressure);
stringBuilder.append(' ');
stringBuilder.append(getPressureUnit());
}
if (groundLevelPressure > 0) {
stringBuilder.append(". Ground-level pressure: ");
stringBuilder.append("; Ground-level pressure: ");
stringBuilder.append(groundLevelPressure);
stringBuilder.append(' ');
stringBuilder.append(getPressureUnit());
@@ -383,105 +260,49 @@ public class Weather implements OpenWeatherResponse {
return stringBuilder.toString();
}
@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);
}
}
public static class WeatherSystemInfo {
@JSONField(name = "type")
// Internal parameter
@Getter
@Setter
private short type;
@JSONField(name = "id")
// Internal parameter
@Getter
@Setter
private long id;
@JSONField(name = "message")
// Internal parameter
@Getter
@Setter
private double message;
@JSONField(name = "country")
// Country code (GB, JP etc.)
@Getter
@Setter
private String country;
@JSONField(name = "sunrise")
// Sunrise time, unix, UTC
@Getter
@Setter
private long sunriseTimestamp;
@JSONField(name = "sunset")
// Sunset time, unix, UTC
@Getter
@Setter
private long sunsetTimestamp;
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 long getSunriseTimestamp() {
return sunriseTimestamp;
}
public void setSunriseTimestamp(long sunriseTimestamp) {
this.sunriseTimestamp = sunriseTimestamp;
}
public Date getSunriseDate() {
return new Date(sunriseTimestamp * 1000);
}
public long getSunsetTimestamp() {
return sunsetTimestamp;
}
public void setSunsetTimestamp(long sunsetTimestamp) {
this.sunsetTimestamp = sunsetTimestamp;
}
public Date getSunsetDate() {
return new Date(sunsetTimestamp * 1000);
}
@@ -507,24 +328,5 @@ public class Weather implements OpenWeatherResponse {
return stringBuilder.toString();
}
@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(sunriseTimestamp, that.sunriseTimestamp) &&
Objects.equals(sunsetTimestamp, that.sunsetTimestamp);
}
@Override
public int hashCode() {
return Objects.hash(type, id, message, country, sunriseTimestamp, sunsetTimestamp);
}
}
}
@@ -23,17 +23,26 @@
package com.github.prominence.openweathermap.api.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public final class JsonUtils {
public final class JSONUtils {
private JsonUtils() {}
private JSONUtils() {}
public static Object parseJson(InputStream inputStream, Class clazz) throws IOException {
public static Object parseJSON(InputStream inputStream, Class clazz) throws IOException {
return JSON.parseObject(getStringFromStream(inputStream), clazz);
}
public static Object parseJSON(InputStream inputStream, TypeReference typeReference) throws IOException {
return JSON.parseObject(getStringFromStream(inputStream), typeReference);
}
private static String getStringFromStream(InputStream inputStream) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder result = new StringBuilder();
@@ -44,6 +53,6 @@ public final class JsonUtils {
reader.close();
return JSON.parseObject(result.toString(), clazz);
return result.toString();
}
}
@@ -32,9 +32,10 @@ import java.net.URL;
public final class RequestUtils {
private RequestUtils() {}
private RequestUtils() {
}
public static InputStream executeGetRequest(URL requestUrl) throws InvalidAuthTokenException, DataNotFoundException {
public static InputStream executeGetRequest(URL requestUrl) {
InputStream resultStream = null;
try {
@@ -48,9 +49,10 @@ public final class RequestUtils {
case HttpURLConnection.HTTP_UNAUTHORIZED:
throw new InvalidAuthTokenException();
case HttpURLConnection.HTTP_NOT_FOUND:
case HttpURLConnection.HTTP_BAD_REQUEST:
throw new DataNotFoundException();
}
} catch (IOException | ClassCastException ex) {
} catch (IOException ex) {
ex.printStackTrace();
}
@@ -0,0 +1,82 @@
/*
* 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 com.github.prominence.openweathermap.api.utils;
import com.github.prominence.openweathermap.api.constants.TimeFrame;
import java.text.SimpleDateFormat;
import java.util.Date;
public final class TimeFrameUtils {
private TimeFrameUtils() {
}
/*
2016-01-02T15:04:05Z
searches between 2016-01-02T15:04:05Z and 2016-01-02T15:04:05.9999Z
2016-01-02T15:04Z
searches between 2016-01-02T15:04:00Z and 2016-01-02T15:04:59.9999Z
2016-01-02T15Z
searches between 2016-01-02T15:00:00Z and 2016-01-02T15:59:59.9999Z
2016-01-02Z
searches between 2016-01-02T00:00:00Z and 2016-01-02T23:59:59.9999Z
2016-01Z
searches between 2016-01-01T00:00:00Z and 2016-12-31T23:59:59.9999Z
2016Z
searches between 2016-01-01T00:00:00Z and 2016-12-31T23:59:99.9999Z
*/
public static String formatDate(Date date, TimeFrame timeFrame) {
SimpleDateFormat formatter;
switch (timeFrame) {
case YEAR:
formatter = new SimpleDateFormat("yyyy'Z'");
break;
case MONTH:
formatter = new SimpleDateFormat("yyyy-MM'Z'");
break;
case DAY:
formatter = new SimpleDateFormat("yyyy-MM-dd'Z'");
break;
case HOUR:
formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH'Z'");
break;
case MINUTE:
formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
break;
case SECOND:
formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
break;
default:
formatter = new SimpleDateFormat("yyyy-MM'Z'");
}
return formatter.format(date);
}
}
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2019 Alexey Zinchenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api.test;
import com.github.prominence.openweathermap.api.AirPollutionRequester;
import com.github.prominence.openweathermap.api.constants.TimeFrame;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.Date;
public class AirPollutionRequestedIntegrationTest extends ApiTest {
private static AirPollutionRequester airPollutionRequester;
@BeforeClass
public static void setup() {
airPollutionRequester = getManager().getAirPollutionRequester(0f, 10f, new Date(116, 11, 25), TimeFrame.DAY);
}
@Test
public void whenRequestAirPollutionState_thenReturnNotNull() {
assert airPollutionRequester.retrieve() != null;
}
@Test(expected = IllegalArgumentException.class)
public void whenRequestAirPollutionStateWithoutAnyParam_thenThrowAnException() {
AirPollutionRequester requester = getManager().getAirPollutionRequester(0f, 10f, null, TimeFrame.DAY);
requester.retrieve();
}
}
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2019 Alexey Zinchenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api.test;
import com.github.prominence.openweathermap.api.OpenWeatherMapManager;
import org.junit.BeforeClass;
public class ApiTest {
private static OpenWeatherMapManager manager;
@BeforeClass
public static void retrieveApiKey() {
String apiKey = System.getenv("OPENWEATHER_API_KEY");
manager = new OpenWeatherMapManager(apiKey);
}
protected static OpenWeatherMapManager getManager() {
return manager;
}
}
@@ -0,0 +1,101 @@
/*
* Copyright (c) 2019 Alexey Zinchenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api.test;
import com.github.prominence.openweathermap.api.HourlyForecastRequester;
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
import com.github.prominence.openweathermap.api.model.Coordinates;
import org.junit.BeforeClass;
import org.junit.Test;
public class HourlyForecastRequesterIntegrationTest extends ApiTest {
private static HourlyForecastRequester hourlyForecastRequester;
@BeforeClass
public static void setup() {
hourlyForecastRequester = getManager().getHourlyForecastRequester();
}
@Test
public void whenRequestForecastForMinskByCity() {
assert hourlyForecastRequester.getByCityName("Minsk") != null;
}
@Test(expected = DataNotFoundException.class)
public void whenRequestForecastByWrongCity_thenThrowAnException() {
hourlyForecastRequester.getByCityId("IncorrectCity");
}
@Test
public void whenRequestForecastForMinskById_thenReturnNotNull() {
assert hourlyForecastRequester.getByCityId("625144") != null;
}
@Test(expected = DataNotFoundException.class)
public void whenRequestForecastByWrongId_thenThrowAnException() {
hourlyForecastRequester.getByCityId("IncorrectId");
}
@Test
public void whenRequestForecastByCoordinates_thenReturnNotNull() {
// given
float latitude = 53.9f;
float longitude = 27.56667f;
Coordinates coordinates = new Coordinates(latitude, longitude);
// expected
assert hourlyForecastRequester.getByCoordinates(coordinates) != null;
assert hourlyForecastRequester.getByCoordinates(latitude, longitude) != null;
}
@Test(expected = NullPointerException.class) // not good, will be reimplemented in further versions
public void whenRequestByNullCoordinates_thenThrowAnException() {
hourlyForecastRequester.getByCoordinates(null);
}
@Test(expected = DataNotFoundException.class)
public void whenRequestForecastByWrongCoordinates_thenThrowAnException() {
hourlyForecastRequester.getByCoordinates(91f, 180f);
}
@Test
public void whenRequestForecastByMaxCoordinates_thenReturnNotNull() {
assert hourlyForecastRequester.getByCoordinates(90f, 180f) != null;
}
@Test
public void whenRequestForecastByMinCoordinates_thenReturnNotNull() {
assert hourlyForecastRequester.getByCoordinates(-90f, -180f) != null;
}
@Test
public void whenRequestForecastByZipCode_thenReturnNotNull() {
assert hourlyForecastRequester.getByZIPCode("220015", "BY") != null;
}
@Test(expected = DataNotFoundException.class)
public void whenRequestForecastByWrongZipCode_thenThrowAnException() {
hourlyForecastRequester.getByZIPCode("wrongZipCode", "BY");
}
}
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2019 Alexey Zinchenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api.test;
import com.github.prominence.openweathermap.api.UltravioletIndexRequester;
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.Date;
public class UltravioletIndexRequestedIntegrationTest extends ApiTest {
private static UltravioletIndexRequester minskUltravioletIndexRequester;
@BeforeClass
public static void setup() {
minskUltravioletIndexRequester = getManager().getUltravioletIndexRequester(53.9f, 27.56667f);
}
@Test
public void whenRequestUVI_thenReturnNotNull() {
assert minskUltravioletIndexRequester.getCurrentUVIndex() != null;
}
@Test
public void whenRequestUVIForecastFor5Days_thenReturnNotNull() {
assert minskUltravioletIndexRequester.getUVIndexForecast(5) != null;
}
@Test(expected = DataNotFoundException.class)
public void whenRequestUVIForecastForWrongAmountOfDays_thenThrowAnException() {
minskUltravioletIndexRequester.getUVIndexForecast(-2);
}
@Test(expected = DataNotFoundException.class)
public void whenRequestUVIForecastForLargeAmountOfDays_thenThrowAnException() {
assert minskUltravioletIndexRequester.getUVIndexForecast(10000) != null;
}
@Test // check it later
public void whenRequestUVIForPeriod_thenReturnNotNull() {
assert minskUltravioletIndexRequester.getUVIndexByPeriod(new Date(), new Date()) != null;
}
@Test(expected = NullPointerException.class) // not good, will be reimplemented in further versions
public void whenRequestUVIForNullPeriod_thenThrowAnException() {
minskUltravioletIndexRequester.getUVIndexByPeriod(null, null);
}
@Test(expected = NullPointerException.class) // not good, will be reimplemented in further versions
public void whenRequestUVIForNullCoordinates_thenThrowAnException() {
UltravioletIndexRequester requester = getManager().getUltravioletIndexRequester(null);
requester.getCurrentUVIndex();
}
}
@@ -0,0 +1,101 @@
/*
* Copyright (c) 2019 Alexey Zinchenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.prominence.openweathermap.api.test;
import com.github.prominence.openweathermap.api.WeatherRequester;
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
import com.github.prominence.openweathermap.api.model.Coordinates;
import org.junit.BeforeClass;
import org.junit.Test;
public class WeatherRequestIntegrationTest extends ApiTest {
private static WeatherRequester weatherRequester;
@BeforeClass
public static void setup() {
weatherRequester = getManager().getWeatherRequester();
}
@Test
public void whenRequestWeatherForMinskByName_thenReturnNotNull() {
assert weatherRequester.getByCityName("Minsk") != null;
}
@Test(expected = DataNotFoundException.class)
public void whenRequestWeatherByWrongCity_thenThrowAnException() {
weatherRequester.getByCityId("IncorrectCity");
}
@Test
public void whenRequestWeatherForMinskById_thenReturnNotNull() {
assert weatherRequester.getByCityId("625144") != null;
}
@Test(expected = DataNotFoundException.class)
public void whenRequestWeatherByWrongId_thenThrowAnException() {
weatherRequester.getByCityId("IncorrectId");
}
@Test
public void whenRequestWeatherByCoordinates_thenReturnNotNull() {
// given
float latitude = 53.9f;
float longitude = 27.56667f;
Coordinates coordinates = new Coordinates(latitude, longitude);
// expected
assert weatherRequester.getByCoordinates(coordinates) != null;
assert weatherRequester.getByCoordinates(latitude, longitude) != null;
}
@Test(expected = NullPointerException.class) // not good, will be reimplemented in further versions
public void whenRequestByNullCoordinates_thenThrowAnException() {
weatherRequester.getByCoordinates(null);
}
@Test(expected = DataNotFoundException.class)
public void whenRequestWeatherByWrongCoordinates_thenThrowAnException() {
weatherRequester.getByCoordinates(91f, 180f);
}
@Test
public void whenRequestWeatherByMaxCoordinates_thenReturnNotNull() {
assert weatherRequester.getByCoordinates(90f, 180f) != null;
}
@Test
public void whenRequestWeatherByMinCoordinates_thenReturnNotNull() {
assert weatherRequester.getByCoordinates(-90f, -180f) != null;
}
@Test
public void whenRequestWeatherByZipCode_thenReturnNotNull() {
assert weatherRequester.getByZIPCode("220015", "BY") != null;
}
@Test(expected = DataNotFoundException.class)
public void whenRequestWeatherByWrongZipCode_thenThrowAnException() {
weatherRequester.getByZIPCode("wrongZipCode", "BY");
}
}