mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-01-09 19:46:41 +03:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a47386fd8f | |||
| 185f4cbe8c | |||
| 249ee09c7e | |||
|
|
23462b6d77 | ||
|
|
7f60964886 | ||
|
|
ff70aeb6fa | ||
|
|
e75cb29b15 | ||
|
|
5b4182826e | ||
|
|
1d3d769849 | ||
|
|
47d52d953a |
31
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
31
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: "[BUG] Change me"
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
- OS: [e.g. iOS]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
10
.github/ISSUE_TEMPLATE/custom.md
vendored
Normal file
10
.github/ISSUE_TEMPLATE/custom.md
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
name: Custom issue template
|
||||
about: Describe this issue template's purpose here.
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
|
||||
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: "[FEATURE] Change me"
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
9
.github/dependabot.yml
vendored
9
.github/dependabot.yml
vendored
@ -1,9 +0,0 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: maven
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
time: "03:00"
|
||||
open-pull-requests-limit: 10
|
||||
target-branch: master
|
||||
128
CODE_OF_CONDUCT.md
Normal file
128
CODE_OF_CONDUCT.md
Normal file
@ -0,0 +1,128 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, religion, or sexual identity
|
||||
and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the
|
||||
overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
* The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
alexey.zinchenko@protonmail.com.
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series
|
||||
of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or
|
||||
permanent ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within
|
||||
the community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.0, available at
|
||||
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||
|
||||
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||
enforcement ladder](https://github.com/mozilla/diversity).
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
https://www.contributor-covenant.org/faq. Translations are available at
|
||||
https://www.contributor-covenant.org/translations.
|
||||
@ -29,14 +29,14 @@ Paid:
|
||||
<dependency>
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>2.4.1`</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
compile('com.github.prominence:openweathermap-api:2.3.0')
|
||||
implementation 'com.github.prominence:openweathermap-api:2.4.1'
|
||||
```
|
||||
|
||||
### Documentation
|
||||
@ -49,6 +49,8 @@ compile('com.github.prominence:openweathermap-api:2.3.0')
|
||||
* [OpenWeatherMap Java API - 2.1.1](docs/Release_2.1.1.md)
|
||||
* [OpenWeatherMap Java API - 2.2.0](docs/Release_2.2.0.md)
|
||||
* [OpenWeatherMap Java API - 2.3.0](docs/Release_2.3.0.md)
|
||||
* [OpenWeatherMap Java API - 2.4.0](docs/Release_2.4.0.md)
|
||||
* [OpenWeatherMap Java API - 2.4.1](docs/Release_2.4.1.md)
|
||||
|
||||
### License
|
||||
MIT
|
||||
|
||||
566
docs/Release_2.4.0.md
Normal file
566
docs/Release_2.4.0.md
Normal file
@ -0,0 +1,566 @@
|
||||
### Implemented features:
|
||||
* Current weather data
|
||||
* 5 day / 3-hour forecast
|
||||
* One Call API
|
||||
* One Call 3 API
|
||||
* Air Pollution
|
||||
|
||||
|
||||
Other:
|
||||
* Request timeout settings
|
||||
|
||||
### Maven coordinates:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>2.4.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
compile('com.github.prominence:openweathermap-api:2.4.0')
|
||||
```
|
||||
|
||||
### How to use:
|
||||
|
||||
Firstly, you need to create the instance of `OpenWeatherMapClient` class:
|
||||
```java
|
||||
OpenWeatherMapClient openWeatherClient = new OpenWeatherMapClient(API_TOKEN);
|
||||
```
|
||||
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
||||
|
||||
Currently, available APIs are:
|
||||
* `currentWeather()`
|
||||
* `forecast5Day3HourStep()`
|
||||
* `oneCall()`
|
||||
* `airPollution()`
|
||||
|
||||
Also, it is possible to set timeouts for the requests on `openWeatherClient` object:
|
||||
```java
|
||||
openWeatherClient.setReadTimeout(1000);
|
||||
openWeatherClient.setConnectTimeout(1000);
|
||||
```
|
||||
Timeout settings are passed to the requesters as a copy.
|
||||
|
||||
Default(more or less) customization points:
|
||||
```java
|
||||
...
|
||||
// response language
|
||||
.language(Language.RUSSIAN)
|
||||
...
|
||||
// response units of measure
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
...
|
||||
```
|
||||
|
||||
Available output forms:
|
||||
* `asJava()`
|
||||
* `asJSON()`
|
||||
|
||||
Additional output forms, available for several APIs:
|
||||
* `asXML()`
|
||||
* `asHTML()`
|
||||
|
||||
_All response forms can be in **sync** and **async** variants._
|
||||
|
||||
#### Current weather data
|
||||
Examples:
|
||||
```java
|
||||
final String weatherJson = openWeatherClient
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byCityName("Minsk")
|
||||
.language(Language.RUSSIAN)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
```
|
||||
|
||||
```java
|
||||
final Weather weather = openWeatherClient
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byCityName("Minsk")
|
||||
.language(Language.RUSSIAN)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final List<Weather> weatherList = openWeatherClient
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
|
||||
.language(Language.GERMAN)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final CompletableFuture<String> weatherXmlFuture = openWeatherClient
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asXML();
|
||||
```
|
||||
|
||||
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.weather.Weather`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getCalculationTime()` | Returns `LocalDateTime` object with data calculation time. |
|
||||
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||
| `getAtmosphericPressure()`| Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees`, `gust` and `unit`. |
|
||||
| `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. |
|
||||
| `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. |
|
||||
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset` and `coordinate`. |
|
||||
| `toString()` | Returns informative string for the whole available weather information. |
|
||||
|
||||
`toString()` output example:
|
||||
```
|
||||
Location: Minsk(BY), Weather: clear sky, -4.22 ℃, 1020.0 hPa, Clouds: 0%
|
||||
```
|
||||
|
||||
#### 5 day / 3-hour forecast
|
||||
Examples:
|
||||
```java
|
||||
final Forecast forecast = openWeatherClient
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("Minsk")
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final String forecastJson = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("New York", "NY", "US")
|
||||
.language(Language.SPANISH)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
```
|
||||
|
||||
```java
|
||||
CompletableFuture<String> forecastFuture = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityId(350001514)
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieveAsync()
|
||||
.asXML();
|
||||
```
|
||||
|
||||
```java
|
||||
final String forecastXml = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byZipCodeInUSA("10005")
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
```
|
||||
|
||||
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.forecast.free.Forecast`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset`, `coordinate` and `population`. |
|
||||
| `getWeatherForecasts()` | Returns list of `WeatherForecast` objects with forecast information. |
|
||||
| `toString()` | Returns informative string for the whole available forecast information. |
|
||||
|
||||
`toString()` output example:
|
||||
```
|
||||
A forecast for Minsk with 15 timestamps.
|
||||
```
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.forecast.WeatherForecast`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees` and `unit`. |
|
||||
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. Can be absent in case of no data. |
|
||||
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. Can be absent in case of no data. |
|
||||
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||
| `getForecastTimeISO()` | Returns String with time of data forecasted, ISO, UTC. |
|
||||
| `getDayTime()` | Returns enumerations representing the part of day(day, night). |
|
||||
| `toString()` | Returns informative string for the forecast of particular timestamp. |
|
||||
|
||||
#### One Call 3 API
|
||||
Examples:
|
||||
```java
|
||||
final CurrentWeatherData currentWeatherData = getClient()
|
||||
.oneCall3()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
#### One Call API (Deprecated)
|
||||
Examples:
|
||||
```java
|
||||
final CurrentWeatherData currentWeatherData = openWeatherClient
|
||||
.oneCall()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final CurrentWeatherData currentWeatherData = openWeatherClient
|
||||
.oneCall()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.exclude(OneCallResultOptions.CURRENT, OneCallResultOptions.MINUTELY)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final CompletableFuture<CurrentWeatherData> currentWeatherDataFuture = openWeatherClient
|
||||
.oneCall()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final String responseJson = openWeatherClient
|
||||
.oneCall()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
```
|
||||
|
||||
```java
|
||||
final HistoricalWeatherData historicalWeatherData = openWeatherClient
|
||||
.oneCall()
|
||||
.historical()
|
||||
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final String responseJson = openWeatherClient
|
||||
.oneCall()
|
||||
.historical()
|
||||
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
```
|
||||
|
||||
```java
|
||||
final CompletableFuture<HistoricalWeatherData> historicalWeatherDataFuture = openWeatherClient
|
||||
.oneCall()
|
||||
.historical()
|
||||
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final CompletableFuture<String> responseJsonFuture = openWeatherClient
|
||||
.oneCall()
|
||||
.historical()
|
||||
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
```
|
||||
|
||||
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|--------------------------------------------------------------------------------|
|
||||
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getTimezone()` | Returns location timezone object. |
|
||||
| `getTimezoneOffset()` | Returns zone offset. |
|
||||
| `getCurrent()` | Returns `Current` object with current weather state if available. |
|
||||
| `getMinutelyList()` | Returns list of `Minutely` objects if available. |
|
||||
| `getHourlyList()` | Returns list of `Houlry` objects if available. |
|
||||
| `getDailyList()` | Returns list of `Daily` objects if available. |
|
||||
| `getAlerts()` | Returns list of `Alert` objects if available. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.Current`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|-------------------------------------------------------------------------------------------------|
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||
| `getUvIndex()` | Returns UV index value. |
|
||||
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.current.Minutely`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|---------------------------------------------------------------|
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `getPrecipitationVolume()` | Returns precipitation volume. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.current.Hourly`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-----------------------------------------------|---------------------------------------------------------------------------------------------------|
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||
| `getUvIndex()` | Returns UV index value. |
|
||||
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
||||
| `getProbabilityOfPrecipitationPercentage()` | Returns probability of precipitation percentage. |
|
||||
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.current.Daily`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|---------------------------------------------|---------------------------------------------------------------------------------------------------|
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||
| `getMoonriseTime()` | Returns `LocalDateTime` object with moonrise time. |
|
||||
| `getMoonsetTime()` | Returns `LocalDateTime` object with moonset time. |
|
||||
| `getMoonPhase()` | Returns `MoonPhase` object with `MoonType` info and value. |
|
||||
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||
| `getTemperature()` | Returns `DailyTemperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||
| `getUvIndex()` | Returns UV index value. |
|
||||
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
||||
| `getProbabilityOfPrecipitationPercentage()` | Returns probability of precipitation percentage. |
|
||||
| `getRain()` | Returns `DailyRain` object. Available fields: `value`. |
|
||||
| `getSnow()` | Returns `DailySnow` object. Available fields: `value`. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.current.Alert`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|------------------------------|--------------------------------------------------------|
|
||||
| `getSenderName()` | Returns alert sender name. |
|
||||
| `getEventName()` | Returns alert event name. |
|
||||
| `getStartTime()` | Returns `LocalDateTime` when event should start. |
|
||||
| `getEndTime()` | Returns `LocalDateTime` when event should end. |
|
||||
| `getDescription()` | Returns alert description. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|-------------------------------------------------------------------------------|
|
||||
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getTimezone()` | Returns location timezone object. |
|
||||
| `getTimezoneOffset()` | Returns zone offset. |
|
||||
| `getHistoricalWeather()` | Returns `HistoricalWeather` object with historical weather state. |
|
||||
| `getHourlyList()` | Returns list of `HourlyHistorical` objects. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeather`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|-------------------------------------------------------------------------------------------------|
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||
| `getUvIndex()` | Returns UV index value. |
|
||||
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.historical.HourlyHistorical`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-----------------------------------|---------------------------------------------------------------------------------------------------|
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||
|
||||
#### Air Pollution API
|
||||
Examples:
|
||||
```java
|
||||
final AirPollutionDetails airPollutionDetails = openWeatherClient
|
||||
.airPollution()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final AirPollutionDetails airPollutionDetails = openWeatherClient
|
||||
.airPollution()
|
||||
.historical()
|
||||
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|---------------------------------------------------------------------------|
|
||||
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getAirPollutionRecords()` | Returns list of `AirPollutionRecord` objects. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionRecord`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|---------------------------------------------------------------------------|
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with air pollution forecast time. |
|
||||
| `getAirQualityIndex()` | Returns `AirQualityIndex` object. |
|
||||
| `getCO()` | Returns carbon monoxide concentration value in μg/m^3.s. |
|
||||
| `getCarbonMonoxide()` | An alias for `getCO()` method. |
|
||||
| `getNO()` | Returns nitrogen monoxide concentration value in μg/m^3. |
|
||||
| `getNitrogenMonoxide()` | An alias for `getNO()` method. |
|
||||
| `getNO2()` | Returns nitrogen dioxide concentration value in μg/m^3. |
|
||||
| `getNitrogenDioxide()` | An alias for `getNO2()` method. |
|
||||
| `getO3()` | Returns ozone concentration value in μg/m^3. |
|
||||
| `getOzone()` | An alias for `getO3()` method. |
|
||||
| `getSO2()` | Returns sulphur dioxide concentration value in μg/m^3. |
|
||||
| `getSulphurDioxide()` | An alias for `getSO2()` method. |
|
||||
| `getPM2_5()` | Returns fine particles matter concentration value in μg/m^3. |
|
||||
| `getFineParticlesMatter()` | An alias for `getPM2_5()` method. |
|
||||
| `getPM10()` | Returns coarse particulate matter concentration value in μg/m^3. |
|
||||
| `getCoarseParticulateMatter()`| An alias for `getPM10()` method. |
|
||||
| `getNH3()` | Returns ammonia concentration value in μg/m^3. |
|
||||
| `getAmmonia()` | An alias for `getNH3()` method. |
|
||||
|
||||
### Constants and options
|
||||
|
||||
#### Language
|
||||
| Constant | Description |
|
||||
|------------------------------|-------------------------------|
|
||||
| Language.AFRIKAANS | Afrikaans language. |
|
||||
| Language.ALBANIAN | ALBANIAN language. |
|
||||
| Language.ARABIC | Arabic language. |
|
||||
| Language.AZERBAIJANI | Azerbaijani language. |
|
||||
| Language.BULGARIAN | Bulgarian language. |
|
||||
| Language.CATALAN | Catalan language. |
|
||||
| Language.CZECH | Czech language. |
|
||||
| Language.DANISH | Danish language. |
|
||||
| Language.GERMAN | German language. |
|
||||
| Language.GREEK | Greek language. |
|
||||
| Language.ENGLISH | English language. |
|
||||
| Language.BASQUE | Basque language. |
|
||||
| Language.PERSIAN | Persian (Farsi) language. |
|
||||
| Language.FINNISH | Finnish language. |
|
||||
| Language.FRENCH | French language. |
|
||||
| Language.GALICIAN | Galician language. |
|
||||
| Language.HEBREW | Hebrew language. |
|
||||
| Language.HINDI | Hindi language. |
|
||||
| Language.CROATIAN | Croatian language. |
|
||||
| Language.HUNGARIAN | Hungarian language. |
|
||||
| Language.INDONESIAN | Indonesian 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.NORWEGIAN | Norwegian language. |
|
||||
| Language.DUTCH | Dutch language. |
|
||||
| Language.POLISH | Polish language. |
|
||||
| Language.PORTUGUESE | Portuguese language. |
|
||||
| Language.PORTUGUES_BRAZIL | Português Brasil 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.SERBIAN | Serbian language. |
|
||||
| Language.THAI | Thai language. |
|
||||
| Language.TURKISH | Turkish language. |
|
||||
| Language.UKRAINIAN | Ukrainian language. |
|
||||
| Language.VIETNAMESE | Vietnamese language. |
|
||||
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||
| Language.ZULU | Zulu 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.fasterxml.jackson.core:jackson-databind:2.13.4.2
|
||||
* org.slf4j:slf4j-api:1.7.36 (*compile*)
|
||||
* org.junit.jupiter:junit-jupiter-engine:5.8.2 (*test*)
|
||||
* org.junit.platform:junit-platform-runner:1.8.2 (*test*)
|
||||
566
docs/Release_2.4.1.md
Normal file
566
docs/Release_2.4.1.md
Normal file
@ -0,0 +1,566 @@
|
||||
### Implemented features:
|
||||
* Current weather data
|
||||
* 5 day / 3-hour forecast
|
||||
* One Call API
|
||||
* One Call 3 API
|
||||
* Air Pollution
|
||||
|
||||
|
||||
Other:
|
||||
* Request timeout settings
|
||||
|
||||
### Maven coordinates:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>2.4.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
compile('com.github.prominence:openweathermap-api:2.4.1')
|
||||
```
|
||||
|
||||
### How to use:
|
||||
|
||||
Firstly, you need to create the instance of `OpenWeatherMapClient` class:
|
||||
```java
|
||||
OpenWeatherMapClient openWeatherClient = new OpenWeatherMapClient(API_TOKEN);
|
||||
```
|
||||
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
||||
|
||||
Currently, available APIs are:
|
||||
* `currentWeather()`
|
||||
* `forecast5Day3HourStep()`
|
||||
* `oneCall()`
|
||||
* `airPollution()`
|
||||
|
||||
Also, it is possible to set timeouts for the requests on `openWeatherClient` object:
|
||||
```java
|
||||
openWeatherClient.setReadTimeout(1000);
|
||||
openWeatherClient.setConnectTimeout(1000);
|
||||
```
|
||||
Timeout settings are passed to the requesters as a copy.
|
||||
|
||||
Default(more or less) customization points:
|
||||
```java
|
||||
...
|
||||
// response language
|
||||
.language(Language.RUSSIAN)
|
||||
...
|
||||
// response units of measure
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
...
|
||||
```
|
||||
|
||||
Available output forms:
|
||||
* `asJava()`
|
||||
* `asJSON()`
|
||||
|
||||
Additional output forms, available for several APIs:
|
||||
* `asXML()`
|
||||
* `asHTML()`
|
||||
|
||||
_All response forms can be in **sync** and **async** variants._
|
||||
|
||||
#### Current weather data
|
||||
Examples:
|
||||
```java
|
||||
final String weatherJson = openWeatherClient
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byCityName("Minsk")
|
||||
.language(Language.RUSSIAN)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
```
|
||||
|
||||
```java
|
||||
final Weather weather = openWeatherClient
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byCityName("Minsk")
|
||||
.language(Language.RUSSIAN)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final List<Weather> weatherList = openWeatherClient
|
||||
.currentWeather()
|
||||
.multiple()
|
||||
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
|
||||
.language(Language.GERMAN)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final CompletableFuture<String> weatherXmlFuture = openWeatherClient
|
||||
.currentWeather()
|
||||
.single()
|
||||
.byZipCodeAndCountry("220015", "by")
|
||||
.language(Language.RUSSIAN)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asXML();
|
||||
```
|
||||
|
||||
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.weather.Weather`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getCalculationTime()` | Returns `LocalDateTime` object with data calculation time. |
|
||||
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||
| `getAtmosphericPressure()`| Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees`, `gust` and `unit`. |
|
||||
| `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. |
|
||||
| `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. |
|
||||
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset` and `coordinate`. |
|
||||
| `toString()` | Returns informative string for the whole available weather information. |
|
||||
|
||||
`toString()` output example:
|
||||
```
|
||||
Location: Minsk(BY), Weather: clear sky, -4.22 ℃, 1020.0 hPa, Clouds: 0%
|
||||
```
|
||||
|
||||
#### 5 day / 3-hour forecast
|
||||
Examples:
|
||||
```java
|
||||
final Forecast forecast = openWeatherClient
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("Minsk")
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final String forecastJson = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityName("New York", "NY", "US")
|
||||
.language(Language.SPANISH)
|
||||
.unitSystem(UnitSystem.IMPERIAL)
|
||||
.count(15)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
```
|
||||
|
||||
```java
|
||||
CompletableFuture<String> forecastFuture = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byCityId(350001514)
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.count(15)
|
||||
.retrieveAsync()
|
||||
.asXML();
|
||||
```
|
||||
|
||||
```java
|
||||
final String forecastXml = getClient()
|
||||
.forecast5Day3HourStep()
|
||||
.byZipCodeInUSA("10005")
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asXML();
|
||||
```
|
||||
|
||||
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.forecast.free.Forecast`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset`, `coordinate` and `population`. |
|
||||
| `getWeatherForecasts()` | Returns list of `WeatherForecast` objects with forecast information. |
|
||||
| `toString()` | Returns informative string for the whole available forecast information. |
|
||||
|
||||
`toString()` output example:
|
||||
```
|
||||
A forecast for Minsk with 15 timestamps.
|
||||
```
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.forecast.WeatherForecast`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees` and `unit`. |
|
||||
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. Can be absent in case of no data. |
|
||||
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. Can be absent in case of no data. |
|
||||
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||
| `getForecastTimeISO()` | Returns String with time of data forecasted, ISO, UTC. |
|
||||
| `getDayTime()` | Returns enumerations representing the part of day(day, night). |
|
||||
| `toString()` | Returns informative string for the forecast of particular timestamp. |
|
||||
|
||||
#### One Call 3 API
|
||||
Examples:
|
||||
```java
|
||||
final CurrentWeatherData currentWeatherData = getClient()
|
||||
.oneCall3()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
#### One Call API (Deprecated)
|
||||
Examples:
|
||||
```java
|
||||
final CurrentWeatherData currentWeatherData = openWeatherClient
|
||||
.oneCall()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final CurrentWeatherData currentWeatherData = openWeatherClient
|
||||
.oneCall()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.exclude(OneCallResultOptions.CURRENT, OneCallResultOptions.MINUTELY)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final CompletableFuture<CurrentWeatherData> currentWeatherDataFuture = openWeatherClient
|
||||
.oneCall()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final String responseJson = openWeatherClient
|
||||
.oneCall()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
```
|
||||
|
||||
```java
|
||||
final HistoricalWeatherData historicalWeatherData = openWeatherClient
|
||||
.oneCall()
|
||||
.historical()
|
||||
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final String responseJson = openWeatherClient
|
||||
.oneCall()
|
||||
.historical()
|
||||
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
```
|
||||
|
||||
```java
|
||||
final CompletableFuture<HistoricalWeatherData> historicalWeatherDataFuture = openWeatherClient
|
||||
.oneCall()
|
||||
.historical()
|
||||
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final CompletableFuture<String> responseJsonFuture = openWeatherClient
|
||||
.oneCall()
|
||||
.historical()
|
||||
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
```
|
||||
|
||||
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|--------------------------------------------------------------------------------|
|
||||
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getTimezone()` | Returns location timezone object. |
|
||||
| `getTimezoneOffset()` | Returns zone offset. |
|
||||
| `getCurrent()` | Returns `Current` object with current weather state if available. |
|
||||
| `getMinutelyList()` | Returns list of `Minutely` objects if available. |
|
||||
| `getHourlyList()` | Returns list of `Houlry` objects if available. |
|
||||
| `getDailyList()` | Returns list of `Daily` objects if available. |
|
||||
| `getAlerts()` | Returns list of `Alert` objects if available. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.Current`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|-------------------------------------------------------------------------------------------------|
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||
| `getUvIndex()` | Returns UV index value. |
|
||||
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.current.Minutely`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|---------------------------------------------------------------|
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `getPrecipitationVolume()` | Returns precipitation volume. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.current.Hourly`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-----------------------------------------------|---------------------------------------------------------------------------------------------------|
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||
| `getUvIndex()` | Returns UV index value. |
|
||||
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
||||
| `getProbabilityOfPrecipitationPercentage()` | Returns probability of precipitation percentage. |
|
||||
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.current.Daily`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|---------------------------------------------|---------------------------------------------------------------------------------------------------|
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||
| `getMoonriseTime()` | Returns `LocalDateTime` object with moonrise time. |
|
||||
| `getMoonsetTime()` | Returns `LocalDateTime` object with moonset time. |
|
||||
| `getMoonPhase()` | Returns `MoonPhase` object with `MoonType` info and value. |
|
||||
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||
| `getTemperature()` | Returns `DailyTemperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||
| `getUvIndex()` | Returns UV index value. |
|
||||
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
||||
| `getProbabilityOfPrecipitationPercentage()` | Returns probability of precipitation percentage. |
|
||||
| `getRain()` | Returns `DailyRain` object. Available fields: `value`. |
|
||||
| `getSnow()` | Returns `DailySnow` object. Available fields: `value`. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.current.Alert`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|------------------------------|--------------------------------------------------------|
|
||||
| `getSenderName()` | Returns alert sender name. |
|
||||
| `getEventName()` | Returns alert event name. |
|
||||
| `getStartTime()` | Returns `LocalDateTime` when event should start. |
|
||||
| `getEndTime()` | Returns `LocalDateTime` when event should end. |
|
||||
| `getDescription()` | Returns alert description. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|-------------------------------------------------------------------------------|
|
||||
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getTimezone()` | Returns location timezone object. |
|
||||
| `getTimezoneOffset()` | Returns zone offset. |
|
||||
| `getHistoricalWeather()` | Returns `HistoricalWeather` object with historical weather state. |
|
||||
| `getHourlyList()` | Returns list of `HourlyHistorical` objects. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeather`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|-------------------------------------------------------------------------------------------------|
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||
| `getUvIndex()` | Returns UV index value. |
|
||||
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.onecall.historical.HourlyHistorical`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-----------------------------------|---------------------------------------------------------------------------------------------------|
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||
|
||||
#### Air Pollution API
|
||||
Examples:
|
||||
```java
|
||||
final AirPollutionDetails airPollutionDetails = openWeatherClient
|
||||
.airPollution()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
```java
|
||||
final AirPollutionDetails airPollutionDetails = openWeatherClient
|
||||
.airPollution()
|
||||
.historical()
|
||||
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
```
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|---------------------------------------------------------------------------|
|
||||
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getAirPollutionRecords()` | Returns list of `AirPollutionRecord` objects. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionRecord`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|---------------------------------------------------------------------------|
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with air pollution forecast time. |
|
||||
| `getAirQualityIndex()` | Returns `AirQualityIndex` object. |
|
||||
| `getCO()` | Returns carbon monoxide concentration value in μg/m^3.s. |
|
||||
| `getCarbonMonoxide()` | An alias for `getCO()` method. |
|
||||
| `getNO()` | Returns nitrogen monoxide concentration value in μg/m^3. |
|
||||
| `getNitrogenMonoxide()` | An alias for `getNO()` method. |
|
||||
| `getNO2()` | Returns nitrogen dioxide concentration value in μg/m^3. |
|
||||
| `getNitrogenDioxide()` | An alias for `getNO2()` method. |
|
||||
| `getO3()` | Returns ozone concentration value in μg/m^3. |
|
||||
| `getOzone()` | An alias for `getO3()` method. |
|
||||
| `getSO2()` | Returns sulphur dioxide concentration value in μg/m^3. |
|
||||
| `getSulphurDioxide()` | An alias for `getSO2()` method. |
|
||||
| `getPM2_5()` | Returns fine particles matter concentration value in μg/m^3. |
|
||||
| `getFineParticlesMatter()` | An alias for `getPM2_5()` method. |
|
||||
| `getPM10()` | Returns coarse particulate matter concentration value in μg/m^3. |
|
||||
| `getCoarseParticulateMatter()`| An alias for `getPM10()` method. |
|
||||
| `getNH3()` | Returns ammonia concentration value in μg/m^3. |
|
||||
| `getAmmonia()` | An alias for `getNH3()` method. |
|
||||
|
||||
### Constants and options
|
||||
|
||||
#### Language
|
||||
| Constant | Description |
|
||||
|------------------------------|-------------------------------|
|
||||
| Language.AFRIKAANS | Afrikaans language. |
|
||||
| Language.ALBANIAN | ALBANIAN language. |
|
||||
| Language.ARABIC | Arabic language. |
|
||||
| Language.AZERBAIJANI | Azerbaijani language. |
|
||||
| Language.BULGARIAN | Bulgarian language. |
|
||||
| Language.CATALAN | Catalan language. |
|
||||
| Language.CZECH | Czech language. |
|
||||
| Language.DANISH | Danish language. |
|
||||
| Language.GERMAN | German language. |
|
||||
| Language.GREEK | Greek language. |
|
||||
| Language.ENGLISH | English language. |
|
||||
| Language.BASQUE | Basque language. |
|
||||
| Language.PERSIAN | Persian (Farsi) language. |
|
||||
| Language.FINNISH | Finnish language. |
|
||||
| Language.FRENCH | French language. |
|
||||
| Language.GALICIAN | Galician language. |
|
||||
| Language.HEBREW | Hebrew language. |
|
||||
| Language.HINDI | Hindi language. |
|
||||
| Language.CROATIAN | Croatian language. |
|
||||
| Language.HUNGARIAN | Hungarian language. |
|
||||
| Language.INDONESIAN | Indonesian 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.NORWEGIAN | Norwegian language. |
|
||||
| Language.DUTCH | Dutch language. |
|
||||
| Language.POLISH | Polish language. |
|
||||
| Language.PORTUGUESE | Portuguese language. |
|
||||
| Language.PORTUGUES_BRAZIL | Português Brasil 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.SERBIAN | Serbian language. |
|
||||
| Language.THAI | Thai language. |
|
||||
| Language.TURKISH | Turkish language. |
|
||||
| Language.UKRAINIAN | Ukrainian language. |
|
||||
| Language.VIETNAMESE | Vietnamese language. |
|
||||
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||
| Language.ZULU | Zulu 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.fasterxml.jackson.core:jackson-databind:2.13.4.2
|
||||
* org.slf4j:slf4j-api:1.7.36 (*compile*)
|
||||
* org.junit.jupiter:junit-jupiter-engine:5.8.2 (*test*)
|
||||
* org.junit.platform:junit-platform-runner:1.8.2 (*test*)
|
||||
6
pom.xml
6
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>2.4.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Java OpenWeatherMap API</name>
|
||||
@ -80,7 +80,7 @@
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||
<version>1.6.9</version>
|
||||
<version>1.6.13</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<serverId>ossrh</serverId>
|
||||
@ -163,7 +163,7 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.13.2.2</version>
|
||||
<version>2.13.4.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
|
||||
@ -31,6 +31,7 @@ import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherRe
|
||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester;
|
||||
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.ALL;
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.SPECIAL;
|
||||
|
||||
/**
|
||||
* The main public API client to communicate with OpenWeatherMap services.
|
||||
@ -80,10 +81,29 @@ public class OpenWeatherMapClient {
|
||||
* @return requester for retrieving one call weather information.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = ALL)
|
||||
@Deprecated
|
||||
public OneCallWeatherRequester oneCall() {
|
||||
return new OneCallWeatherRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||
}
|
||||
|
||||
/**
|
||||
* One Call 3 API <a href="https://openweathermap.org/api/one-call-3">API</a>.
|
||||
* Includes a weather summary statement in addition to the information provided by {@link #oneCall()}
|
||||
*
|
||||
* Please note, that One Call API 3.0 is included in the "One Call by Call" subscription only.
|
||||
* This separate subscription includes 1,000 calls/day for free and allows you to pay only for the number of API calls made to this product.
|
||||
* Please note, that you do not need to subscribe to any other OpenWeather subscription plans to get access to the One Call API 3.0.
|
||||
* Please find more details on the pricing page and FAQ or ask Ulla, OpenWeather AI assistant.
|
||||
*
|
||||
* @return requester for retrieving one call weather information for the OneCall 3 API.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = SPECIAL)
|
||||
public OneCallWeatherRequester oneCall3() {
|
||||
RequestSettings requestSettings = new RequestSettings(apiKey, timeoutSettings);
|
||||
requestSettings.setUseApi3();
|
||||
return new OneCallWeatherRequester(requestSettings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Air Pollution <a href="https://openweathermap.org/api/air-pollution">API</a>.
|
||||
* Air Pollution API provides current, forecast and historical air pollution data for any coordinates on the globe.
|
||||
|
||||
@ -56,4 +56,9 @@ public enum SubscriptionPlan {
|
||||
* All existing subscription plans.
|
||||
*/
|
||||
ALL,
|
||||
|
||||
/**
|
||||
* Special subscription cases.
|
||||
*/
|
||||
SPECIAL,
|
||||
}
|
||||
|
||||
@ -213,6 +213,7 @@ public class OneCallWeatherResponseMapper {
|
||||
daily.setMoonPhase(new MoonPhase(moonPhaseNode.asDouble()));
|
||||
}
|
||||
|
||||
daily.setSummary(parseSummary(dailyNode));
|
||||
daily.setWeatherState(parseWeatherState(dailyNode.get("weather").get(0)));
|
||||
daily.setTemperature(parseDailyTemperature(dailyNode));
|
||||
daily.setAtmosphericPressure(parsePressure(dailyNode));
|
||||
@ -417,7 +418,7 @@ public class OneCallWeatherResponseMapper {
|
||||
if (snowNode != null) {
|
||||
final JsonNode OneHourNode = snowNode.get("1h");
|
||||
if (OneHourNode != null) {
|
||||
Rain.withOneHourLevelValue(OneHourNode.asDouble());
|
||||
return Snow.withOneHourLevelValue(OneHourNode.asDouble());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -439,4 +440,12 @@ public class OneCallWeatherResponseMapper {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String parseSummary(JsonNode dailyNode) {
|
||||
final JsonNode summaryNode = dailyNode.get("summary");
|
||||
if(summaryNode != null) {
|
||||
return summaryNode.asText();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,6 +43,7 @@ public class Daily {
|
||||
private LocalDateTime moonsetTime;
|
||||
private MoonPhase moonPhase;
|
||||
|
||||
private String summary;
|
||||
private WeatherState weatherState;
|
||||
private DailyTemperature temperature;
|
||||
private AtmosphericPressure atmosphericPressure;
|
||||
@ -162,6 +163,24 @@ public class Daily {
|
||||
this.moonPhase = moonPhase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets summary.
|
||||
*
|
||||
* @return the summary
|
||||
*/
|
||||
public String getSummary() {
|
||||
return summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets summary.
|
||||
*
|
||||
* @param summary the summary
|
||||
*/
|
||||
public void setSummary(String summary) {
|
||||
this.summary = summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets weather state.
|
||||
*
|
||||
@ -435,4 +454,5 @@ public class Daily {
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -45,6 +45,7 @@ public class RequestSettings {
|
||||
|
||||
private Language language = Language.ENGLISH;
|
||||
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
||||
private boolean useApi3 = false;
|
||||
|
||||
public RequestSettings(String apiKey, TimeoutSettings timeoutSettings) {
|
||||
this.putRequestParameter(API_KEY_PARAM_NAME, apiKey);
|
||||
@ -94,6 +95,14 @@ public class RequestSettings {
|
||||
urlAppenderBuilder.append(appendix);
|
||||
}
|
||||
|
||||
public void setUseApi3() {
|
||||
this.useApi3 = true;
|
||||
}
|
||||
|
||||
public boolean getUseApi3() {
|
||||
return this.useApi3;
|
||||
}
|
||||
|
||||
public StringBuilder getUrlAppender() {
|
||||
return urlAppenderBuilder;
|
||||
}
|
||||
|
||||
@ -29,13 +29,11 @@ import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -44,7 +42,8 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public final class RequestUtils {
|
||||
|
||||
private static final String OWM_URL_BASE = "http://api.openweathermap.org/data/2.5/";
|
||||
private static final String OWM_URL_BASE = "https://api.openweathermap.org/data/2.5/";
|
||||
private static final String OWM_URL_BASE_3_0 = "https://api.openweathermap.org/data/3.0/";
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(RequestUtils.class);
|
||||
|
||||
@ -53,10 +52,19 @@ public final class RequestUtils {
|
||||
|
||||
public static String getResponse(RequestSettings requestSettings) {
|
||||
StringBuilder requestUrlBuilder = new StringBuilder(OWM_URL_BASE);
|
||||
if(requestSettings.getUseApi3()) {
|
||||
requestUrlBuilder = new StringBuilder(OWM_URL_BASE_3_0);
|
||||
}
|
||||
requestUrlBuilder.append(requestSettings.getUrlAppender());
|
||||
requestUrlBuilder.append('?');
|
||||
String parameters = requestSettings.getRequestParameters().entrySet().stream()
|
||||
.map(entry -> entry.getKey() + "=" + entry.getValue())
|
||||
.map(entry -> {
|
||||
try {
|
||||
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
})
|
||||
.collect(Collectors.joining("&"));
|
||||
requestUrlBuilder.append(parameters);
|
||||
|
||||
|
||||
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.request.onecall.current;
|
||||
|
||||
import com.github.prominence.openweathermap.api.ApiTest;
|
||||
import com.github.prominence.openweathermap.api.OpenWeatherMapClient;
|
||||
import com.github.prominence.openweathermap.api.enums.Language;
|
||||
import com.github.prominence.openweathermap.api.enums.OneCallResultOptions;
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class CurrentWeatherOneCallApi3IntegrationTest extends ApiTest {
|
||||
@Test
|
||||
public void whenRetrieveCurrentOneCallResponseAsJava_thenOk() {
|
||||
final CurrentWeatherData currentWeatherData = getClient()
|
||||
.oneCall3()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(currentWeatherData);
|
||||
assertNotNull(currentWeatherData.getDailyList().get(0).getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveCurrentOneCallResponseAsJSON_thenOk() {
|
||||
final String responseJson = getClient()
|
||||
.oneCall3()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(responseJson);
|
||||
assertNotEquals("", responseJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveCurrentOneCallResponseWithExclusionAsJava_thenOk() {
|
||||
final CurrentWeatherData currentWeatherData = getClient()
|
||||
.oneCall3()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.exclude(OneCallResultOptions.CURRENT, OneCallResultOptions.MINUTELY)
|
||||
.retrieve()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(currentWeatherData);
|
||||
assertNull(currentWeatherData.getCurrent());
|
||||
assertNull(currentWeatherData.getMinutelyList());
|
||||
assertNotNull(currentWeatherData.getDailyList().get(0).getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveCurrentOneCallAsyncResponseAsJava_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<CurrentWeatherData> currentWeatherDataFuture = getClient()
|
||||
.oneCall3()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asJava();
|
||||
|
||||
assertNotNull(currentWeatherDataFuture);
|
||||
assertNotNull(currentWeatherDataFuture.get());
|
||||
assertNotNull(currentWeatherDataFuture.get().getDailyList().get(0).getSummary());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrieveCurrentOneCallAsyncResponseAsJSON_thenOk() throws ExecutionException, InterruptedException {
|
||||
final CompletableFuture<String> responseJsonFuture = getClient()
|
||||
.oneCall3()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieveAsync()
|
||||
.asJSON();
|
||||
|
||||
assertNotNull(responseJsonFuture);
|
||||
final String responseJson = responseJsonFuture.get();
|
||||
assertNotNull(responseJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestOnecallWithInvalidApiKey_thenThrowAnException() {
|
||||
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
|
||||
assertThrows(InvalidAuthTokenException.class, () ->
|
||||
client
|
||||
.oneCall3()
|
||||
.current()
|
||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||
.language(Language.ENGLISH)
|
||||
.unitSystem(UnitSystem.METRIC)
|
||||
.retrieve()
|
||||
.asJSON()
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user