|
1 | 1 | ### Implemented features: |
2 | 2 | * Current weather data |
| 3 | +* 5 day / 3-hour forecast |
| 4 | + |
3 | 5 | ### Maven coordinates: |
4 | 6 |
|
5 | 7 | ```xml |
6 | 8 | <dependency> |
7 | 9 | <groupId>com.github.prominence</groupId> |
8 | 10 | <artifactId>openweathermap-api</artifactId> |
9 | | - <version>2.0-SNAPSHOT</version> |
| 11 | + <version>2.0.0-SNAPSHOT</version> |
10 | 12 | </dependency> |
11 | 13 | ``` |
12 | 14 |
|
13 | 15 | ### Gradle coordinates: |
14 | 16 |
|
15 | 17 | ```groovy |
16 | | -compile('com.github.prominence:openweathermap-api:2.0-SNAPSHOT') |
| 18 | +compile('com.github.prominence:openweathermap-api:2.0.0-SNAPSHOT') |
17 | 19 | ``` |
18 | 20 |
|
19 | 21 | ### How to use: |
20 | 22 |
|
21 | | -Firstly, you need to create the instance of `OpenWeatherMapManager` class: |
| 23 | +Firstly, you need to create the instance of `OpenWeatherMapClient` class: |
22 | 24 | ```java |
23 | 25 | OpenWeatherMapClient openWeatherClient = new OpenWeatherMapClient(API_TOKEN); |
24 | 26 | ``` |
25 | 27 | where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`. |
26 | 28 |
|
| 29 | +Currently, available APIs are: |
| 30 | +* `currentWeather()` |
| 31 | +* `forecast5Day3HourStep()` |
| 32 | + |
| 33 | +Default(more or less) customization points: |
| 34 | +```java |
| 35 | +... |
| 36 | +// response language |
| 37 | +.language(Language.RUSSIAN) |
| 38 | +... |
| 39 | +// response units of measure |
| 40 | +.unitSystem(UnitSystem.IMPERIAL) |
| 41 | +... |
| 42 | +``` |
| 43 | + |
| 44 | +Available output forms: |
| 45 | +* `asJava()` |
| 46 | +* `asJSON()` |
| 47 | + |
| 48 | +Additional output forms, available for several APIs: |
| 49 | +* `asXML()` |
| 50 | +* `asHTML()` |
| 51 | + |
| 52 | +_All response forms can be in **sync** and **async** variants._ |
| 53 | + |
27 | 54 | #### Current weather data |
28 | | -Current weather request chain structure: |
| 55 | +Examples: |
29 | 56 | ```java |
30 | | -openWeatherClient |
31 | | - .currentWeather() |
32 | | - .<single|multiple location(s)>() |
33 | | - .<location definition> |
34 | | - .<customize unitSystem/language/accuracy (1)> |
35 | | - ... |
36 | | - .<customize unitSystem/language/accuracy (N)> |
37 | | - .<request/requestAsync>() |
38 | | - .as(Java|JSON|XML|HTML)(); |
39 | | -``` |
40 | | - |
41 | | -Available methods for location selection for **single** result request: |
42 | | -* `byCityName(String cityName)` |
43 | | -* `byCityName(String cityName, String countryCode)` |
44 | | -* `byCityId(long cityId)` |
45 | | -* `byCoordinate(Coordinate coordinate)` |
46 | | -* `byZipCodeAndCountry(String zipCode, String countryCode)` |
47 | | - |
48 | | -Available methods for location selection for **multiple** result request: |
49 | | -* `byRectangle(CoordinateRectangle rectangle, int zoom)` |
50 | | -* `byRectangle(CoordinateRectangle rectangle, int zoom, boolean useServerClustering)` |
51 | | -* `byCitiesInCycle(Coordinate point, int citiesCount)` |
52 | | -* `byCitiesInCycle(Coordinate point, int citiesCount, boolean useServerClustering)` |
53 | | - |
54 | | -Single location request examples: |
| 57 | +final String weatherJson = openWeatherClient |
| 58 | + .currentWeather() |
| 59 | + .single() |
| 60 | + .byCityName("Minsk") |
| 61 | + .language(Language.RUSSIAN) |
| 62 | + .unitSystem(UnitSystem.IMPERIAL) |
| 63 | + .retrieve() |
| 64 | + .asJSON(); |
| 65 | +``` |
| 66 | + |
55 | 67 | ```java |
56 | 68 | final Weather weather = openWeatherClient |
57 | | - .currentWeather() |
58 | | - .single() |
59 | | - .byCoordinate(new Coordinate(5, 5)) |
60 | | - .accuracy(Accuracy.ACCURATE) |
61 | | - .language(Language.ROMANIAN) |
62 | | - .unitSystem(UnitSystem.METRIC) |
63 | | - .retrieve() |
64 | | - .asJava(); |
| 69 | + .currentWeather() |
| 70 | + .single() |
| 71 | + .byCityName("Minsk") |
| 72 | + .language(Language.RUSSIAN) |
| 73 | + .unitSystem(UnitSystem.METRIC) |
| 74 | + .retrieve() |
| 75 | + .asJava(); |
| 76 | +``` |
| 77 | + |
| 78 | +```java |
| 79 | +final List<Weather> weatherList = openWeatherClient |
| 80 | + .currentWeather() |
| 81 | + .multiple() |
| 82 | + .byCitiesInCycle(Coordinate.withValues(55.5, 37.5)) |
| 83 | + .language(Language.GERMAN) |
| 84 | + .unitSystem(UnitSystem.IMPERIAL) |
| 85 | + .retrieve() |
| 86 | + .asJava(); |
| 87 | +``` |
65 | 88 |
|
| 89 | +```java |
66 | 90 | final CompletableFuture<String> weatherXmlFuture = openWeatherClient |
67 | | - .currentWeather() |
68 | | - .single() |
69 | | - .byZipCodeAndCountry("220015", "by") |
70 | | - .language(Language.RUSSIAN) |
71 | | - .unitSystem(UnitSystem.METRIC) |
72 | | - .retrieveAsync() |
73 | | - .asXML(); |
| 91 | + .currentWeather() |
| 92 | + .single() |
| 93 | + .byZipCodeAndCountry("220015", "by") |
| 94 | + .language(Language.RUSSIAN) |
| 95 | + .unitSystem(UnitSystem.METRIC) |
| 96 | + .retrieveAsync() |
| 97 | + .asXML(); |
| 98 | +``` |
| 99 | + |
| 100 | +You are able to set preferable options(via chain methods) and execute appropriate request. |
| 101 | + |
| 102 | +`com.github.prominence.openweathermap.api.model.weather.Weather`'s useful public methods(setters are not listed): |
| 103 | + |
| 104 | +| Method | Description | |
| 105 | +|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 106 | +| `getState()` | Returns short weather description. Example: `Clear`. | |
| 107 | +| `getDescription()` | Returns weather description. Example: `clear sky`. | |
| 108 | +| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. | |
| 109 | +| `getCalculatedOn()` | Returns `LocalDateTime` object with data calculation time. | |
| 110 | +| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. | |
| 111 | +| `getAtmosphericPressure()`| Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. | |
| 112 | +| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. | |
| 113 | +| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees`, `gust` and `unit`. | |
| 114 | +| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last one hour and/or the last 3 hours. Can be absent in case of no data. | |
| 115 | +| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last one hour and/or the last 3 hours. Can be absent in case of no data. | |
| 116 | +| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. | |
| 117 | +| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset` and `coordinate`. | |
| 118 | +| `toString()` | Returns informative string for the whole available weather information. | |
| 119 | + |
| 120 | +`toString()` output example: |
| 121 | +``` |
| 122 | +Location: Minsk(BY), Weather: clear sky, -4.22 ℃, 1020.0 hPa, Clouds: 0% |
| 123 | +``` |
| 124 | + |
| 125 | +#### 5 day / 3-hour forecast |
| 126 | +Examples: |
| 127 | +```java |
| 128 | +final Forecast forecast = openWeatherClient |
| 129 | + .forecast5Day3HourStep() |
| 130 | + .byCityName("Minsk") |
| 131 | + .language(Language.ENGLISH) |
| 132 | + .unitSystem(UnitSystem.METRIC) |
| 133 | + .count(15) |
| 134 | + .retrieve() |
| 135 | + .asJava(); |
74 | 136 | ``` |
75 | 137 |
|
76 | | -Multiple locations request examples: |
77 | 138 | ```java |
78 | | -final String weatherListJson = openWeatherClient |
79 | | - .currentWeather() |
80 | | - .multiple() |
81 | | - .byRectangle(new CoordinateRectangle(12, 32, 15, 37), 10, true) |
82 | | - .accuracy(Accuracy.ACCURATE) |
83 | | - .language(Language.ROMANIAN) |
84 | | - .unitSystem(UnitSystem.METRIC) |
85 | | - .retrieve() |
86 | | - .asJSON(); |
87 | | - |
88 | | -final CompletableFuture<List<Weather>> weatherListFuture = openWeatherClient |
89 | | - .currentWeather() |
90 | | - .multiple() |
91 | | - .byCitiesInCycle(new Coordinate(55.5, 37.5), 10, true) |
92 | | - .unitSystem(UnitSystem.IMPERIAL) |
93 | | - .retrieveAsync() |
94 | | - .asJava(); |
95 | | -``` |
96 | | - |
97 | | -`Weather`'s useful public methods(setters are not listed): |
98 | | - |
99 | | -| Method | Description | |
100 | | -|---------------------------|-------------------------------------------------------------------------------------------------------------------------------------| |
101 | | -| `getWeatherState()` | Returns weather identifier. Example: `Clouds`, `Clear`. | |
102 | | -| `getWeatherDescription()` | Returns weather description. Example: `clear sky`. | |
103 | | -| `getWeatherIconUrl()` | Returns weather icon url. | |
104 | | -| `getRequestedOn()` | Returns `LocalDateTime` instance which represents date when request was made. | |
105 | | -| `getTemperature()` | Returns `Temperature` instance with temperature and max/min values. | |
106 | | -| `getPressure()` | Returns `Pressure` instance that contains information about atmosphericPressure and(not always) atmosphericPressure on ground/sea level. | |
107 | | -| `getHumidity()` | Returns `Humidity` instance that contains information about humidity. | |
108 | | -| `getWind()` | Returns `Wind` instance that contains *humidity* percentage information. | |
109 | | -| `getRain()` | Returns `Rain` instance that contains information about rain level for the last 1 and 3 hours. | |
110 | | -| `getSnow()` | Returns `Snow` instance that contains information about snow level for the last 1 and 3 hours. | |
111 | | -| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. | |
112 | | -| `getLocation()` | Returns `Location` instance that contains location information: coordinate, name and etc. | |
| 139 | +final String forecastJson = getClient() |
| 140 | + .forecast5Day3HourStep() |
| 141 | + .byCityName("New York", "NY", "US") |
| 142 | + .language(Language.SPANISH) |
| 143 | + .unitSystem(UnitSystem.IMPERIAL) |
| 144 | + .count(15) |
| 145 | + .retrieve() |
| 146 | + .asJSON(); |
| 147 | +``` |
| 148 | + |
| 149 | +```java |
| 150 | +CompletableFuture<String> forecastFuture = getClient() |
| 151 | + .forecast5Day3HourStep() |
| 152 | + .byCityId(350001514) |
| 153 | + .language(Language.ENGLISH) |
| 154 | + .unitSystem(UnitSystem.METRIC) |
| 155 | + .count(15) |
| 156 | + .retrieveAsync() |
| 157 | + .asXML(); |
| 158 | +``` |
| 159 | + |
| 160 | +```java |
| 161 | +final String forecastXml = getClient() |
| 162 | + .forecast5Day3HourStep() |
| 163 | + .byZipCodeInUSA("10005") |
| 164 | + .language(Language.ENGLISH) |
| 165 | + .unitSystem(UnitSystem.METRIC) |
| 166 | + .retrieve() |
| 167 | + .asXML(); |
| 168 | +``` |
| 169 | + |
| 170 | +You are able to set preferable options(via chain methods) and execute appropriate request. |
| 171 | + |
| 172 | +`com.github.prominence.openweathermap.api.request.forecast.free.Forecast`'s useful public methods(setters are not listed): |
| 173 | + |
| 174 | +| Method | Description | |
| 175 | +|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 176 | +| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset`, `coordinate` and `population`. | |
| 177 | +| `getWeatherForecasts()` | Returns list of `WeatherForecast` objects with forecast information. | |
| 178 | +| `toString()` | Returns informative string for the whole available forecast information. | |
113 | 179 |
|
114 | 180 | `toString()` output example: |
115 | 181 | ``` |
116 | | -Location: Minsk(BY), Weather: слегка облачно, 20.0 ℃, 1019.0 hPa, Clouds: 40% |
| 182 | +A forecast for Minsk with 15 timestamps. |
117 | 183 | ``` |
118 | 184 |
|
119 | | -### Constants and options |
| 185 | +`com.github.prominence.openweathermap.api.model.forecast.WeatherForecast`'s useful public methods(setters are not listed): |
| 186 | + |
| 187 | +| Method | Description | |
| 188 | +|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 189 | +| `getState()` | Returns short weather description. Example: `Clear`. | |
| 190 | +| `getDescription()` | Returns weather description. Example: `clear sky`. | |
| 191 | +| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. | |
| 192 | +| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. | |
| 193 | +| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. | |
| 194 | +| `getAtmosphericPressure()` | Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. | |
| 195 | +| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. | |
| 196 | +| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees` and `unit`. | |
| 197 | +| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. Can be absent in case of no data. | |
| 198 | +| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. Can be absent in case of no data. | |
| 199 | +| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. | |
| 200 | +| `getForecastTimeISO()` | Returns String with time of data forecasted, ISO, UTC. | |
| 201 | +| `getDayTime()` | Returns enumerations representing the part of day(day, night). | |
| 202 | +| `toString()` | Returns informative string for the forecast of particular timestamp. | |
120 | 203 |
|
121 | | -#### Accuracy |
122 | | -| Constant | Description | |
123 | | -|--------------------|------------------| |
124 | | -| Accuracy.LIKE | Close result. | |
125 | | -| Accuracy.ACCURATE | Accurate result. | |
| 204 | +### Constants and options |
126 | 205 |
|
127 | 206 | #### Language |
128 | 207 | | Constant | Description | |
@@ -164,11 +243,11 @@ Location: Minsk(BY), Weather: слегка облачно, 20.0 ℃, 1019.0 hPa, |
164 | 243 | #### Unit |
165 | 244 | | Constant | Description | |
166 | 245 | |----------------------|------------------------------------------------| |
167 | | -| UnitSystem.METRIC | Celsius, meter/sec, hPa, mm(rain, snow). | |
168 | | -| UnitSystem.IMPERIAL | Fahrenheit, miles/hour, hPa, mm(rain, snow). | |
169 | | -| UnitSystem.STANDARD | Kelvin, meter/sec, hPa, mm(rain, snow) | |
| 246 | +| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). | |
| 247 | +| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). | |
| 248 | +| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow). | |
170 | 249 |
|
171 | 250 | ### Dependencies |
172 | | -* com.fasterxml.jackson.core:jackson-databind:2.9.9 |
173 | | -* org.slf4j:slf4j-api:1.7.26 (*compile*) |
174 | | -* junit:junit:4.12 (*test*) |
| 251 | +* com.fasterxml.jackson.core:jackson-databind:2.12.2 |
| 252 | +* org.slf4j:slf4j-api:1.7.30 (*compile*) |
| 253 | +* junit:junit:4.13.1 (*test*) |
0 commit comments