mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-01-11 12:26:42 +03:00
Compare commits
No commits in common. "master" and "2.1.1" have entirely different histories.
31
.github/ISSUE_TEMPLATE/bug_report.md
vendored
31
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -1,31 +0,0 @@
|
|||||||
---
|
|
||||||
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
10
.github/ISSUE_TEMPLATE/custom.md
vendored
@ -1,10 +0,0 @@
|
|||||||
---
|
|
||||||
name: Custom issue template
|
|
||||||
about: Describe this issue template's purpose here.
|
|
||||||
title: ''
|
|
||||||
labels: ''
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
|
|
||||||
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
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.
|
|
||||||
@ -1,128 +0,0 @@
|
|||||||
# 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.
|
|
||||||
14
README.md
14
README.md
@ -6,14 +6,11 @@ Free:
|
|||||||
* Current weather data
|
* Current weather data
|
||||||
* 5 day / 3-hour forecast
|
* 5 day / 3-hour forecast
|
||||||
* One Call API
|
* One Call API
|
||||||
* Air pollution
|
|
||||||
|
|
||||||
Other:
|
|
||||||
* Request timeout settings
|
|
||||||
|
|
||||||
### Will be implemented later:
|
### Will be implemented later:
|
||||||
|
|
||||||
Free:
|
Free:
|
||||||
|
* Air pollution
|
||||||
* Geocoding API
|
* Geocoding API
|
||||||
* Weather Stations
|
* Weather Stations
|
||||||
* Weather Triggers
|
* Weather Triggers
|
||||||
@ -29,14 +26,14 @@ Paid:
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.prominence</groupId>
|
<groupId>com.github.prominence</groupId>
|
||||||
<artifactId>openweathermap-api</artifactId>
|
<artifactId>openweathermap-api</artifactId>
|
||||||
<version>2.4.1`</version>
|
<version>2.1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
implementation 'com.github.prominence:openweathermap-api:2.4.1'
|
compile('com.github.prominence:openweathermap-api:2.1.1')
|
||||||
```
|
```
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
@ -47,10 +44,7 @@ implementation 'com.github.prominence:openweathermap-api:2.4.1'
|
|||||||
* [OpenWeatherMap Java API - 2.0.1](docs/Release_2.0.1.md)
|
* [OpenWeatherMap Java API - 2.0.1](docs/Release_2.0.1.md)
|
||||||
* [OpenWeatherMap Java API - 2.1.0](docs/Release_2.1.0.md)
|
* [OpenWeatherMap Java API - 2.1.0](docs/Release_2.1.0.md)
|
||||||
* [OpenWeatherMap Java API - 2.1.1](docs/Release_2.1.1.md)
|
* [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 - SNAPSHOT](docs/SNAPSHOT.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
|
### License
|
||||||
MIT
|
MIT
|
||||||
|
|||||||
@ -1,552 +0,0 @@
|
|||||||
### Implemented features:
|
|
||||||
* Current weather data
|
|
||||||
* 5 day / 3-hour forecast
|
|
||||||
* One Call API
|
|
||||||
* Air Pollution
|
|
||||||
|
|
||||||
|
|
||||||
Other:
|
|
||||||
* Request timeout settings
|
|
||||||
|
|
||||||
### Maven coordinates:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.prominence</groupId>
|
|
||||||
<artifactId>openweathermap-api</artifactId>
|
|
||||||
<version>2.3.0</version>
|
|
||||||
</dependency>
|
|
||||||
```
|
|
||||||
|
|
||||||
### Gradle coordinates:
|
|
||||||
|
|
||||||
```groovy
|
|
||||||
compile('com.github.prominence:openweathermap-api:2.3.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 API
|
|
||||||
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.2.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*)
|
|
||||||
@ -1,566 +0,0 @@
|
|||||||
### 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*)
|
|
||||||
@ -1,566 +0,0 @@
|
|||||||
### 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*)
|
|
||||||
@ -2,7 +2,6 @@
|
|||||||
* Current weather data
|
* Current weather data
|
||||||
* 5 day / 3-hour forecast
|
* 5 day / 3-hour forecast
|
||||||
* One Call API
|
* One Call API
|
||||||
* Air Pollution
|
|
||||||
|
|
||||||
### Maven coordinates:
|
### Maven coordinates:
|
||||||
|
|
||||||
@ -10,14 +9,14 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.prominence</groupId>
|
<groupId>com.github.prominence</groupId>
|
||||||
<artifactId>openweathermap-api</artifactId>
|
<artifactId>openweathermap-api</artifactId>
|
||||||
<version>2.2.0</version>
|
<version>2.1.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:2.2.0')
|
compile('com.github.prominence:openweathermap-api:2.1.1-SNAPSHOT')
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to use:
|
### How to use:
|
||||||
@ -32,7 +31,6 @@ Currently, available APIs are:
|
|||||||
* `currentWeather()`
|
* `currentWeather()`
|
||||||
* `forecast5Day3HourStep()`
|
* `forecast5Day3HourStep()`
|
||||||
* `oneCall()`
|
* `oneCall()`
|
||||||
* `airPollution()`
|
|
||||||
|
|
||||||
Default(more or less) customization points:
|
Default(more or less) customization points:
|
||||||
```java
|
```java
|
||||||
@ -422,56 +420,6 @@ You are able to set preferable options(via chain methods) and execute appropriat
|
|||||||
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
| `getSnow()` | Returns `Snow` 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
|
### Constants and options
|
||||||
|
|
||||||
#### Language
|
#### Language
|
||||||
18
pom.xml
18
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.github.prominence</groupId>
|
<groupId>com.github.prominence</groupId>
|
||||||
<artifactId>openweathermap-api</artifactId>
|
<artifactId>openweathermap-api</artifactId>
|
||||||
<version>2.4.1</version>
|
<version>2.1.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>Java OpenWeatherMap API</name>
|
<name>Java OpenWeatherMap API</name>
|
||||||
@ -80,7 +80,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.sonatype.plugins</groupId>
|
<groupId>org.sonatype.plugins</groupId>
|
||||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||||
<version>1.6.13</version>
|
<version>1.6.8</version>
|
||||||
<extensions>true</extensions>
|
<extensions>true</extensions>
|
||||||
<configuration>
|
<configuration>
|
||||||
<serverId>ossrh</serverId>
|
<serverId>ossrh</serverId>
|
||||||
@ -104,7 +104,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>3.2.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>8</source>
|
<source>8</source>
|
||||||
</configuration>
|
</configuration>
|
||||||
@ -120,7 +120,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-gpg-plugin</artifactId>
|
<artifactId>maven-gpg-plugin</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>1.6</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>sign-artifacts</id>
|
<id>sign-artifacts</id>
|
||||||
@ -134,7 +134,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.jacoco</groupId>
|
<groupId>org.jacoco</groupId>
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
<version>0.8.7</version>
|
<version>0.8.6</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
@ -163,25 +163,25 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>2.13.4.2</version>
|
<version>2.12.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>1.7.36</version>
|
<version>1.7.30</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<version>5.8.2</version>
|
<version>5.7.1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.platform</groupId>
|
<groupId>org.junit.platform</groupId>
|
||||||
<artifactId>junit-platform-runner</artifactId>
|
<artifactId>junit-platform-runner</artifactId>
|
||||||
<version>1.8.2</version>
|
<version>1.7.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@ -23,15 +23,14 @@
|
|||||||
package com.github.prominence.openweathermap.api;
|
package com.github.prominence.openweathermap.api;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.annotation.SubscriptionAvailability;
|
import com.github.prominence.openweathermap.api.annotation.SubscriptionAvailability;
|
||||||
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequester;
|
|
||||||
import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThreeHourStepForecastRequester;
|
import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThreeHourStepForecastRequester;
|
||||||
|
import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThreeHourStepForecastRequesterImpl;
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherRequester;
|
||||||
|
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherRequesterImpl;
|
||||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequesterImpl;
|
||||||
|
|
||||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.ALL;
|
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.*;
|
||||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.SPECIAL;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main public API client to communicate with OpenWeatherMap services.
|
* The main public API client to communicate with OpenWeatherMap services.
|
||||||
@ -39,7 +38,6 @@ import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.SP
|
|||||||
*/
|
*/
|
||||||
public class OpenWeatherMapClient {
|
public class OpenWeatherMapClient {
|
||||||
private final String apiKey;
|
private final String apiKey;
|
||||||
private final TimeoutSettings timeoutSettings = new TimeoutSettings();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created OpenWeatherMap client object.
|
* Created OpenWeatherMap client object.
|
||||||
@ -49,21 +47,13 @@ public class OpenWeatherMapClient {
|
|||||||
this.apiKey = apiKey;
|
this.apiKey = apiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConnectionTimeout(int connectionTimeout) {
|
|
||||||
timeoutSettings.setConnectionTimeout(connectionTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReadTimeout(int readTimeout) {
|
|
||||||
timeoutSettings.setReadTimeout(readTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current Weather <a href="https://openweathermap.org/current">API</a>.
|
* Current Weather <a href="https://openweathermap.org/current">API</a>.
|
||||||
* @return requester for retrieving current weather information.
|
* @return requester for retrieving current weather information.
|
||||||
*/
|
*/
|
||||||
@SubscriptionAvailability(plans = ALL)
|
@SubscriptionAvailability(plans = ALL)
|
||||||
public CurrentWeatherRequester currentWeather() {
|
public CurrentWeatherRequester currentWeather() {
|
||||||
return new CurrentWeatherRequester(new RequestSettings(apiKey, timeoutSettings));
|
return new CurrentWeatherRequesterImpl(apiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,7 +62,7 @@ public class OpenWeatherMapClient {
|
|||||||
*/
|
*/
|
||||||
@SubscriptionAvailability(plans = ALL)
|
@SubscriptionAvailability(plans = ALL)
|
||||||
public FiveDayThreeHourStepForecastRequester forecast5Day3HourStep() {
|
public FiveDayThreeHourStepForecastRequester forecast5Day3HourStep() {
|
||||||
return new FiveDayThreeHourStepForecastRequester(new RequestSettings(apiKey, timeoutSettings));
|
return new FiveDayThreeHourStepForecastRequesterImpl(apiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,36 +71,7 @@ public class OpenWeatherMapClient {
|
|||||||
* @return requester for retrieving one call weather information.
|
* @return requester for retrieving one call weather information.
|
||||||
*/
|
*/
|
||||||
@SubscriptionAvailability(plans = ALL)
|
@SubscriptionAvailability(plans = ALL)
|
||||||
@Deprecated
|
|
||||||
public OneCallWeatherRequester oneCall() {
|
public OneCallWeatherRequester oneCall() {
|
||||||
return new OneCallWeatherRequester(new RequestSettings(apiKey, timeoutSettings));
|
return new OneCallWeatherRequesterImpl(apiKey);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
* @return requester for air pollution information retrieval.
|
|
||||||
*/
|
|
||||||
@SubscriptionAvailability(plans = ALL)
|
|
||||||
public AirPollutionRequester airPollution() {
|
|
||||||
return new AirPollutionRequester(new RequestSettings(apiKey, timeoutSettings));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * 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.enums;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The enum Air quality index.
|
|
||||||
*/
|
|
||||||
public enum AirQualityIndex {
|
|
||||||
/**
|
|
||||||
* Good air quality index.
|
|
||||||
*/
|
|
||||||
GOOD(1),
|
|
||||||
/**
|
|
||||||
* Fair air quality index.
|
|
||||||
*/
|
|
||||||
FAIR(2),
|
|
||||||
/**
|
|
||||||
* Moderate air quality index.
|
|
||||||
*/
|
|
||||||
MODERATE(3),
|
|
||||||
/**
|
|
||||||
* Poor air quality index.
|
|
||||||
*/
|
|
||||||
POOR(4),
|
|
||||||
/**
|
|
||||||
* Very poor air quality index.
|
|
||||||
*/
|
|
||||||
VERY_POOR(5);
|
|
||||||
|
|
||||||
private final int value;
|
|
||||||
|
|
||||||
AirQualityIndex(int index) {
|
|
||||||
this.value = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets value.
|
|
||||||
*
|
|
||||||
* @return the value
|
|
||||||
*/
|
|
||||||
public int getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets by index.
|
|
||||||
*
|
|
||||||
* @param index the index
|
|
||||||
* @return the by index
|
|
||||||
*/
|
|
||||||
public static AirQualityIndex getByIndex(int index) {
|
|
||||||
final Optional<AirQualityIndex> optionalAirQualityIndex = Arrays.stream(values()).filter(airQualityIndex -> airQualityIndex.getValue() == index).findFirst();
|
|
||||||
return optionalAirQualityIndex.orElse(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -233,9 +233,9 @@ public enum Language {
|
|||||||
TURKISH("tr"),
|
TURKISH("tr"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ukrainian language.
|
* Ukranian language.
|
||||||
*/
|
*/
|
||||||
UKRAINIAN("uk"),
|
UKRANIAN("uk"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vietnamese language.
|
* Vietnamese language.
|
||||||
|
|||||||
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022 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.enums;
|
|
||||||
|
|
||||||
public enum MoonType {
|
|
||||||
NEW_MOON,
|
|
||||||
WAXING_CRESCENT,
|
|
||||||
FIRST_QUARTER_MOON,
|
|
||||||
WAXING_GIBBOUS,
|
|
||||||
FULL_MOON,
|
|
||||||
WANING_GIBBOUS,
|
|
||||||
LAST_QUARTER_MOON,
|
|
||||||
WANING_CRESCENT,
|
|
||||||
INVALID;
|
|
||||||
|
|
||||||
private static final double precision = 0.000001d;
|
|
||||||
|
|
||||||
public static MoonType valueOf(double numericValue) {
|
|
||||||
if (equals(numericValue, 0) || equals(numericValue, 1)) {
|
|
||||||
return NEW_MOON;
|
|
||||||
} else if (equals(numericValue, 0.25)) {
|
|
||||||
return FIRST_QUARTER_MOON;
|
|
||||||
} else if (equals(numericValue, 0.5)) {
|
|
||||||
return FULL_MOON;
|
|
||||||
} else if (equals(numericValue, 0.75)) {
|
|
||||||
return LAST_QUARTER_MOON;
|
|
||||||
} else if (numericValue > 0 && numericValue < 0.25) {
|
|
||||||
return WAXING_CRESCENT;
|
|
||||||
} else if (numericValue > 0.25 && numericValue < 0.5) {
|
|
||||||
return WAXING_GIBBOUS;
|
|
||||||
} else if (numericValue > 0.5 && numericValue < 0.75) {
|
|
||||||
return WANING_GIBBOUS;
|
|
||||||
} else if (numericValue > 0.75 && numericValue < 1) {
|
|
||||||
return WANING_CRESCENT;
|
|
||||||
}
|
|
||||||
return INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean equals(double d1, double d2) {
|
|
||||||
return Math.abs(d1 - d2) < precision;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -56,9 +56,4 @@ public enum SubscriptionPlan {
|
|||||||
* All existing subscription plans.
|
* All existing subscription plans.
|
||||||
*/
|
*/
|
||||||
ALL,
|
ALL,
|
||||||
|
|
||||||
/**
|
|
||||||
* Special subscription cases.
|
|
||||||
*/
|
|
||||||
SPECIAL,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,102 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022 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.mapper;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.AirQualityIndex;
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
|
||||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionRecord;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Air pollution response mapper.
|
|
||||||
*/
|
|
||||||
public class AirPollutionResponseMapper {
|
|
||||||
/**
|
|
||||||
* Map to air pollution air pollution.
|
|
||||||
*
|
|
||||||
* @param json the json
|
|
||||||
* @return the air pollution
|
|
||||||
*/
|
|
||||||
public AirPollutionDetails mapToAirPollution(String json) {
|
|
||||||
final ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
AirPollutionDetails airPollutionDetails;
|
|
||||||
try {
|
|
||||||
final JsonNode root = objectMapper.readTree(json);
|
|
||||||
airPollutionDetails = mapToAirPollution(root);
|
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
throw new RuntimeException("Cannot parse Air Pollution response");
|
|
||||||
}
|
|
||||||
|
|
||||||
return airPollutionDetails;
|
|
||||||
}
|
|
||||||
|
|
||||||
private AirPollutionDetails mapToAirPollution(JsonNode rootNode) {
|
|
||||||
final AirPollutionDetails airPollutionDetails = new AirPollutionDetails();
|
|
||||||
airPollutionDetails.setCoordinate(parseCoordinate(rootNode.get("coord")));
|
|
||||||
|
|
||||||
final List<AirPollutionRecord> sampleList = new ArrayList<>();
|
|
||||||
final JsonNode sampleListNode = rootNode.get("list");
|
|
||||||
sampleListNode.forEach(sampleNode -> {
|
|
||||||
sampleList.add(parseAirPollutionSample(sampleNode));
|
|
||||||
});
|
|
||||||
airPollutionDetails.setAirPollutionRecords(sampleList);
|
|
||||||
|
|
||||||
return airPollutionDetails;
|
|
||||||
}
|
|
||||||
|
|
||||||
private AirPollutionRecord parseAirPollutionSample(JsonNode sampleNode) {
|
|
||||||
AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
|
||||||
airPollutionRecord.setForecastTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(sampleNode.get("dt").asInt()), TimeZone.getDefault().toZoneId()));
|
|
||||||
airPollutionRecord.setAirQualityIndex(AirQualityIndex.getByIndex(sampleNode.get("main").get("aqi").asInt()));
|
|
||||||
|
|
||||||
final JsonNode componentsNode = sampleNode.get("components");
|
|
||||||
airPollutionRecord.setCO(componentsNode.get("co").asDouble());
|
|
||||||
airPollutionRecord.setNO(componentsNode.get("no").asDouble());
|
|
||||||
airPollutionRecord.setNO2(componentsNode.get("no2").asDouble());
|
|
||||||
airPollutionRecord.setO3(componentsNode.get("o3").asDouble());
|
|
||||||
airPollutionRecord.setSO2(componentsNode.get("so2").asDouble());
|
|
||||||
airPollutionRecord.setPM2_5(componentsNode.get("pm2_5").asDouble());
|
|
||||||
airPollutionRecord.setPM10(componentsNode.get("pm10").asDouble());
|
|
||||||
airPollutionRecord.setNH3(componentsNode.get("nh3").asDouble());
|
|
||||||
|
|
||||||
return airPollutionRecord;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Coordinate parseCoordinate(JsonNode rootNode) {
|
|
||||||
final JsonNode latitudeNode = rootNode.get("lat");
|
|
||||||
final JsonNode longitudeNode = rootNode.get("lon");
|
|
||||||
if (latitudeNode != null && longitudeNode != null) {
|
|
||||||
return Coordinate.of(latitudeNode.asDouble(), longitudeNode.asDouble());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * 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.model.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Air pollution.
|
|
||||||
*/
|
|
||||||
public class AirPollutionDetails {
|
|
||||||
private Coordinate coordinate;
|
|
||||||
private List<AirPollutionRecord> airPollutionRecords;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets coordinate.
|
|
||||||
*
|
|
||||||
* @return the coordinate
|
|
||||||
*/
|
|
||||||
public Coordinate getCoordinate() {
|
|
||||||
return coordinate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets coordinate.
|
|
||||||
*
|
|
||||||
* @param coordinate the coordinate
|
|
||||||
*/
|
|
||||||
public void setCoordinate(Coordinate coordinate) {
|
|
||||||
this.coordinate = coordinate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets air pollution details.
|
|
||||||
*
|
|
||||||
* @return the air pollution details
|
|
||||||
*/
|
|
||||||
public List<AirPollutionRecord> getAirPollutionRecords() {
|
|
||||||
return airPollutionRecords;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets air pollution details.
|
|
||||||
*
|
|
||||||
* @param airPollutionRecords the air pollution details
|
|
||||||
*/
|
|
||||||
public void setAirPollutionRecords(List<AirPollutionRecord> airPollutionRecords) {
|
|
||||||
this.airPollutionRecords = airPollutionRecords;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
AirPollutionDetails that = (AirPollutionDetails) o;
|
|
||||||
return Objects.equals(coordinate, that.coordinate) && Objects.equals(airPollutionRecords, that.airPollutionRecords);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(coordinate, airPollutionRecords);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,376 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * 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.model.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.AirQualityIndex;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Air pollution record.
|
|
||||||
*/
|
|
||||||
public class AirPollutionRecord {
|
|
||||||
private LocalDateTime forecastTime;
|
|
||||||
private AirQualityIndex airQualityIndex;
|
|
||||||
|
|
||||||
private Double CO;
|
|
||||||
private Double NO;
|
|
||||||
private Double NO2;
|
|
||||||
private Double O3;
|
|
||||||
private Double SO2;
|
|
||||||
private Double PM2_5;
|
|
||||||
private Double PM10;
|
|
||||||
private Double NH3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets forecast time.
|
|
||||||
*
|
|
||||||
* @return the forecast time
|
|
||||||
*/
|
|
||||||
public LocalDateTime getForecastTime() {
|
|
||||||
return forecastTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets forecast time.
|
|
||||||
*
|
|
||||||
* @param forecastTime the forecast time
|
|
||||||
*/
|
|
||||||
public void setForecastTime(LocalDateTime forecastTime) {
|
|
||||||
this.forecastTime = forecastTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets air quality index.
|
|
||||||
*
|
|
||||||
* @return the air quality index
|
|
||||||
*/
|
|
||||||
public AirQualityIndex getAirQualityIndex() {
|
|
||||||
return airQualityIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets air quality index.
|
|
||||||
*
|
|
||||||
* @param airQualityIndex the air quality index
|
|
||||||
*/
|
|
||||||
public void setAirQualityIndex(AirQualityIndex airQualityIndex) {
|
|
||||||
this.airQualityIndex = airQualityIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets carbon monoxide concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @return the carbon monoxide value
|
|
||||||
*/
|
|
||||||
public Double getCO() {
|
|
||||||
return CO;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets carbon monoxide concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @return the carbon monoxide value
|
|
||||||
*/
|
|
||||||
public Double getCarbonMonoxide() {
|
|
||||||
return getCO();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets carbon monoxide concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @param CO the carbon monoxide value
|
|
||||||
*/
|
|
||||||
public void setCO(Double CO) {
|
|
||||||
this.CO = CO;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets nitrogen monoxide concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @return the nitrogen monoxide value
|
|
||||||
*/
|
|
||||||
public Double getNO() {
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets nitrogen monoxide concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @return the nitrogen monoxide value
|
|
||||||
*/
|
|
||||||
public Double getNitrogenMonoxide() {
|
|
||||||
return getNO();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets nitrogen monoxide concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @param NO the nitrogen monoxide value
|
|
||||||
*/
|
|
||||||
public void setNO(Double NO) {
|
|
||||||
this.NO = NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets nitrogen dioxide concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @return the nitrogen dioxide value
|
|
||||||
*/
|
|
||||||
public Double getNO2() {
|
|
||||||
return NO2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets nitrogen dioxide concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @return the nitrogen dioxide value
|
|
||||||
*/
|
|
||||||
public Double getNitrogenDioxide() {
|
|
||||||
return getNO2();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets nitrogen dioxide concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @param NO2 the nitrogen dioxide value
|
|
||||||
*/
|
|
||||||
public void setNO2(Double NO2) {
|
|
||||||
this.NO2 = NO2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets ozone concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @return the ozone value
|
|
||||||
*/
|
|
||||||
public Double getO3() {
|
|
||||||
return O3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets ozone concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @return the ozone value
|
|
||||||
*/
|
|
||||||
public Double getOzone() {
|
|
||||||
return getO3();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets ozone concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @param o3 the ozone value
|
|
||||||
*/
|
|
||||||
public void setO3(Double o3) {
|
|
||||||
O3 = o3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets sulphur dioxide concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @return the sulphur dioxide value
|
|
||||||
*/
|
|
||||||
public Double getSO2() {
|
|
||||||
return SO2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets sulphur dioxide concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @return the sulphur dioxide value
|
|
||||||
*/
|
|
||||||
public Double getSulphurDioxide() {
|
|
||||||
return getSO2();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets sulphur dioxide concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @param SO2 the sulphur dioxide value
|
|
||||||
*/
|
|
||||||
public void setSO2(Double SO2) {
|
|
||||||
this.SO2 = SO2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets fine particles matter concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @return the fine particles matter value
|
|
||||||
*/
|
|
||||||
public Double getPM2_5() {
|
|
||||||
return PM2_5;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets fine particles matter concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @return the fine particles matter value
|
|
||||||
*/
|
|
||||||
public Double getFineParticlesMatter() {
|
|
||||||
return getPM2_5();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets fine particles matter concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @param PM2_5 the fine particles matter value
|
|
||||||
*/
|
|
||||||
public void setPM2_5(Double PM2_5) {
|
|
||||||
this.PM2_5 = PM2_5;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets coarse particulate matter concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @return the coarse particulate matter value
|
|
||||||
*/
|
|
||||||
public Double getPM10() {
|
|
||||||
return PM10;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets coarse particulate matter concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @return the coarse particulate matter value
|
|
||||||
*/
|
|
||||||
public Double getCoarseParticulateMatter() {
|
|
||||||
return getPM10();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets coarse particulate matter concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @param PM10 the coarse particulate matter value
|
|
||||||
*/
|
|
||||||
public void setPM10(Double PM10) {
|
|
||||||
this.PM10 = PM10;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets ammonia concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @return the ammonia value
|
|
||||||
*/
|
|
||||||
public Double getNH3() {
|
|
||||||
return NH3;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets ammonia concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @return the ammonia value
|
|
||||||
*/
|
|
||||||
public Double getAmmonia() {
|
|
||||||
return getNH3();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets ammonia concentration value in μg/m^3.
|
|
||||||
*
|
|
||||||
* @param NH3 the ammonia value
|
|
||||||
*/
|
|
||||||
public void setNH3(Double NH3) {
|
|
||||||
this.NH3 = NH3;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
AirPollutionRecord that = (AirPollutionRecord) o;
|
|
||||||
return Objects.equals(forecastTime, that.forecastTime) && airQualityIndex == that.airQualityIndex && Objects.equals(CO, that.CO) && Objects.equals(NO, that.NO) && Objects.equals(NO2, that.NO2) && Objects.equals(O3, that.O3) && Objects.equals(SO2, that.SO2) && Objects.equals(PM2_5, that.PM2_5) && Objects.equals(PM10, that.PM10) && Objects.equals(NH3, that.NH3);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(forecastTime, airQualityIndex, CO, NO, NO2, O3, SO2, PM2_5, PM10, NH3);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
final StringBuilder stringBuilder = new StringBuilder()
|
|
||||||
.append("Air Pollution Record for ")
|
|
||||||
.append(forecastTime)
|
|
||||||
.append(", AQI=")
|
|
||||||
.append(airQualityIndex.name())
|
|
||||||
.append(".");
|
|
||||||
final boolean anyConcentrationAvailable = Stream.of(CO, NO, NO2, O3, SO2, PM2_5, PM10, NH3).anyMatch(Objects::nonNull);
|
|
||||||
if (anyConcentrationAvailable) {
|
|
||||||
stringBuilder.append(" Concentrations:");
|
|
||||||
if (CO != null) {
|
|
||||||
stringBuilder
|
|
||||||
.append(" CO(Carbon monoxide) = ")
|
|
||||||
.append(CO)
|
|
||||||
.append(" μg/m^3;");
|
|
||||||
}
|
|
||||||
if (NO != null) {
|
|
||||||
stringBuilder
|
|
||||||
.append(" NO(Nitrogen monoxide) = ")
|
|
||||||
.append(NO)
|
|
||||||
.append(" μg/m^3;");
|
|
||||||
}
|
|
||||||
if (NO2 != null) {
|
|
||||||
stringBuilder
|
|
||||||
.append(" NO2(Nitrogen dioxide) = ")
|
|
||||||
.append(NO2)
|
|
||||||
.append(" μg/m^3;");
|
|
||||||
}
|
|
||||||
if (O3 != null) {
|
|
||||||
stringBuilder
|
|
||||||
.append(" O3(Ozone) = ")
|
|
||||||
.append(O3)
|
|
||||||
.append(" μg/m^3;");
|
|
||||||
}
|
|
||||||
if (SO2 != null) {
|
|
||||||
stringBuilder
|
|
||||||
.append(" SO2(Sulphur dioxide) = ")
|
|
||||||
.append(SO2)
|
|
||||||
.append(" μg/m^3;");
|
|
||||||
}
|
|
||||||
if (PM2_5 != null) {
|
|
||||||
stringBuilder
|
|
||||||
.append(" PM2.5(Fine particles matter) = ")
|
|
||||||
.append(PM2_5)
|
|
||||||
.append(" μg/m^3;");
|
|
||||||
}
|
|
||||||
if (PM10 != null) {
|
|
||||||
stringBuilder
|
|
||||||
.append(" PM10(Coarse particulate matter) = ")
|
|
||||||
.append(PM10)
|
|
||||||
.append(" μg/m^3;");
|
|
||||||
}
|
|
||||||
if (NH3 != null) {
|
|
||||||
stringBuilder
|
|
||||||
.append(" NH3(Ammonia) = ")
|
|
||||||
.append(NH3)
|
|
||||||
.append(" μg/m^3;");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -39,11 +39,6 @@ public class Daily {
|
|||||||
private LocalDateTime sunriseTime;
|
private LocalDateTime sunriseTime;
|
||||||
private LocalDateTime sunsetTime;
|
private LocalDateTime sunsetTime;
|
||||||
|
|
||||||
private LocalDateTime moonriseTime;
|
|
||||||
private LocalDateTime moonsetTime;
|
|
||||||
private MoonPhase moonPhase;
|
|
||||||
|
|
||||||
private String summary;
|
|
||||||
private WeatherState weatherState;
|
private WeatherState weatherState;
|
||||||
private DailyTemperature temperature;
|
private DailyTemperature temperature;
|
||||||
private AtmosphericPressure atmosphericPressure;
|
private AtmosphericPressure atmosphericPressure;
|
||||||
@ -109,78 +104,6 @@ public class Daily {
|
|||||||
this.sunsetTime = sunsetTime;
|
this.sunsetTime = sunsetTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets moonrise time.
|
|
||||||
*
|
|
||||||
* @return the moonrise time
|
|
||||||
*/
|
|
||||||
public LocalDateTime getMoonriseTime() {
|
|
||||||
return moonriseTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets moonrise time.
|
|
||||||
*
|
|
||||||
* @param moonriseTime the moonrise time
|
|
||||||
*/
|
|
||||||
public void setMoonriseTime(LocalDateTime moonriseTime) {
|
|
||||||
this.moonriseTime = moonriseTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets moonset time.
|
|
||||||
*
|
|
||||||
* @return the moonset time
|
|
||||||
*/
|
|
||||||
public LocalDateTime getMoonsetTime() {
|
|
||||||
return moonsetTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets moonset time.
|
|
||||||
*
|
|
||||||
* @param moonsetTime the moonset time
|
|
||||||
*/
|
|
||||||
public void setMoonsetTime(LocalDateTime moonsetTime) {
|
|
||||||
this.moonsetTime = moonsetTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets moon phase.
|
|
||||||
*
|
|
||||||
* @return the moon phase
|
|
||||||
*/
|
|
||||||
public MoonPhase getMoonPhase() {
|
|
||||||
return moonPhase;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets moon phase.
|
|
||||||
*
|
|
||||||
* @param moonPhase the moon phase
|
|
||||||
*/
|
|
||||||
public void setMoonPhase(MoonPhase moonPhase) {
|
|
||||||
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.
|
* Gets weather state.
|
||||||
*
|
*
|
||||||
@ -388,9 +311,6 @@ public class Daily {
|
|||||||
return Objects.equals(forecastTime, daily.forecastTime) &&
|
return Objects.equals(forecastTime, daily.forecastTime) &&
|
||||||
Objects.equals(sunriseTime, daily.sunriseTime) &&
|
Objects.equals(sunriseTime, daily.sunriseTime) &&
|
||||||
Objects.equals(sunsetTime, daily.sunsetTime) &&
|
Objects.equals(sunsetTime, daily.sunsetTime) &&
|
||||||
Objects.equals(moonriseTime, daily.moonriseTime) &&
|
|
||||||
Objects.equals(moonsetTime, daily.moonsetTime) &&
|
|
||||||
Objects.equals(moonPhase, daily.moonPhase) &&
|
|
||||||
Objects.equals(weatherState, daily.weatherState) &&
|
Objects.equals(weatherState, daily.weatherState) &&
|
||||||
Objects.equals(temperature, daily.temperature) &&
|
Objects.equals(temperature, daily.temperature) &&
|
||||||
Objects.equals(atmosphericPressure, daily.atmosphericPressure) &&
|
Objects.equals(atmosphericPressure, daily.atmosphericPressure) &&
|
||||||
@ -405,7 +325,7 @@ public class Daily {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(forecastTime, sunriseTime, sunsetTime, moonriseTime, moonsetTime, moonPhase, weatherState, temperature, atmosphericPressure, humidity, wind, clouds, uvIndex, probabilityOfPrecipitation, rain, snow);
|
return Objects.hash(forecastTime, sunriseTime, sunsetTime, weatherState, temperature, atmosphericPressure, humidity, wind, clouds, uvIndex, probabilityOfPrecipitation, rain, snow);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -435,7 +355,7 @@ public class Daily {
|
|||||||
}
|
}
|
||||||
if (clouds != null) {
|
if (clouds != null) {
|
||||||
stringBuilder.append(" Clouds: ");
|
stringBuilder.append(" Clouds: ");
|
||||||
stringBuilder.append(clouds);
|
stringBuilder.append(clouds.toString());
|
||||||
stringBuilder.append('.');
|
stringBuilder.append('.');
|
||||||
}
|
}
|
||||||
if (rain != null) {
|
if (rain != null) {
|
||||||
@ -454,5 +374,4 @@ public class Daily {
|
|||||||
}
|
}
|
||||||
return stringBuilder.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.model.onecall.current;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.MoonType;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class MoonPhase {
|
|
||||||
private final double value;
|
|
||||||
private final MoonType type;
|
|
||||||
|
|
||||||
public MoonPhase(Double value) {
|
|
||||||
this.value = value;
|
|
||||||
this.type = MoonType.valueOf(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MoonType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
MoonPhase moonPhase = (MoonPhase) o;
|
|
||||||
return Double.compare(moonPhase.value, value) == 0 && type == moonPhase.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(value, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return type.name() + "(" + value + ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,23 +20,15 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.enums;
|
package com.github.prominence.openweathermap.api.request;
|
||||||
|
|
||||||
public enum ResponseType {
|
import java.util.concurrent.CompletableFuture;
|
||||||
HTML("html"),
|
|
||||||
XML("xml");
|
|
||||||
|
|
||||||
private final String value;
|
/**
|
||||||
|
* The interface Async request terminator.
|
||||||
ResponseType(String value) {
|
*
|
||||||
this.value = value;
|
* @param <T> the type parameter
|
||||||
}
|
* @param <S> the type parameter
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns language's value.
|
|
||||||
* @return value.
|
|
||||||
*/
|
*/
|
||||||
public String getValue() {
|
public interface AsyncRequestTerminator<T, S> extends RequestTerminator<CompletableFuture<T>, CompletableFuture<S>> {
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,29 +20,31 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
package com.github.prominence.openweathermap.api.request;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Current air pollution requester.
|
* The interface Request customizer.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
*/
|
*/
|
||||||
public class CurrentAirPollutionRequester {
|
public interface RequestCustomizer<T extends RequestCustomizer<?>> {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Current air pollution requester.
|
* Customize language.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @param language the language
|
||||||
|
* @return the request customizer
|
||||||
*/
|
*/
|
||||||
public CurrentAirPollutionRequester(RequestSettings requestSettings) {
|
T language(Language language);
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate) {
|
/**
|
||||||
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
* Customize unit system.
|
||||||
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
*
|
||||||
return new AirPollutionRequestCustomizer(requestSettings);
|
* @param unitSystem the unit system
|
||||||
}
|
* @return the request customizer
|
||||||
|
*/
|
||||||
|
T unitSystem(UnitSystem unitSystem);
|
||||||
}
|
}
|
||||||
@ -1,109 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022 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;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.ResponseType;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class RequestSettings {
|
|
||||||
|
|
||||||
private static final String LANG_PARAM = "lang";
|
|
||||||
private static final String UNITS_PARAM = "units";
|
|
||||||
private static final String MODE_PARAM = "mode";
|
|
||||||
private static final String API_KEY_PARAM_NAME = "appid";
|
|
||||||
|
|
||||||
private final TimeoutSettings timeoutSettings;
|
|
||||||
|
|
||||||
private final Map<String, String> requestParameters = new HashMap<>(8);
|
|
||||||
|
|
||||||
private final StringBuilder urlAppenderBuilder = new StringBuilder("");
|
|
||||||
|
|
||||||
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);
|
|
||||||
// make a copy
|
|
||||||
this.timeoutSettings = new TimeoutSettings(timeoutSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TimeoutSettings getTimeoutSettings() {
|
|
||||||
return timeoutSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UnitSystem getUnitSystem() {
|
|
||||||
return unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUnitSystem(UnitSystem unitSystem) {
|
|
||||||
this.putRequestParameter(UNITS_PARAM, unitSystem.getValue());
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Language getLanguage() {
|
|
||||||
return language;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLanguage(Language language) {
|
|
||||||
this.putRequestParameter(LANG_PARAM, language.getValue());
|
|
||||||
this.language = language;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResponseType(ResponseType responseType) {
|
|
||||||
this.putRequestParameter(MODE_PARAM, responseType.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void putRequestParameter(String key, String value) {
|
|
||||||
this.requestParameters.put(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeRequestParameter(String key) {
|
|
||||||
this.requestParameters.remove(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> getRequestParameters() {
|
|
||||||
return requestParameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void appendToURL(String appendix) {
|
|
||||||
urlAppenderBuilder.append(appendix);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUseApi3() {
|
|
||||||
this.useApi3 = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getUseApi3() {
|
|
||||||
return this.useApi3;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringBuilder getUrlAppender() {
|
|
||||||
return urlAppenderBuilder;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,39 +20,27 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.conf;
|
package com.github.prominence.openweathermap.api.request;
|
||||||
|
|
||||||
public class TimeoutSettings {
|
/**
|
||||||
private Integer connectionTimeout;
|
* The interface Request terminator.
|
||||||
private Integer readTimeout;
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param <S> the type parameter
|
||||||
|
*/
|
||||||
|
public interface RequestTerminator<T, S> {
|
||||||
|
|
||||||
public TimeoutSettings() {
|
/**
|
||||||
this(2000, 2000);
|
* Java object response format.
|
||||||
}
|
*
|
||||||
|
* @return the java object
|
||||||
|
*/
|
||||||
|
T asJava();
|
||||||
|
|
||||||
public TimeoutSettings(Integer connectionTimeout, Integer readTimeout) {
|
/**
|
||||||
this.connectionTimeout = connectionTimeout;
|
* JSON response format.
|
||||||
this.readTimeout = readTimeout;
|
*
|
||||||
}
|
* @return the JSON string
|
||||||
|
*/
|
||||||
public TimeoutSettings(TimeoutSettings from) {
|
S asJSON();
|
||||||
this.connectionTimeout = from.connectionTimeout;
|
|
||||||
this.readTimeout = from.readTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getConnectionTimeout() {
|
|
||||||
return connectionTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConnectionTimeout(Integer connectionTimeout) {
|
|
||||||
this.connectionTimeout = connectionTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getReadTimeout() {
|
|
||||||
return readTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReadTimeout(Integer readTimeout) {
|
|
||||||
this.readTimeout = readTimeout;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Request url builder.
|
||||||
|
*/
|
||||||
|
public class RequestUrlBuilder {
|
||||||
|
|
||||||
|
private static final String API_KEY_PARAM_NAME = "appid";
|
||||||
|
|
||||||
|
private final StringBuilder builder = new StringBuilder("http://api.openweathermap.org/data/2.5/");
|
||||||
|
private final Map<String, Object> requestParameters = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Request url builder.
|
||||||
|
*
|
||||||
|
* @param key the API key
|
||||||
|
*/
|
||||||
|
public RequestUrlBuilder(String key) {
|
||||||
|
requestParameters.put(API_KEY_PARAM_NAME, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends value.
|
||||||
|
*
|
||||||
|
* @param value the value
|
||||||
|
*/
|
||||||
|
public void append(String value) {
|
||||||
|
builder.append(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds request parameter.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
*/
|
||||||
|
public void addRequestParameter(String key, Object value) {
|
||||||
|
requestParameters.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies customization.
|
||||||
|
*
|
||||||
|
* @param language the language
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
public void applyCustomization(Language language, UnitSystem unitSystem) {
|
||||||
|
if (language != null) {
|
||||||
|
addRequestParameter("lang", language.getValue());
|
||||||
|
}
|
||||||
|
if (unitSystem != null && unitSystem != UnitSystem.STANDARD) {
|
||||||
|
addRequestParameter("units", unitSystem.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds url string.
|
||||||
|
*
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
public String buildUrl() {
|
||||||
|
final String joinedParameters = requestParameters.entrySet().stream()
|
||||||
|
.map(entry -> entry.getKey() + "=" + entry.getValue())
|
||||||
|
.collect(Collectors.joining("&"));
|
||||||
|
builder.append('?');
|
||||||
|
builder.append(joinedParameters);
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * 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.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.AirPollutionResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Air pollution async request terminator.
|
|
||||||
*/
|
|
||||||
public class AirPollutionAsyncRequestTerminator {
|
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Air pollution async request terminator.
|
|
||||||
*
|
|
||||||
* @param requestSettings request settings object.
|
|
||||||
*/
|
|
||||||
public AirPollutionAsyncRequestTerminator(RequestSettings requestSettings) {
|
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<AirPollutionDetails> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new AirPollutionResponseMapper().mapToAirPollution(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * 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.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Air Pollution request customizer.
|
|
||||||
*/
|
|
||||||
public class AirPollutionRequestCustomizer {
|
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Air pollution request customizer.
|
|
||||||
*
|
|
||||||
* @param requestSettings request settings object.
|
|
||||||
*/
|
|
||||||
public AirPollutionRequestCustomizer(RequestSettings requestSettings) {
|
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AirPollutionRequestTerminator retrieve() {
|
|
||||||
return new AirPollutionRequestTerminator(requestSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AirPollutionAsyncRequestTerminator retrieveAsync() {
|
|
||||||
return new AirPollutionAsyncRequestTerminator(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * 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.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.AirPollutionResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Air pollution request terminator.
|
|
||||||
*/
|
|
||||||
public class AirPollutionRequestTerminator {
|
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Air pollution request terminator.
|
|
||||||
*
|
|
||||||
* @param requestSettings request settings object.
|
|
||||||
*/
|
|
||||||
public AirPollutionRequestTerminator(RequestSettings requestSettings) {
|
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AirPollutionDetails asJava() {
|
|
||||||
return new AirPollutionResponseMapper().mapToAirPollution(getRawResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * 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.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Air pollution requester.
|
|
||||||
*/
|
|
||||||
public class AirPollutionRequester {
|
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Air pollution requester.
|
|
||||||
*
|
|
||||||
* @param requestSettings request settings object.
|
|
||||||
*/
|
|
||||||
public AirPollutionRequester(RequestSettings requestSettings) {
|
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CurrentAirPollutionRequester current() {
|
|
||||||
requestSettings.appendToURL("air_pollution");
|
|
||||||
return new CurrentAirPollutionRequester(requestSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ForecastAirPollutionRequester forecast() {
|
|
||||||
requestSettings.appendToURL("air_pollution/forecast");
|
|
||||||
return new ForecastAirPollutionRequester(requestSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public HistoricalAirPollutionRequester historical() {
|
|
||||||
requestSettings.appendToURL("air_pollution/history");
|
|
||||||
return new HistoricalAirPollutionRequester(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -22,43 +22,21 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.ResponseType;
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.FiveDayThreeHourStepForecastResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Async request terminator.
|
* The forecast async request terminator interface.
|
||||||
*/
|
*/
|
||||||
public class FiveDayThreeHourStepForecastAsyncRequestTerminator {
|
public interface FiveDayThreeHourStepForecastAsyncRequestTerminator extends AsyncRequestTerminator<Forecast, String> {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new async request terminator.
|
* XML response format.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @return the completable future
|
||||||
*/
|
*/
|
||||||
FiveDayThreeHourStepForecastAsyncRequestTerminator(RequestSettings requestSettings) {
|
CompletableFuture<String> asXML();
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<Forecast> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new FiveDayThreeHourStepForecastResponseMapper(requestSettings.getUnitSystem()).mapToForecast(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<String> asXML() {
|
|
||||||
requestSettings.setResponseType(ResponseType.XML);
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* 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.forecast.free;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Async request terminator.
|
||||||
|
*/
|
||||||
|
public class FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl implements FiveDayThreeHourStepForecastAsyncRequestTerminator {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new async request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Forecast> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new FiveDayThreeHourStepForecastResponseMapper(unitSystem).mapToForecast(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asXML() {
|
||||||
|
urlBuilder.addRequestParameter("mode", "xml");
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,45 +22,31 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The forecast request customizer.
|
* The forecast request customizer interface.
|
||||||
*/
|
*/
|
||||||
public class FiveDayThreeHourStepForecastRequestCustomizer {
|
public interface FiveDayThreeHourStepForecastRequestCustomizer extends RequestCustomizer<FiveDayThreeHourStepForecastRequestCustomizer> {
|
||||||
private final RequestSettings requestSettings;
|
/**
|
||||||
|
* Count customizer.
|
||||||
|
*
|
||||||
|
* @param numberOfTimestamps the number of timestamps
|
||||||
|
* @return forecast request customizer
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestCustomizer count(int numberOfTimestamps);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new forecast request customizer.
|
* Retrieve forecast request terminator.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @return forecast request terminator
|
||||||
*/
|
*/
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer(RequestSettings requestSettings) {
|
FiveDayThreeHourStepForecastRequestTerminator retrieve();
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer language(Language language) {
|
/**
|
||||||
requestSettings.setLanguage(language);
|
* Retrieve forecast async request terminator.
|
||||||
return this;
|
*
|
||||||
}
|
* @return forecast async request terminator
|
||||||
|
*/
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
FiveDayThreeHourStepForecastAsyncRequestTerminator retrieveAsync();
|
||||||
requestSettings.setUnitSystem(unitSystem);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer count(int numberOfTimestamps) {
|
|
||||||
requestSettings.putRequestParameter("cnt", Integer.toString(numberOfTimestamps));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FiveDayThreeHourStepForecastRequestTerminator retrieve() {
|
|
||||||
return new FiveDayThreeHourStepForecastRequestTerminator(requestSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FiveDayThreeHourStepForecastAsyncRequestTerminator retrieveAsync() {
|
|
||||||
return new FiveDayThreeHourStepForecastAsyncRequestTerminator(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* 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.forecast.free;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The forecast request customizer.
|
||||||
|
*/
|
||||||
|
public class FiveDayThreeHourStepForecastRequestCustomizerImpl implements FiveDayThreeHourStepForecastRequestCustomizer {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
private Language language;
|
||||||
|
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
||||||
|
private int count = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new forecast request customizer.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer language(Language language) {
|
||||||
|
this.language = language;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer count(int numberOfTimestamps) {
|
||||||
|
count = numberOfTimestamps;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestTerminator retrieve() {
|
||||||
|
applyCustomization();
|
||||||
|
return new FiveDayThreeHourStepForecastRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastAsyncRequestTerminator retrieveAsync() {
|
||||||
|
applyCustomization();
|
||||||
|
return new FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyCustomization() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
if (count >= 0) {
|
||||||
|
urlBuilder.addRequestParameter("cnt", count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,41 +22,19 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.ResponseType;
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.FiveDayThreeHourStepForecastResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The forecast request terminator.
|
* The forecast request terminator interface.
|
||||||
*/
|
*/
|
||||||
public class FiveDayThreeHourStepForecastRequestTerminator {
|
public interface FiveDayThreeHourStepForecastRequestTerminator extends RequestTerminator<Forecast, String> {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new forecast request terminator.
|
* XML response format.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @return the XML string
|
||||||
*/
|
*/
|
||||||
FiveDayThreeHourStepForecastRequestTerminator(RequestSettings requestSettings) {
|
String asXML();
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Forecast asJava() {
|
|
||||||
return new FiveDayThreeHourStepForecastResponseMapper(requestSettings.getUnitSystem()).mapToForecast(getRawResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String asXML() {
|
|
||||||
requestSettings.setResponseType(ResponseType.XML);
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* 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.forecast.free;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The forecast request terminator.
|
||||||
|
*/
|
||||||
|
public class FiveDayThreeHourStepForecastRequestTerminatorImpl implements FiveDayThreeHourStepForecastRequestTerminator {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new forecast request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Forecast asJava() {
|
||||||
|
return new FiveDayThreeHourStepForecastResponseMapper(unitSystem).mapToForecast(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asXML() {
|
||||||
|
urlBuilder.addRequestParameter("mode", "xml");
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,57 +23,69 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The forecast requester.
|
* An interface for <a href="https://openweathermap.org/forecast5">API</a> methods.
|
||||||
*/
|
*/
|
||||||
public class FiveDayThreeHourStepForecastRequester {
|
public interface FiveDayThreeHourStepForecastRequester {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new forecast requester.
|
* By city name forecast request customizer.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @param cityName the city name
|
||||||
|
* @return the forecast request customizer
|
||||||
*/
|
*/
|
||||||
public FiveDayThreeHourStepForecastRequester(RequestSettings requestSettings) {
|
FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName);
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
this.requestSettings.appendToURL("forecast");
|
|
||||||
}
|
|
||||||
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName) {
|
/**
|
||||||
requestSettings.putRequestParameter("q", cityName);
|
* By city name forecast request customizer.
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
*
|
||||||
}
|
* @param cityName the city name
|
||||||
|
* @param stateCode the state code
|
||||||
|
* @return the forecast request customizer
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode);
|
||||||
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode) {
|
/**
|
||||||
requestSettings.putRequestParameter("q", cityName + "," + stateCode);
|
* By city name forecast request customizer.
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
*
|
||||||
}
|
* @param cityName the city name
|
||||||
|
* @param stateCode the state code
|
||||||
|
* @param countryCode the country code
|
||||||
|
* @return the forecast request customizer
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode, String countryCode);
|
||||||
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode, String countryCode) {
|
/**
|
||||||
requestSettings.putRequestParameter("q", cityName + "," + stateCode + "," + countryCode);
|
* By city id forecast request customizer.
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
*
|
||||||
}
|
* @param cityId the city id
|
||||||
|
* @return the forecast request customizer
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestCustomizer byCityId(long cityId);
|
||||||
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byCityId(long cityId) {
|
/**
|
||||||
requestSettings.putRequestParameter("id", Long.toString(cityId));
|
* By coordinate forecast request customizer.
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
*
|
||||||
}
|
* @param coordinate the coordinate
|
||||||
|
* @return the forecast request customizer
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestCustomizer byCoordinate(Coordinate coordinate);
|
||||||
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byCoordinate(Coordinate coordinate) {
|
/**
|
||||||
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
* By zip code and country forecast request customizer.
|
||||||
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
*
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
* @param zipCode the zip code
|
||||||
}
|
* @param countryCode the country code
|
||||||
|
* @return the forecast request customizer
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode);
|
||||||
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode) {
|
/**
|
||||||
requestSettings.putRequestParameter("zip", zipCode + "," + countryCode);
|
* By zip code in USA forecast request customizer.
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
*
|
||||||
}
|
* @param zipCode the zip code
|
||||||
|
* @return the forecast request customizer
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byZipCodeInUSA(String zipCode) {
|
*/
|
||||||
requestSettings.putRequestParameter("zip", zipCode);
|
FiveDayThreeHourStepForecastRequestCustomizer byZipCodeInUSA(String zipCode);
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* 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.forecast.free;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The forecast requester.
|
||||||
|
*/
|
||||||
|
public class FiveDayThreeHourStepForecastRequesterImpl implements FiveDayThreeHourStepForecastRequester {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new forecast requester.
|
||||||
|
*
|
||||||
|
* @param apiKey the api key
|
||||||
|
*/
|
||||||
|
public FiveDayThreeHourStepForecastRequesterImpl(String apiKey) {
|
||||||
|
urlBuilder = new RequestUrlBuilder(apiKey);
|
||||||
|
urlBuilder.append("forecast");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName) {
|
||||||
|
urlBuilder.addRequestParameter("q", cityName);
|
||||||
|
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode) {
|
||||||
|
urlBuilder.addRequestParameter("q", cityName + "," + stateCode);
|
||||||
|
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode, String countryCode) {
|
||||||
|
urlBuilder.addRequestParameter("q", cityName + "," + stateCode + "," + countryCode);
|
||||||
|
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer byCityId(long cityId) {
|
||||||
|
urlBuilder.addRequestParameter("id", cityId);
|
||||||
|
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer byCoordinate(Coordinate coordinate) {
|
||||||
|
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||||
|
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||||
|
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode) {
|
||||||
|
urlBuilder.addRequestParameter("zip", zipCode + "," + countryCode);
|
||||||
|
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer byZipCodeInUSA(String zipCode) {
|
||||||
|
urlBuilder.addRequestParameter("zip", zipCode);
|
||||||
|
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.mapper;
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
@ -22,30 +22,24 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall;
|
package com.github.prominence.openweathermap.api.request.onecall;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.current.OneCallCurrentWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.onecall.current.OneCallCurrentWeatherRequester;
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.historical.OneCallHistoricalWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.onecall.historical.OneCallHistoricalWeatherRequester;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type One call weather requester.
|
* The interface One call weather requester.
|
||||||
*/
|
*/
|
||||||
public class OneCallWeatherRequester {
|
public interface OneCallWeatherRequester {
|
||||||
private final RequestSettings requestSettings;
|
/**
|
||||||
|
* Current one call current weather requester.
|
||||||
|
*
|
||||||
|
* @return the one call current weather requester
|
||||||
|
*/
|
||||||
|
OneCallCurrentWeatherRequester current();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new One call weather requester.
|
* Historical one call historical weather requester.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @return the one call historical weather requester
|
||||||
*/
|
*/
|
||||||
public OneCallWeatherRequester(RequestSettings requestSettings) {
|
OneCallHistoricalWeatherRequester historical();
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OneCallCurrentWeatherRequester current() {
|
|
||||||
return new OneCallCurrentWeatherRequester(requestSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OneCallHistoricalWeatherRequester historical() {
|
|
||||||
return new OneCallHistoricalWeatherRequester(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.onecall.current.OneCallCurrentWeatherRequester;
|
||||||
|
import com.github.prominence.openweathermap.api.request.onecall.current.OneCallCurrentWeatherRequesterImpl;
|
||||||
|
import com.github.prominence.openweathermap.api.request.onecall.historical.OneCallHistoricalWeatherRequester;
|
||||||
|
import com.github.prominence.openweathermap.api.request.onecall.historical.OneCallHistoricalWeatherRequesterImpl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type One call weather requester.
|
||||||
|
*/
|
||||||
|
public class OneCallWeatherRequesterImpl implements OneCallWeatherRequester {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new One call weather requester.
|
||||||
|
*
|
||||||
|
* @param apiKey the api key
|
||||||
|
*/
|
||||||
|
public OneCallWeatherRequesterImpl(String apiKey) {
|
||||||
|
urlBuilder = new RequestUrlBuilder(apiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OneCallCurrentWeatherRequester current() {
|
||||||
|
return new OneCallCurrentWeatherRequesterImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OneCallHistoricalWeatherRequester historical() {
|
||||||
|
return new OneCallHistoricalWeatherRequesterImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.mapper;
|
package com.github.prominence.openweathermap.api.request.onecall;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
@ -72,7 +72,7 @@ public class OneCallWeatherResponseMapper {
|
|||||||
final JsonNode root = objectMapper.readTree(json);
|
final JsonNode root = objectMapper.readTree(json);
|
||||||
currentData = mapToCurrent(root);
|
currentData = mapToCurrent(root);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new RuntimeException("Cannot parse OneCall response");
|
throw new RuntimeException("Cannot parse Forecast response");
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentData;
|
return currentData;
|
||||||
@ -91,7 +91,7 @@ public class OneCallWeatherResponseMapper {
|
|||||||
final JsonNode root = objectMapper.readTree(json);
|
final JsonNode root = objectMapper.readTree(json);
|
||||||
historicalData = mapToHistorical(root);
|
historicalData = mapToHistorical(root);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new RuntimeException("Cannot parse OneCall response");
|
throw new RuntimeException("Cannot parse Forecast response");
|
||||||
}
|
}
|
||||||
|
|
||||||
return historicalData;
|
return historicalData;
|
||||||
@ -200,20 +200,7 @@ public class OneCallWeatherResponseMapper {
|
|||||||
daily.setForecastTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(dailyNode.get("dt").asInt()), TimeZone.getDefault().toZoneId()));
|
daily.setForecastTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(dailyNode.get("dt").asInt()), TimeZone.getDefault().toZoneId()));
|
||||||
daily.setSunriseTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(dailyNode.get("sunrise").asInt()), TimeZone.getDefault().toZoneId()));
|
daily.setSunriseTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(dailyNode.get("sunrise").asInt()), TimeZone.getDefault().toZoneId()));
|
||||||
daily.setSunsetTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(dailyNode.get("sunset").asInt()), TimeZone.getDefault().toZoneId()));
|
daily.setSunsetTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(dailyNode.get("sunset").asInt()), TimeZone.getDefault().toZoneId()));
|
||||||
final JsonNode moonriseTimeNode = dailyNode.get("moonrise");
|
|
||||||
if (moonriseTimeNode != null) {
|
|
||||||
daily.setMoonriseTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(moonriseTimeNode.asInt()), TimeZone.getDefault().toZoneId()));
|
|
||||||
}
|
|
||||||
final JsonNode moonsetTimeNode = dailyNode.get("moonset");
|
|
||||||
if (moonsetTimeNode != null) {
|
|
||||||
daily.setMoonsetTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(moonsetTimeNode.asInt()), TimeZone.getDefault().toZoneId()));
|
|
||||||
}
|
|
||||||
final JsonNode moonPhaseNode = dailyNode.get("moon_phase");
|
|
||||||
if (moonPhaseNode != null) {
|
|
||||||
daily.setMoonPhase(new MoonPhase(moonPhaseNode.asDouble()));
|
|
||||||
}
|
|
||||||
|
|
||||||
daily.setSummary(parseSummary(dailyNode));
|
|
||||||
daily.setWeatherState(parseWeatherState(dailyNode.get("weather").get(0)));
|
daily.setWeatherState(parseWeatherState(dailyNode.get("weather").get(0)));
|
||||||
daily.setTemperature(parseDailyTemperature(dailyNode));
|
daily.setTemperature(parseDailyTemperature(dailyNode));
|
||||||
daily.setAtmosphericPressure(parsePressure(dailyNode));
|
daily.setAtmosphericPressure(parsePressure(dailyNode));
|
||||||
@ -418,7 +405,7 @@ public class OneCallWeatherResponseMapper {
|
|||||||
if (snowNode != null) {
|
if (snowNode != null) {
|
||||||
final JsonNode OneHourNode = snowNode.get("1h");
|
final JsonNode OneHourNode = snowNode.get("1h");
|
||||||
if (OneHourNode != null) {
|
if (OneHourNode != null) {
|
||||||
return Snow.withOneHourLevelValue(OneHourNode.asDouble());
|
Rain.withOneHourLevelValue(OneHourNode.asDouble());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -440,12 +427,4 @@ public class OneCallWeatherResponseMapper {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String parseSummary(JsonNode dailyNode) {
|
|
||||||
final JsonNode summaryNode = dailyNode.get("summary");
|
|
||||||
if(summaryNode != null) {
|
|
||||||
return summaryNode.asText();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -22,37 +22,11 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
package com.github.prominence.openweathermap.api.request.onecall.current;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type One call current weather async request terminator.
|
* The interface One call current weather async request terminator.
|
||||||
*/
|
*/
|
||||||
public class OneCallCurrentWeatherAsyncRequestTerminator {
|
public interface OneCallCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<CurrentWeatherData, String> {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call current weather async request terminator.
|
|
||||||
*
|
|
||||||
* @param requestSettings request settings object.
|
|
||||||
*/
|
|
||||||
OneCallCurrentWeatherAsyncRequestTerminator(RequestSettings requestSettings) {
|
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<CurrentWeatherData> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new OneCallWeatherResponseMapper(requestSettings.getUnitSystem()).mapToCurrent(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* 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.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type One call current weather async request terminator.
|
||||||
|
*/
|
||||||
|
public class OneCallCurrentWeatherAsyncRequestTerminatorImpl implements OneCallCurrentWeatherAsyncRequestTerminator {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new One call current weather async request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
OneCallCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<CurrentWeatherData> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new OneCallWeatherResponseMapper(unitSystem).mapToCurrent(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,53 +22,32 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
package com.github.prominence.openweathermap.api.request.onecall.current;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.OneCallResultOptions;
|
import com.github.prominence.openweathermap.api.enums.OneCallResultOptions;
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type One call current weather request customizer.
|
* The interface One call current weather request customizer.
|
||||||
*/
|
*/
|
||||||
public class OneCallCurrentWeatherRequestCustomizer {
|
public interface OneCallCurrentWeatherRequestCustomizer extends RequestCustomizer<OneCallCurrentWeatherRequestCustomizer> {
|
||||||
private final RequestSettings requestSettings;
|
/**
|
||||||
|
* Exclude one call current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param excludeOptions the exclude options
|
||||||
|
* @return the one call current weather request customizer
|
||||||
|
*/
|
||||||
|
OneCallCurrentWeatherRequestCustomizer exclude(OneCallResultOptions... excludeOptions);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new One call current weather request customizer.
|
* Retrieve one call current weather request terminator.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @return the one call current weather request terminator
|
||||||
*/
|
*/
|
||||||
OneCallCurrentWeatherRequestCustomizer(RequestSettings requestSettings) {
|
OneCallCurrentWeatherRequestTerminator retrieve();
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OneCallCurrentWeatherRequestCustomizer language(Language language) {
|
/**
|
||||||
requestSettings.setLanguage(language);
|
* Retrieve async one call current weather async request terminator.
|
||||||
return this;
|
*
|
||||||
}
|
* @return the one call current weather async request terminator
|
||||||
|
*/
|
||||||
public OneCallCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
OneCallCurrentWeatherAsyncRequestTerminator retrieveAsync();
|
||||||
this.requestSettings.setUnitSystem(unitSystem);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OneCallCurrentWeatherRequestCustomizer exclude(OneCallResultOptions... excludeOptions) {
|
|
||||||
if (excludeOptions != null && excludeOptions.length > 0) {
|
|
||||||
requestSettings.putRequestParameter("exclude", Stream.of(excludeOptions).map(OneCallResultOptions::getValue).collect(Collectors.joining(",")));
|
|
||||||
} else {
|
|
||||||
requestSettings.removeRequestParameter("exclude");
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OneCallCurrentWeatherRequestTerminator retrieve() {
|
|
||||||
return new OneCallCurrentWeatherRequestTerminator(requestSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OneCallCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
|
||||||
return new OneCallCurrentWeatherAsyncRequestTerminator(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* 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.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.OneCallResultOptions;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type One call current weather request customizer.
|
||||||
|
*/
|
||||||
|
public class OneCallCurrentWeatherRequestCustomizerImpl implements OneCallCurrentWeatherRequestCustomizer {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
private Language language;
|
||||||
|
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
||||||
|
private OneCallResultOptions[] excludeOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new One call current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
*/
|
||||||
|
OneCallCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OneCallCurrentWeatherRequestCustomizer language(Language language) {
|
||||||
|
this.language = language;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OneCallCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OneCallCurrentWeatherRequestCustomizer exclude(OneCallResultOptions... excludeOptions) {
|
||||||
|
this.excludeOptions = excludeOptions;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OneCallCurrentWeatherRequestTerminator retrieve() {
|
||||||
|
applyCustomization();
|
||||||
|
return new OneCallCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OneCallCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
||||||
|
applyCustomization();
|
||||||
|
return new OneCallCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyCustomization() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
if (excludeOptions != null) {
|
||||||
|
urlBuilder.addRequestParameter("exclude", Stream.of(excludeOptions).map(OneCallResultOptions::getValue).collect(Collectors.joining(",")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,35 +22,12 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
package com.github.prominence.openweathermap.api.request.onecall.current;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type One call current weather request terminator.
|
* The interface One call current weather request terminator.
|
||||||
*/
|
*/
|
||||||
public class OneCallCurrentWeatherRequestTerminator {
|
public interface OneCallCurrentWeatherRequestTerminator extends RequestTerminator<CurrentWeatherData, String> {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call current weather request terminator.
|
|
||||||
*
|
|
||||||
* @param requestSettings request settings object.
|
|
||||||
*/
|
|
||||||
OneCallCurrentWeatherRequestTerminator(RequestSettings requestSettings) {
|
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CurrentWeatherData asJava() {
|
|
||||||
return new OneCallWeatherResponseMapper(requestSettings.getUnitSystem()).mapToCurrent(getRawResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type One call current weather request terminator.
|
||||||
|
*/
|
||||||
|
public class OneCallCurrentWeatherRequestTerminatorImpl implements OneCallCurrentWeatherRequestTerminator {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new One call current weather request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
OneCallCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CurrentWeatherData asJava() {
|
||||||
|
return new OneCallWeatherResponseMapper(unitSystem).mapToCurrent(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,27 +23,16 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
package com.github.prominence.openweathermap.api.request.onecall.current;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type One call current weather requester.
|
* The interface One call current weather requester.
|
||||||
*/
|
*/
|
||||||
public class OneCallCurrentWeatherRequester {
|
public interface OneCallCurrentWeatherRequester {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new One call current weather requester.
|
* By coordinate one call current weather request customizer.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @param coordinate the coordinate
|
||||||
|
* @return the one call current weather request customizer
|
||||||
*/
|
*/
|
||||||
public OneCallCurrentWeatherRequester(RequestSettings requestSettings) {
|
OneCallCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate);
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
this.requestSettings.appendToURL("onecall");
|
|
||||||
}
|
|
||||||
|
|
||||||
public OneCallCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate) {
|
|
||||||
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
|
||||||
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
|
||||||
return new OneCallCurrentWeatherRequestCustomizer(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,29 +20,31 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
package com.github.prominence.openweathermap.api.request.onecall.current;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Forecast air pollution requester.
|
* The type One call current weather requester.
|
||||||
*/
|
*/
|
||||||
public class ForecastAirPollutionRequester {
|
public class OneCallCurrentWeatherRequesterImpl implements OneCallCurrentWeatherRequester {
|
||||||
private final RequestSettings requestSettings;
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Forecast air pollution requester.
|
* Instantiates a new One call current weather requester.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @param urlBuilder the url builder
|
||||||
*/
|
*/
|
||||||
public ForecastAirPollutionRequester(RequestSettings requestSettings) {
|
public OneCallCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
|
||||||
this.requestSettings = requestSettings;
|
this.urlBuilder = urlBuilder;
|
||||||
|
urlBuilder.append("onecall");
|
||||||
}
|
}
|
||||||
|
|
||||||
public AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate) {
|
@Override
|
||||||
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
public OneCallCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate) {
|
||||||
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||||
return new AirPollutionRequestCustomizer(requestSettings);
|
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||||
|
return new OneCallCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -22,37 +22,11 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type One call historical weather async request terminator.
|
* The interface One call historical weather async request terminator.
|
||||||
*/
|
*/
|
||||||
public class OneCallHistoricalWeatherAsyncRequestTerminator {
|
public interface OneCallHistoricalWeatherAsyncRequestTerminator extends AsyncRequestTerminator<HistoricalWeatherData, String> {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call historical weather async request terminator.
|
|
||||||
*
|
|
||||||
* @param requestSettings request settings object.
|
|
||||||
*/
|
|
||||||
public OneCallHistoricalWeatherAsyncRequestTerminator(RequestSettings requestSettings) {
|
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<HistoricalWeatherData> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new OneCallWeatherResponseMapper(requestSettings.getUnitSystem()).mapToHistorical(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* 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.historical;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type One call historical weather async request terminator.
|
||||||
|
*/
|
||||||
|
public class OneCallHistoricalWeatherAsyncRequestTerminatorImpl implements OneCallHistoricalWeatherAsyncRequestTerminator {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new One call historical weather async request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
public OneCallHistoricalWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<HistoricalWeatherData> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new OneCallWeatherResponseMapper(unitSystem).mapToHistorical(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,40 +22,23 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type One call historical weather request customizer.
|
* The interface One call historical weather request customizer.
|
||||||
*/
|
*/
|
||||||
public class OneCallHistoricalWeatherRequestCustomizer {
|
public interface OneCallHistoricalWeatherRequestCustomizer extends RequestCustomizer<OneCallHistoricalWeatherRequestCustomizer> {
|
||||||
private final RequestSettings requestSettings;
|
/**
|
||||||
|
* Retrieve one call historical weather request terminator.
|
||||||
|
*
|
||||||
|
* @return the one call historical weather request terminator
|
||||||
|
*/
|
||||||
|
OneCallHistoricalWeatherRequestTerminator retrieve();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new One call historical weather request customizer.
|
* Retrieve async one call historical weather async request terminator.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @return the one call historical weather async request terminator
|
||||||
*/
|
*/
|
||||||
public OneCallHistoricalWeatherRequestCustomizer(RequestSettings requestSettings) {
|
OneCallHistoricalWeatherAsyncRequestTerminator retrieveAsync();
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OneCallHistoricalWeatherRequestCustomizer language(Language language) {
|
|
||||||
requestSettings.setLanguage(language);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OneCallHistoricalWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
|
||||||
requestSettings.setUnitSystem(unitSystem);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OneCallHistoricalWeatherRequestTerminator retrieve() {
|
|
||||||
return new OneCallHistoricalWeatherRequestTerminator(requestSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OneCallHistoricalWeatherAsyncRequestTerminator retrieveAsync() {
|
|
||||||
return new OneCallHistoricalWeatherAsyncRequestTerminator(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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.historical;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type One call historical weather request customizer.
|
||||||
|
*/
|
||||||
|
public class OneCallHistoricalWeatherRequestCustomizerImpl implements OneCallHistoricalWeatherRequestCustomizer {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
private Language language;
|
||||||
|
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new One call historical weather request customizer.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
*/
|
||||||
|
public OneCallHistoricalWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OneCallHistoricalWeatherRequestCustomizer language(Language language) {
|
||||||
|
this.language = language;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OneCallHistoricalWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OneCallHistoricalWeatherRequestTerminator retrieve() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
return new OneCallHistoricalWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OneCallHistoricalWeatherAsyncRequestTerminator retrieveAsync() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
return new OneCallHistoricalWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,35 +22,11 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type One call historical weather request terminator.
|
* The interface One call historical weather request terminator.
|
||||||
*/
|
*/
|
||||||
public class OneCallHistoricalWeatherRequestTerminator {
|
public interface OneCallHistoricalWeatherRequestTerminator extends RequestTerminator<HistoricalWeatherData, String> {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call historical weather request terminator.
|
|
||||||
*
|
|
||||||
* @param requestSettings request settings object.
|
|
||||||
*/
|
|
||||||
public OneCallHistoricalWeatherRequestTerminator(RequestSettings requestSettings) {
|
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HistoricalWeatherData asJava() {
|
|
||||||
return new OneCallWeatherResponseMapper(requestSettings.getUnitSystem()).mapToHistorical(getRawResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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.historical;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type One call historical weather request terminator.
|
||||||
|
*/
|
||||||
|
public class OneCallHistoricalWeatherRequestTerminatorImpl implements OneCallHistoricalWeatherRequestTerminator {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new One call historical weather request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
public OneCallHistoricalWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HistoricalWeatherData asJava() {
|
||||||
|
return new OneCallWeatherResponseMapper(unitSystem).mapToHistorical(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,28 +23,17 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type One call historical weather requester.
|
* The interface One call historical weather requester.
|
||||||
*/
|
*/
|
||||||
public class OneCallHistoricalWeatherRequester {
|
public interface OneCallHistoricalWeatherRequester {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new One call historical weather requester.
|
* By coordinate and timestamp one call historical weather request customizer.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @param coordinate the coordinate
|
||||||
|
* @param unixTime the unix time
|
||||||
|
* @return the one call historical weather request customizer
|
||||||
*/
|
*/
|
||||||
public OneCallHistoricalWeatherRequester(RequestSettings requestSettings) {
|
OneCallHistoricalWeatherRequestCustomizer byCoordinateAndTimestamp(Coordinate coordinate, long unixTime);
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
this.requestSettings.appendToURL("onecall/timemachine");
|
|
||||||
}
|
|
||||||
|
|
||||||
public OneCallHistoricalWeatherRequestCustomizer byCoordinateAndTimestamp(Coordinate coordinate, long unixTime) {
|
|
||||||
requestSettings.putRequestParameter("lat", Double.toString(coordinate.getLatitude()));
|
|
||||||
requestSettings.putRequestParameter("lon", Double.toString(coordinate.getLongitude()));
|
|
||||||
requestSettings.putRequestParameter("dt", Long.toString(unixTime));
|
|
||||||
return new OneCallHistoricalWeatherRequestCustomizer(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,31 +20,32 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Historical air pollution requester.
|
* The type One call historical weather requester.
|
||||||
*/
|
*/
|
||||||
public class HistoricalAirPollutionRequester {
|
public class OneCallHistoricalWeatherRequesterImpl implements OneCallHistoricalWeatherRequester {
|
||||||
private final RequestSettings requestSettings;
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Historical air pollution requester.
|
* Instantiates a new One call historical weather requester.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @param urlBuilder the url builder
|
||||||
*/
|
*/
|
||||||
public HistoricalAirPollutionRequester(RequestSettings requestSettings) {
|
public OneCallHistoricalWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
|
||||||
this.requestSettings = requestSettings;
|
this.urlBuilder = urlBuilder;
|
||||||
|
urlBuilder.append("onecall/timemachine");
|
||||||
}
|
}
|
||||||
|
|
||||||
public AirPollutionRequestCustomizer byCoordinateAndPeriod(Coordinate coordinate, long startUnixTime, long endUnixTime) {
|
@Override
|
||||||
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
public OneCallHistoricalWeatherRequestCustomizer byCoordinateAndTimestamp(Coordinate coordinate, long unixTime) {
|
||||||
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
urlBuilder.addRequestParameter("lat", coordinate.getLatitude());
|
||||||
requestSettings.putRequestParameter("start", String.valueOf(startUnixTime));
|
urlBuilder.addRequestParameter("lon", coordinate.getLongitude());
|
||||||
requestSettings.putRequestParameter("end", String.valueOf(endUnixTime));
|
urlBuilder.addRequestParameter("dt", unixTime);
|
||||||
return new AirPollutionRequestCustomizer(requestSettings);
|
return new OneCallHistoricalWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -22,30 +22,25 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather;
|
package com.github.prominence.openweathermap.api.request.weather;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsCurrentWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsCurrentWeatherRequester;
|
||||||
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequester;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Current weather requester.
|
* An interface for <a href="https://openweathermap.org/current">API</a> methods.
|
||||||
*/
|
*/
|
||||||
public class CurrentWeatherRequester {
|
public interface CurrentWeatherRequester {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Current weather requester.
|
* Single location current weather requester.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @return the single location current weather requester
|
||||||
*/
|
*/
|
||||||
public CurrentWeatherRequester(RequestSettings requestSettings) {
|
SingleLocationCurrentWeatherRequester single();
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SingleLocationCurrentWeatherRequester single() {
|
/**
|
||||||
return new SingleLocationCurrentWeatherRequester(requestSettings);
|
* Multiple locations current weather requester.
|
||||||
}
|
*
|
||||||
|
* @return the multiple locations current weather requester
|
||||||
public MultipleLocationsCurrentWeatherRequester multiple() {
|
*/
|
||||||
return new MultipleLocationsCurrentWeatherRequester(requestSettings);
|
MultipleLocationsCurrentWeatherRequester multiple();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* 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.weather;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsCurrentWeatherRequesterImpl;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsCurrentWeatherRequester;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequesterImpl;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequester;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Current weather requester.
|
||||||
|
*/
|
||||||
|
public class CurrentWeatherRequesterImpl implements CurrentWeatherRequester {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Current weather requester.
|
||||||
|
*
|
||||||
|
* @param apiKey the api key
|
||||||
|
*/
|
||||||
|
public CurrentWeatherRequesterImpl(String apiKey) {
|
||||||
|
urlBuilder = new RequestUrlBuilder(apiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleLocationCurrentWeatherRequester single() {
|
||||||
|
return new SingleLocationCurrentWeatherRequesterImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipleLocationsCurrentWeatherRequester multiple() {
|
||||||
|
return new MultipleLocationsCurrentWeatherRequesterImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.mapper;
|
package com.github.prominence.openweathermap.api.request.weather;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
@ -24,45 +24,36 @@ package com.github.prominence.openweathermap.api.request.weather.multiple;
|
|||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
|
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Multiple locations current weather requester.
|
* The interface Multiple locations current weather requester.
|
||||||
*/
|
*/
|
||||||
public class MultipleLocationsCurrentWeatherRequester {
|
public interface MultipleLocationsCurrentWeatherRequester {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Multiple locations current weather requester.
|
* By rectangle multiple result current weather request customizer.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @param rectangle the rectangle
|
||||||
|
* @param zoom the zoom
|
||||||
|
* @return the multiple result current weather request customizer
|
||||||
*/
|
*/
|
||||||
public MultipleLocationsCurrentWeatherRequester(RequestSettings requestSettings) {
|
MultipleResultCurrentWeatherRequestCustomizer byRectangle(CoordinateRectangle rectangle, int zoom);
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MultipleResultCurrentWeatherRequestCustomizer byRectangle(CoordinateRectangle rectangle, int zoom) {
|
/**
|
||||||
String coordinates = rectangle.getFormattedRequestString() + "," + zoom;
|
* By cities in cycle multiple result current weather request customizer.
|
||||||
requestSettings.appendToURL("box/city");
|
*
|
||||||
requestSettings.putRequestParameter("bbox", coordinates);
|
* @param point the point
|
||||||
|
* @return the multiple result cities in circle current weather request customizer
|
||||||
|
*/
|
||||||
|
MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point);
|
||||||
|
|
||||||
return new MultipleResultCurrentWeatherRequestCustomizer(requestSettings);
|
/**
|
||||||
}
|
* By cities in cycle multiple result current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param point the point
|
||||||
|
* @param citiesCount the cities count
|
||||||
|
* @return the multiple result cities in circle current weather request customizer
|
||||||
|
*/
|
||||||
|
MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point, int citiesCount);
|
||||||
|
|
||||||
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point, int citiesCount) {
|
|
||||||
requestSettings.appendToURL("find");
|
|
||||||
requestSettings.putRequestParameter("lat", Double.toString(point.getLatitude()));
|
|
||||||
requestSettings.putRequestParameter("lon", Double.toString(point.getLongitude()));
|
|
||||||
requestSettings.putRequestParameter("cnt", Integer.toString(citiesCount));
|
|
||||||
|
|
||||||
return new MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer(requestSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point) {
|
|
||||||
requestSettings.appendToURL("find");
|
|
||||||
requestSettings.putRequestParameter("lat", Double.toString(point.getLatitude()));
|
|
||||||
requestSettings.putRequestParameter("lon", Double.toString(point.getLongitude()));
|
|
||||||
|
|
||||||
return new MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* 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.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Multiple locations current weather requester.
|
||||||
|
*/
|
||||||
|
public class MultipleLocationsCurrentWeatherRequesterImpl implements MultipleLocationsCurrentWeatherRequester {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Multiple locations current weather requester.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
*/
|
||||||
|
public MultipleLocationsCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCurrentWeatherRequestCustomizer byRectangle(CoordinateRectangle rectangle, int zoom) {
|
||||||
|
String coordinates = rectangle.getFormattedRequestString() + "," + zoom;
|
||||||
|
urlBuilder.append("box/city");
|
||||||
|
urlBuilder.addRequestParameter("bbox", coordinates);
|
||||||
|
|
||||||
|
return new MultipleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point, int citiesCount) {
|
||||||
|
urlBuilder.append("find");
|
||||||
|
urlBuilder.addRequestParameter("lat", Double.toString(point.getLatitude()));
|
||||||
|
urlBuilder.addRequestParameter("lon", Double.toString(point.getLongitude()));
|
||||||
|
urlBuilder.addRequestParameter("cnt", Integer.toString(citiesCount));
|
||||||
|
|
||||||
|
return new MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point) {
|
||||||
|
urlBuilder.append("find");
|
||||||
|
urlBuilder.addRequestParameter("lat", Double.toString(point.getLatitude()));
|
||||||
|
urlBuilder.addRequestParameter("lon", Double.toString(point.getLongitude()));
|
||||||
|
|
||||||
|
return new MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,44 +22,20 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.ResponseType;
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
||||||
import com.github.prominence.openweathermap.api.mapper.CurrentWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Multiple result current weather async request terminator.
|
* The interface Multiple result current weather async request terminator.
|
||||||
*/
|
*/
|
||||||
public class MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator {
|
public interface MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<List<Weather>, String> {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Multiple result current weather async request terminator.
|
* XML response format.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @return the completable future
|
||||||
*/
|
*/
|
||||||
MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator(RequestSettings requestSettings) {
|
CompletableFuture<String> asXML();
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<List<Weather>> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(requestSettings.getUnitSystem()).getList(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<String> asXML() {
|
|
||||||
requestSettings.setResponseType(ResponseType.XML);
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* 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.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Multiple result current weather async request terminator.
|
||||||
|
*/
|
||||||
|
public class MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl implements MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Multiple result current weather async request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<List<Weather>> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asXML() {
|
||||||
|
urlBuilder.addRequestParameter("mode", "xml");
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,40 +22,23 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Multiple result current weather request customizer.
|
* The interface Multiple result current weather request customizer.
|
||||||
*/
|
*/
|
||||||
public class MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer {
|
public interface MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer extends RequestCustomizer<MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer> {
|
||||||
private final RequestSettings requestSettings;
|
/**
|
||||||
|
* Retrieve multiple result current weather request terminator.
|
||||||
|
*
|
||||||
|
* @return the multiple result current weather request terminator
|
||||||
|
*/
|
||||||
|
MultipleResultCitiesInCircleCurrentWeatherRequestTerminator retrieve();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Multiple result current weather request customizer.
|
* Retrieve async multiple result current weather async request terminator.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @return the multiple result current weather async request terminator
|
||||||
*/
|
*/
|
||||||
MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer(RequestSettings requestSettings) {
|
MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator retrieveAsync();
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer language(Language language) {
|
|
||||||
requestSettings.setLanguage(language);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
|
||||||
requestSettings.setUnitSystem(unitSystem);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MultipleResultCitiesInCircleCurrentWeatherRequestTerminator retrieve() {
|
|
||||||
return new MultipleResultCitiesInCircleCurrentWeatherRequestTerminator(requestSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
|
||||||
return new MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Multiple result current weather request customizer.
|
||||||
|
*/
|
||||||
|
public class MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl implements MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
private Language language;
|
||||||
|
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Multiple result current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
*/
|
||||||
|
MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer language(Language language) {
|
||||||
|
this.language = language;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherRequestTerminator retrieve() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
return new MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
return new MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,43 +22,19 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.ResponseType;
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
||||||
import com.github.prominence.openweathermap.api.mapper.CurrentWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Multiple result current weather request terminator.
|
* The interface Multiple result current weather request terminator.
|
||||||
*/
|
*/
|
||||||
public class MultipleResultCitiesInCircleCurrentWeatherRequestTerminator {
|
public interface MultipleResultCitiesInCircleCurrentWeatherRequestTerminator extends RequestTerminator<List<Weather>, String> {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Multiple result current weather request terminator.
|
* XML response format.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @return the XML string
|
||||||
*/
|
*/
|
||||||
MultipleResultCitiesInCircleCurrentWeatherRequestTerminator(RequestSettings requestSettings) {
|
String asXML();
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Weather> asJava() {
|
|
||||||
return new CurrentWeatherResponseMapper(requestSettings.getUnitSystem()).getList(getRawResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String asXML() {
|
|
||||||
requestSettings.setResponseType(ResponseType.XML);
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Multiple result current weather request terminator.
|
||||||
|
*/
|
||||||
|
public class MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl implements MultipleResultCitiesInCircleCurrentWeatherRequestTerminator {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Multiple result current weather request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Weather> asJava() {
|
||||||
|
return new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asXML() {
|
||||||
|
urlBuilder.addRequestParameter("mode", "xml");
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,37 +23,12 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
||||||
import com.github.prominence.openweathermap.api.mapper.CurrentWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Multiple result current weather async request terminator.
|
* The interface Multiple result current weather async request terminator.
|
||||||
*/
|
*/
|
||||||
public class MultipleResultCurrentWeatherAsyncRequestTerminator {
|
public interface MultipleResultCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<List<Weather>, String> {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Multiple result current weather async request terminator.
|
|
||||||
*
|
|
||||||
* @param requestSettings request settings object.
|
|
||||||
*/
|
|
||||||
MultipleResultCurrentWeatherAsyncRequestTerminator(RequestSettings requestSettings) {
|
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<List<Weather>> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(requestSettings.getUnitSystem()).getList(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* 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.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Multiple result current weather async request terminator.
|
||||||
|
*/
|
||||||
|
public class MultipleResultCurrentWeatherAsyncRequestTerminatorImpl implements MultipleResultCurrentWeatherAsyncRequestTerminator {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Multiple result current weather async request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
MultipleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<List<Weather>> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,40 +22,23 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Multiple result current weather request customizer.
|
* The interface Multiple result current weather request customizer.
|
||||||
*/
|
*/
|
||||||
public class MultipleResultCurrentWeatherRequestCustomizer {
|
public interface MultipleResultCurrentWeatherRequestCustomizer extends RequestCustomizer<MultipleResultCurrentWeatherRequestCustomizer> {
|
||||||
private final RequestSettings requestSettings;
|
/**
|
||||||
|
* Retrieve multiple result current weather request terminator.
|
||||||
|
*
|
||||||
|
* @return the multiple result current weather request terminator
|
||||||
|
*/
|
||||||
|
MultipleResultCurrentWeatherRequestTerminator retrieve();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Multiple result current weather request customizer.
|
* Retrieve async multiple result current weather async request terminator.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @return the multiple result current weather async request terminator
|
||||||
*/
|
*/
|
||||||
MultipleResultCurrentWeatherRequestCustomizer(RequestSettings requestSettings) {
|
MultipleResultCurrentWeatherAsyncRequestTerminator retrieveAsync();
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MultipleResultCurrentWeatherRequestCustomizer language(Language language) {
|
|
||||||
requestSettings.setLanguage(language);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MultipleResultCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
|
||||||
requestSettings.setUnitSystem(unitSystem);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MultipleResultCurrentWeatherRequestTerminator retrieve() {
|
|
||||||
return new MultipleResultCurrentWeatherRequestTerminator(requestSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MultipleResultCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
|
||||||
return new MultipleResultCurrentWeatherAsyncRequestTerminator(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Multiple result current weather request customizer.
|
||||||
|
*/
|
||||||
|
public class MultipleResultCurrentWeatherRequestCustomizerImpl implements MultipleResultCurrentWeatherRequestCustomizer {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
private Language language;
|
||||||
|
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Multiple result current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
*/
|
||||||
|
MultipleResultCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCurrentWeatherRequestCustomizer language(Language language) {
|
||||||
|
this.language = language;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCurrentWeatherRequestTerminator retrieve() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
return new MultipleResultCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
return new MultipleResultCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,36 +23,12 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
||||||
import com.github.prominence.openweathermap.api.mapper.CurrentWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Multiple result current weather request terminator.
|
* The interface Multiple result current weather request terminator.
|
||||||
*/
|
*/
|
||||||
public class MultipleResultCurrentWeatherRequestTerminator {
|
public interface MultipleResultCurrentWeatherRequestTerminator extends RequestTerminator<List<Weather>, String> {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Multiple result current weather request terminator.
|
|
||||||
*
|
|
||||||
* @param requestSettings request settings object.
|
|
||||||
*/
|
|
||||||
MultipleResultCurrentWeatherRequestTerminator(RequestSettings requestSettings) {
|
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Weather> asJava() {
|
|
||||||
return new CurrentWeatherResponseMapper(requestSettings.getUnitSystem()).getList(getRawResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* 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.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Multiple result current weather request terminator.
|
||||||
|
*/
|
||||||
|
public class MultipleResultCurrentWeatherRequestTerminatorImpl implements MultipleResultCurrentWeatherRequestTerminator {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Multiple result current weather request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
MultipleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Weather> asJava() {
|
||||||
|
return new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,57 +23,69 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Single location current weather requester.
|
* The interface Single location current weather requester.
|
||||||
*/
|
*/
|
||||||
public class SingleLocationCurrentWeatherRequester {
|
public interface SingleLocationCurrentWeatherRequester {
|
||||||
private final RequestSettings requestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Single location current weather requester.
|
* By city name current weather request customizer.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @param cityName the city name
|
||||||
|
* @return the single result current weather request customizer
|
||||||
*/
|
*/
|
||||||
public SingleLocationCurrentWeatherRequester(RequestSettings requestSettings) {
|
SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName);
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
this.requestSettings.appendToURL("weather");
|
|
||||||
}
|
|
||||||
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName) {
|
/**
|
||||||
requestSettings.putRequestParameter("q", cityName);
|
* By city name current weather request customizer.
|
||||||
return new SingleResultCurrentWeatherRequestCustomizer(requestSettings);
|
*
|
||||||
}
|
* @param cityName the city name
|
||||||
|
* @param countryCode the country code
|
||||||
|
* @return the single result current weather request customizer
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String countryCode);
|
||||||
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String countryCode) {
|
/**
|
||||||
requestSettings.putRequestParameter("q", cityName + "," + countryCode);
|
* By city name current weather request customizer.
|
||||||
return new SingleResultCurrentWeatherRequestCustomizer(requestSettings);
|
*
|
||||||
}
|
* @param cityName the city name
|
||||||
|
* @param stateCode the state code
|
||||||
|
* @param countryCode the country code
|
||||||
|
* @return the single result current weather request customizer
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String stateCode, String countryCode);
|
||||||
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String stateCode, String countryCode) {
|
/**
|
||||||
requestSettings.putRequestParameter("q", cityName + "," + stateCode + "," + countryCode);
|
* By city id current weather request customizer.
|
||||||
return new SingleResultCurrentWeatherRequestCustomizer(requestSettings);
|
*
|
||||||
}
|
* @param cityId the city id
|
||||||
|
* @return the single result current weather request customizer
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestCustomizer byCityId(long cityId);
|
||||||
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer byCityId(long cityId) {
|
/**
|
||||||
requestSettings.putRequestParameter("id", String.valueOf(cityId));
|
* By coordinate current weather request customizer.
|
||||||
return new SingleResultCurrentWeatherRequestCustomizer(requestSettings);
|
*
|
||||||
}
|
* @param coordinate the coordinate
|
||||||
|
* @return the single result current weather request customizer
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate);
|
||||||
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate) {
|
/**
|
||||||
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
* By zip code and country current weather request customizer.
|
||||||
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
*
|
||||||
return new SingleResultCurrentWeatherRequestCustomizer(requestSettings);
|
* @param zipCode the zip code
|
||||||
}
|
* @param countryCode the country code
|
||||||
|
* @return the single result current weather request customizer
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode);
|
||||||
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode) {
|
/**
|
||||||
requestSettings.putRequestParameter("zip", zipCode + "," + countryCode);
|
* By zip code in usa current weather request customizer.
|
||||||
return new SingleResultCurrentWeatherRequestCustomizer(requestSettings);
|
*
|
||||||
}
|
* @param zipCode the zip code
|
||||||
|
* @return the single result current weather request customizer
|
||||||
public SingleResultCurrentWeatherRequestCustomizer byZipCodeInUSA(String zipCode) {
|
*/
|
||||||
requestSettings.putRequestParameter("zip", zipCode);
|
SingleResultCurrentWeatherRequestCustomizer byZipCodeInUSA(String zipCode);
|
||||||
return new SingleResultCurrentWeatherRequestCustomizer(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* 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.weather.single;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Single location current weather requester.
|
||||||
|
*/
|
||||||
|
public class SingleLocationCurrentWeatherRequesterImpl implements SingleLocationCurrentWeatherRequester {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Single location current weather requester.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
*/
|
||||||
|
public SingleLocationCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
urlBuilder.append("weather");
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName) {
|
||||||
|
urlBuilder.addRequestParameter("q", cityName);
|
||||||
|
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String countryCode) {
|
||||||
|
urlBuilder.addRequestParameter("q", cityName + "," + countryCode);
|
||||||
|
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String stateCode, String countryCode) {
|
||||||
|
urlBuilder.addRequestParameter("q", cityName + "," + stateCode + "," + countryCode);
|
||||||
|
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer byCityId(long cityId) {
|
||||||
|
urlBuilder.addRequestParameter("id", cityId);
|
||||||
|
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate) {
|
||||||
|
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||||
|
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||||
|
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode) {
|
||||||
|
urlBuilder.addRequestParameter("zip", zipCode + "," + countryCode);
|
||||||
|
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer byZipCodeInUSA(String zipCode) {
|
||||||
|
urlBuilder.addRequestParameter("zip", zipCode);
|
||||||
|
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,48 +22,26 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.ResponseType;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.CurrentWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Single result current weather async request terminator.
|
* The current weather async request terminator interface.
|
||||||
*/
|
*/
|
||||||
public class SingleResultCurrentWeatherAsyncRequestTerminator {
|
public interface SingleResultCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<Weather, String> {
|
||||||
private final RequestSettings requestSettings;
|
/**
|
||||||
|
* XML response format.
|
||||||
|
*
|
||||||
|
* @return the completable future
|
||||||
|
*/
|
||||||
|
CompletableFuture<String> asXML();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Single result current weather async request terminator.
|
* HTML response format.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @return the completable future
|
||||||
*/
|
*/
|
||||||
SingleResultCurrentWeatherAsyncRequestTerminator(RequestSettings requestSettings) {
|
CompletableFuture<String> asHTML();
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<Weather> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(requestSettings.getUnitSystem()).getSingle(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<String> asXML() {
|
|
||||||
requestSettings.setResponseType(ResponseType.XML);
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<String> asHTML() {
|
|
||||||
requestSettings.setResponseType(ResponseType.HTML);
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* 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.weather.single;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Single result current weather async request terminator.
|
||||||
|
*/
|
||||||
|
public class SingleResultCurrentWeatherAsyncRequestTerminatorImpl implements SingleResultCurrentWeatherAsyncRequestTerminator {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Single result current weather async request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Weather> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(unitSystem).getSingle(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asXML() {
|
||||||
|
urlBuilder.addRequestParameter("mode", "xml");
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asHTML() {
|
||||||
|
urlBuilder.addRequestParameter("mode", "html");
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,40 +22,24 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Single result current weather request customizer.
|
* The current weather request customizer interface.
|
||||||
*/
|
*/
|
||||||
public class SingleResultCurrentWeatherRequestCustomizer {
|
public interface SingleResultCurrentWeatherRequestCustomizer extends RequestCustomizer<SingleResultCurrentWeatherRequestCustomizer> {
|
||||||
private final RequestSettings requestSettings;
|
/**
|
||||||
|
* Retrieve current weather request terminator.
|
||||||
|
*
|
||||||
|
* @return the single result current weather request terminator
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestTerminator retrieve();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Single result current weather request customizer.
|
* Retrieve current weather async request terminator.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @return the single result current weather async request terminator
|
||||||
*/
|
*/
|
||||||
SingleResultCurrentWeatherRequestCustomizer(RequestSettings requestSettings) {
|
SingleResultCurrentWeatherAsyncRequestTerminator retrieveAsync();
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer language(Language language) {
|
|
||||||
requestSettings.setLanguage(language);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
|
||||||
requestSettings.setUnitSystem(unitSystem);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SingleResultCurrentWeatherRequestTerminator retrieve() {
|
|
||||||
return new SingleResultCurrentWeatherRequestTerminator(requestSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SingleResultCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
|
||||||
return new SingleResultCurrentWeatherAsyncRequestTerminator(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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.weather.single;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Single result current weather request customizer.
|
||||||
|
*/
|
||||||
|
public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleResultCurrentWeatherRequestCustomizer {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
private Language language;
|
||||||
|
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Single result current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer language(Language language) {
|
||||||
|
this.language = language;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SingleResultCurrentWeatherRequestTerminator retrieve() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
return new SingleResultCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SingleResultCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
return new SingleResultCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,46 +22,24 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.ResponseType;
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
||||||
import com.github.prominence.openweathermap.api.mapper.CurrentWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Single result current weather request terminator.
|
* The current weather request terminator interface.
|
||||||
*/
|
*/
|
||||||
public class SingleResultCurrentWeatherRequestTerminator {
|
public interface SingleResultCurrentWeatherRequestTerminator extends RequestTerminator<Weather, String> {
|
||||||
private final RequestSettings requestSettings;
|
/**
|
||||||
|
* XML response format.
|
||||||
|
*
|
||||||
|
* @return the XML string
|
||||||
|
*/
|
||||||
|
String asXML();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new Single result current weather request terminator.
|
* HTML response format.
|
||||||
*
|
*
|
||||||
* @param requestSettings request settings object.
|
* @return the HTML string
|
||||||
*/
|
*/
|
||||||
SingleResultCurrentWeatherRequestTerminator(RequestSettings requestSettings) {
|
String asHTML();
|
||||||
this.requestSettings = requestSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Weather asJava() {
|
|
||||||
return new CurrentWeatherResponseMapper(requestSettings.getUnitSystem()).getSingle(asJSON());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String asXML() {
|
|
||||||
requestSettings.setResponseType(ResponseType.XML);
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String asHTML() {
|
|
||||||
requestSettings.setResponseType(ResponseType.HTML);
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(requestSettings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* 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.weather.single;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Single result current weather request terminator.
|
||||||
|
*/
|
||||||
|
public class SingleResultCurrentWeatherRequestTerminatorImpl implements SingleResultCurrentWeatherRequestTerminator {
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Single result current weather request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Weather asJava() {
|
||||||
|
return new CurrentWeatherResponseMapper(unitSystem).getSingle(asJSON());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asXML() {
|
||||||
|
urlBuilder.addRequestParameter("mode", "xml");
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asHTML() {
|
||||||
|
urlBuilder.addRequestParameter("mode", "html");
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,55 +22,30 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.utils;
|
package com.github.prominence.openweathermap.api.utils;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
|
||||||
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
|
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
|
||||||
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for API calls execution.
|
* Utility class for API calls execution.
|
||||||
*/
|
*/
|
||||||
public final class RequestUtils {
|
public final class RequestUtils {
|
||||||
|
|
||||||
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);
|
private static final Logger logger = LoggerFactory.getLogger(RequestUtils.class);
|
||||||
|
|
||||||
private RequestUtils() {
|
private 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 -> {
|
|
||||||
try {
|
|
||||||
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), "UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect(Collectors.joining("&"));
|
|
||||||
requestUrlBuilder.append(parameters);
|
|
||||||
|
|
||||||
return getResponse(requestUrlBuilder.toString(), requestSettings.getTimeoutSettings());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes call to provided API url and retrieves response in <code>String</code> representation.
|
* Executes call to provided API url and retrieves response in <code>String</code> representation.
|
||||||
*
|
*
|
||||||
@ -79,18 +54,6 @@ public final class RequestUtils {
|
|||||||
* @throws IllegalArgumentException in case if provided parameter isn't a valid url for {@link URL} instance.
|
* @throws IllegalArgumentException in case if provided parameter isn't a valid url for {@link URL} instance.
|
||||||
*/
|
*/
|
||||||
public static String getResponse(String url) {
|
public static String getResponse(String url) {
|
||||||
return getResponse(url, new TimeoutSettings());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes call to provided API url and retrieves response in <code>String</code> representation.
|
|
||||||
*
|
|
||||||
* @param url the url to make API request.
|
|
||||||
* @param timeoutSettings an object with timeout settings.
|
|
||||||
* @return response from the request in <code>String</code> representation.
|
|
||||||
* @throws IllegalArgumentException in case if provided parameter isn't a valid url for {@link URL} instance.
|
|
||||||
*/
|
|
||||||
public static String getResponse(String url, TimeoutSettings timeoutSettings) {
|
|
||||||
URL requestUrl;
|
URL requestUrl;
|
||||||
try {
|
try {
|
||||||
requestUrl = new URL(url);
|
requestUrl = new URL(url);
|
||||||
@ -99,7 +62,7 @@ public final class RequestUtils {
|
|||||||
throw new IllegalArgumentException(ex);
|
throw new IllegalArgumentException(ex);
|
||||||
}
|
}
|
||||||
logger.debug("Executing OpenWeatherMap API request: " + url);
|
logger.debug("Executing OpenWeatherMap API request: " + url);
|
||||||
final InputStream requestInputStream = executeRequest(requestUrl, timeoutSettings);
|
final InputStream requestInputStream = executeRequest(requestUrl);
|
||||||
|
|
||||||
return convertInputStreamToString(requestInputStream);
|
return convertInputStreamToString(requestInputStream);
|
||||||
}
|
}
|
||||||
@ -112,20 +75,11 @@ public final class RequestUtils {
|
|||||||
* @throws InvalidAuthTokenException in case if authentication token wasn't set or requested functionality is not permitted for its subscription plan.
|
* @throws InvalidAuthTokenException in case if authentication token wasn't set or requested functionality is not permitted for its subscription plan.
|
||||||
* @throws NoDataFoundException in case if there is no any data for requested location(s) or request is invalid.
|
* @throws NoDataFoundException in case if there is no any data for requested location(s) or request is invalid.
|
||||||
*/
|
*/
|
||||||
private static InputStream executeRequest(URL requestUrl, TimeoutSettings timeoutSettings) {
|
private static InputStream executeRequest(URL requestUrl) {
|
||||||
InputStream resultStream;
|
InputStream resultStream;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();
|
||||||
|
|
||||||
if (timeoutSettings.getConnectionTimeout() != null) {
|
|
||||||
connection.setConnectTimeout(timeoutSettings.getConnectionTimeout());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (timeoutSettings.getReadTimeout() != null) {
|
|
||||||
connection.setReadTimeout(timeoutSettings.getReadTimeout());
|
|
||||||
}
|
|
||||||
|
|
||||||
connection.setRequestMethod("GET");
|
connection.setRequestMethod("GET");
|
||||||
|
|
||||||
switch (connection.getResponseCode()) {
|
switch (connection.getResponseCode()) {
|
||||||
|
|||||||
@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * 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.model.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
public class AirPollutionDetailsUnitTest {
|
|
||||||
@Test
|
|
||||||
public void getCoordinate() {
|
|
||||||
final AirPollutionDetails airPollutionDetails = new AirPollutionDetails();
|
|
||||||
final Coordinate coordinate = Coordinate.of(22.3, 44.2);
|
|
||||||
airPollutionDetails.setCoordinate(coordinate);
|
|
||||||
|
|
||||||
assertEquals(coordinate, airPollutionDetails.getCoordinate());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAirPollutionSamples() {
|
|
||||||
final AirPollutionDetails airPollutionDetails = new AirPollutionDetails();
|
|
||||||
final List<AirPollutionRecord> airPollutionRecords = new ArrayList<>();
|
|
||||||
airPollutionDetails.setAirPollutionRecords(airPollutionRecords);
|
|
||||||
|
|
||||||
assertEquals(airPollutionRecords, airPollutionDetails.getAirPollutionRecords());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEquals() {
|
|
||||||
final AirPollutionDetails first = new AirPollutionDetails();
|
|
||||||
final AirPollutionDetails second = new AirPollutionDetails();
|
|
||||||
final Coordinate coordinate = Coordinate.of(22.3, 44.2);
|
|
||||||
final List<AirPollutionRecord> airPollutionRecords = new ArrayList<>();
|
|
||||||
|
|
||||||
assertEquals(first, first);
|
|
||||||
assertNotEquals(first, null);
|
|
||||||
assertEquals(first, second);
|
|
||||||
assertNotEquals(first, new Object());
|
|
||||||
|
|
||||||
assertEquals(first, second);
|
|
||||||
|
|
||||||
first.setCoordinate(coordinate);
|
|
||||||
|
|
||||||
assertNotEquals(first, second);
|
|
||||||
|
|
||||||
second.setCoordinate(coordinate);
|
|
||||||
|
|
||||||
assertEquals(first, second);
|
|
||||||
|
|
||||||
first.setAirPollutionRecords(airPollutionRecords);
|
|
||||||
|
|
||||||
assertNotEquals(first, second);
|
|
||||||
|
|
||||||
second.setAirPollutionRecords(airPollutionRecords);
|
|
||||||
|
|
||||||
assertEquals(first, second);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHashCode() {
|
|
||||||
final AirPollutionDetails first = new AirPollutionDetails();
|
|
||||||
final AirPollutionDetails second = new AirPollutionDetails();
|
|
||||||
final Coordinate coordinate = Coordinate.of(22.3, 44.2);
|
|
||||||
|
|
||||||
assertEquals(first.hashCode(), second.hashCode());
|
|
||||||
|
|
||||||
first.setCoordinate(coordinate);
|
|
||||||
|
|
||||||
assertNotEquals(first.hashCode(), second.hashCode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,280 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * 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.model.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.AirQualityIndex;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
public class AirPollutionRecordUnitTest {
|
|
||||||
@Test
|
|
||||||
public void getForecastTime() {
|
|
||||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
|
||||||
final LocalDateTime now = LocalDateTime.now();
|
|
||||||
airPollutionRecord.setForecastTime(now);
|
|
||||||
|
|
||||||
assertEquals(now, airPollutionRecord.getForecastTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAirQualityIndex() {
|
|
||||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
|
||||||
airPollutionRecord.setAirQualityIndex(AirQualityIndex.FAIR);
|
|
||||||
|
|
||||||
assertEquals(AirQualityIndex.FAIR, airPollutionRecord.getAirQualityIndex());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getCarbonMonoxide() {
|
|
||||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
|
||||||
final double value = 0.55;
|
|
||||||
airPollutionRecord.setCO(value);
|
|
||||||
|
|
||||||
assertEquals(value, airPollutionRecord.getCarbonMonoxide(), 0.00001);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getNitrogenMonoxide() {
|
|
||||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
|
||||||
final double value = 0.55;
|
|
||||||
airPollutionRecord.setNO(value);
|
|
||||||
|
|
||||||
assertEquals(value, airPollutionRecord.getNitrogenMonoxide(), 0.00001);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getNitrogenDioxide() {
|
|
||||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
|
||||||
final double value = 0.55;
|
|
||||||
airPollutionRecord.setNO2(value);
|
|
||||||
|
|
||||||
assertEquals(value, airPollutionRecord.getNitrogenDioxide(), 0.00001);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getOzone() {
|
|
||||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
|
||||||
final double value = 0.55;
|
|
||||||
airPollutionRecord.setO3(value);
|
|
||||||
|
|
||||||
assertEquals(value, airPollutionRecord.getOzone(), 0.00001);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSulphurDioxide() {
|
|
||||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
|
||||||
final double value = 0.55;
|
|
||||||
airPollutionRecord.setSO2(value);
|
|
||||||
|
|
||||||
assertEquals(value, airPollutionRecord.getSulphurDioxide(), 0.00001);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getFineParticlesMatter() {
|
|
||||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
|
||||||
final double value = 0.55;
|
|
||||||
airPollutionRecord.setPM2_5(value);
|
|
||||||
|
|
||||||
assertEquals(value, airPollutionRecord.getFineParticlesMatter(), 0.00001);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getCoarseParticulateMatter() {
|
|
||||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
|
||||||
final double value = 0.55;
|
|
||||||
airPollutionRecord.setPM10(value);
|
|
||||||
|
|
||||||
assertEquals(value, airPollutionRecord.getCoarseParticulateMatter(), 0.00001);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAmmonia() {
|
|
||||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
|
||||||
final double value = 0.55;
|
|
||||||
airPollutionRecord.setNH3(value);
|
|
||||||
|
|
||||||
assertEquals(value, airPollutionRecord.getAmmonia());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEquals() {
|
|
||||||
final AirPollutionRecord first = new AirPollutionRecord();
|
|
||||||
final AirPollutionRecord second = new AirPollutionRecord();
|
|
||||||
final LocalDateTime now = LocalDateTime.now();
|
|
||||||
final AirQualityIndex aqi = AirQualityIndex.GOOD;
|
|
||||||
final double value = 0.55;
|
|
||||||
|
|
||||||
assertEquals(first, first);
|
|
||||||
assertNotEquals(first, null);
|
|
||||||
assertEquals(first, second);
|
|
||||||
assertNotEquals(first, new Object());
|
|
||||||
|
|
||||||
assertEquals(first, second);
|
|
||||||
|
|
||||||
first.setForecastTime(now);
|
|
||||||
|
|
||||||
assertNotEquals(first, second);
|
|
||||||
|
|
||||||
second.setForecastTime(now);
|
|
||||||
|
|
||||||
assertEquals(first, second);
|
|
||||||
|
|
||||||
first.setAirQualityIndex(aqi);
|
|
||||||
|
|
||||||
assertNotEquals(first, second);
|
|
||||||
|
|
||||||
second.setAirQualityIndex(aqi);
|
|
||||||
|
|
||||||
assertEquals(first, second);
|
|
||||||
|
|
||||||
first.setCO(value);
|
|
||||||
|
|
||||||
assertNotEquals(first, second);
|
|
||||||
|
|
||||||
second.setCO(value);
|
|
||||||
|
|
||||||
assertEquals(first, second);
|
|
||||||
|
|
||||||
first.setNO(value);
|
|
||||||
|
|
||||||
assertNotEquals(first, second);
|
|
||||||
|
|
||||||
second.setNO(value);
|
|
||||||
|
|
||||||
assertEquals(first, second);
|
|
||||||
|
|
||||||
first.setNO2(value);
|
|
||||||
|
|
||||||
assertNotEquals(first, second);
|
|
||||||
|
|
||||||
second.setNO2(value);
|
|
||||||
|
|
||||||
assertEquals(first, second);
|
|
||||||
|
|
||||||
first.setO3(value);
|
|
||||||
|
|
||||||
assertNotEquals(first, second);
|
|
||||||
|
|
||||||
second.setO3(value);
|
|
||||||
|
|
||||||
assertEquals(first, second);
|
|
||||||
|
|
||||||
first.setSO2(value);
|
|
||||||
|
|
||||||
assertNotEquals(first, second);
|
|
||||||
|
|
||||||
second.setSO2(value);
|
|
||||||
|
|
||||||
assertEquals(first, second);
|
|
||||||
|
|
||||||
first.setPM2_5(value);
|
|
||||||
|
|
||||||
assertNotEquals(first, second);
|
|
||||||
|
|
||||||
second.setPM2_5(value);
|
|
||||||
|
|
||||||
assertEquals(first, second);
|
|
||||||
|
|
||||||
first.setPM10(value);
|
|
||||||
|
|
||||||
assertNotEquals(first, second);
|
|
||||||
|
|
||||||
second.setPM10(value);
|
|
||||||
|
|
||||||
assertEquals(first, second);
|
|
||||||
|
|
||||||
first.setNH3(value);
|
|
||||||
|
|
||||||
assertNotEquals(first, second);
|
|
||||||
|
|
||||||
second.setNH3(value);
|
|
||||||
|
|
||||||
assertEquals(first, second);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHashCode() {
|
|
||||||
final AirPollutionRecord first = new AirPollutionRecord();
|
|
||||||
final AirPollutionRecord second = new AirPollutionRecord();
|
|
||||||
|
|
||||||
assertEquals(first.hashCode(), second.hashCode());
|
|
||||||
|
|
||||||
first.setSO2(33.2);
|
|
||||||
|
|
||||||
assertNotEquals(first.hashCode(), second.hashCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testToString() {
|
|
||||||
final AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
|
||||||
final LocalDateTime now = LocalDateTime.now();
|
|
||||||
final AirQualityIndex aqi = AirQualityIndex.GOOD;
|
|
||||||
final double value = 0.55;
|
|
||||||
|
|
||||||
airPollutionRecord.setForecastTime(now);
|
|
||||||
airPollutionRecord.setAirQualityIndex(aqi);
|
|
||||||
|
|
||||||
assertNotNull(airPollutionRecord.toString());
|
|
||||||
|
|
||||||
airPollutionRecord.setCO(value);
|
|
||||||
|
|
||||||
assertNotNull(airPollutionRecord.toString());
|
|
||||||
|
|
||||||
airPollutionRecord.setNO(value);
|
|
||||||
|
|
||||||
assertNotNull(airPollutionRecord.toString());
|
|
||||||
|
|
||||||
airPollutionRecord.setNO2(value);
|
|
||||||
|
|
||||||
assertNotNull(airPollutionRecord.toString());
|
|
||||||
|
|
||||||
airPollutionRecord.setO3(value);
|
|
||||||
|
|
||||||
assertNotNull(airPollutionRecord.toString());
|
|
||||||
|
|
||||||
airPollutionRecord.setSO2(value);
|
|
||||||
|
|
||||||
assertNotNull(airPollutionRecord.toString());
|
|
||||||
|
|
||||||
airPollutionRecord.setPM2_5(value);
|
|
||||||
|
|
||||||
assertNotNull(airPollutionRecord.toString());
|
|
||||||
|
|
||||||
airPollutionRecord.setPM10(value);
|
|
||||||
|
|
||||||
assertNotNull(airPollutionRecord.toString());
|
|
||||||
|
|
||||||
airPollutionRecord.setNH3(value);
|
|
||||||
|
|
||||||
assertNotNull(airPollutionRecord.toString());
|
|
||||||
|
|
||||||
airPollutionRecord.setCO(null);
|
|
||||||
|
|
||||||
assertNotNull(airPollutionRecord.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,100 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.model.onecall.current;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.MoonType;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
|
||||||
|
|
||||||
public class MoonPhaseUnitTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getValue() {
|
|
||||||
final MoonPhase moonPhase = new MoonPhase(0.67);
|
|
||||||
|
|
||||||
assertEquals(0.67, moonPhase.getValue(), 0.000001);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getType() {
|
|
||||||
final MoonPhase newMoon1 = new MoonPhase(0d);
|
|
||||||
assertEquals(MoonType.NEW_MOON, newMoon1.getType());
|
|
||||||
|
|
||||||
final MoonPhase newMoon2 = new MoonPhase(1d);
|
|
||||||
assertEquals(MoonType.NEW_MOON, newMoon2.getType());
|
|
||||||
|
|
||||||
final MoonPhase firstQuarterMoon = new MoonPhase(0.25d);
|
|
||||||
assertEquals(MoonType.FIRST_QUARTER_MOON, firstQuarterMoon.getType());
|
|
||||||
|
|
||||||
final MoonPhase fullMoon = new MoonPhase(0.5d);
|
|
||||||
assertEquals(MoonType.FULL_MOON, fullMoon.getType());
|
|
||||||
|
|
||||||
final MoonPhase lastQuarterMoon = new MoonPhase(0.75d);
|
|
||||||
assertEquals(MoonType.LAST_QUARTER_MOON, lastQuarterMoon.getType());
|
|
||||||
|
|
||||||
final MoonPhase waxingCrescentMoon = new MoonPhase(0.1d);
|
|
||||||
assertEquals(MoonType.WAXING_CRESCENT, waxingCrescentMoon.getType());
|
|
||||||
|
|
||||||
final MoonPhase waxingGibbousMoon = new MoonPhase(0.4d);
|
|
||||||
assertEquals(MoonType.WAXING_GIBBOUS, waxingGibbousMoon.getType());
|
|
||||||
|
|
||||||
final MoonPhase waningGibbousMoon = new MoonPhase(0.623d);
|
|
||||||
assertEquals(MoonType.WANING_GIBBOUS, waningGibbousMoon.getType());
|
|
||||||
|
|
||||||
final MoonPhase waningCrescentMoon = new MoonPhase(0.9999d);
|
|
||||||
assertEquals(MoonType.WANING_CRESCENT, waningCrescentMoon.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getEquals() {
|
|
||||||
final MoonPhase phase1 = new MoonPhase(0d);
|
|
||||||
final MoonPhase phase2 = new MoonPhase(0.5d);
|
|
||||||
|
|
||||||
assertNotEquals(phase1, phase2);
|
|
||||||
|
|
||||||
final MoonPhase phase3 = new MoonPhase(0d);
|
|
||||||
|
|
||||||
assertEquals(phase1, phase3);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getHashCode() {
|
|
||||||
final MoonPhase phase1 = new MoonPhase(0d);
|
|
||||||
final MoonPhase phase2 = new MoonPhase(0.5d);
|
|
||||||
|
|
||||||
assertNotEquals(phase1.hashCode(), phase2.hashCode());
|
|
||||||
|
|
||||||
final MoonPhase phase3 = new MoonPhase(0d);
|
|
||||||
|
|
||||||
assertEquals(phase1.hashCode(), phase3.hashCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getToString() {
|
|
||||||
final MoonPhase phase2 = new MoonPhase(0.5d);
|
|
||||||
|
|
||||||
assertEquals("FULL_MOON(0.5)", phase2.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,208 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * 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.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.ApiTest;
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
||||||
|
|
||||||
public class AirPollutionIntegrationTest extends ApiTest {
|
|
||||||
@Test
|
|
||||||
public void whenRetrieveCurrentAirPollutionResponseAsJava_thenOk() {
|
|
||||||
final AirPollutionDetails airPollutionDetails = getClient()
|
|
||||||
.airPollution()
|
|
||||||
.current()
|
|
||||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
|
||||||
.retrieve()
|
|
||||||
.asJava();
|
|
||||||
|
|
||||||
assertNotNull(airPollutionDetails);
|
|
||||||
airPollutionDetails.getAirPollutionRecords().forEach(airPollutionRecord -> {
|
|
||||||
assertNotNull(airPollutionRecord);
|
|
||||||
System.out.println(airPollutionRecord);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenRetrieveCurrentAirPollutionResponseAsJSON_thenOk() {
|
|
||||||
final String jsonString = getClient()
|
|
||||||
.airPollution()
|
|
||||||
.current()
|
|
||||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
|
||||||
.retrieve()
|
|
||||||
.asJSON();
|
|
||||||
|
|
||||||
assertNotNull(jsonString);
|
|
||||||
System.out.println(jsonString);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenRetrieveCurrentAirPollutionAsyncResponseAsJava_thenOk() throws ExecutionException, InterruptedException {
|
|
||||||
final CompletableFuture<AirPollutionDetails> pollutionDetailsFuture = getClient()
|
|
||||||
.airPollution()
|
|
||||||
.current()
|
|
||||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
|
||||||
.retrieveAsync()
|
|
||||||
.asJava();
|
|
||||||
|
|
||||||
assertNotNull(pollutionDetailsFuture);
|
|
||||||
assertNotNull(pollutionDetailsFuture.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenRetrieveCurrentAirPollutionAsyncResponseAsJSON_thenOk() throws ExecutionException, InterruptedException {
|
|
||||||
final CompletableFuture<String> jsonStringFuture = getClient()
|
|
||||||
.airPollution()
|
|
||||||
.current()
|
|
||||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
|
||||||
.retrieveAsync()
|
|
||||||
.asJSON();
|
|
||||||
|
|
||||||
assertNotNull(jsonStringFuture);
|
|
||||||
final String jsonString = jsonStringFuture.get();
|
|
||||||
assertNotNull(jsonString);
|
|
||||||
System.out.println(jsonString);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenRetrieveForecastAirPollutionResponseAsJava_thenOk() {
|
|
||||||
final AirPollutionDetails airPollutionDetails = getClient()
|
|
||||||
.airPollution()
|
|
||||||
.forecast()
|
|
||||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
|
||||||
.retrieve()
|
|
||||||
.asJava();
|
|
||||||
|
|
||||||
assertNotNull(airPollutionDetails);
|
|
||||||
airPollutionDetails.getAirPollutionRecords().forEach(airPollutionRecord -> {
|
|
||||||
assertNotNull(airPollutionRecord);
|
|
||||||
System.out.println(airPollutionRecord);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenRetrieveForecastAirPollutionResponseAsJSON_thenOk() {
|
|
||||||
final String jsonString = getClient()
|
|
||||||
.airPollution()
|
|
||||||
.forecast()
|
|
||||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
|
||||||
.retrieve()
|
|
||||||
.asJSON();
|
|
||||||
|
|
||||||
assertNotNull(jsonString);
|
|
||||||
System.out.println(jsonString);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenRetrieveForecastAirPollutionAsyncResponseAsJava_thenOk() throws ExecutionException, InterruptedException {
|
|
||||||
final CompletableFuture<AirPollutionDetails> pollutionDetailsFuture = getClient()
|
|
||||||
.airPollution()
|
|
||||||
.forecast()
|
|
||||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
|
||||||
.retrieveAsync()
|
|
||||||
.asJava();
|
|
||||||
|
|
||||||
assertNotNull(pollutionDetailsFuture);
|
|
||||||
assertNotNull(pollutionDetailsFuture.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenRetrieveForecastAirPollutionAsyncResponseAsJSON_thenOk() throws ExecutionException, InterruptedException {
|
|
||||||
final CompletableFuture<String> jsonStringFuture = getClient()
|
|
||||||
.airPollution()
|
|
||||||
.forecast()
|
|
||||||
.byCoordinate(Coordinate.of(53.54, 27.34))
|
|
||||||
.retrieveAsync()
|
|
||||||
.asJSON();
|
|
||||||
|
|
||||||
assertNotNull(jsonStringFuture);
|
|
||||||
final String jsonString = jsonStringFuture.get();
|
|
||||||
assertNotNull(jsonString);
|
|
||||||
System.out.println(jsonString);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenRetrieveHistoricalAirPollutionResponseAsJava_thenOk() {
|
|
||||||
final AirPollutionDetails airPollutionDetails = getClient()
|
|
||||||
.airPollution()
|
|
||||||
.historical()
|
|
||||||
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
|
||||||
.retrieve()
|
|
||||||
.asJava();
|
|
||||||
|
|
||||||
assertNotNull(airPollutionDetails);
|
|
||||||
airPollutionDetails.getAirPollutionRecords().forEach(airPollutionRecord -> {
|
|
||||||
assertNotNull(airPollutionRecord);
|
|
||||||
System.out.println(airPollutionRecord);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenRetrieveHistoricalAirPollutionResponseAsJSON_thenOk() {
|
|
||||||
final String jsonString = getClient()
|
|
||||||
.airPollution()
|
|
||||||
.historical()
|
|
||||||
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
|
||||||
.retrieve()
|
|
||||||
.asJSON();
|
|
||||||
|
|
||||||
assertNotNull(jsonString);
|
|
||||||
System.out.println(jsonString);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenRetrieveHistoricalAirPollutionAsyncResponseAsJava_thenOk() throws ExecutionException, InterruptedException {
|
|
||||||
final CompletableFuture<AirPollutionDetails> pollutionDetailsFuture = getClient()
|
|
||||||
.airPollution()
|
|
||||||
.historical()
|
|
||||||
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
|
||||||
.retrieveAsync()
|
|
||||||
.asJava();
|
|
||||||
|
|
||||||
assertNotNull(pollutionDetailsFuture);
|
|
||||||
assertNotNull(pollutionDetailsFuture.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenRetrieveHistoricalAirPollutionAsyncResponseAsJSON_thenOk() throws ExecutionException, InterruptedException {
|
|
||||||
final CompletableFuture<String> jsonStringFuture = getClient()
|
|
||||||
.airPollution()
|
|
||||||
.historical()
|
|
||||||
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
|
||||||
.retrieveAsync()
|
|
||||||
.asJSON();
|
|
||||||
|
|
||||||
assertNotNull(jsonStringFuture);
|
|
||||||
final String jsonString = jsonStringFuture.get();
|
|
||||||
assertNotNull(jsonString);
|
|
||||||
System.out.println(jsonString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * 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.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.mapper.AirPollutionResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
||||||
|
|
||||||
public class AirPollutionResponseMapperUnitTest {
|
|
||||||
@Test
|
|
||||||
public void mapToAirPollution_withInvalidJSON() {
|
|
||||||
final String jsonString = "{\"coord\":{lon\":27.34,\"lat\":53.54},\"list\":[{\"main\":{\"aqi\":1},\"components\":{\"co\":243.66,\"no\":0,\"no2\":4.07,\"o3\":62.23,\"so2\":1.77,\"pm2_5\":3.87,\"pm10\":4.58,\"nh3\":2.41},\"dt\":1618610400}]}";
|
|
||||||
assertThrows(RuntimeException.class, () -> new AirPollutionResponseMapper().mapToAirPollution(jsonString));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void mapToAirPollution_withCoordinatesVariation() {
|
|
||||||
String jsonResponse = "{\"coord\":{},\"list\":[{\"main\":{\"aqi\":1},\"components\":{\"co\":243.66,\"no\":0,\"no2\":4.07,\"o3\":62.23,\"so2\":1.77,\"pm2_5\":3.87,\"pm10\":4.58,\"nh3\":2.41},\"dt\":1618610400}]}";
|
|
||||||
AirPollutionDetails airPollutionDetails = new AirPollutionResponseMapper().mapToAirPollution(jsonResponse);
|
|
||||||
|
|
||||||
assertNotNull(airPollutionDetails);
|
|
||||||
|
|
||||||
jsonResponse = "{\"coord\":{\"lon\":27.34},\"list\":[{\"main\":{\"aqi\":1},\"components\":{\"co\":243.66,\"no\":0,\"no2\":4.07,\"o3\":62.23,\"so2\":1.77,\"pm2_5\":3.87,\"pm10\":4.58,\"nh3\":2.41},\"dt\":1618610400}]}";
|
|
||||||
airPollutionDetails = new AirPollutionResponseMapper().mapToAirPollution(jsonResponse);
|
|
||||||
|
|
||||||
assertNotNull(airPollutionDetails);
|
|
||||||
|
|
||||||
jsonResponse = "{\"coord\":{\"lat\":53.54},\"list\":[{\"main\":{\"aqi\":1},\"components\":{\"co\":243.66,\"no\":0,\"no2\":4.07,\"o3\":62.23,\"so2\":1.77,\"pm2_5\":3.87,\"pm10\":4.58,\"nh3\":2.41},\"dt\":1618610400}]}";
|
|
||||||
airPollutionDetails = new AirPollutionResponseMapper().mapToAirPollution(jsonResponse);
|
|
||||||
|
|
||||||
assertNotNull(airPollutionDetails);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -23,7 +23,6 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
import com.github.prominence.openweathermap.api.mapper.FiveDayThreeHourStepForecastResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -1,136 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -23,7 +23,6 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.weather;
|
package com.github.prominence.openweathermap.api.request.weather;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
import com.github.prominence.openweathermap.api.mapper.CurrentWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|||||||
@ -86,34 +86,6 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
|
|||||||
assertTrue(weatherJson.startsWith("{"));
|
assertTrue(weatherJson.startsWith("{"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenGetMultipleCurrentWeatherByCoordinateRectangleAsyncRequestAsJava_thenReturnNotNull() throws ExecutionException, InterruptedException {
|
|
||||||
final CompletableFuture<List<Weather>> weatherListFuture = getClient()
|
|
||||||
.currentWeather()
|
|
||||||
.multiple()
|
|
||||||
.byRectangle(CoordinateRectangle.withValues(12, 32, 15, 37), 10)
|
|
||||||
.language(Language.ROMANIAN)
|
|
||||||
.unitSystem(UnitSystem.METRIC)
|
|
||||||
.retrieveAsync()
|
|
||||||
.asJava();
|
|
||||||
|
|
||||||
assertNotNull(weatherListFuture.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenGetMultipleCurrentWeatherByCoordinateRectangleAsyncRequestAsJSON_thenReturnNotNull() throws ExecutionException, InterruptedException {
|
|
||||||
final CompletableFuture<String> weatherJsonFuture = getClient()
|
|
||||||
.currentWeather()
|
|
||||||
.multiple()
|
|
||||||
.byRectangle(CoordinateRectangle.withValues(12, 32, 15, 37), 10)
|
|
||||||
.language(Language.ROMANIAN)
|
|
||||||
.unitSystem(UnitSystem.METRIC)
|
|
||||||
.retrieveAsync()
|
|
||||||
.asJSON();
|
|
||||||
|
|
||||||
assertTrue(weatherJsonFuture.get().startsWith("{"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsJava_thenReturnNotNull() {
|
public void whenGetMultipleCurrentWeatherByCitiesInCycleRequestAsJava_thenReturnNotNull() {
|
||||||
final List<Weather> weatherList = getClient()
|
final List<Weather> weatherList = getClient()
|
||||||
@ -253,21 +225,6 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest {
|
|||||||
System.out.println(weatherFuture.get());
|
System.out.println(weatherFuture.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenGetMultipleCurrentWeatherByCoordinateAsyncRequestAsXML_thenReturnNotNull() throws ExecutionException, InterruptedException {
|
|
||||||
final CompletableFuture<String> weatherXMLFuture = getClient()
|
|
||||||
.currentWeather()
|
|
||||||
.multiple()
|
|
||||||
.byCitiesInCycle(Coordinate.of(55.5, 37.5), 10)
|
|
||||||
.language(Language.GERMAN)
|
|
||||||
.unitSystem(UnitSystem.IMPERIAL)
|
|
||||||
.retrieveAsync()
|
|
||||||
.asXML();
|
|
||||||
|
|
||||||
assertNotNull(weatherXMLFuture);
|
|
||||||
System.out.println(weatherXMLFuture.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() {
|
public void whenRequestCurrentWeatherWithInvalidApiKey_thenThrowAnException() {
|
||||||
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
|
OpenWeatherMapClient client = new OpenWeatherMapClient("invalidKey");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user