mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-03 11:16:44 +03:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 44da350e3c | |||
| 39ee5aa38c | |||
| c6bbf7be90 | |||
| 340383afc8 | |||
| 6ffa524ce7 | |||
| 87fb040169 |
@@ -4,11 +4,12 @@ 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:
|
||||
|
||||
@@ -16,18 +17,20 @@ Java API for OpenWeatherMap services.
|
||||
<dependency>
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>1.0</version>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
compile('com.github.prominence:openweathermap-api:1.0')
|
||||
compile('com.github.prominence:openweathermap-api:1.2')
|
||||
```
|
||||
|
||||
### 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
|
||||
|
||||
@@ -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*)
|
||||
@@ -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*)
|
||||
+2
-2
@@ -11,14 +11,14 @@
|
||||
<dependency>
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
compile('com.github.prominence:openweathermap-api:1.0-SNAPSHOT')
|
||||
compile('com.github.prominence:openweathermap-api:1.1-SNAPSHOT')
|
||||
```
|
||||
|
||||
### How to use:
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>1.1</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>
|
||||
@@ -143,6 +143,12 @@
|
||||
<version>1.18.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -24,13 +24,11 @@
|
||||
package com.github.prominence.openweathermap.api;
|
||||
|
||||
import com.github.prominence.openweathermap.api.constants.TimeFrame;
|
||||
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 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 com.github.prominence.openweathermap.api.utils.TimeFrameUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -44,8 +42,11 @@ public class AirPollutionRequester extends AuthenticationTokenBasedRequester {
|
||||
private TimeFrame timeFrame;
|
||||
private Date date;
|
||||
|
||||
AirPollutionRequester(String authToken) {
|
||||
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) {
|
||||
@@ -68,15 +69,16 @@ public class AirPollutionRequester extends AuthenticationTokenBasedRequester {
|
||||
return this;
|
||||
}
|
||||
|
||||
public AirPollution retrieve() throws InvalidAuthTokenException, DataNotFoundException {
|
||||
public AirPollution retrieve() {
|
||||
if (coordinates == null || timeFrame == null || date == null) {
|
||||
throw new IllegalArgumentException("You must execute 'setCoordinates', 'setTimeFrame' and 'setDate' and least once.");
|
||||
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) {
|
||||
@@ -86,13 +88,20 @@ public class AirPollutionRequester extends AuthenticationTokenBasedRequester {
|
||||
return airPollution;
|
||||
}
|
||||
|
||||
private InputStream executeRequest(String requestType, String requestSpecificParameters) throws MalformedURLException, InvalidAuthTokenException, DataNotFoundException {
|
||||
private InputStream executeRequest(String requestType, String requestSpecificParameters) {
|
||||
|
||||
String url = OPEN_WEATHER_BASE_URL + requestType +
|
||||
requestSpecificParameters +
|
||||
"?appid=" +
|
||||
authToken;
|
||||
return RequestUtils.executeGetRequest(new URL(url));
|
||||
InputStream getRequest = null;
|
||||
try {
|
||||
getRequest = RequestUtils.executeGetRequest(new URL(url));
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return getRequest;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
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.Coordinates;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
@@ -41,27 +39,27 @@ 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(OPEN_WEATHER_API_URL);
|
||||
urlBuilder.append(getRequestType());
|
||||
@@ -96,7 +94,14 @@ abstract class BasicRequester<T> extends AuthenticationTokenBasedRequester {
|
||||
});
|
||||
}
|
||||
|
||||
return new URL(urlBuilder.toString());
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL(urlBuilder.toString());
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
protected Map<String, String> getAdditionalParameters() {
|
||||
@@ -104,6 +109,7 @@ abstract class BasicRequester<T> extends AuthenticationTokenBasedRequester {
|
||||
}
|
||||
|
||||
protected abstract String getRequestType();
|
||||
protected abstract T executeRequest(String requestSpecificParameters) throws InvalidAuthTokenException, DataNotFoundException;
|
||||
|
||||
protected abstract T executeRequest(String requestSpecificParameters);
|
||||
|
||||
}
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
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.DailyForecast;
|
||||
import com.github.prominence.openweathermap.api.utils.JSONUtils;
|
||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||
@@ -64,12 +62,12 @@ public class DailyForecastRequester extends BasicRequester<DailyForecast> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DailyForecast executeRequest(String requestSpecificParameters) throws InvalidAuthTokenException, DataNotFoundException {
|
||||
protected DailyForecast executeRequest(String requestSpecificParameters) {
|
||||
DailyForecast forecastResponse = null;
|
||||
|
||||
try {
|
||||
InputStream requestResult = RequestUtils.executeGetRequest(buildURL(requestSpecificParameters));
|
||||
forecastResponse = (DailyForecast)JSONUtils.parseJSON(requestResult, DailyForecast.class);
|
||||
forecastResponse = (DailyForecast) JSONUtils.parseJSON(requestResult, DailyForecast.class);
|
||||
|
||||
char temperatureUnit = Unit.getTemperatureUnit(unitSystem);
|
||||
String windUnit = Unit.getWindUnit(unitSystem);
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
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.RequestUtils;
|
||||
@@ -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;
|
||||
@@ -42,11 +47,19 @@ public class OpenWeatherMapManager {
|
||||
return new DailyForecastRequester(authToken);
|
||||
}
|
||||
|
||||
public UltravioletIndexRequester getUltravioletIndexRequester() {
|
||||
return new UltravioletIndexRequester(authToken);
|
||||
public UltravioletIndexRequester getUltravioletIndexRequester(float latitude, float longitude) {
|
||||
return new UltravioletIndexRequester(authToken, latitude, longitude);
|
||||
}
|
||||
|
||||
public AirPollutionRequester getAirPollutionRequester() {
|
||||
return new AirPollutionRequester(authToken);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
+20
-13
@@ -23,10 +23,8 @@
|
||||
package com.github.prominence.openweathermap.api;
|
||||
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
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 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;
|
||||
|
||||
@@ -41,8 +39,9 @@ public class UltravioletIndexRequester extends AuthenticationTokenBasedRequester
|
||||
|
||||
private Coordinates coordinates;
|
||||
|
||||
UltravioletIndexRequester(String authToken) {
|
||||
UltravioletIndexRequester(String authToken, float latitude, float longitude) {
|
||||
super(authToken);
|
||||
this.coordinates = new Coordinates(latitude, longitude);
|
||||
}
|
||||
|
||||
public UltravioletIndexRequester setCoordinates(Coordinates coordinates) {
|
||||
@@ -55,22 +54,22 @@ public class UltravioletIndexRequester extends AuthenticationTokenBasedRequester
|
||||
return this;
|
||||
}
|
||||
|
||||
public UltravioletIndex getCurrentUVIndex() throws InvalidAuthTokenException, DataNotFoundException {
|
||||
public UltravioletIndex getCurrentUVIndex() {
|
||||
String requestParameters = String.format("lat=%f&lon=%f", coordinates.getLatitude(), coordinates.getLongitude());
|
||||
return getSingleObject(requestParameters);
|
||||
}
|
||||
|
||||
public List<UltravioletIndex> getUVIndexForecast(int amountOfDays) throws InvalidAuthTokenException, DataNotFoundException {
|
||||
public List<UltravioletIndex> getUVIndexForecast(int amountOfDays) {
|
||||
String requestParameters = String.format("lat=%f&lon=%f&cnt=%d", coordinates.getLatitude(), coordinates.getLongitude(), amountOfDays);
|
||||
return getListOfObjects(requestParameters);
|
||||
return getListOfObjects(requestParameters);
|
||||
}
|
||||
|
||||
public List<UltravioletIndex> getUVIndexByPeriod(Date from, Date to) throws InvalidAuthTokenException, DataNotFoundException {
|
||||
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) throws InvalidAuthTokenException, DataNotFoundException {
|
||||
private UltravioletIndex getSingleObject(String requestParameters) {
|
||||
UltravioletIndex ultravioletIndex = null;
|
||||
|
||||
try (InputStream response = executeRequest("uvi", requestParameters)) {
|
||||
@@ -82,10 +81,11 @@ public class UltravioletIndexRequester extends AuthenticationTokenBasedRequester
|
||||
return ultravioletIndex;
|
||||
}
|
||||
|
||||
private List<UltravioletIndex> getListOfObjects(String requestParameters) throws InvalidAuthTokenException, DataNotFoundException {
|
||||
private List<UltravioletIndex> getListOfObjects(String requestParameters) {
|
||||
List<UltravioletIndex> ultravioletIndex = null;
|
||||
|
||||
TypeReference<List<UltravioletIndex>> typeRef = new TypeReference<List<UltravioletIndex>>() {};
|
||||
TypeReference<List<UltravioletIndex>> typeRef = new TypeReference<List<UltravioletIndex>>() {
|
||||
};
|
||||
|
||||
try (InputStream response = executeRequest("uvi/forecast", requestParameters)) {
|
||||
ultravioletIndex = (List<UltravioletIndex>) JSONUtils.parseJSON(response, typeRef);
|
||||
@@ -96,7 +96,7 @@ public class UltravioletIndexRequester extends AuthenticationTokenBasedRequester
|
||||
return ultravioletIndex;
|
||||
}
|
||||
|
||||
private InputStream executeRequest(String requestType, String requestSpecificParameters) throws MalformedURLException, InvalidAuthTokenException, DataNotFoundException {
|
||||
private InputStream executeRequest(String requestType, String requestSpecificParameters) {
|
||||
|
||||
StringBuilder urlBuilder = new StringBuilder(OPEN_WEATHER_API_URL);
|
||||
urlBuilder.append(requestType);
|
||||
@@ -106,7 +106,14 @@ public class UltravioletIndexRequester extends AuthenticationTokenBasedRequester
|
||||
urlBuilder.append("&appid=");
|
||||
urlBuilder.append(authToken);
|
||||
|
||||
return RequestUtils.executeGetRequest(new URL(urlBuilder.toString()));
|
||||
InputStream getRequest = null;
|
||||
try {
|
||||
getRequest = RequestUtils.executeGetRequest(new URL(urlBuilder.toString()));
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return getRequest;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
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.RequestUtils;
|
||||
@@ -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));
|
||||
|
||||
+1
-1
@@ -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.");
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
|
||||
package com.github.prominence.openweathermap.api.exception;
|
||||
|
||||
public class InvalidAuthTokenException extends Exception {
|
||||
public class InvalidAuthTokenException extends RuntimeException {
|
||||
|
||||
public InvalidAuthTokenException() {
|
||||
super("Check your authentication token! You can get it here: https://home.openweathermap.org/api_keys/.");
|
||||
|
||||
@@ -33,13 +33,13 @@ import lombok.Setter;
|
||||
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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
+51
@@ -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;
|
||||
}
|
||||
}
|
||||
+101
@@ -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");
|
||||
}
|
||||
}
|
||||
+76
@@ -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();
|
||||
}
|
||||
}
|
||||
+101
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user