mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-03 19:26:43 +03:00
Compare commits
146 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a2b0360e4b | |||
| b83b121e90 | |||
| fb2e0e01be | |||
| 2d81dadfad | |||
| 5e4b34632e | |||
| 6c1a1642f1 | |||
| 8a1daa0fe2 | |||
| 7e88fe597c | |||
| aa48ac3aa0 | |||
| 7f0866ffa2 | |||
| 4fdb48986e | |||
| 8ca55b15f7 | |||
| 5ca31780da | |||
| 91a5acdb43 | |||
| 3f5b7f6649 | |||
| 9c2a127703 | |||
| e6833c3007 | |||
| d1bac609e8 | |||
| a17f687976 | |||
| 1ae02e0e49 | |||
| 46602e1f93 | |||
| 2553f13fbe | |||
| 905d3876c3 | |||
| 45f0b494b3 | |||
| 93b6b357c1 | |||
| c0dd184965 | |||
| 08d0aa091d | |||
| 93ae514550 | |||
| 47d52d953a | |||
| 2a15788569 | |||
| 37d7a2b3f5 | |||
| 6790848c32 | |||
| ec988c5f26 | |||
| 7b8d46bb7a | |||
| 6ae281af0d | |||
| 23a1fa5a7b | |||
| 1cac951aaa | |||
| 58e648be42 | |||
| f30bcad5dc | |||
| 5793722181 | |||
| 40462397c1 | |||
| 44b543e65c | |||
| 13b20fc7e9 | |||
| 2a531dd683 | |||
| 1e1054903e | |||
| ff5b6c7a33 | |||
| db1cf858d8 | |||
| c2cc110dab | |||
| d4c2472254 | |||
| 380e3e458b | |||
| 246c07db97 | |||
| f19a627313 | |||
| 6438c323ff | |||
| 1cbff68338 | |||
| 1e08f4f8ae | |||
| bfa15fd9fe | |||
| 3c8b00eae1 | |||
| f2c672b864 | |||
| e594ffb7ad | |||
| 4cfa8ab843 | |||
| 196f9ec289 | |||
| 4998663298 | |||
| f5d202aee3 | |||
| 4c1b079e05 | |||
| 7ad0f9d415 | |||
| e9a5011c5c | |||
| cba15e6420 | |||
| cd8209e677 | |||
| 64e02cd7a8 | |||
| b301d93b39 | |||
| c68c6fd2b6 | |||
| cd263234bc | |||
| bcee4135fc | |||
| 9b67c57d7e | |||
| 848b5397ac | |||
| fd3ff3f133 | |||
| d555eeaf32 | |||
| cdc5a4b380 | |||
| 48d0c9479d | |||
| 53af39f598 | |||
| 02d42c0cd0 | |||
| c650ba2387 | |||
| c2138a4503 | |||
| 7d3c9ba358 | |||
| ba1a5a1016 | |||
| 48d631b747 | |||
| e9b8f00c5a | |||
| 4ce9548e7a | |||
| a0e289cc2c | |||
| ef138d3bfe | |||
| ae082d41c1 | |||
| 6d44b2adec | |||
| 4c7b553b81 | |||
| 7003935869 | |||
| 764b1b7189 | |||
| 599faf60cc | |||
| 930776f5c2 | |||
| 5d6b8c4d97 | |||
| f7741e1df6 | |||
| ea39441e83 | |||
| d63de824b3 | |||
| 10ba59652b | |||
| 83f3a8e63b | |||
| 4d844a3f0a | |||
| 2c54375cfe | |||
| 3820409ce8 | |||
| 3845e41bcd | |||
| babc48bf6c | |||
| d3ca16472b | |||
| dbc5b08f43 | |||
| 1101ec03db | |||
| a9fd20b494 | |||
| ba241cdd82 | |||
| 42574d1111 | |||
| 1e9a335240 | |||
| f53dee6953 | |||
| 9c4da76b8f | |||
| d083a5a07b | |||
| 3cb26b7d20 | |||
| 6e0ddc2a83 | |||
| c44e97745f | |||
| 134424c21f | |||
| f7ffe3683b | |||
| ef2ac57f32 | |||
| 6fb08153f4 | |||
| 3195c32f97 | |||
| 1812a39108 | |||
| aed72a5ab5 | |||
| 44da350e3c | |||
| 39ee5aa38c | |||
| c6bbf7be90 | |||
| 340383afc8 | |||
| 6ffa524ce7 | |||
| 87fb040169 | |||
| d4db442b63 | |||
| 39d56b6782 | |||
| 0487e0f2d0 | |||
| c288f71826 | |||
| 157959e537 | |||
| 126bfc2d56 | |||
| e5dee248b6 | |||
| 20adced4d7 | |||
| 86b0d52586 | |||
| d86b228c6e | |||
| 61eea0b8f6 | |||
| d1ee732f91 |
+13
@@ -0,0 +1,13 @@
|
||||
container:
|
||||
image: gradle:jdk8
|
||||
|
||||
testCoverage_task:
|
||||
gradle_cache:
|
||||
folder: ~/.gradle/caches
|
||||
testCoverage_script: gradle jacocoTestReport && bash <(curl -s https://codecov.io/bash)
|
||||
cleanup_before_cache_script:
|
||||
- rm -rf ~/.gradle/caches/$GRADLE_VERSION/
|
||||
- rm -rf ~/.gradle/caches/transforms-1
|
||||
- rm -rf ~/.gradle/caches/journal-1
|
||||
- rm -rf ~/.gradle/caches/jars-3/*/buildSrc.jar
|
||||
- find ~/.gradle/caches/ -name "*.lock" -type f -delete
|
||||
@@ -0,0 +1,9 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: maven
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
time: "03:00"
|
||||
open-pull-requests-limit: 10
|
||||
target-branch: dev
|
||||
@@ -0,0 +1,67 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ dev ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ dev ]
|
||||
schedule:
|
||||
- cron: '27 20 * * 1'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'java' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||
# Learn more:
|
||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
+5
-24
@@ -1,25 +1,6 @@
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
*.iml
|
||||
.idea/
|
||||
target/
|
||||
**/ApplicationTest.java
|
||||
.idea
|
||||
.gradle
|
||||
build
|
||||
target
|
||||
out
|
||||
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Alexey Zinchenko
|
||||
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
|
||||
|
||||
@@ -1,266 +1,110 @@
|
||||
# OpenWeatherMap Java API
|
||||
# OpenWeatherMap Java API [![Build Status][ci-shield]][ci-link] [![codecov][codecov-shield]][codecov-link] [![FOSSA Status][FOSSA-shield]][FOSSA-link]
|
||||
Java API for OpenWeatherMap services.
|
||||
|
||||
### Implemented features:
|
||||
Free:
|
||||
* Current weather data
|
||||
* 5 day / 3 hour forecast
|
||||
* 5 day / 3-hour forecast
|
||||
* One Call API
|
||||
* Air pollution
|
||||
* Geocoding API
|
||||
|
||||
Paid:
|
||||
* Hourly Forecast 4 days
|
||||
* Daily Forecast 16 days
|
||||
* Climatic Forecast 30 days
|
||||
* Solar Radiation API
|
||||
* Road Risk API
|
||||
|
||||
Other:
|
||||
* Request timeout settings
|
||||
|
||||
### Will be implemented later:
|
||||
* 16 day / daily forecast
|
||||
* UV Index(beta)
|
||||
* Air pollution(beta)
|
||||
|
||||
Free:
|
||||
* Weather Stations
|
||||
* Weather Triggers
|
||||
|
||||
Paid:
|
||||
* Bulk Downloading
|
||||
* Historical Weather API
|
||||
* Historical Weather API 40 years by timestamp
|
||||
* Historical Weather API 40 years full archive
|
||||
* History Bulk
|
||||
* History Forecast Bulk
|
||||
* Statistical Weather Data API
|
||||
* Accumulated Parameters
|
||||
* Historical Weather Data by State for all ZIP codes, USA
|
||||
|
||||
### Maven coordinates:
|
||||
|
||||
_Not available yet._
|
||||
|
||||
### How to use:
|
||||
|
||||
Firstly, you need to create the instance of `OpenWeatherMapManager` class:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
```
|
||||
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
||||
|
||||
Currently available methods:
|
||||
* `getWeatherRequester()`
|
||||
* `getForecastRequester()`
|
||||
|
||||
#### Current weather data
|
||||
First step is retrieving `WeatherRequester` instance:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
WeatherRequester weatherRequester = openWeatherManager.getWeatherRequester();
|
||||
```
|
||||
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||
```
|
||||
Weather weatherResponse = weatherRequester
|
||||
.setLanguage(Language.ENGLISH)
|
||||
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||
.setAccuracy(Accuracy.ACCURATE)
|
||||
.getByCityName("Minsk");
|
||||
```
|
||||
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||
|
||||
Available requests:
|
||||
* `getByCityId(String cityId)`
|
||||
* `getByCityName(String cityName)`
|
||||
* `getByCoordinates(double latitude, double longitude)`
|
||||
* `getByCoordinates(Coordinates coordinates)`
|
||||
* `getByZIPCode(String zipCode, String countryCode)`
|
||||
|
||||
`Weather`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||
| `getBase()` | Returns `String` with some internal information. Example: `cmc stations` - from official documentation. |
|
||||
| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, pressure and humidity. |
|
||||
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
|
||||
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
|
||||
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
||||
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
||||
| `getDataCalculationTime()`| Returns `long` value that represents data calculation timestamp. |
|
||||
| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset time. |
|
||||
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||
| `getCountry()` | An alias for `getWeatherSystemInfo().getCountry()`. |
|
||||
| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. |
|
||||
| `getDataCalculationDate()`| Returns data calculation time in `Date` representation. |
|
||||
| `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. |
|
||||
| `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. |
|
||||
| `getPressure()` | An alias for `getWeatherInfo().getPressure()`. |
|
||||
| `getPressureUnit()` | An alias for `getWeatherInfo().getPressureUnit()`. |
|
||||
| `getHumidityPercentage()` | An alias for `getWeatherInfo().getHumidity()`. |
|
||||
| `toString()` | Returns pretty string for the whole available weather information. |
|
||||
|
||||
`toString()` output example:
|
||||
```
|
||||
City: Minsk(625144). Coordinates: latitude=53.9, longitude=27.56
|
||||
Country: BY
|
||||
Sunrise: Sun Jul 15 04:58:27 MSK 2018
|
||||
Sunset: Sun Jul 15 21:32:19 MSK 2018
|
||||
Weather: light intensity shower rain
|
||||
Temperature: 17.0 ℃. Minimum temparature: 17.0 ℃. Maximum temperature: 17.0 ℃
|
||||
Humidity: 93%
|
||||
Pressure: 1008 hPa
|
||||
Wind: 2.0 meter/sec, 20 degrees
|
||||
Cloudiness: 75%
|
||||
Data calculation time: Mon Jul 16 00:00:00 MSK 2018
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
#### 5 day / 3 hour forecast
|
||||
First step is retrieving `HourlyForecastRequester` instance:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
ForecastRequester forecastRequester = openWeatherManager.getForecastRequester();
|
||||
```
|
||||
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||
```
|
||||
HourlyForecast forecastResponse = forecastRequester
|
||||
.setLanguage(Language.ENGLISH)
|
||||
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||
.setAccuracy(Accuracy.ACCURATE)
|
||||
.getByCityName("Pruzhany");
|
||||
```
|
||||
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||
|
||||
Available requests:
|
||||
* `getByCityId(String cityId)`
|
||||
* `getByCityName(String cityName)`
|
||||
* `getByCoordinates(double latitude, double longitude)`
|
||||
* `getByCoordinates(Coordinates coordinates)`
|
||||
* `getByZIPCode(String zipCode, String countryCode)`
|
||||
|
||||
`HourlyForecast`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-----------------------------|--------------------------------------------------------------------------------------------|
|
||||
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||
| `getCityInfo()` | Returns `HourlyForecast.CityInfo` instance that contains information about city. |
|
||||
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
|
||||
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
|
||||
| `getAverageTemperature()` | Returns average temperature from forecasts. |
|
||||
| `getMinimumTemperature()` | Returns minimum temperature from forecasts. |
|
||||
| `getMaximumTemperature()` | Returns maximum temperature from forecasts. |
|
||||
| `getByMinimumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is minimal. |
|
||||
| `getByMaximumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is maximal. |
|
||||
| `getAveragePressure()` | Returns average pressure from forecasts. |
|
||||
| `getMinimumPressure()` | Returns minimum pressure from forecasts. |
|
||||
| `getMaximumPressure()` | Returns maximum pressure from forecasts. |
|
||||
| `getByMinimumPressure()` | Returns `HourlyForecast.Forecast` for the time where pressure is minimal. |
|
||||
| `getByMaximumPressure()` | Returns `HourlyForecast.Forecast` for the time where pressure is maximal. |
|
||||
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||
|
||||
`toString()` output example:
|
||||
```
|
||||
City: Pruzhany(622997). Coordinates: latitude=52.5582, longitude=24.4567
|
||||
Country: BY
|
||||
Forecasts:
|
||||
Time: Tue Jul 17 00:00:00 MSK 2018. Weather: light rain. Temperature: 16.24 ℃. Minimum temperature: 16.24 ℃. Maximum temperature: 17.36 ℃. Pressure: 997.38 hPa. Sea-level pressure: 1018.59 hPa. Ground-level pressure: 997.38 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 2.85 meter/sec, 324 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 03:00:00 MSK 2018. Weather: moderate rain. Temperature: 16.0 ℃. Minimum temperature: 16.0 ℃. Maximum temperature: 16.83 ℃. Pressure: 996.88 hPa. Sea-level pressure: 1017.86 hPa. Ground-level pressure: 996.88 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 1.86 meter/sec, 349 degrees. Rain(last 3 hrs): 3 mm
|
||||
Time: Tue Jul 17 06:00:00 MSK 2018. Weather: light rain. Temperature: 15.76 ℃. Minimum temperature: 15.76 ℃. Maximum temperature: 16.31 ℃. Pressure: 996.7 hPa. Sea-level pressure: 1017.72 hPa. Ground-level pressure: 996.7 hPa. Humidity: 94%. Cloudiness: 76%. Wind: 1.62 meter/sec, 113 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 09:00:00 MSK 2018. Weather: light rain. Temperature: 18.23 ℃. Minimum temperature: 18.23 ℃. Maximum temperature: 18.51 ℃. Pressure: 997.17 hPa. Sea-level pressure: 1018.18 hPa. Ground-level pressure: 997.17 hPa. Humidity: 100%. Cloudiness: 76%. Wind: 2.11 meter/sec, 107 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 12:00:00 MSK 2018. Weather: light rain. Temperature: 21.0 ℃. Minimum temperature: 21.0 ℃. Maximum temperature: 21.0 ℃. Pressure: 997.6 hPa. Sea-level pressure: 1018.5 hPa. Ground-level pressure: 997.6 hPa. Humidity: 100%. Cloudiness: 68%. Wind: 2.51 meter/sec, 82 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 15:00:00 MSK 2018. Weather: light rain. Temperature: 21.78 ℃. Minimum temperature: 21.78 ℃. Maximum temperature: 21.78 ℃. Pressure: 997.73 hPa. Sea-level pressure: 1018.66 hPa. Ground-level pressure: 997.73 hPa. Humidity: 92%. Cloudiness: 88%. Wind: 4.05 meter/sec, 78 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 18:00:00 MSK 2018. Weather: light rain. Temperature: 22.9 ℃. Minimum temperature: 22.9 ℃. Maximum temperature: 22.9 ℃. Pressure: 997.66 hPa. Sea-level pressure: 1018.55 hPa. Ground-level pressure: 997.66 hPa. Humidity: 93%. Cloudiness: 68%. Wind: 3.06 meter/sec, 67 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 21:00:00 MSK 2018. Weather: light rain. Temperature: 23.04 ℃. Minimum temperature: 23.04 ℃. Maximum temperature: 23.04 ℃. Pressure: 996.89 hPa. Sea-level pressure: 1017.99 hPa. Ground-level pressure: 996.89 hPa. Humidity: 83%. Cloudiness: 88%. Wind: 3.17 meter/sec, 16 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 00:00:00 MSK 2018. Weather: moderate rain. Temperature: 18.5 ℃. Minimum temperature: 18.5 ℃. Maximum temperature: 18.5 ℃. Pressure: 997.33 hPa. Sea-level pressure: 1018.34 hPa. Ground-level pressure: 997.33 hPa. Humidity: 97%. Cloudiness: 44%. Wind: 3.56 meter/sec, 31 degrees. Rain(last 3 hrs): 7 mm
|
||||
Time: Wed Jul 18 03:00:00 MSK 2018. Weather: few clouds. Temperature: 18.57 ℃. Minimum temperature: 18.57 ℃. Maximum temperature: 18.57 ℃. Pressure: 996.91 hPa. Sea-level pressure: 1017.87 hPa. Ground-level pressure: 996.91 hPa. Humidity: 95%. Cloudiness: 24%. Wind: 5.26 meter/sec, 44 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 06:00:00 MSK 2018. Weather: few clouds. Temperature: 18.94 ℃. Minimum temperature: 18.94 ℃. Maximum temperature: 18.94 ℃. Pressure: 997.07 hPa. Sea-level pressure: 1018.06 hPa. Ground-level pressure: 997.07 hPa. Humidity: 95%. Cloudiness: 20%. Wind: 4.8 meter/sec, 45 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 09:00:00 MSK 2018. Weather: light rain. Temperature: 20.6 ℃. Minimum temperature: 20.6 ℃. Maximum temperature: 20.6 ℃. Pressure: 997.8 hPa. Sea-level pressure: 1018.66 hPa. Ground-level pressure: 997.8 hPa. Humidity: 97%. Cloudiness: 48%. Wind: 5.56 meter/sec, 54 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 12:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.87 ℃. Minimum temperature: 23.87 ℃. Maximum temperature: 23.87 ℃. Pressure: 998.06 hPa. Sea-level pressure: 1019.05 hPa. Ground-level pressure: 998.06 hPa. Humidity: 88%. Cloudiness: 32%. Wind: 5.86 meter/sec, 52 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 24.67 ℃. Minimum temperature: 24.67 ℃. Maximum temperature: 24.67 ℃. Pressure: 998.51 hPa. Sea-level pressure: 1019.33 hPa. Ground-level pressure: 998.51 hPa. Humidity: 84%. Cloudiness: 36%. Wind: 5.63 meter/sec, 51 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.15 ℃. Minimum temperature: 25.15 ℃. Maximum temperature: 25.15 ℃. Pressure: 998.79 hPa. Sea-level pressure: 1019.64 hPa. Ground-level pressure: 998.79 hPa. Humidity: 78%. Cloudiness: 44%. Wind: 5.47 meter/sec, 38 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.23 ℃. Minimum temperature: 23.23 ℃. Maximum temperature: 23.23 ℃. Pressure: 999.08 hPa. Sea-level pressure: 1020.04 hPa. Ground-level pressure: 999.08 hPa. Humidity: 75%. Cloudiness: 48%. Wind: 4.62 meter/sec, 25 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 20.79 ℃. Minimum temperature: 20.79 ℃. Maximum temperature: 20.79 ℃. Pressure: 999.67 hPa. Sea-level pressure: 1020.68 hPa. Ground-level pressure: 999.67 hPa. Humidity: 76%. Cloudiness: 48%. Wind: 4.29 meter/sec, 13 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 03:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.45 ℃. Minimum temperature: 19.45 ℃. Maximum temperature: 19.45 ℃. Pressure: 999.95 hPa. Sea-level pressure: 1021.02 hPa. Ground-level pressure: 999.95 hPa. Humidity: 80%. Cloudiness: 48%. Wind: 4.22 meter/sec, 17 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 06:00:00 MSK 2018. Weather: light rain. Temperature: 18.9 ℃. Minimum temperature: 18.9 ℃. Maximum temperature: 18.9 ℃. Pressure: 1000.6 hPa. Sea-level pressure: 1021.62 hPa. Ground-level pressure: 1000.6 hPa. Humidity: 83%. Cloudiness: 92%. Wind: 4.43 meter/sec, 10 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 09:00:00 MSK 2018. Weather: light rain. Temperature: 21.37 ℃. Minimum temperature: 21.37 ℃. Maximum temperature: 21.37 ℃. Pressure: 1000.95 hPa. Sea-level pressure: 1022.01 hPa. Ground-level pressure: 1000.95 hPa. Humidity: 87%. Cloudiness: 0%. Wind: 4.36 meter/sec, 6 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.92 ℃. Minimum temperature: 23.92 ℃. Maximum temperature: 23.92 ℃. Pressure: 1001.5 hPa. Sea-level pressure: 1022.43 hPa. Ground-level pressure: 1001.5 hPa. Humidity: 77%. Cloudiness: 0%. Wind: 5.66 meter/sec, 12 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 15:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.7 ℃. Minimum temperature: 23.7 ℃. Maximum temperature: 23.7 ℃. Pressure: 1001.75 hPa. Sea-level pressure: 1022.72 hPa. Ground-level pressure: 1001.75 hPa. Humidity: 72%. Cloudiness: 56%. Wind: 5.87 meter/sec, 349 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 18:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.82 ℃. Minimum temperature: 23.82 ℃. Maximum temperature: 23.82 ℃. Pressure: 1001.55 hPa. Sea-level pressure: 1022.59 hPa. Ground-level pressure: 1001.55 hPa. Humidity: 72%. Cloudiness: 68%. Wind: 5.47 meter/sec, 340 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.22 ℃. Minimum temperature: 22.22 ℃. Maximum temperature: 22.22 ℃. Pressure: 1001.82 hPa. Sea-level pressure: 1022.93 hPa. Ground-level pressure: 1001.82 hPa. Humidity: 67%. Cloudiness: 76%. Wind: 4.12 meter/sec, 333 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.76 ℃. Minimum temperature: 19.76 ℃. Maximum temperature: 19.76 ℃. Pressure: 1001.98 hPa. Sea-level pressure: 1023.13 hPa. Ground-level pressure: 1001.98 hPa. Humidity: 76%. Cloudiness: 32%. Wind: 4.11 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 03:00:00 MSK 2018. Weather: clear sky. Temperature: 17.53 ℃. Minimum temperature: 17.53 ℃. Maximum temperature: 17.53 ℃. Pressure: 1001.93 hPa. Sea-level pressure: 1023.13 hPa. Ground-level pressure: 1001.93 hPa. Humidity: 87%. Cloudiness: 8%. Wind: 4.21 meter/sec, 309 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 16.83 ℃. Minimum temperature: 16.83 ℃. Maximum temperature: 16.83 ℃. Pressure: 1001.79 hPa. Sea-level pressure: 1022.99 hPa. Ground-level pressure: 1001.79 hPa. Humidity: 91%. Cloudiness: 44%. Wind: 3.65 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 09:00:00 MSK 2018. Weather: light rain. Temperature: 19.57 ℃. Minimum temperature: 19.57 ℃. Maximum temperature: 19.57 ℃. Pressure: 1001.34 hPa. Sea-level pressure: 1022.41 hPa. Ground-level pressure: 1001.34 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 4.38 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.5 ℃. Minimum temperature: 23.5 ℃. Maximum temperature: 23.5 ℃. Pressure: 1001.0 hPa. Sea-level pressure: 1021.99 hPa. Ground-level pressure: 1001.0 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 5.36 meter/sec, 299 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.14 ℃. Minimum temperature: 25.14 ℃. Maximum temperature: 25.14 ℃. Pressure: 1000.5 hPa. Sea-level pressure: 1021.51 hPa. Ground-level pressure: 1000.5 hPa. Humidity: 73%. Cloudiness: 32%. Wind: 6.72 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 18:00:00 MSK 2018. Weather: overcast clouds. Temperature: 23.56 ℃. Minimum temperature: 23.56 ℃. Maximum temperature: 23.56 ℃. Pressure: 1000.7 hPa. Sea-level pressure: 1021.58 hPa. Ground-level pressure: 1000.7 hPa. Humidity: 66%. Cloudiness: 88%. Wind: 6.57 meter/sec, 317 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.41 ℃. Minimum temperature: 22.41 ℃. Maximum temperature: 22.41 ℃. Pressure: 1000.64 hPa. Sea-level pressure: 1021.67 hPa. Ground-level pressure: 1000.64 hPa. Humidity: 68%. Cloudiness: 64%. Wind: 4.31 meter/sec, 326 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 00:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.92 ℃. Minimum temperature: 20.92 ℃. Maximum temperature: 20.92 ℃. Pressure: 1001.06 hPa. Sea-level pressure: 1022.14 hPa. Ground-level pressure: 1001.06 hPa. Humidity: 78%. Cloudiness: 68%. Wind: 3.42 meter/sec, 327 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 03:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.28 ℃. Minimum temperature: 20.28 ℃. Maximum temperature: 20.28 ℃. Pressure: 1001.04 hPa. Sea-level pressure: 1022.13 hPa. Ground-level pressure: 1001.04 hPa. Humidity: 78%. Cloudiness: 76%. Wind: 4.27 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.11 ℃. Minimum temperature: 19.11 ℃. Maximum temperature: 19.11 ℃. Pressure: 1001.13 hPa. Sea-level pressure: 1022.28 hPa. Ground-level pressure: 1001.13 hPa. Humidity: 74%. Cloudiness: 32%. Wind: 4.96 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 09:00:00 MSK 2018. Weather: few clouds. Temperature: 20.16 ℃. Minimum temperature: 20.16 ℃. Maximum temperature: 20.16 ℃. Pressure: 1001.43 hPa. Sea-level pressure: 1022.62 hPa. Ground-level pressure: 1001.43 hPa. Humidity: 86%. Cloudiness: 20%. Wind: 5.16 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 12:00:00 MSK 2018. Weather: few clouds. Temperature: 22.37 ℃. Minimum temperature: 22.37 ℃. Maximum temperature: 22.37 ℃. Pressure: 1001.53 hPa. Sea-level pressure: 1022.62 hPa. Ground-level pressure: 1001.53 hPa. Humidity: 88%. Cloudiness: 20%. Wind: 5.56 meter/sec, 307 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.85 ℃. Minimum temperature: 22.85 ℃. Maximum temperature: 22.85 ℃. Pressure: 1001.63 hPa. Sea-level pressure: 1022.65 hPa. Ground-level pressure: 1001.63 hPa. Humidity: 81%. Cloudiness: 44%. Wind: 5.46 meter/sec, 314 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.79 ℃. Minimum temperature: 23.79 ℃. Maximum temperature: 23.79 ℃. Pressure: 1001.53 hPa. Sea-level pressure: 1022.53 hPa. Ground-level pressure: 1001.53 hPa. Humidity: 72%. Cloudiness: 32%. Wind: 5.56 meter/sec, 313 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.56 ℃. Minimum temperature: 22.56 ℃. Maximum temperature: 22.56 ℃. Pressure: 1001.72 hPa. Sea-level pressure: 1022.7 hPa. Ground-level pressure: 1001.72 hPa. Humidity: 66%. Cloudiness: 48%. Wind: 3.96 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||
```xml
|
||||
<repositories>
|
||||
...
|
||||
<!-- Repository for snapshot versions -->
|
||||
<repository>
|
||||
<id>oss.sonatype.org-snapshot</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
...
|
||||
</repositories>
|
||||
```
|
||||
|
||||
`Forecast`'s useful public methods(setters are not listed):
|
||||
### Gradle coordinates:
|
||||
|
||||
| Method | Description |
|
||||
|-----------------------------|------------------------------------------------------------------------------------------------------------------|
|
||||
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
|
||||
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
|
||||
| `getWeatherInfo()` | Returns `HourlyForecast.WeatherInfo` instance that contains information about temperature, pressure and humidity.|
|
||||
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
|
||||
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
|
||||
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
||||
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
||||
| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. |
|
||||
| `getDt_txt()` | Returns `String` value that represents data calculation time. |
|
||||
| `toString()` | Returns pretty string for the whole available weather information. |
|
||||
```groovy
|
||||
implementation 'com.github.prominence:openweathermap-api:3.0.0-SNAPSHOT'
|
||||
```
|
||||
|
||||
```groovy
|
||||
repositories {
|
||||
...
|
||||
// Repository for snapshot versions
|
||||
maven {
|
||||
url "https://oss.sonatype.org/content/repositories/snapshots"
|
||||
mavenContent {
|
||||
snapshotsOnly()
|
||||
}
|
||||
}
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
### Constants and options
|
||||
|
||||
#### Accuracy
|
||||
| Constant | Description |
|
||||
|--------------------|------------------|
|
||||
| Accuracy.LIKE | Close result. |
|
||||
| Accuracy.ACCURATE | Accurate result. |
|
||||
|
||||
#### Language
|
||||
| Constant | Description |
|
||||
|-----------------------------------|-------------------------------|
|
||||
| Language.ARABIC | Arabic language. |
|
||||
| Language.BULGARIAN | Bulgarian language. |
|
||||
| Language.CATALAN | Catalan language. |
|
||||
| Language.CZECH | Czech language. |
|
||||
| Language.GERMAN | German language. |
|
||||
| Language.GREEK | Greek language. |
|
||||
| Language.ENGLISH | English language. |
|
||||
| Language.PERSIAN | Persian (Farsi) language. |
|
||||
| Language.FINNISH | Finnish language. |
|
||||
| Language.FRENCH | French language. |
|
||||
| Language.GALICIAN | Galician language. |
|
||||
| Language.CROATIAN | Croatian language. |
|
||||
| Language.HUNGARIAN | Hungarian language. |
|
||||
| Language.ITALIAN | Italian language. |
|
||||
| Language.JAPANESE | Japanese language. |
|
||||
| Language.KOREAN | Korean language. |
|
||||
| Language.LATVIAN | Latvian language. |
|
||||
| Language.LITHUANIAN | Lithuanian language. |
|
||||
| Language.MACEDONIAN | Macedonian language. |
|
||||
| Language.DUTCH | Dutch language. |
|
||||
| Language.POLISH | Polish language. |
|
||||
| Language.PORTUGUESE | Portuguese language. |
|
||||
| Language.ROMANIAN | Romanian language. |
|
||||
| Language.RUSSIAN | Russian language. |
|
||||
| Language.SWEDISH | Swedish language. |
|
||||
| Language.SLOVAK | Slovak language. |
|
||||
| Language.SLOVENIAN | Slovenian language. |
|
||||
| Language.SPANISH | Spanish language. |
|
||||
| Language.TURKISH | Turkish language. |
|
||||
| Language.UKRANIAN | Ukrainian language. |
|
||||
| Language.VIETNAMESE | Vietnamese language. |
|
||||
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||
|
||||
#### System
|
||||
| Constant | Description |
|
||||
|-------------------------------|-----------------------|
|
||||
|System.OPEN_WEATHER_API_URL | Basic API url. |
|
||||
|System.OPEN_WEATHER_API_VERSION| Current API version. |
|
||||
|
||||
#### Unit
|
||||
| Constant | Description |
|
||||
|----------------------|------------------------------------------------|
|
||||
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
|
||||
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
|
||||
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow) |
|
||||
|
||||
### Dependencies
|
||||
* com.alibaba:fastjson:1.2.44
|
||||
### Documentation
|
||||
* [OpenWeatherMap Java API - 1.0](docs/Release_1.0.md)
|
||||
* [OpenWeatherMap Java API - 1.1](docs/Release_1.1.md)
|
||||
* [OpenWeatherMap Java API - 1.2](docs/Release_1.2.md)
|
||||
* [OpenWeatherMap Java API - 2.0.0](docs/Release_2.0.0.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.1](docs/Release_2.1.1.md)
|
||||
* [OpenWeatherMap Java API - 2.2.0](docs/Release_2.2.0.md)
|
||||
* [OpenWeatherMap Java API - 2.3.0](docs/Release_2.3.0.md)
|
||||
* [OpenWeatherMap Java API - SNAPSHOT](docs/SNAPSHOT.md)
|
||||
|
||||
### License
|
||||
MIT
|
||||
|
||||
[ci-shield]: https://api.cirrus-ci.com/github/Prominence/openweathermap-java-api.svg?branch=dev
|
||||
[ci-link]: https://api.cirrus-ci.com/github/Prominence/openweathermap-java-api
|
||||
|
||||
|
||||
[codecov-shield]: https://codecov.io/gh/Prominence/openweathermap-java-api/branch/dev/graph/badge.svg
|
||||
[codecov-link]: https://codecov.io/gh/Prominence/openweathermap-java-api
|
||||
|
||||
[FOSSA-shield]: https://app.fossa.com/api/projects/git%2Bgithub.com%2FProminence%2Fopenweathermap-java-api.svg?type=shield
|
||||
[FOSSA-link]: https://app.fossa.com/projects/git%2Bgithub.com%2FProminence%2Fopenweathermap-java-api?ref=badge_shield
|
||||
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
plugins {
|
||||
id 'java-library'
|
||||
id 'maven-publish'
|
||||
id 'signing'
|
||||
id 'jacoco'
|
||||
id 'io.freefair.lombok' version '6.5.0.3'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.4'
|
||||
implementation 'org.slf4j:slf4j-api:1.7.36'
|
||||
|
||||
testImplementation 'org.junit.platform:junit-platform-runner:1.9.0'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.0'
|
||||
testImplementation 'ch.qos.logback:logback-classic:1.2.11'
|
||||
testImplementation 'commons-io:commons-io:2.11.0'
|
||||
testImplementation 'org.mockito:mockito-core:4.8.0'
|
||||
}
|
||||
|
||||
group = 'com.github.prominence'
|
||||
version = '3.0.0-SNAPSHOT'
|
||||
description = 'Java OpenWeatherMap API'
|
||||
|
||||
configure([tasks.compileJava]) {
|
||||
sourceCompatibility = 8
|
||||
}
|
||||
|
||||
ext {
|
||||
isReleaseVersion = !version.endsWith("SNAPSHOT")
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
withJavadocJar()
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
from components.java
|
||||
|
||||
pom {
|
||||
name = 'Java OpenWeatherMap API'
|
||||
description = 'Java API for OpenWeatherMap services.'
|
||||
url = 'https://github.com/Prominence/openweathermap-java-api'
|
||||
|
||||
licenses {
|
||||
license {
|
||||
name = 'MIT License'
|
||||
url = 'https://www.opensource.org/licenses/mit-license.php'
|
||||
}
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id = 'Prominence'
|
||||
name = 'Alexey Zinchenko'
|
||||
email = 'alexey.zinchenko@protonmail.com'
|
||||
url = 'https://github.com/prominence'
|
||||
}
|
||||
}
|
||||
scm {
|
||||
connection = 'scm:git:git://github.com/Prominence/openweathermap-java-api.git'
|
||||
developerConnection = 'scm:git:git@github.com:prominence/openweathermap-java-api.git'
|
||||
url = 'https://github.com/Prominence/openweathermap-java-api'
|
||||
}
|
||||
issueManagement {
|
||||
url = 'https://github.com/Prominence/openweathermap-java-api/issues'
|
||||
system = 'GitHub Issues'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
credentials {
|
||||
username = project.findProperty('ossrhUsername')
|
||||
password = project.findProperty('ossrhPassword')
|
||||
}
|
||||
|
||||
url = isReleaseVersion ?
|
||||
'https://oss.sonatype.org/service/local/staging/deploy/maven2/' :
|
||||
'https://oss.sonatype.org/content/repositories/snapshots/'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signing {
|
||||
sign publishing.publications.mavenJava
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
|
||||
tasks.withType(GenerateModuleMetadata) {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
jacocoTestReport {
|
||||
dependsOn test // tests are required to run before generating the report
|
||||
reports {
|
||||
csv.required = false
|
||||
xml.required = true
|
||||
xml.outputLocation = layout.buildDirectory.file('reports/jacoco/report.xml')
|
||||
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
### Implemented features:
|
||||
* Current weather data
|
||||
* 5 day / 3 hour forecast
|
||||
|
||||
### Maven coordinates:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
implementation 'com.github.prominence:openweathermap-api:1.0'
|
||||
```
|
||||
|
||||
### How to use:
|
||||
|
||||
Firstly, you need to create the instance of `OpenWeatherMapManager` class:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
```
|
||||
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
||||
|
||||
Currently available methods:
|
||||
* `getWeatherRequester()`
|
||||
* `getForecastRequester()`
|
||||
|
||||
#### Current weather data
|
||||
First step is retrieving `WeatherRequester` instance:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
WeatherRequester weatherRequester = openWeatherManager.getWeatherRequester();
|
||||
```
|
||||
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||
```
|
||||
Weather weatherResponse = weatherRequester
|
||||
.setLanguage(Language.ENGLISH)
|
||||
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||
.setAccuracy(Accuracy.ACCURATE)
|
||||
.getByCityName("Minsk");
|
||||
```
|
||||
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||
|
||||
Available requests:
|
||||
* `getByCityId(String cityId)`
|
||||
* `getByCityName(String cityName)`
|
||||
* `getByCoordinates(double latitude, double longitude)`
|
||||
* `getByCoordinates(Coordinates coordinates)`
|
||||
* `getByZIPCode(String zipCode, String countryCode)`
|
||||
|
||||
`Weather`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||
| `getBase()` | Returns `String` with some internal information. Example: `cmc stations` - from official documentation. |
|
||||
| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, atmosphericPressure and humidity. |
|
||||
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
|
||||
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
|
||||
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
||||
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
||||
| `getDataCalculationTime()`| Returns `long` value that represents data calculation timestamp. |
|
||||
| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset time. |
|
||||
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||
| `getCountry()` | An alias for `getWeatherSystemInfo().getCountry()`. |
|
||||
| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. |
|
||||
| `getDataCalculationDate()`| Returns data calculation time in `Date` representation. |
|
||||
| `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. |
|
||||
| `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. |
|
||||
| `getPressure()` | An alias for `getWeatherInfo().getPressure()`. |
|
||||
| `getPressureUnit()` | An alias for `getWeatherInfo().getPressureUnit()`. |
|
||||
| `getHumidityPercentage()` | An alias for `getWeatherInfo().getHumidity()`. |
|
||||
| `toString()` | Returns pretty string for the whole available weather information. |
|
||||
|
||||
`toString()` output example:
|
||||
```
|
||||
City: Minsk(625144). Coordinates: latitude=53.9, longitude=27.56
|
||||
Country: BY
|
||||
Sunrise: Sun Jul 15 04:58:27 MSK 2018
|
||||
Sunset: Sun Jul 15 21:32:19 MSK 2018
|
||||
Weather: light intensity shower rain
|
||||
Temperature: 17.0 ℃. Minimum temparature: 17.0 ℃. Maximum temperature: 17.0 ℃
|
||||
Humidity: 93%
|
||||
Pressure: 1008 hPa
|
||||
Wind: 2.0 meter/sec, 20 degrees
|
||||
Cloudiness: 75%
|
||||
Data calculation time: Mon Jul 16 00:00:00 MSK 2018
|
||||
```
|
||||
|
||||
#### 5 day / 3 hour forecast
|
||||
First step is retrieving `HourlyForecastRequester` instance:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
ForecastRequester forecastRequester = openWeatherManager.getForecastRequester();
|
||||
```
|
||||
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||
```
|
||||
HourlyForecast forecastResponse = forecastRequester
|
||||
.setLanguage(Language.ENGLISH)
|
||||
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||
.setAccuracy(Accuracy.ACCURATE)
|
||||
.getByCityName("Pruzhany");
|
||||
```
|
||||
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||
|
||||
Available requests:
|
||||
* `getByCityId(String cityId)`
|
||||
* `getByCityName(String cityName)`
|
||||
* `getByCoordinates(double latitude, double longitude)`
|
||||
* `getByCoordinates(Coordinates coordinates)`
|
||||
* `getByZIPCode(String zipCode, String countryCode)`
|
||||
|
||||
`HourlyForecast`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-----------------------------|--------------------------------------------------------------------------------------------|
|
||||
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||
| `getCityInfo()` | Returns `HourlyForecast.CityInfo` instance that contains information about city. |
|
||||
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
|
||||
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
|
||||
| `getAverageTemperature()` | Returns average temperature from forecasts. |
|
||||
| `getMinimumTemperature()` | Returns minimum temperature from forecasts. |
|
||||
| `getMaximumTemperature()` | Returns maximum temperature from forecasts. |
|
||||
| `getByMinimumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is minimal. |
|
||||
| `getByMaximumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is maximal. |
|
||||
| `getAveragePressure()` | Returns average atmosphericPressure from forecasts. |
|
||||
| `getMinimumPressure()` | Returns minimum atmosphericPressure from forecasts. |
|
||||
| `getMaximumPressure()` | Returns maximum atmosphericPressure from forecasts. |
|
||||
| `getByMinimumPressure()` | Returns `HourlyForecast.Forecast` for the time where atmosphericPressure is minimal. |
|
||||
| `getByMaximumPressure()` | Returns `HourlyForecast.Forecast` for the time where atmosphericPressure is maximal. |
|
||||
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||
|
||||
`toString()` output example:
|
||||
```
|
||||
City: Pruzhany(622997). Coordinates: latitude=52.5582, longitude=24.4567
|
||||
Country: BY
|
||||
Forecasts:
|
||||
Time: Tue Jul 17 00:00:00 MSK 2018. Weather: light rain. Temperature: 16.24 ℃. Minimum temperature: 16.24 ℃. Maximum temperature: 17.36 ℃. Pressure: 997.38 hPa. Sea-level atmosphericPressure: 1018.59 hPa. Ground-level atmosphericPressure: 997.38 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 2.85 meter/sec, 324 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 03:00:00 MSK 2018. Weather: moderate rain. Temperature: 16.0 ℃. Minimum temperature: 16.0 ℃. Maximum temperature: 16.83 ℃. Pressure: 996.88 hPa. Sea-level atmosphericPressure: 1017.86 hPa. Ground-level atmosphericPressure: 996.88 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 1.86 meter/sec, 349 degrees. Rain(last 3 hrs): 3 mm
|
||||
Time: Tue Jul 17 06:00:00 MSK 2018. Weather: light rain. Temperature: 15.76 ℃. Minimum temperature: 15.76 ℃. Maximum temperature: 16.31 ℃. Pressure: 996.7 hPa. Sea-level atmosphericPressure: 1017.72 hPa. Ground-level atmosphericPressure: 996.7 hPa. Humidity: 94%. Cloudiness: 76%. Wind: 1.62 meter/sec, 113 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 09:00:00 MSK 2018. Weather: light rain. Temperature: 18.23 ℃. Minimum temperature: 18.23 ℃. Maximum temperature: 18.51 ℃. Pressure: 997.17 hPa. Sea-level atmosphericPressure: 1018.18 hPa. Ground-level atmosphericPressure: 997.17 hPa. Humidity: 100%. Cloudiness: 76%. Wind: 2.11 meter/sec, 107 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 12:00:00 MSK 2018. Weather: light rain. Temperature: 21.0 ℃. Minimum temperature: 21.0 ℃. Maximum temperature: 21.0 ℃. Pressure: 997.6 hPa. Sea-level atmosphericPressure: 1018.5 hPa. Ground-level atmosphericPressure: 997.6 hPa. Humidity: 100%. Cloudiness: 68%. Wind: 2.51 meter/sec, 82 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 15:00:00 MSK 2018. Weather: light rain. Temperature: 21.78 ℃. Minimum temperature: 21.78 ℃. Maximum temperature: 21.78 ℃. Pressure: 997.73 hPa. Sea-level atmosphericPressure: 1018.66 hPa. Ground-level atmosphericPressure: 997.73 hPa. Humidity: 92%. Cloudiness: 88%. Wind: 4.05 meter/sec, 78 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 18:00:00 MSK 2018. Weather: light rain. Temperature: 22.9 ℃. Minimum temperature: 22.9 ℃. Maximum temperature: 22.9 ℃. Pressure: 997.66 hPa. Sea-level atmosphericPressure: 1018.55 hPa. Ground-level atmosphericPressure: 997.66 hPa. Humidity: 93%. Cloudiness: 68%. Wind: 3.06 meter/sec, 67 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 21:00:00 MSK 2018. Weather: light rain. Temperature: 23.04 ℃. Minimum temperature: 23.04 ℃. Maximum temperature: 23.04 ℃. Pressure: 996.89 hPa. Sea-level atmosphericPressure: 1017.99 hPa. Ground-level atmosphericPressure: 996.89 hPa. Humidity: 83%. Cloudiness: 88%. Wind: 3.17 meter/sec, 16 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 00:00:00 MSK 2018. Weather: moderate rain. Temperature: 18.5 ℃. Minimum temperature: 18.5 ℃. Maximum temperature: 18.5 ℃. Pressure: 997.33 hPa. Sea-level atmosphericPressure: 1018.34 hPa. Ground-level atmosphericPressure: 997.33 hPa. Humidity: 97%. Cloudiness: 44%. Wind: 3.56 meter/sec, 31 degrees. Rain(last 3 hrs): 7 mm
|
||||
Time: Wed Jul 18 03:00:00 MSK 2018. Weather: few clouds. Temperature: 18.57 ℃. Minimum temperature: 18.57 ℃. Maximum temperature: 18.57 ℃. Pressure: 996.91 hPa. Sea-level atmosphericPressure: 1017.87 hPa. Ground-level atmosphericPressure: 996.91 hPa. Humidity: 95%. Cloudiness: 24%. Wind: 5.26 meter/sec, 44 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 06:00:00 MSK 2018. Weather: few clouds. Temperature: 18.94 ℃. Minimum temperature: 18.94 ℃. Maximum temperature: 18.94 ℃. Pressure: 997.07 hPa. Sea-level atmosphericPressure: 1018.06 hPa. Ground-level atmosphericPressure: 997.07 hPa. Humidity: 95%. Cloudiness: 20%. Wind: 4.8 meter/sec, 45 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 09:00:00 MSK 2018. Weather: light rain. Temperature: 20.6 ℃. Minimum temperature: 20.6 ℃. Maximum temperature: 20.6 ℃. Pressure: 997.8 hPa. Sea-level atmosphericPressure: 1018.66 hPa. Ground-level atmosphericPressure: 997.8 hPa. Humidity: 97%. Cloudiness: 48%. Wind: 5.56 meter/sec, 54 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 12:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.87 ℃. Minimum temperature: 23.87 ℃. Maximum temperature: 23.87 ℃. Pressure: 998.06 hPa. Sea-level atmosphericPressure: 1019.05 hPa. Ground-level atmosphericPressure: 998.06 hPa. Humidity: 88%. Cloudiness: 32%. Wind: 5.86 meter/sec, 52 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 24.67 ℃. Minimum temperature: 24.67 ℃. Maximum temperature: 24.67 ℃. Pressure: 998.51 hPa. Sea-level atmosphericPressure: 1019.33 hPa. Ground-level atmosphericPressure: 998.51 hPa. Humidity: 84%. Cloudiness: 36%. Wind: 5.63 meter/sec, 51 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.15 ℃. Minimum temperature: 25.15 ℃. Maximum temperature: 25.15 ℃. Pressure: 998.79 hPa. Sea-level atmosphericPressure: 1019.64 hPa. Ground-level atmosphericPressure: 998.79 hPa. Humidity: 78%. Cloudiness: 44%. Wind: 5.47 meter/sec, 38 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.23 ℃. Minimum temperature: 23.23 ℃. Maximum temperature: 23.23 ℃. Pressure: 999.08 hPa. Sea-level atmosphericPressure: 1020.04 hPa. Ground-level atmosphericPressure: 999.08 hPa. Humidity: 75%. Cloudiness: 48%. Wind: 4.62 meter/sec, 25 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 20.79 ℃. Minimum temperature: 20.79 ℃. Maximum temperature: 20.79 ℃. Pressure: 999.67 hPa. Sea-level atmosphericPressure: 1020.68 hPa. Ground-level atmosphericPressure: 999.67 hPa. Humidity: 76%. Cloudiness: 48%. Wind: 4.29 meter/sec, 13 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 03:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.45 ℃. Minimum temperature: 19.45 ℃. Maximum temperature: 19.45 ℃. Pressure: 999.95 hPa. Sea-level atmosphericPressure: 1021.02 hPa. Ground-level atmosphericPressure: 999.95 hPa. Humidity: 80%. Cloudiness: 48%. Wind: 4.22 meter/sec, 17 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 06:00:00 MSK 2018. Weather: light rain. Temperature: 18.9 ℃. Minimum temperature: 18.9 ℃. Maximum temperature: 18.9 ℃. Pressure: 1000.6 hPa. Sea-level atmosphericPressure: 1021.62 hPa. Ground-level atmosphericPressure: 1000.6 hPa. Humidity: 83%. Cloudiness: 92%. Wind: 4.43 meter/sec, 10 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 09:00:00 MSK 2018. Weather: light rain. Temperature: 21.37 ℃. Minimum temperature: 21.37 ℃. Maximum temperature: 21.37 ℃. Pressure: 1000.95 hPa. Sea-level atmosphericPressure: 1022.01 hPa. Ground-level atmosphericPressure: 1000.95 hPa. Humidity: 87%. Cloudiness: 0%. Wind: 4.36 meter/sec, 6 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.92 ℃. Minimum temperature: 23.92 ℃. Maximum temperature: 23.92 ℃. Pressure: 1001.5 hPa. Sea-level atmosphericPressure: 1022.43 hPa. Ground-level atmosphericPressure: 1001.5 hPa. Humidity: 77%. Cloudiness: 0%. Wind: 5.66 meter/sec, 12 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 15:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.7 ℃. Minimum temperature: 23.7 ℃. Maximum temperature: 23.7 ℃. Pressure: 1001.75 hPa. Sea-level atmosphericPressure: 1022.72 hPa. Ground-level atmosphericPressure: 1001.75 hPa. Humidity: 72%. Cloudiness: 56%. Wind: 5.87 meter/sec, 349 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 18:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.82 ℃. Minimum temperature: 23.82 ℃. Maximum temperature: 23.82 ℃. Pressure: 1001.55 hPa. Sea-level atmosphericPressure: 1022.59 hPa. Ground-level atmosphericPressure: 1001.55 hPa. Humidity: 72%. Cloudiness: 68%. Wind: 5.47 meter/sec, 340 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.22 ℃. Minimum temperature: 22.22 ℃. Maximum temperature: 22.22 ℃. Pressure: 1001.82 hPa. Sea-level atmosphericPressure: 1022.93 hPa. Ground-level atmosphericPressure: 1001.82 hPa. Humidity: 67%. Cloudiness: 76%. Wind: 4.12 meter/sec, 333 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.76 ℃. Minimum temperature: 19.76 ℃. Maximum temperature: 19.76 ℃. Pressure: 1001.98 hPa. Sea-level atmosphericPressure: 1023.13 hPa. Ground-level atmosphericPressure: 1001.98 hPa. Humidity: 76%. Cloudiness: 32%. Wind: 4.11 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 03:00:00 MSK 2018. Weather: clear sky. Temperature: 17.53 ℃. Minimum temperature: 17.53 ℃. Maximum temperature: 17.53 ℃. Pressure: 1001.93 hPa. Sea-level atmosphericPressure: 1023.13 hPa. Ground-level atmosphericPressure: 1001.93 hPa. Humidity: 87%. Cloudiness: 8%. Wind: 4.21 meter/sec, 309 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 16.83 ℃. Minimum temperature: 16.83 ℃. Maximum temperature: 16.83 ℃. Pressure: 1001.79 hPa. Sea-level atmosphericPressure: 1022.99 hPa. Ground-level atmosphericPressure: 1001.79 hPa. Humidity: 91%. Cloudiness: 44%. Wind: 3.65 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 09:00:00 MSK 2018. Weather: light rain. Temperature: 19.57 ℃. Minimum temperature: 19.57 ℃. Maximum temperature: 19.57 ℃. Pressure: 1001.34 hPa. Sea-level atmosphericPressure: 1022.41 hPa. Ground-level atmosphericPressure: 1001.34 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 4.38 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.5 ℃. Minimum temperature: 23.5 ℃. Maximum temperature: 23.5 ℃. Pressure: 1001.0 hPa. Sea-level atmosphericPressure: 1021.99 hPa. Ground-level atmosphericPressure: 1001.0 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 5.36 meter/sec, 299 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.14 ℃. Minimum temperature: 25.14 ℃. Maximum temperature: 25.14 ℃. Pressure: 1000.5 hPa. Sea-level atmosphericPressure: 1021.51 hPa. Ground-level atmosphericPressure: 1000.5 hPa. Humidity: 73%. Cloudiness: 32%. Wind: 6.72 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 18:00:00 MSK 2018. Weather: overcast clouds. Temperature: 23.56 ℃. Minimum temperature: 23.56 ℃. Maximum temperature: 23.56 ℃. Pressure: 1000.7 hPa. Sea-level atmosphericPressure: 1021.58 hPa. Ground-level atmosphericPressure: 1000.7 hPa. Humidity: 66%. Cloudiness: 88%. Wind: 6.57 meter/sec, 317 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.41 ℃. Minimum temperature: 22.41 ℃. Maximum temperature: 22.41 ℃. Pressure: 1000.64 hPa. Sea-level atmosphericPressure: 1021.67 hPa. Ground-level atmosphericPressure: 1000.64 hPa. Humidity: 68%. Cloudiness: 64%. Wind: 4.31 meter/sec, 326 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 00:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.92 ℃. Minimum temperature: 20.92 ℃. Maximum temperature: 20.92 ℃. Pressure: 1001.06 hPa. Sea-level atmosphericPressure: 1022.14 hPa. Ground-level atmosphericPressure: 1001.06 hPa. Humidity: 78%. Cloudiness: 68%. Wind: 3.42 meter/sec, 327 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 03:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.28 ℃. Minimum temperature: 20.28 ℃. Maximum temperature: 20.28 ℃. Pressure: 1001.04 hPa. Sea-level atmosphericPressure: 1022.13 hPa. Ground-level atmosphericPressure: 1001.04 hPa. Humidity: 78%. Cloudiness: 76%. Wind: 4.27 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.11 ℃. Minimum temperature: 19.11 ℃. Maximum temperature: 19.11 ℃. Pressure: 1001.13 hPa. Sea-level atmosphericPressure: 1022.28 hPa. Ground-level atmosphericPressure: 1001.13 hPa. Humidity: 74%. Cloudiness: 32%. Wind: 4.96 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 09:00:00 MSK 2018. Weather: few clouds. Temperature: 20.16 ℃. Minimum temperature: 20.16 ℃. Maximum temperature: 20.16 ℃. Pressure: 1001.43 hPa. Sea-level atmosphericPressure: 1022.62 hPa. Ground-level atmosphericPressure: 1001.43 hPa. Humidity: 86%. Cloudiness: 20%. Wind: 5.16 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 12:00:00 MSK 2018. Weather: few clouds. Temperature: 22.37 ℃. Minimum temperature: 22.37 ℃. Maximum temperature: 22.37 ℃. Pressure: 1001.53 hPa. Sea-level atmosphericPressure: 1022.62 hPa. Ground-level atmosphericPressure: 1001.53 hPa. Humidity: 88%. Cloudiness: 20%. Wind: 5.56 meter/sec, 307 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.85 ℃. Minimum temperature: 22.85 ℃. Maximum temperature: 22.85 ℃. Pressure: 1001.63 hPa. Sea-level atmosphericPressure: 1022.65 hPa. Ground-level atmosphericPressure: 1001.63 hPa. Humidity: 81%. Cloudiness: 44%. Wind: 5.46 meter/sec, 314 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.79 ℃. Minimum temperature: 23.79 ℃. Maximum temperature: 23.79 ℃. Pressure: 1001.53 hPa. Sea-level atmosphericPressure: 1022.53 hPa. Ground-level atmosphericPressure: 1001.53 hPa. Humidity: 72%. Cloudiness: 32%. Wind: 5.56 meter/sec, 313 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.56 ℃. Minimum temperature: 22.56 ℃. Maximum temperature: 22.56 ℃. Pressure: 1001.72 hPa. Sea-level atmosphericPressure: 1022.7 hPa. Ground-level atmosphericPressure: 1001.72 hPa. Humidity: 66%. Cloudiness: 48%. Wind: 3.96 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||
```
|
||||
|
||||
`Forecast`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-----------------------------|------------------------------------------------------------------------------------------------------------------|
|
||||
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
|
||||
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
|
||||
| `getWeatherInfo()` | Returns `HourlyForecast.WeatherInfo` instance that contains information about temperature, atmosphericPressure and humidity.|
|
||||
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
|
||||
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
|
||||
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
||||
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
||||
| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. |
|
||||
| `getDt_txt()` | Returns `String` value that represents data calculation time. |
|
||||
| `toString()` | Returns pretty string for the whole available weather information. |
|
||||
|
||||
|
||||
### Constants and options
|
||||
|
||||
#### Accuracy
|
||||
| Constant | Description |
|
||||
|--------------------|------------------|
|
||||
| Accuracy.LIKE | Close result. |
|
||||
| Accuracy.ACCURATE | Accurate result. |
|
||||
|
||||
#### Language
|
||||
| Constant | Description |
|
||||
|-----------------------------------|-------------------------------|
|
||||
| Language.ARABIC | Arabic language. |
|
||||
| Language.BULGARIAN | Bulgarian language. |
|
||||
| Language.CATALAN | Catalan language. |
|
||||
| Language.CZECH | Czech language. |
|
||||
| Language.GERMAN | German language. |
|
||||
| Language.GREEK | Greek language. |
|
||||
| Language.ENGLISH | English language. |
|
||||
| Language.PERSIAN | Persian (Farsi) language. |
|
||||
| Language.FINNISH | Finnish language. |
|
||||
| Language.FRENCH | French language. |
|
||||
| Language.GALICIAN | Galician language. |
|
||||
| Language.CROATIAN | Croatian language. |
|
||||
| Language.HUNGARIAN | Hungarian language. |
|
||||
| Language.ITALIAN | Italian language. |
|
||||
| Language.JAPANESE | Japanese language. |
|
||||
| Language.KOREAN | Korean language. |
|
||||
| Language.LATVIAN | Latvian language. |
|
||||
| Language.LITHUANIAN | Lithuanian language. |
|
||||
| Language.MACEDONIAN | Macedonian language. |
|
||||
| Language.DUTCH | Dutch language. |
|
||||
| Language.POLISH | Polish language. |
|
||||
| Language.PORTUGUESE | Portuguese language. |
|
||||
| Language.ROMANIAN | Romanian language. |
|
||||
| Language.RUSSIAN | Russian language. |
|
||||
| Language.SWEDISH | Swedish language. |
|
||||
| Language.SLOVAK | Slovak language. |
|
||||
| Language.SLOVENIAN | Slovenian language. |
|
||||
| Language.SPANISH | Spanish language. |
|
||||
| Language.TURKISH | Turkish language. |
|
||||
| Language.UKRANIAN | Ukrainian language. |
|
||||
| Language.VIETNAMESE | Vietnamese language. |
|
||||
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||
|
||||
#### System
|
||||
| Constant | Description |
|
||||
|-------------------------------|-----------------------|
|
||||
|System.OPEN_WEATHER_API_URL | Basic API url. |
|
||||
|System.OPEN_WEATHER_API_VERSION| Current API version. |
|
||||
|
||||
#### Unit
|
||||
| Constant | Description |
|
||||
|----------------------|------------------------------------------------|
|
||||
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
|
||||
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
|
||||
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow) |
|
||||
|
||||
### Dependencies
|
||||
* com.alibaba:fastjson:1.2.44
|
||||
@@ -0,0 +1,390 @@
|
||||
### Implemented features:
|
||||
* Current weather data
|
||||
* 5 day / 3 hour forecast
|
||||
* 16 day / daily forecast
|
||||
* UV Index
|
||||
* Air Pollution
|
||||
|
||||
### Maven coordinates:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
implementation 'com.github.prominence:openweathermap-api:1.1'
|
||||
```
|
||||
|
||||
### How to use:
|
||||
|
||||
Firstly, you need to create the instance of `OpenWeatherMapManager` class:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
```
|
||||
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
||||
|
||||
Currently available methods:
|
||||
* `getWeatherRequester()`
|
||||
* `getHourlyForecastRequester()`
|
||||
* `getDailyForecastRequester()`
|
||||
* `getUltravioletIndexRequester()`
|
||||
* `getAirPollutionRequester()`
|
||||
|
||||
#### Current weather data
|
||||
First step is retrieving `WeatherRequester` instance:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
WeatherRequester weatherRequester = openWeatherManager.getWeatherRequester();
|
||||
```
|
||||
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||
```
|
||||
Weather weatherResponse = weatherRequester
|
||||
.setLanguage(Language.ENGLISH)
|
||||
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||
.setAccuracy(Accuracy.ACCURATE)
|
||||
.getByCityName("Minsk");
|
||||
```
|
||||
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||
|
||||
Available requests:
|
||||
* `getByCityId(String cityId)`
|
||||
* `getByCityName(String cityName)`
|
||||
* `getByCoordinates(double latitude, double longitude)`
|
||||
* `getByCoordinates(Coordinates coordinates)`
|
||||
* `getByZIPCode(String zipCode, String countryCode)`
|
||||
|
||||
`Weather`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||
| `getBase()` | Returns `String` with some internal information. Example: `cmc stations` - from official documentation. |
|
||||
| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, atmosphericPressure and humidity. |
|
||||
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
|
||||
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
|
||||
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
||||
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
||||
| `getDataCalculationTime()`| Returns `long` value that represents data calculation timestamp. |
|
||||
| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset time. |
|
||||
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||
| `getCountry()` | An alias for `getWeatherSystemInfo().getCountry()`. |
|
||||
| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. |
|
||||
| `getDataCalculationDate()`| Returns data calculation time in `Date` representation. |
|
||||
| `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. |
|
||||
| `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. |
|
||||
| `getPressure()` | An alias for `getWeatherInfo().getPressure()`. |
|
||||
| `getPressureUnit()` | An alias for `getWeatherInfo().getPressureUnit()`. |
|
||||
| `getHumidityPercentage()` | An alias for `getWeatherInfo().getHumidity()`. |
|
||||
| `toString()` | Returns pretty string for the whole available weather information. |
|
||||
|
||||
`toString()` output example:
|
||||
```
|
||||
City: Minsk(625144). Coordinates: latitude=53.9, longitude=27.56
|
||||
Country: BY
|
||||
Sunrise: Sun Jul 15 04:58:27 MSK 2018
|
||||
Sunset: Sun Jul 15 21:32:19 MSK 2018
|
||||
Weather: light intensity shower rain
|
||||
Temperature: 17.0 ℃. Minimum temparature: 17.0 ℃. Maximum temperature: 17.0 ℃
|
||||
Humidity: 93%
|
||||
Pressure: 1008 hPa
|
||||
Wind: 2.0 meter/sec, 20 degrees
|
||||
Cloudiness: 75%
|
||||
Data calculation time: Mon Jul 16 00:00:00 MSK 2018
|
||||
```
|
||||
|
||||
#### 5 day / 3 hour forecast
|
||||
First step is retrieving `HourlyForecastRequester` instance:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
HourlyForecastRequester forecastRequester = openWeatherManager.getHourlyForecastRequester();
|
||||
```
|
||||
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||
```
|
||||
HourlyForecast forecastResponse = forecastRequester
|
||||
.setLanguage(Language.ENGLISH)
|
||||
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||
.setAccuracy(Accuracy.ACCURATE)
|
||||
.getByCityName("Pruzhany");
|
||||
```
|
||||
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||
|
||||
Available requests:
|
||||
* `getByCityId(String cityId)`
|
||||
* `getByCityName(String cityName)`
|
||||
* `getByCoordinates(double latitude, double longitude)`
|
||||
* `getByCoordinates(Coordinates coordinates)`
|
||||
* `getByZIPCode(String zipCode, String countryCode)`
|
||||
|
||||
`HourlyForecast`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-----------------------------|--------------------------------------------------------------------------------------------|
|
||||
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||
| `getCityInfo()` | Returns `CityInfo` instance that contains information about city. |
|
||||
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
|
||||
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
|
||||
| `getAverageTemperature()` | Returns average temperature from forecasts. |
|
||||
| `getMinimumTemperature()` | Returns minimum temperature from forecasts. |
|
||||
| `getMaximumTemperature()` | Returns maximum temperature from forecasts. |
|
||||
| `getByMinimumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is minimal. |
|
||||
| `getByMaximumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is maximal. |
|
||||
| `getAveragePressure()` | Returns average atmosphericPressure from forecasts. |
|
||||
| `getMinimumPressure()` | Returns minimum atmosphericPressure from forecasts. |
|
||||
| `getMaximumPressure()` | Returns maximum atmosphericPressure from forecasts. |
|
||||
| `getByMinimumPressure()` | Returns `HourlyForecast.Forecast` for the time where atmosphericPressure is minimal. |
|
||||
| `getByMaximumPressure()` | Returns `HourlyForecast.Forecast` for the time where atmosphericPressure is maximal. |
|
||||
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||
|
||||
`toString()` output example:
|
||||
```
|
||||
City: Pruzhany(622997). Coordinates: latitude=52.5582, longitude=24.4567
|
||||
Country: BY
|
||||
Forecasts:
|
||||
Time: Tue Jul 17 00:00:00 MSK 2018. Weather: light rain. Temperature: 16.24 ℃. Minimum temperature: 16.24 ℃. Maximum temperature: 17.36 ℃. Pressure: 997.38 hPa. Sea-level atmosphericPressure: 1018.59 hPa. Ground-level atmosphericPressure: 997.38 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 2.85 meter/sec, 324 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 03:00:00 MSK 2018. Weather: moderate rain. Temperature: 16.0 ℃. Minimum temperature: 16.0 ℃. Maximum temperature: 16.83 ℃. Pressure: 996.88 hPa. Sea-level atmosphericPressure: 1017.86 hPa. Ground-level atmosphericPressure: 996.88 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 1.86 meter/sec, 349 degrees. Rain(last 3 hrs): 3 mm
|
||||
Time: Tue Jul 17 06:00:00 MSK 2018. Weather: light rain. Temperature: 15.76 ℃. Minimum temperature: 15.76 ℃. Maximum temperature: 16.31 ℃. Pressure: 996.7 hPa. Sea-level atmosphericPressure: 1017.72 hPa. Ground-level atmosphericPressure: 996.7 hPa. Humidity: 94%. Cloudiness: 76%. Wind: 1.62 meter/sec, 113 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 09:00:00 MSK 2018. Weather: light rain. Temperature: 18.23 ℃. Minimum temperature: 18.23 ℃. Maximum temperature: 18.51 ℃. Pressure: 997.17 hPa. Sea-level atmosphericPressure: 1018.18 hPa. Ground-level atmosphericPressure: 997.17 hPa. Humidity: 100%. Cloudiness: 76%. Wind: 2.11 meter/sec, 107 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 12:00:00 MSK 2018. Weather: light rain. Temperature: 21.0 ℃. Minimum temperature: 21.0 ℃. Maximum temperature: 21.0 ℃. Pressure: 997.6 hPa. Sea-level atmosphericPressure: 1018.5 hPa. Ground-level atmosphericPressure: 997.6 hPa. Humidity: 100%. Cloudiness: 68%. Wind: 2.51 meter/sec, 82 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 15:00:00 MSK 2018. Weather: light rain. Temperature: 21.78 ℃. Minimum temperature: 21.78 ℃. Maximum temperature: 21.78 ℃. Pressure: 997.73 hPa. Sea-level atmosphericPressure: 1018.66 hPa. Ground-level atmosphericPressure: 997.73 hPa. Humidity: 92%. Cloudiness: 88%. Wind: 4.05 meter/sec, 78 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 18:00:00 MSK 2018. Weather: light rain. Temperature: 22.9 ℃. Minimum temperature: 22.9 ℃. Maximum temperature: 22.9 ℃. Pressure: 997.66 hPa. Sea-level atmosphericPressure: 1018.55 hPa. Ground-level atmosphericPressure: 997.66 hPa. Humidity: 93%. Cloudiness: 68%. Wind: 3.06 meter/sec, 67 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 21:00:00 MSK 2018. Weather: light rain. Temperature: 23.04 ℃. Minimum temperature: 23.04 ℃. Maximum temperature: 23.04 ℃. Pressure: 996.89 hPa. Sea-level atmosphericPressure: 1017.99 hPa. Ground-level atmosphericPressure: 996.89 hPa. Humidity: 83%. Cloudiness: 88%. Wind: 3.17 meter/sec, 16 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 00:00:00 MSK 2018. Weather: moderate rain. Temperature: 18.5 ℃. Minimum temperature: 18.5 ℃. Maximum temperature: 18.5 ℃. Pressure: 997.33 hPa. Sea-level atmosphericPressure: 1018.34 hPa. Ground-level atmosphericPressure: 997.33 hPa. Humidity: 97%. Cloudiness: 44%. Wind: 3.56 meter/sec, 31 degrees. Rain(last 3 hrs): 7 mm
|
||||
Time: Wed Jul 18 03:00:00 MSK 2018. Weather: few clouds. Temperature: 18.57 ℃. Minimum temperature: 18.57 ℃. Maximum temperature: 18.57 ℃. Pressure: 996.91 hPa. Sea-level atmosphericPressure: 1017.87 hPa. Ground-level atmosphericPressure: 996.91 hPa. Humidity: 95%. Cloudiness: 24%. Wind: 5.26 meter/sec, 44 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 06:00:00 MSK 2018. Weather: few clouds. Temperature: 18.94 ℃. Minimum temperature: 18.94 ℃. Maximum temperature: 18.94 ℃. Pressure: 997.07 hPa. Sea-level atmosphericPressure: 1018.06 hPa. Ground-level atmosphericPressure: 997.07 hPa. Humidity: 95%. Cloudiness: 20%. Wind: 4.8 meter/sec, 45 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 09:00:00 MSK 2018. Weather: light rain. Temperature: 20.6 ℃. Minimum temperature: 20.6 ℃. Maximum temperature: 20.6 ℃. Pressure: 997.8 hPa. Sea-level atmosphericPressure: 1018.66 hPa. Ground-level atmosphericPressure: 997.8 hPa. Humidity: 97%. Cloudiness: 48%. Wind: 5.56 meter/sec, 54 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 12:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.87 ℃. Minimum temperature: 23.87 ℃. Maximum temperature: 23.87 ℃. Pressure: 998.06 hPa. Sea-level atmosphericPressure: 1019.05 hPa. Ground-level atmosphericPressure: 998.06 hPa. Humidity: 88%. Cloudiness: 32%. Wind: 5.86 meter/sec, 52 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 24.67 ℃. Minimum temperature: 24.67 ℃. Maximum temperature: 24.67 ℃. Pressure: 998.51 hPa. Sea-level atmosphericPressure: 1019.33 hPa. Ground-level atmosphericPressure: 998.51 hPa. Humidity: 84%. Cloudiness: 36%. Wind: 5.63 meter/sec, 51 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.15 ℃. Minimum temperature: 25.15 ℃. Maximum temperature: 25.15 ℃. Pressure: 998.79 hPa. Sea-level atmosphericPressure: 1019.64 hPa. Ground-level atmosphericPressure: 998.79 hPa. Humidity: 78%. Cloudiness: 44%. Wind: 5.47 meter/sec, 38 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.23 ℃. Minimum temperature: 23.23 ℃. Maximum temperature: 23.23 ℃. Pressure: 999.08 hPa. Sea-level atmosphericPressure: 1020.04 hPa. Ground-level atmosphericPressure: 999.08 hPa. Humidity: 75%. Cloudiness: 48%. Wind: 4.62 meter/sec, 25 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 20.79 ℃. Minimum temperature: 20.79 ℃. Maximum temperature: 20.79 ℃. Pressure: 999.67 hPa. Sea-level atmosphericPressure: 1020.68 hPa. Ground-level atmosphericPressure: 999.67 hPa. Humidity: 76%. Cloudiness: 48%. Wind: 4.29 meter/sec, 13 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 03:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.45 ℃. Minimum temperature: 19.45 ℃. Maximum temperature: 19.45 ℃. Pressure: 999.95 hPa. Sea-level atmosphericPressure: 1021.02 hPa. Ground-level atmosphericPressure: 999.95 hPa. Humidity: 80%. Cloudiness: 48%. Wind: 4.22 meter/sec, 17 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 06:00:00 MSK 2018. Weather: light rain. Temperature: 18.9 ℃. Minimum temperature: 18.9 ℃. Maximum temperature: 18.9 ℃. Pressure: 1000.6 hPa. Sea-level atmosphericPressure: 1021.62 hPa. Ground-level atmosphericPressure: 1000.6 hPa. Humidity: 83%. Cloudiness: 92%. Wind: 4.43 meter/sec, 10 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 09:00:00 MSK 2018. Weather: light rain. Temperature: 21.37 ℃. Minimum temperature: 21.37 ℃. Maximum temperature: 21.37 ℃. Pressure: 1000.95 hPa. Sea-level atmosphericPressure: 1022.01 hPa. Ground-level atmosphericPressure: 1000.95 hPa. Humidity: 87%. Cloudiness: 0%. Wind: 4.36 meter/sec, 6 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.92 ℃. Minimum temperature: 23.92 ℃. Maximum temperature: 23.92 ℃. Pressure: 1001.5 hPa. Sea-level atmosphericPressure: 1022.43 hPa. Ground-level atmosphericPressure: 1001.5 hPa. Humidity: 77%. Cloudiness: 0%. Wind: 5.66 meter/sec, 12 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 15:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.7 ℃. Minimum temperature: 23.7 ℃. Maximum temperature: 23.7 ℃. Pressure: 1001.75 hPa. Sea-level atmosphericPressure: 1022.72 hPa. Ground-level atmosphericPressure: 1001.75 hPa. Humidity: 72%. Cloudiness: 56%. Wind: 5.87 meter/sec, 349 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 18:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.82 ℃. Minimum temperature: 23.82 ℃. Maximum temperature: 23.82 ℃. Pressure: 1001.55 hPa. Sea-level atmosphericPressure: 1022.59 hPa. Ground-level atmosphericPressure: 1001.55 hPa. Humidity: 72%. Cloudiness: 68%. Wind: 5.47 meter/sec, 340 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.22 ℃. Minimum temperature: 22.22 ℃. Maximum temperature: 22.22 ℃. Pressure: 1001.82 hPa. Sea-level atmosphericPressure: 1022.93 hPa. Ground-level atmosphericPressure: 1001.82 hPa. Humidity: 67%. Cloudiness: 76%. Wind: 4.12 meter/sec, 333 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.76 ℃. Minimum temperature: 19.76 ℃. Maximum temperature: 19.76 ℃. Pressure: 1001.98 hPa. Sea-level atmosphericPressure: 1023.13 hPa. Ground-level atmosphericPressure: 1001.98 hPa. Humidity: 76%. Cloudiness: 32%. Wind: 4.11 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 03:00:00 MSK 2018. Weather: clear sky. Temperature: 17.53 ℃. Minimum temperature: 17.53 ℃. Maximum temperature: 17.53 ℃. Pressure: 1001.93 hPa. Sea-level atmosphericPressure: 1023.13 hPa. Ground-level atmosphericPressure: 1001.93 hPa. Humidity: 87%. Cloudiness: 8%. Wind: 4.21 meter/sec, 309 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 16.83 ℃. Minimum temperature: 16.83 ℃. Maximum temperature: 16.83 ℃. Pressure: 1001.79 hPa. Sea-level atmosphericPressure: 1022.99 hPa. Ground-level atmosphericPressure: 1001.79 hPa. Humidity: 91%. Cloudiness: 44%. Wind: 3.65 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 09:00:00 MSK 2018. Weather: light rain. Temperature: 19.57 ℃. Minimum temperature: 19.57 ℃. Maximum temperature: 19.57 ℃. Pressure: 1001.34 hPa. Sea-level atmosphericPressure: 1022.41 hPa. Ground-level atmosphericPressure: 1001.34 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 4.38 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.5 ℃. Minimum temperature: 23.5 ℃. Maximum temperature: 23.5 ℃. Pressure: 1001.0 hPa. Sea-level atmosphericPressure: 1021.99 hPa. Ground-level atmosphericPressure: 1001.0 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 5.36 meter/sec, 299 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.14 ℃. Minimum temperature: 25.14 ℃. Maximum temperature: 25.14 ℃. Pressure: 1000.5 hPa. Sea-level atmosphericPressure: 1021.51 hPa. Ground-level atmosphericPressure: 1000.5 hPa. Humidity: 73%. Cloudiness: 32%. Wind: 6.72 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 18:00:00 MSK 2018. Weather: overcast clouds. Temperature: 23.56 ℃. Minimum temperature: 23.56 ℃. Maximum temperature: 23.56 ℃. Pressure: 1000.7 hPa. Sea-level atmosphericPressure: 1021.58 hPa. Ground-level atmosphericPressure: 1000.7 hPa. Humidity: 66%. Cloudiness: 88%. Wind: 6.57 meter/sec, 317 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.41 ℃. Minimum temperature: 22.41 ℃. Maximum temperature: 22.41 ℃. Pressure: 1000.64 hPa. Sea-level atmosphericPressure: 1021.67 hPa. Ground-level atmosphericPressure: 1000.64 hPa. Humidity: 68%. Cloudiness: 64%. Wind: 4.31 meter/sec, 326 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 00:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.92 ℃. Minimum temperature: 20.92 ℃. Maximum temperature: 20.92 ℃. Pressure: 1001.06 hPa. Sea-level atmosphericPressure: 1022.14 hPa. Ground-level atmosphericPressure: 1001.06 hPa. Humidity: 78%. Cloudiness: 68%. Wind: 3.42 meter/sec, 327 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 03:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.28 ℃. Minimum temperature: 20.28 ℃. Maximum temperature: 20.28 ℃. Pressure: 1001.04 hPa. Sea-level atmosphericPressure: 1022.13 hPa. Ground-level atmosphericPressure: 1001.04 hPa. Humidity: 78%. Cloudiness: 76%. Wind: 4.27 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.11 ℃. Minimum temperature: 19.11 ℃. Maximum temperature: 19.11 ℃. Pressure: 1001.13 hPa. Sea-level atmosphericPressure: 1022.28 hPa. Ground-level atmosphericPressure: 1001.13 hPa. Humidity: 74%. Cloudiness: 32%. Wind: 4.96 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 09:00:00 MSK 2018. Weather: few clouds. Temperature: 20.16 ℃. Minimum temperature: 20.16 ℃. Maximum temperature: 20.16 ℃. Pressure: 1001.43 hPa. Sea-level atmosphericPressure: 1022.62 hPa. Ground-level atmosphericPressure: 1001.43 hPa. Humidity: 86%. Cloudiness: 20%. Wind: 5.16 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 12:00:00 MSK 2018. Weather: few clouds. Temperature: 22.37 ℃. Minimum temperature: 22.37 ℃. Maximum temperature: 22.37 ℃. Pressure: 1001.53 hPa. Sea-level atmosphericPressure: 1022.62 hPa. Ground-level atmosphericPressure: 1001.53 hPa. Humidity: 88%. Cloudiness: 20%. Wind: 5.56 meter/sec, 307 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.85 ℃. Minimum temperature: 22.85 ℃. Maximum temperature: 22.85 ℃. Pressure: 1001.63 hPa. Sea-level atmosphericPressure: 1022.65 hPa. Ground-level atmosphericPressure: 1001.63 hPa. Humidity: 81%. Cloudiness: 44%. Wind: 5.46 meter/sec, 314 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.79 ℃. Minimum temperature: 23.79 ℃. Maximum temperature: 23.79 ℃. Pressure: 1001.53 hPa. Sea-level atmosphericPressure: 1022.53 hPa. Ground-level atmosphericPressure: 1001.53 hPa. Humidity: 72%. Cloudiness: 32%. Wind: 5.56 meter/sec, 313 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.56 ℃. Minimum temperature: 22.56 ℃. Maximum temperature: 22.56 ℃. Pressure: 1001.72 hPa. Sea-level atmosphericPressure: 1022.7 hPa. Ground-level atmosphericPressure: 1001.72 hPa. Humidity: 66%. Cloudiness: 48%. Wind: 3.96 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||
```
|
||||
|
||||
`HourlyForecast.Forecast`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-----------------------------|------------------------------------------------------------------------------------------------------------------|
|
||||
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
|
||||
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
|
||||
| `getWeatherInfo()` | Returns `HourlyForecast.WeatherInfo` instance that contains information about temperature, atmosphericPressure and humidity.|
|
||||
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
|
||||
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
|
||||
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
||||
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
||||
| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. |
|
||||
| `getDt_txt()` | Returns `String` value that represents data calculation time. |
|
||||
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||
|
||||
#### 16 day / daily forecast
|
||||
First step is retrieving `DailyForecastRequester` instance:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
DailyForecastRequester forecastRequester = openWeatherManager.getDailyForecastRequester();
|
||||
```
|
||||
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||
```
|
||||
DailyForecast forecastResponse = forecastRequester
|
||||
.setLanguage(Language.ENGLISH)
|
||||
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||
.setAccuracy(Accuracy.ACCURATE)
|
||||
.getByCityName("Pruzhany");
|
||||
```
|
||||
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||
|
||||
Available requests:
|
||||
* `getByCityId(String cityId)`
|
||||
* `getByCityName(String cityName)`
|
||||
* `getByCoordinates(double latitude, double longitude)`
|
||||
* `getByCoordinates(Coordinates coordinates)`
|
||||
* `getByZIPCode(String zipCode, String countryCode)`
|
||||
|
||||
`DailyForecast`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-----------------------------|--------------------------------------------------------------------------------------------|
|
||||
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||
| `getCityInfo()` | Returns `CityInfo` instance that contains information about city. |
|
||||
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
|
||||
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
|
||||
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||
|
||||
`DailyForecast.Forecast`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-----------------------------|------------------------------------------------------------------------------------------------------------------|
|
||||
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
|
||||
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
|
||||
| `getTemperature()` | Returns `DailyForecast.Forecast.Temperature` instance that contains information about temperature(avg, min, max).|
|
||||
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||
| `getCloudiness()` | Returns *cloudiness* percentage information. |
|
||||
| `getHumidity()` | Returns *humidity* percentage information. |
|
||||
| `getWindSpeed()` | Returns wind's speed. |
|
||||
| `getWindDegrees()` | Returns wind's degree. |
|
||||
| `getWindUnit()` | Returns wind's unit. |
|
||||
| `getPressure()` | Returns atmosphericPressure value. |
|
||||
| `getPressureUnit()` | Returns atmosphericPressure's unit. |
|
||||
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||
|
||||
#### UV Index
|
||||
|
||||
First step is retrieving `UltravioletIndexRequester` instance:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
UltravioletIndexRequester requester = openWeatherMapManager.getUltravioletIndexRequester();
|
||||
```
|
||||
after you need to set coordinates and execute appropriate request:
|
||||
```
|
||||
UltravioletIndex uvResponse = requester
|
||||
.setCoodrinates(55.33f, 24.27f)
|
||||
.getCurrentUVIndex();
|
||||
```
|
||||
|
||||
Available requests:
|
||||
* `getCurrentUVIndex()`
|
||||
* `getUVIndexForecast(int amountOfDays)`
|
||||
* `getUVIndexByPeriod(Date from, Date to)`
|
||||
|
||||
`UltravioletIndex`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|---------------------------|---------------------------------------------------------------|
|
||||
| `getLatitude()` | Returns latitude. |
|
||||
| `getLongitude()` | Returns longitude. |
|
||||
| `getDateISO()` | Returns ISO date in String representation. |
|
||||
| `getDateTimestamp()` | Returns date timestamp. |
|
||||
| `getValue()` | Returns UV value. |
|
||||
| `getCalculationDate()` | Returns date in Date representation`. |
|
||||
| `toString()` | Returns pretty string for the whole available UV information. |
|
||||
|
||||
`toString()` output example:
|
||||
```
|
||||
Date: Tue Jul 31 15:00:00 MSK 2018, Ultraviolet value: 6.230000
|
||||
```
|
||||
|
||||
#### Air pollution
|
||||
|
||||
First step is retrieving `AirPollutionRequester` instance:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
AirPollutionRequester requester = openWeatherMapManager.getAirPollutionRequester();
|
||||
```
|
||||
after you need to set coordinates, time frame, date and execute appropriate request:
|
||||
```
|
||||
AirPollution airPollutionResponse = forecastRequester
|
||||
.setCoordinates(0.0f, 10.0f)
|
||||
.setTimeFrame(TimeFrame.YEAR)
|
||||
.setDate(new Date())
|
||||
.retrieve();
|
||||
```
|
||||
|
||||
Available requests:
|
||||
* `retrieve()`
|
||||
|
||||
`AirPollution`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|---------------------------|---------------------------------------------------------------------------|
|
||||
| `getCoordinates()` | Returns `Coordinates` instance. |
|
||||
| `getLongitude()` | Returns longitude. |
|
||||
| `airPollutionInfo()` | Returns list of `AirPollution.AirPollutionInfo` instances. |
|
||||
| `toString()` | Returns pretty string for the whole available air pollution information. |
|
||||
|
||||
`toString()` output example:
|
||||
```
|
||||
AirPollution[Date: Tue Jul 24 01:04:40 MSK 2018; Coordinates: latitude=0.0, longitude=9.9955]
|
||||
[Value: 8.0347114E-8, Value: 9.5041536E-8, Value: 7.7667146E-8, Value: 7.251491E-8, Value: 5.899763E-8, Value: 1.9186361E-8, Value: 1.729535E-8, Value: 1.25645805E-8, Value: 3.0852514E-9]
|
||||
```
|
||||
|
||||
### Constants and options
|
||||
|
||||
#### Accuracy
|
||||
| Constant | Description |
|
||||
|--------------------|------------------|
|
||||
| Accuracy.LIKE | Close result. |
|
||||
| Accuracy.ACCURATE | Accurate result. |
|
||||
|
||||
#### Language
|
||||
| Constant | Description |
|
||||
|-----------------------------------|-------------------------------|
|
||||
| Language.ARABIC | Arabic language. |
|
||||
| Language.BULGARIAN | Bulgarian language. |
|
||||
| Language.CATALAN | Catalan language. |
|
||||
| Language.CZECH | Czech language. |
|
||||
| Language.GERMAN | German language. |
|
||||
| Language.GREEK | Greek language. |
|
||||
| Language.ENGLISH | English language. |
|
||||
| Language.PERSIAN | Persian (Farsi) language. |
|
||||
| Language.FINNISH | Finnish language. |
|
||||
| Language.FRENCH | French language. |
|
||||
| Language.GALICIAN | Galician language. |
|
||||
| Language.CROATIAN | Croatian language. |
|
||||
| Language.HUNGARIAN | Hungarian language. |
|
||||
| Language.ITALIAN | Italian language. |
|
||||
| Language.JAPANESE | Japanese language. |
|
||||
| Language.KOREAN | Korean language. |
|
||||
| Language.LATVIAN | Latvian language. |
|
||||
| Language.LITHUANIAN | Lithuanian language. |
|
||||
| Language.MACEDONIAN | Macedonian language. |
|
||||
| Language.DUTCH | Dutch language. |
|
||||
| Language.POLISH | Polish language. |
|
||||
| Language.PORTUGUESE | Portuguese language. |
|
||||
| Language.ROMANIAN | Romanian language. |
|
||||
| Language.RUSSIAN | Russian language. |
|
||||
| Language.SWEDISH | Swedish language. |
|
||||
| Language.SLOVAK | Slovak language. |
|
||||
| Language.SLOVENIAN | Slovenian language. |
|
||||
| Language.SPANISH | Spanish language. |
|
||||
| Language.TURKISH | Turkish language. |
|
||||
| Language.UKRANIAN | Ukrainian language. |
|
||||
| Language.VIETNAMESE | Vietnamese language. |
|
||||
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||
|
||||
#### Unit
|
||||
| Constant | Description |
|
||||
|----------------------|------------------------------------------------|
|
||||
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
|
||||
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
|
||||
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow) |
|
||||
|
||||
### Dependencies
|
||||
* com.alibaba:fastjson:1.2.44
|
||||
* org.projectlombok:lombok:1.18.0 (*provided*)
|
||||
@@ -0,0 +1,402 @@
|
||||
### Implemented features:
|
||||
* Current weather data
|
||||
* 5 day / 3 hour forecast
|
||||
* 16 day / daily forecast
|
||||
* UV Index
|
||||
* Air Pollution
|
||||
|
||||
### Maven coordinates:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
implementation 'com.github.prominence:openweathermap-api:1.2'
|
||||
```
|
||||
|
||||
### How to use:
|
||||
|
||||
Firstly, you need to create the instance of `OpenWeatherMapManager` class:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
```
|
||||
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
||||
|
||||
Currently available methods:
|
||||
* `getWeatherRequester()`
|
||||
* `getHourlyForecastRequester()`
|
||||
* `getDailyForecastRequester()`
|
||||
* `getUltravioletIndexRequester(...)`
|
||||
* `getAirPollutionRequester(...)`
|
||||
|
||||
#### Current weather data
|
||||
First step is retrieving `WeatherRequester` instance:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
WeatherRequester weatherRequester = openWeatherManager.getWeatherRequester();
|
||||
```
|
||||
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||
```
|
||||
Weather weatherResponse = weatherRequester
|
||||
.setLanguage(Language.ENGLISH)
|
||||
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||
.setAccuracy(Accuracy.ACCURATE)
|
||||
.getByCityName("Minsk");
|
||||
```
|
||||
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||
|
||||
Available requests:
|
||||
* `getByCityId(String cityId)`
|
||||
* `getByCityName(String cityName)`
|
||||
* `getByCoordinates(double latitude, double longitude)`
|
||||
* `getByCoordinates(Coordinates coordinates)`
|
||||
* `getByZIPCode(String zipCode, String countryCode)`
|
||||
|
||||
`Weather`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||
| `getBase()` | Returns `String` with some internal information. Example: `cmc stations` - from official documentation. |
|
||||
| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, atmosphericPressure and humidity. |
|
||||
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
|
||||
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
|
||||
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
||||
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
||||
| `getDataCalculationTime()`| Returns `long` value that represents data calculation timestamp. |
|
||||
| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset time. |
|
||||
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||
| `getCountry()` | An alias for `getWeatherSystemInfo().getCountry()`. |
|
||||
| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. |
|
||||
| `getDataCalculationDate()`| Returns data calculation time in `Date` representation. |
|
||||
| `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. |
|
||||
| `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. |
|
||||
| `getPressure()` | An alias for `getWeatherInfo().getPressure()`. |
|
||||
| `getPressureUnit()` | An alias for `getWeatherInfo().getPressureUnit()`. |
|
||||
| `getHumidityPercentage()` | An alias for `getWeatherInfo().getHumidity()`. |
|
||||
| `toString()` | Returns pretty string for the whole available weather information. |
|
||||
|
||||
`toString()` output example:
|
||||
```
|
||||
City: Minsk(625144). Coordinates: latitude=53.9, longitude=27.56
|
||||
Country: BY
|
||||
Sunrise: Sun Jul 15 04:58:27 MSK 2018
|
||||
Sunset: Sun Jul 15 21:32:19 MSK 2018
|
||||
Weather: light intensity shower rain
|
||||
Temperature: 17.0 ℃. Minimum temparature: 17.0 ℃. Maximum temperature: 17.0 ℃
|
||||
Humidity: 93%
|
||||
Pressure: 1008 hPa
|
||||
Wind: 2.0 meter/sec, 20 degrees
|
||||
Cloudiness: 75%
|
||||
Data calculation time: Mon Jul 16 00:00:00 MSK 2018
|
||||
```
|
||||
|
||||
#### 5 day / 3 hour forecast
|
||||
First step is retrieving `HourlyForecastRequester` instance:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
HourlyForecastRequester forecastRequester = openWeatherManager.getHourlyForecastRequester();
|
||||
```
|
||||
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||
```
|
||||
HourlyForecast forecastResponse = forecastRequester
|
||||
.setLanguage(Language.ENGLISH)
|
||||
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||
.setAccuracy(Accuracy.ACCURATE)
|
||||
.getByCityName("Pruzhany");
|
||||
```
|
||||
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||
|
||||
Available requests:
|
||||
* `getByCityId(String cityId)`
|
||||
* `getByCityName(String cityName)`
|
||||
* `getByCoordinates(double latitude, double longitude)`
|
||||
* `getByCoordinates(Coordinates coordinates)`
|
||||
* `getByZIPCode(String zipCode, String countryCode)`
|
||||
|
||||
`HourlyForecast`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-----------------------------|--------------------------------------------------------------------------------------------|
|
||||
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||
| `getCityInfo()` | Returns `CityInfo` instance that contains information about city. |
|
||||
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
|
||||
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
|
||||
| `getAverageTemperature()` | Returns average temperature from forecasts. |
|
||||
| `getMinimumTemperature()` | Returns minimum temperature from forecasts. |
|
||||
| `getMaximumTemperature()` | Returns maximum temperature from forecasts. |
|
||||
| `getByMinimumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is minimal. |
|
||||
| `getByMaximumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is maximal. |
|
||||
| `getAveragePressure()` | Returns average atmosphericPressure from forecasts. |
|
||||
| `getMinimumPressure()` | Returns minimum atmosphericPressure from forecasts. |
|
||||
| `getMaximumPressure()` | Returns maximum atmosphericPressure from forecasts. |
|
||||
| `getByMinimumPressure()` | Returns `HourlyForecast.Forecast` for the time where atmosphericPressure is minimal. |
|
||||
| `getByMaximumPressure()` | Returns `HourlyForecast.Forecast` for the time where atmosphericPressure is maximal. |
|
||||
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||
|
||||
`toString()` output example:
|
||||
```
|
||||
City: Pruzhany(622997). Coordinates: latitude=52.5582, longitude=24.4567
|
||||
Country: BY
|
||||
Forecasts:
|
||||
Time: Tue Jul 17 00:00:00 MSK 2018. Weather: light rain. Temperature: 16.24 ℃. Minimum temperature: 16.24 ℃. Maximum temperature: 17.36 ℃. Pressure: 997.38 hPa. Sea-level atmosphericPressure: 1018.59 hPa. Ground-level atmosphericPressure: 997.38 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 2.85 meter/sec, 324 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 03:00:00 MSK 2018. Weather: moderate rain. Temperature: 16.0 ℃. Minimum temperature: 16.0 ℃. Maximum temperature: 16.83 ℃. Pressure: 996.88 hPa. Sea-level atmosphericPressure: 1017.86 hPa. Ground-level atmosphericPressure: 996.88 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 1.86 meter/sec, 349 degrees. Rain(last 3 hrs): 3 mm
|
||||
Time: Tue Jul 17 06:00:00 MSK 2018. Weather: light rain. Temperature: 15.76 ℃. Minimum temperature: 15.76 ℃. Maximum temperature: 16.31 ℃. Pressure: 996.7 hPa. Sea-level atmosphericPressure: 1017.72 hPa. Ground-level atmosphericPressure: 996.7 hPa. Humidity: 94%. Cloudiness: 76%. Wind: 1.62 meter/sec, 113 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 09:00:00 MSK 2018. Weather: light rain. Temperature: 18.23 ℃. Minimum temperature: 18.23 ℃. Maximum temperature: 18.51 ℃. Pressure: 997.17 hPa. Sea-level atmosphericPressure: 1018.18 hPa. Ground-level atmosphericPressure: 997.17 hPa. Humidity: 100%. Cloudiness: 76%. Wind: 2.11 meter/sec, 107 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 12:00:00 MSK 2018. Weather: light rain. Temperature: 21.0 ℃. Minimum temperature: 21.0 ℃. Maximum temperature: 21.0 ℃. Pressure: 997.6 hPa. Sea-level atmosphericPressure: 1018.5 hPa. Ground-level atmosphericPressure: 997.6 hPa. Humidity: 100%. Cloudiness: 68%. Wind: 2.51 meter/sec, 82 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 15:00:00 MSK 2018. Weather: light rain. Temperature: 21.78 ℃. Minimum temperature: 21.78 ℃. Maximum temperature: 21.78 ℃. Pressure: 997.73 hPa. Sea-level atmosphericPressure: 1018.66 hPa. Ground-level atmosphericPressure: 997.73 hPa. Humidity: 92%. Cloudiness: 88%. Wind: 4.05 meter/sec, 78 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 18:00:00 MSK 2018. Weather: light rain. Temperature: 22.9 ℃. Minimum temperature: 22.9 ℃. Maximum temperature: 22.9 ℃. Pressure: 997.66 hPa. Sea-level atmosphericPressure: 1018.55 hPa. Ground-level atmosphericPressure: 997.66 hPa. Humidity: 93%. Cloudiness: 68%. Wind: 3.06 meter/sec, 67 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Tue Jul 17 21:00:00 MSK 2018. Weather: light rain. Temperature: 23.04 ℃. Minimum temperature: 23.04 ℃. Maximum temperature: 23.04 ℃. Pressure: 996.89 hPa. Sea-level atmosphericPressure: 1017.99 hPa. Ground-level atmosphericPressure: 996.89 hPa. Humidity: 83%. Cloudiness: 88%. Wind: 3.17 meter/sec, 16 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 00:00:00 MSK 2018. Weather: moderate rain. Temperature: 18.5 ℃. Minimum temperature: 18.5 ℃. Maximum temperature: 18.5 ℃. Pressure: 997.33 hPa. Sea-level atmosphericPressure: 1018.34 hPa. Ground-level atmosphericPressure: 997.33 hPa. Humidity: 97%. Cloudiness: 44%. Wind: 3.56 meter/sec, 31 degrees. Rain(last 3 hrs): 7 mm
|
||||
Time: Wed Jul 18 03:00:00 MSK 2018. Weather: few clouds. Temperature: 18.57 ℃. Minimum temperature: 18.57 ℃. Maximum temperature: 18.57 ℃. Pressure: 996.91 hPa. Sea-level atmosphericPressure: 1017.87 hPa. Ground-level atmosphericPressure: 996.91 hPa. Humidity: 95%. Cloudiness: 24%. Wind: 5.26 meter/sec, 44 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 06:00:00 MSK 2018. Weather: few clouds. Temperature: 18.94 ℃. Minimum temperature: 18.94 ℃. Maximum temperature: 18.94 ℃. Pressure: 997.07 hPa. Sea-level atmosphericPressure: 1018.06 hPa. Ground-level atmosphericPressure: 997.07 hPa. Humidity: 95%. Cloudiness: 20%. Wind: 4.8 meter/sec, 45 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 09:00:00 MSK 2018. Weather: light rain. Temperature: 20.6 ℃. Minimum temperature: 20.6 ℃. Maximum temperature: 20.6 ℃. Pressure: 997.8 hPa. Sea-level atmosphericPressure: 1018.66 hPa. Ground-level atmosphericPressure: 997.8 hPa. Humidity: 97%. Cloudiness: 48%. Wind: 5.56 meter/sec, 54 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 12:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.87 ℃. Minimum temperature: 23.87 ℃. Maximum temperature: 23.87 ℃. Pressure: 998.06 hPa. Sea-level atmosphericPressure: 1019.05 hPa. Ground-level atmosphericPressure: 998.06 hPa. Humidity: 88%. Cloudiness: 32%. Wind: 5.86 meter/sec, 52 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 24.67 ℃. Minimum temperature: 24.67 ℃. Maximum temperature: 24.67 ℃. Pressure: 998.51 hPa. Sea-level atmosphericPressure: 1019.33 hPa. Ground-level atmosphericPressure: 998.51 hPa. Humidity: 84%. Cloudiness: 36%. Wind: 5.63 meter/sec, 51 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.15 ℃. Minimum temperature: 25.15 ℃. Maximum temperature: 25.15 ℃. Pressure: 998.79 hPa. Sea-level atmosphericPressure: 1019.64 hPa. Ground-level atmosphericPressure: 998.79 hPa. Humidity: 78%. Cloudiness: 44%. Wind: 5.47 meter/sec, 38 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Wed Jul 18 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.23 ℃. Minimum temperature: 23.23 ℃. Maximum temperature: 23.23 ℃. Pressure: 999.08 hPa. Sea-level atmosphericPressure: 1020.04 hPa. Ground-level atmosphericPressure: 999.08 hPa. Humidity: 75%. Cloudiness: 48%. Wind: 4.62 meter/sec, 25 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 20.79 ℃. Minimum temperature: 20.79 ℃. Maximum temperature: 20.79 ℃. Pressure: 999.67 hPa. Sea-level atmosphericPressure: 1020.68 hPa. Ground-level atmosphericPressure: 999.67 hPa. Humidity: 76%. Cloudiness: 48%. Wind: 4.29 meter/sec, 13 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 03:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.45 ℃. Minimum temperature: 19.45 ℃. Maximum temperature: 19.45 ℃. Pressure: 999.95 hPa. Sea-level atmosphericPressure: 1021.02 hPa. Ground-level atmosphericPressure: 999.95 hPa. Humidity: 80%. Cloudiness: 48%. Wind: 4.22 meter/sec, 17 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 06:00:00 MSK 2018. Weather: light rain. Temperature: 18.9 ℃. Minimum temperature: 18.9 ℃. Maximum temperature: 18.9 ℃. Pressure: 1000.6 hPa. Sea-level atmosphericPressure: 1021.62 hPa. Ground-level atmosphericPressure: 1000.6 hPa. Humidity: 83%. Cloudiness: 92%. Wind: 4.43 meter/sec, 10 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 09:00:00 MSK 2018. Weather: light rain. Temperature: 21.37 ℃. Minimum temperature: 21.37 ℃. Maximum temperature: 21.37 ℃. Pressure: 1000.95 hPa. Sea-level atmosphericPressure: 1022.01 hPa. Ground-level atmosphericPressure: 1000.95 hPa. Humidity: 87%. Cloudiness: 0%. Wind: 4.36 meter/sec, 6 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.92 ℃. Minimum temperature: 23.92 ℃. Maximum temperature: 23.92 ℃. Pressure: 1001.5 hPa. Sea-level atmosphericPressure: 1022.43 hPa. Ground-level atmosphericPressure: 1001.5 hPa. Humidity: 77%. Cloudiness: 0%. Wind: 5.66 meter/sec, 12 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 15:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.7 ℃. Minimum temperature: 23.7 ℃. Maximum temperature: 23.7 ℃. Pressure: 1001.75 hPa. Sea-level atmosphericPressure: 1022.72 hPa. Ground-level atmosphericPressure: 1001.75 hPa. Humidity: 72%. Cloudiness: 56%. Wind: 5.87 meter/sec, 349 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 18:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.82 ℃. Minimum temperature: 23.82 ℃. Maximum temperature: 23.82 ℃. Pressure: 1001.55 hPa. Sea-level atmosphericPressure: 1022.59 hPa. Ground-level atmosphericPressure: 1001.55 hPa. Humidity: 72%. Cloudiness: 68%. Wind: 5.47 meter/sec, 340 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Thu Jul 19 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.22 ℃. Minimum temperature: 22.22 ℃. Maximum temperature: 22.22 ℃. Pressure: 1001.82 hPa. Sea-level atmosphericPressure: 1022.93 hPa. Ground-level atmosphericPressure: 1001.82 hPa. Humidity: 67%. Cloudiness: 76%. Wind: 4.12 meter/sec, 333 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.76 ℃. Minimum temperature: 19.76 ℃. Maximum temperature: 19.76 ℃. Pressure: 1001.98 hPa. Sea-level atmosphericPressure: 1023.13 hPa. Ground-level atmosphericPressure: 1001.98 hPa. Humidity: 76%. Cloudiness: 32%. Wind: 4.11 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 03:00:00 MSK 2018. Weather: clear sky. Temperature: 17.53 ℃. Minimum temperature: 17.53 ℃. Maximum temperature: 17.53 ℃. Pressure: 1001.93 hPa. Sea-level atmosphericPressure: 1023.13 hPa. Ground-level atmosphericPressure: 1001.93 hPa. Humidity: 87%. Cloudiness: 8%. Wind: 4.21 meter/sec, 309 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 16.83 ℃. Minimum temperature: 16.83 ℃. Maximum temperature: 16.83 ℃. Pressure: 1001.79 hPa. Sea-level atmosphericPressure: 1022.99 hPa. Ground-level atmosphericPressure: 1001.79 hPa. Humidity: 91%. Cloudiness: 44%. Wind: 3.65 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 09:00:00 MSK 2018. Weather: light rain. Temperature: 19.57 ℃. Minimum temperature: 19.57 ℃. Maximum temperature: 19.57 ℃. Pressure: 1001.34 hPa. Sea-level atmosphericPressure: 1022.41 hPa. Ground-level atmosphericPressure: 1001.34 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 4.38 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.5 ℃. Minimum temperature: 23.5 ℃. Maximum temperature: 23.5 ℃. Pressure: 1001.0 hPa. Sea-level atmosphericPressure: 1021.99 hPa. Ground-level atmosphericPressure: 1001.0 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 5.36 meter/sec, 299 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.14 ℃. Minimum temperature: 25.14 ℃. Maximum temperature: 25.14 ℃. Pressure: 1000.5 hPa. Sea-level atmosphericPressure: 1021.51 hPa. Ground-level atmosphericPressure: 1000.5 hPa. Humidity: 73%. Cloudiness: 32%. Wind: 6.72 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 18:00:00 MSK 2018. Weather: overcast clouds. Temperature: 23.56 ℃. Minimum temperature: 23.56 ℃. Maximum temperature: 23.56 ℃. Pressure: 1000.7 hPa. Sea-level atmosphericPressure: 1021.58 hPa. Ground-level atmosphericPressure: 1000.7 hPa. Humidity: 66%. Cloudiness: 88%. Wind: 6.57 meter/sec, 317 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Fri Jul 20 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.41 ℃. Minimum temperature: 22.41 ℃. Maximum temperature: 22.41 ℃. Pressure: 1000.64 hPa. Sea-level atmosphericPressure: 1021.67 hPa. Ground-level atmosphericPressure: 1000.64 hPa. Humidity: 68%. Cloudiness: 64%. Wind: 4.31 meter/sec, 326 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 00:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.92 ℃. Minimum temperature: 20.92 ℃. Maximum temperature: 20.92 ℃. Pressure: 1001.06 hPa. Sea-level atmosphericPressure: 1022.14 hPa. Ground-level atmosphericPressure: 1001.06 hPa. Humidity: 78%. Cloudiness: 68%. Wind: 3.42 meter/sec, 327 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 03:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.28 ℃. Minimum temperature: 20.28 ℃. Maximum temperature: 20.28 ℃. Pressure: 1001.04 hPa. Sea-level atmosphericPressure: 1022.13 hPa. Ground-level atmosphericPressure: 1001.04 hPa. Humidity: 78%. Cloudiness: 76%. Wind: 4.27 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.11 ℃. Minimum temperature: 19.11 ℃. Maximum temperature: 19.11 ℃. Pressure: 1001.13 hPa. Sea-level atmosphericPressure: 1022.28 hPa. Ground-level atmosphericPressure: 1001.13 hPa. Humidity: 74%. Cloudiness: 32%. Wind: 4.96 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 09:00:00 MSK 2018. Weather: few clouds. Temperature: 20.16 ℃. Minimum temperature: 20.16 ℃. Maximum temperature: 20.16 ℃. Pressure: 1001.43 hPa. Sea-level atmosphericPressure: 1022.62 hPa. Ground-level atmosphericPressure: 1001.43 hPa. Humidity: 86%. Cloudiness: 20%. Wind: 5.16 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 12:00:00 MSK 2018. Weather: few clouds. Temperature: 22.37 ℃. Minimum temperature: 22.37 ℃. Maximum temperature: 22.37 ℃. Pressure: 1001.53 hPa. Sea-level atmosphericPressure: 1022.62 hPa. Ground-level atmosphericPressure: 1001.53 hPa. Humidity: 88%. Cloudiness: 20%. Wind: 5.56 meter/sec, 307 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.85 ℃. Minimum temperature: 22.85 ℃. Maximum temperature: 22.85 ℃. Pressure: 1001.63 hPa. Sea-level atmosphericPressure: 1022.65 hPa. Ground-level atmosphericPressure: 1001.63 hPa. Humidity: 81%. Cloudiness: 44%. Wind: 5.46 meter/sec, 314 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.79 ℃. Minimum temperature: 23.79 ℃. Maximum temperature: 23.79 ℃. Pressure: 1001.53 hPa. Sea-level atmosphericPressure: 1022.53 hPa. Ground-level atmosphericPressure: 1001.53 hPa. Humidity: 72%. Cloudiness: 32%. Wind: 5.56 meter/sec, 313 degrees. Rain(last 3 hrs): 0 mm
|
||||
Time: Sat Jul 21 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.56 ℃. Minimum temperature: 22.56 ℃. Maximum temperature: 22.56 ℃. Pressure: 1001.72 hPa. Sea-level atmosphericPressure: 1022.7 hPa. Ground-level atmosphericPressure: 1001.72 hPa. Humidity: 66%. Cloudiness: 48%. Wind: 3.96 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||
```
|
||||
|
||||
`HourlyForecast.Forecast`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-----------------------------|------------------------------------------------------------------------------------------------------------------|
|
||||
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
|
||||
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
|
||||
| `getWeatherInfo()` | Returns `HourlyForecast.WeatherInfo` instance that contains information about temperature, atmosphericPressure and humidity.|
|
||||
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
|
||||
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
|
||||
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
||||
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
||||
| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. |
|
||||
| `getDt_txt()` | Returns `String` value that represents data calculation time. |
|
||||
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||
|
||||
#### 16 day / daily forecast
|
||||
First step is retrieving `DailyForecastRequester` instance:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
DailyForecastRequester forecastRequester = openWeatherManager.getDailyForecastRequester();
|
||||
```
|
||||
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||
```
|
||||
DailyForecast forecastResponse = forecastRequester
|
||||
.setLanguage(Language.ENGLISH)
|
||||
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||
.setAccuracy(Accuracy.ACCURATE)
|
||||
.getByCityName("Pruzhany");
|
||||
```
|
||||
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||
|
||||
Available requests:
|
||||
* `getByCityId(String cityId)`
|
||||
* `getByCityName(String cityName)`
|
||||
* `getByCoordinates(double latitude, double longitude)`
|
||||
* `getByCoordinates(Coordinates coordinates)`
|
||||
* `getByZIPCode(String zipCode, String countryCode)`
|
||||
|
||||
`DailyForecast`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-----------------------------|--------------------------------------------------------------------------------------------|
|
||||
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||
| `getCityInfo()` | Returns `CityInfo` instance that contains information about city. |
|
||||
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
|
||||
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
|
||||
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||
|
||||
`DailyForecast.Forecast`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-----------------------------|------------------------------------------------------------------------------------------------------------------|
|
||||
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
|
||||
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
|
||||
| `getTemperature()` | Returns `DailyForecast.Forecast.Temperature` instance that contains information about temperature(avg, min, max).|
|
||||
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||
| `getCloudiness()` | Returns *cloudiness* percentage information. |
|
||||
| `getHumidity()` | Returns *humidity* percentage information. |
|
||||
| `getWindSpeed()` | Returns wind's speed. |
|
||||
| `getWindDegrees()` | Returns wind's degree. |
|
||||
| `getWindUnit()` | Returns wind's unit. |
|
||||
| `getPressure()` | Returns atmosphericPressure value. |
|
||||
| `getPressureUnit()` | Returns atmosphericPressure's unit. |
|
||||
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||
|
||||
#### UV Index
|
||||
|
||||
First step is retrieving `UltravioletIndexRequester` instance:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
UltravioletIndexRequester requester = openWeatherMapManager.getUltravioletIndexRequester(34.23f, -22.45f);
|
||||
```
|
||||
or
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
Coordinates coordinates = new Coordinates(34.23f, -22.45f);
|
||||
UltravioletIndexRequester requester = openWeatherMapManager.getUltravioletIndexRequester(coordinates);
|
||||
```
|
||||
|
||||
after you need to execute appropriate request:
|
||||
```
|
||||
UltravioletIndex uvResponse = requester.getCurrentUVIndex();
|
||||
```
|
||||
|
||||
You can change required coordinates via: `requester.setCoordinates(Coordinates coordinates);` or `requester.setCoordinates(float latitude, float longitude);`
|
||||
|
||||
Available requests:
|
||||
* `getCurrentUVIndex()`
|
||||
* `getUVIndexForecast(int amountOfDays)`
|
||||
* `getUVIndexByPeriod(Date from, Date to)`
|
||||
|
||||
`UltravioletIndex`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|---------------------------|---------------------------------------------------------------|
|
||||
| `getLatitude()` | Returns latitude. |
|
||||
| `getLongitude()` | Returns longitude. |
|
||||
| `getDateISO()` | Returns ISO date in String representation. |
|
||||
| `getDateTimestamp()` | Returns date timestamp. |
|
||||
| `getValue()` | Returns UV value. |
|
||||
| `getCalculationDate()` | Returns date in Date representation`. |
|
||||
| `toString()` | Returns pretty string for the whole available UV information. |
|
||||
|
||||
`toString()` output example:
|
||||
```
|
||||
Date: Tue Jul 31 15:00:00 MSK 2018, Ultraviolet value: 6.230000
|
||||
```
|
||||
|
||||
#### Air pollution
|
||||
|
||||
First step is retrieving `AirPollutionRequester` instance:
|
||||
```java
|
||||
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
|
||||
AirPollutionRequester requester = openWeatherMapManager.getAirPollutionRequester(0f, 10f, new Date(), TimeFrame.DAY);
|
||||
```
|
||||
after you need to execute appropriate request:
|
||||
```
|
||||
AirPollution airPolutionResponse = requester.retrieve();
|
||||
```
|
||||
|
||||
You can modify parameters anytime:
|
||||
```java
|
||||
requester.setCoordinates(Coordinates coordinates);
|
||||
requester.setCoordinates(float latitude, float longitude);
|
||||
requester.setTimeFrame(TimeFrame timeFrame);
|
||||
requester.setDate(Date date);
|
||||
```
|
||||
|
||||
Available requests:
|
||||
* `retrieve()`
|
||||
|
||||
`AirPollution`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|---------------------------|---------------------------------------------------------------------------|
|
||||
| `getCoordinates()` | Returns `Coordinates` instance. |
|
||||
| `getLongitude()` | Returns longitude. |
|
||||
| `airPollutionInfo()` | Returns list of `AirPollution.AirPollutionInfo` instances. |
|
||||
| `toString()` | Returns pretty string for the whole available air pollution information. |
|
||||
|
||||
`toString()` output example:
|
||||
```
|
||||
AirPollution[Date: Tue Jul 24 01:04:40 MSK 2018; Coordinates: latitude=0.0, longitude=9.9955]
|
||||
[Value: 8.0347114E-8, Value: 9.5041536E-8, Value: 7.7667146E-8, Value: 7.251491E-8, Value: 5.899763E-8, Value: 1.9186361E-8, Value: 1.729535E-8, Value: 1.25645805E-8, Value: 3.0852514E-9]
|
||||
```
|
||||
|
||||
### Constants and options
|
||||
|
||||
#### Accuracy
|
||||
| Constant | Description |
|
||||
|--------------------|------------------|
|
||||
| Accuracy.LIKE | Close result. |
|
||||
| Accuracy.ACCURATE | Accurate result. |
|
||||
|
||||
#### Language
|
||||
| Constant | Description |
|
||||
|-----------------------------------|-------------------------------|
|
||||
| Language.ARABIC | Arabic language. |
|
||||
| Language.BULGARIAN | Bulgarian language. |
|
||||
| Language.CATALAN | Catalan language. |
|
||||
| Language.CZECH | Czech language. |
|
||||
| Language.GERMAN | German language. |
|
||||
| Language.GREEK | Greek language. |
|
||||
| Language.ENGLISH | English language. |
|
||||
| Language.PERSIAN | Persian (Farsi) language. |
|
||||
| Language.FINNISH | Finnish language. |
|
||||
| Language.FRENCH | French language. |
|
||||
| Language.GALICIAN | Galician language. |
|
||||
| Language.CROATIAN | Croatian language. |
|
||||
| Language.HUNGARIAN | Hungarian language. |
|
||||
| Language.ITALIAN | Italian language. |
|
||||
| Language.JAPANESE | Japanese language. |
|
||||
| Language.KOREAN | Korean language. |
|
||||
| Language.LATVIAN | Latvian language. |
|
||||
| Language.LITHUANIAN | Lithuanian language. |
|
||||
| Language.MACEDONIAN | Macedonian language. |
|
||||
| Language.DUTCH | Dutch language. |
|
||||
| Language.POLISH | Polish language. |
|
||||
| Language.PORTUGUESE | Portuguese language. |
|
||||
| Language.ROMANIAN | Romanian language. |
|
||||
| Language.RUSSIAN | Russian language. |
|
||||
| Language.SWEDISH | Swedish language. |
|
||||
| Language.SLOVAK | Slovak language. |
|
||||
| Language.SLOVENIAN | Slovenian language. |
|
||||
| Language.SPANISH | Spanish language. |
|
||||
| Language.TURKISH | Turkish language. |
|
||||
| Language.UKRANIAN | Ukrainian language. |
|
||||
| Language.VIETNAMESE | Vietnamese language. |
|
||||
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||
|
||||
#### Unit
|
||||
| Constant | Description |
|
||||
|----------------------|------------------------------------------------|
|
||||
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
|
||||
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
|
||||
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow) |
|
||||
|
||||
### Dependencies
|
||||
* com.alibaba:fastjson:1.2.44
|
||||
* org.projectlombok:lombok:1.18.0 (*provided*)
|
||||
* junit:junit:4.12 (*test*)
|
||||
@@ -0,0 +1,253 @@
|
||||
### Implemented features:
|
||||
* Current weather data
|
||||
* 5 day / 3-hour forecast
|
||||
|
||||
### Maven coordinates:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
implementation 'com.github.prominence:openweathermap-api:2.0.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()`
|
||||
|
||||
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 |
|
||||
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getState()` | Returns short weather description. Example: `Clear`. |
|
||||
| `getDescription()` | Returns weather description. Example: `clear sky`. |
|
||||
| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. |
|
||||
| `getCalculatedOn()` | Returns `LocalDateTime` object with data calculation time. |
|
||||
| `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.request.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 |
|
||||
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getState()` | Returns short weather description. Example: `Clear`. |
|
||||
| `getDescription()` | Returns weather description. Example: `clear sky`. |
|
||||
| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. |
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `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. |
|
||||
|
||||
### Constants and options
|
||||
|
||||
#### Language
|
||||
| Constant | Description |
|
||||
|-----------------------------------|-------------------------------|
|
||||
| Language.ARABIC | Arabic language. |
|
||||
| Language.BULGARIAN | Bulgarian language. |
|
||||
| Language.CATALAN | Catalan language. |
|
||||
| Language.CZECH | Czech language. |
|
||||
| Language.GERMAN | German language. |
|
||||
| Language.GREEK | Greek language. |
|
||||
| Language.ENGLISH | English language. |
|
||||
| Language.PERSIAN | Persian (Farsi) language. |
|
||||
| Language.FINNISH | Finnish language. |
|
||||
| Language.FRENCH | French language. |
|
||||
| Language.GALICIAN | Galician language. |
|
||||
| Language.CROATIAN | Croatian language. |
|
||||
| Language.HUNGARIAN | Hungarian language. |
|
||||
| Language.ITALIAN | Italian language. |
|
||||
| Language.JAPANESE | Japanese language. |
|
||||
| Language.KOREAN | Korean language. |
|
||||
| Language.LATVIAN | Latvian language. |
|
||||
| Language.LITHUANIAN | Lithuanian language. |
|
||||
| Language.MACEDONIAN | Macedonian language. |
|
||||
| Language.DUTCH | Dutch language. |
|
||||
| Language.POLISH | Polish language. |
|
||||
| Language.PORTUGUESE | Portuguese language. |
|
||||
| Language.ROMANIAN | Romanian language. |
|
||||
| Language.RUSSIAN | Russian language. |
|
||||
| Language.SWEDISH | Swedish language. |
|
||||
| Language.SLOVAK | Slovak language. |
|
||||
| Language.SLOVENIAN | Slovenian language. |
|
||||
| Language.SPANISH | Spanish language. |
|
||||
| Language.TURKISH | Turkish language. |
|
||||
| Language.UKRANIAN | Ukrainian language. |
|
||||
| Language.VIETNAMESE | Vietnamese language. |
|
||||
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||
|
||||
#### Unit
|
||||
| Constant | Description |
|
||||
|----------------------|------------------------------------------------|
|
||||
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
|
||||
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
|
||||
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow). |
|
||||
|
||||
### Dependencies
|
||||
* com.fasterxml.jackson.core:jackson-databind:2.12.2
|
||||
* org.slf4j:slf4j-api:1.7.30 (*compile*)
|
||||
* junit:junit:4.13.1 (*test*)
|
||||
@@ -0,0 +1,253 @@
|
||||
### Implemented features:
|
||||
* Current weather data
|
||||
* 5 day / 3-hour forecast
|
||||
|
||||
### Maven coordinates:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
implementation 'com.github.prominence:openweathermap-api:2.0.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()`
|
||||
|
||||
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 |
|
||||
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getState()` | Returns short weather description. Example: `Clear`. |
|
||||
| `getDescription()` | Returns weather description. Example: `clear sky`. |
|
||||
| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. |
|
||||
| `getCalculatedOn()` | Returns `LocalDateTime` object with data calculation time. |
|
||||
| `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.request.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 |
|
||||
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getState()` | Returns short weather description. Example: `Clear`. |
|
||||
| `getDescription()` | Returns weather description. Example: `clear sky`. |
|
||||
| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. |
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `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. |
|
||||
|
||||
### Constants and options
|
||||
|
||||
#### Language
|
||||
| Constant | Description |
|
||||
|-----------------------------------|-------------------------------|
|
||||
| Language.ARABIC | Arabic language. |
|
||||
| Language.BULGARIAN | Bulgarian language. |
|
||||
| Language.CATALAN | Catalan language. |
|
||||
| Language.CZECH | Czech language. |
|
||||
| Language.GERMAN | German language. |
|
||||
| Language.GREEK | Greek language. |
|
||||
| Language.ENGLISH | English language. |
|
||||
| Language.PERSIAN | Persian (Farsi) language. |
|
||||
| Language.FINNISH | Finnish language. |
|
||||
| Language.FRENCH | French language. |
|
||||
| Language.GALICIAN | Galician language. |
|
||||
| Language.CROATIAN | Croatian language. |
|
||||
| Language.HUNGARIAN | Hungarian language. |
|
||||
| Language.ITALIAN | Italian language. |
|
||||
| Language.JAPANESE | Japanese language. |
|
||||
| Language.KOREAN | Korean language. |
|
||||
| Language.LATVIAN | Latvian language. |
|
||||
| Language.LITHUANIAN | Lithuanian language. |
|
||||
| Language.MACEDONIAN | Macedonian language. |
|
||||
| Language.DUTCH | Dutch language. |
|
||||
| Language.POLISH | Polish language. |
|
||||
| Language.PORTUGUESE | Portuguese language. |
|
||||
| Language.ROMANIAN | Romanian language. |
|
||||
| Language.RUSSIAN | Russian language. |
|
||||
| Language.SWEDISH | Swedish language. |
|
||||
| Language.SLOVAK | Slovak language. |
|
||||
| Language.SLOVENIAN | Slovenian language. |
|
||||
| Language.SPANISH | Spanish language. |
|
||||
| Language.TURKISH | Turkish language. |
|
||||
| Language.UKRANIAN | Ukrainian language. |
|
||||
| Language.VIETNAMESE | Vietnamese language. |
|
||||
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||
|
||||
#### Unit
|
||||
| Constant | Description |
|
||||
|----------------------|------------------------------------------------|
|
||||
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
|
||||
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
|
||||
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow). |
|
||||
|
||||
### Dependencies
|
||||
* com.fasterxml.jackson.core:jackson-databind:2.12.2
|
||||
* org.slf4j:slf4j-api:1.7.30 (*compile*)
|
||||
* junit:junit:4.13.1 (*test*)
|
||||
@@ -0,0 +1,484 @@
|
||||
### Implemented features:
|
||||
* Current weather data
|
||||
* 5 day / 3-hour forecast
|
||||
* One Call API
|
||||
|
||||
### Maven coordinates:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
implementation 'com.github.prominence:openweathermap-api:2.1.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()`
|
||||
|
||||
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). |
|
||||
| `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. |
|
||||
| `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). |
|
||||
| `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`. |
|
||||
|
||||
### 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.UKRANIAN | 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.12.2
|
||||
* org.slf4j:slf4j-api:1.7.30 (*compile*)
|
||||
* org.junit.jupiter:junit-jupiter-engine:5.7.1 (*test*)
|
||||
* org.junit.platform:junit-platform-runner:1.7.1 (*test*)
|
||||
@@ -0,0 +1,486 @@
|
||||
### Implemented features:
|
||||
* Current weather data
|
||||
* 5 day / 3-hour forecast
|
||||
* One Call API
|
||||
|
||||
### Maven coordinates:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>2.1.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
implementation 'com.github.prominence:openweathermap-api:2.1.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()`
|
||||
|
||||
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. |
|
||||
| `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`. |
|
||||
|
||||
### 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.UKRANIAN | 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.12.2
|
||||
* org.slf4j:slf4j-api:1.7.30 (*compile*)
|
||||
* org.junit.jupiter:junit-jupiter-engine:5.7.1 (*test*)
|
||||
* org.junit.platform:junit-platform-runner:1.7.1 (*test*)
|
||||
@@ -0,0 +1,538 @@
|
||||
### Implemented features:
|
||||
* Current weather data
|
||||
* 5 day / 3-hour forecast
|
||||
* One Call API
|
||||
* Air Pollution
|
||||
|
||||
### Maven coordinates:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>2.2.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
implementation 'com.github.prominence:openweathermap-api:2.2.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()`
|
||||
|
||||
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. |
|
||||
| `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.UKRANIAN | 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.12.2
|
||||
* org.slf4j:slf4j-api:1.7.30 (*compile*)
|
||||
* org.junit.jupiter:junit-jupiter-engine:5.7.1 (*test*)
|
||||
* org.junit.platform:junit-platform-runner:1.7.1 (*test*)
|
||||
@@ -0,0 +1,552 @@
|
||||
### 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
|
||||
implementation '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*)
|
||||
@@ -0,0 +1,589 @@
|
||||
### Implemented features:
|
||||
* Current weather data
|
||||
* Hourly forecast
|
||||
* One Call API
|
||||
* Daily forecast
|
||||
* Solar Radiation API
|
||||
* 5 day / 3-hour forecast
|
||||
* Road Risk API
|
||||
* Air Pollution
|
||||
* Geocoding API
|
||||
|
||||
|
||||
Other:
|
||||
* Request timeout settings
|
||||
|
||||
### Maven coordinates:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
```xml
|
||||
<repositories>
|
||||
...
|
||||
<!-- Repository for snapshot versions -->
|
||||
<repository>
|
||||
<id>oss.sonatype.org-snapshot</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
...
|
||||
</repositories>
|
||||
```
|
||||
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
implementation 'com.github.prominence:openweathermap-api:3.0.0-SNAPSHOT'
|
||||
```
|
||||
|
||||
```groovy
|
||||
repositories {
|
||||
...
|
||||
// Repository for snapshot versions
|
||||
maven {
|
||||
url "https://oss.sonatype.org/content/repositories/snapshots"
|
||||
mavenContent {
|
||||
snapshotsOnly()
|
||||
}
|
||||
}
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
### 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 `coordinates`. |
|
||||
| `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`, `coordinates` 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.free.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 |
|
||||
|-------------------------------|--------------------------------------------------------------------------------|
|
||||
| `getCoordinates()` | 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 |
|
||||
|-------------------------------|-------------------------------------------------------------------------------|
|
||||
| `getCoordinates()` | 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 |
|
||||
|-------------------------------|---------------------------------------------------------------------------|
|
||||
| `getCoordinates()` | 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*)
|
||||
Vendored
BIN
Binary file not shown.
+5
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -0,0 +1,234 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
Vendored
+89
@@ -0,0 +1,89 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -0,0 +1,5 @@
|
||||
# This file is generated by the 'io.freefair.lombok' Gradle plugin
|
||||
config.stopBubbling = true
|
||||
lombok.addSuppressWarnings = true
|
||||
lombok.addLombokGeneratedAnnotation = true
|
||||
lombok.nonNull.exceptionType = IllegalArgumentException
|
||||
@@ -1,141 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Java OpenWeatherMap API</name>
|
||||
<description>Java API for OpenWeatherMap services.</description>
|
||||
<url>https://github.com/Prominence/openweathermap-java-api</url>
|
||||
|
||||
<scm>
|
||||
<url>https://github.com/Prominence/openweathermap-java-api</url>
|
||||
<connection>scm:git:git://github.com/Prominence/openweathermap-java-api.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:prominence/openweathermap-java-api.git</developerConnection>
|
||||
</scm>
|
||||
|
||||
<issueManagement>
|
||||
<url>https://github.com/Prominence/openweathermap-java-api/issues</url>
|
||||
<system>GitHub Issues</system>
|
||||
</issueManagement>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>MIT License</name>
|
||||
<url>http://www.opensource.org/licenses/mit-license.php</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<email>alexey.zinchenko@protonmail.com</email>
|
||||
<name>Alexey Zinchenko</name>
|
||||
<url>https://github.com/prominence</url>
|
||||
<id>Prominence</id>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>ossrh</id>
|
||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>ApplicationTest.class</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||
<version>1.6.7</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<serverId>ossrh</serverId>
|
||||
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
|
||||
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.9.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.44</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1 @@
|
||||
rootProject.name = 'openweathermap-api'
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
|
||||
import com.github.prominence.openweathermap.api.constants.System;
|
||||
import com.github.prominence.openweathermap.api.constants.Unit;
|
||||
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
|
||||
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
abstract class BasicRequester<T> extends AuthenticationTokenBasedRequester {
|
||||
|
||||
protected String language;
|
||||
protected String unitSystem = Unit.STANDARD_SYSTEM;
|
||||
protected String accuracy;
|
||||
|
||||
protected BasicRequester(String authToken) {
|
||||
super(authToken);
|
||||
}
|
||||
|
||||
public T getByCityId(String id) throws InvalidAuthTokenException, DataNotFoundException {
|
||||
return executeRequest("?id=" + id);
|
||||
}
|
||||
|
||||
public T getByCityName(String name) throws InvalidAuthTokenException, DataNotFoundException {
|
||||
return executeRequest("?q=" + name);
|
||||
}
|
||||
|
||||
public T getByCoordinates(double latitude, double longitude) throws InvalidAuthTokenException, DataNotFoundException {
|
||||
return executeRequest("?lat=" + latitude + "&lon=" + longitude);
|
||||
}
|
||||
|
||||
public T getByCoordinates(Coordinates coordinates) throws InvalidAuthTokenException, DataNotFoundException {
|
||||
return getByCoordinates(coordinates.getLatitude(), coordinates.getLongitude());
|
||||
}
|
||||
|
||||
public T getByZIPCode(String zipCode, String countryCode) throws InvalidAuthTokenException, DataNotFoundException {
|
||||
return executeRequest("?zip=" + zipCode + "," + countryCode);
|
||||
}
|
||||
|
||||
protected URL buildURL(String requestSpecificParameters) throws MalformedURLException {
|
||||
|
||||
StringBuilder urlBuilder = new StringBuilder(System.OPEN_WEATHER_API_URL);
|
||||
urlBuilder.append(getRequestType());
|
||||
urlBuilder.append(requestSpecificParameters);
|
||||
|
||||
urlBuilder.append("&appid=");
|
||||
urlBuilder.append(authToken);
|
||||
|
||||
|
||||
if (language != null) {
|
||||
urlBuilder.append("&lang=");
|
||||
urlBuilder.append(language);
|
||||
}
|
||||
|
||||
if (!Unit.STANDARD_SYSTEM.equals(unitSystem)) {
|
||||
urlBuilder.append("&units=");
|
||||
urlBuilder.append(unitSystem);
|
||||
}
|
||||
|
||||
if (accuracy != null) {
|
||||
urlBuilder.append("&type=");
|
||||
urlBuilder.append(accuracy);
|
||||
}
|
||||
|
||||
return new URL(urlBuilder.toString());
|
||||
}
|
||||
|
||||
protected abstract String getRequestType();
|
||||
protected abstract T executeRequest(String requestSpecificParamsString) throws InvalidAuthTokenException, DataNotFoundException;
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
|
||||
import com.github.prominence.openweathermap.api.constants.Unit;
|
||||
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
|
||||
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||
import com.github.prominence.openweathermap.api.model.response.HourlyForecast;
|
||||
import com.github.prominence.openweathermap.api.utils.JsonUtils;
|
||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class HourlyForecastRequester extends BasicRequester<HourlyForecast> {
|
||||
|
||||
HourlyForecastRequester(String authToken) {
|
||||
super(authToken);
|
||||
}
|
||||
|
||||
public HourlyForecastRequester setLanguage(String language) {
|
||||
this.language = language;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HourlyForecastRequester setUnitSystem(String unitSystem) {
|
||||
this.unitSystem = unitSystem;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HourlyForecastRequester setAccuracy(String accuracy) {
|
||||
this.accuracy = accuracy;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected String getRequestType() {
|
||||
return "forecast";
|
||||
}
|
||||
|
||||
protected HourlyForecast executeRequest(String requestSpecificParameters) throws InvalidAuthTokenException, DataNotFoundException {
|
||||
|
||||
HourlyForecast forecastResponse = null;
|
||||
|
||||
try {
|
||||
InputStream requestResult = RequestUtils.executeGetRequest(buildURL(requestSpecificParameters));
|
||||
forecastResponse = (HourlyForecast)JsonUtils.parseJson(requestResult, HourlyForecast.class);
|
||||
|
||||
char temperatureUnit = Unit.getTemperatureUnit(unitSystem);
|
||||
String windUnit = Unit.getWindUnit(unitSystem);
|
||||
|
||||
forecastResponse.getForecasts().forEach(forecastInfo -> {
|
||||
forecastInfo.getWind().setUnit(windUnit);
|
||||
forecastInfo.getWeatherInfo().setTemperatureUnit(temperatureUnit);
|
||||
});
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return forecastResponse;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
|
||||
import com.github.prominence.openweathermap.api.annotation.SubscriptionAvailability;
|
||||
import com.github.prominence.openweathermap.api.context.ApiConfiguration;
|
||||
import com.github.prominence.openweathermap.api.context.ApiConfigurationHolder;
|
||||
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.climatic.ClimaticForecastRequester;
|
||||
import com.github.prominence.openweathermap.api.request.forecast.daily.DailyForecastRequester;
|
||||
import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThreeHourStepForecastRequester;
|
||||
import com.github.prominence.openweathermap.api.request.forecast.hourly.FourDaysHourlyForecastRequester;
|
||||
import com.github.prominence.openweathermap.api.request.geocoding.GeocodingRequester;
|
||||
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherRequester;
|
||||
import com.github.prominence.openweathermap.api.request.radiation.SolarRadiationRequester;
|
||||
import com.github.prominence.openweathermap.api.request.roadrisk.RoadRiskRequester;
|
||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester;
|
||||
import lombok.NonNull;
|
||||
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.ALL;
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.DEVELOPER;
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.ENTERPRISE;
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.PAID;
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.PROFESSIONAL;
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.SPECIAL;
|
||||
|
||||
/**
|
||||
* The main public API client to communicate with OpenWeatherMap services.
|
||||
* Requires API key for usage. More info on the website <a href="https://openweathermap.org/api">https://openweathermap.org/api</a>.
|
||||
*/
|
||||
public class OpenWeatherMapClient {
|
||||
private final ApiConfiguration apiConfiguration;
|
||||
|
||||
public OpenWeatherMapClient() {
|
||||
this(ApiConfigurationHolder.getConfiguration());
|
||||
}
|
||||
|
||||
/**
|
||||
* Created OpenWeatherMap client object.
|
||||
*
|
||||
* @param apiConfiguration configuration options.
|
||||
*/
|
||||
public OpenWeatherMapClient(@NonNull ApiConfiguration apiConfiguration) {
|
||||
this.apiConfiguration = apiConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current Weather <a href="https://openweathermap.org/current">API</a>.
|
||||
*
|
||||
* @return requester for retrieving current weather information.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = ALL)
|
||||
public CurrentWeatherRequester currentWeather() {
|
||||
return new CurrentWeatherRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Hourly forecast <a href="https://openweathermap.org/api/hourly-forecast">API</a>.
|
||||
*
|
||||
* @return requester for retrieving hourly weather forecast information for 4 days.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = {DEVELOPER, PROFESSIONAL, ENTERPRISE})
|
||||
public FourDaysHourlyForecastRequester forecastHourly4Days() {
|
||||
return new FourDaysHourlyForecastRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* One Call <a href="https://openweathermap.org/api/one-call-api">API</a>.
|
||||
* To get information about current weather, minute forecast for 1 hour, hourly forecast for 48 hours, daily forecast for 7 days and government weather alerts.
|
||||
*
|
||||
* @return requester for retrieving one call weather information.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = ALL)
|
||||
public OneCallWeatherRequester oneCall() {
|
||||
return new OneCallWeatherRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Daily forecast <a href="https://openweathermap.org/api/hourly-forecast">API</a>.
|
||||
*
|
||||
* @return requester for retrieving daily weather forecast information for 16 days.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = PAID)
|
||||
public DailyForecastRequester forecastDaily16Days() {
|
||||
return new DailyForecastRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Climatic forecast <a href="https://openweathermap.org/api/forecast30">API</a>.
|
||||
*
|
||||
* @return requester for retrieving climatic weather forecast information for 30 days.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = {DEVELOPER, PROFESSIONAL, ENTERPRISE})
|
||||
public ClimaticForecastRequester climaticForecast30Days() {
|
||||
return new ClimaticForecastRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Solar Radiation <a href="https://openweathermap.org/api/solar-radiation">API</a>.
|
||||
*
|
||||
* @return requester for retrieving solar radiation information.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = SPECIAL)
|
||||
public SolarRadiationRequester solarRadiation() {
|
||||
return new SolarRadiationRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* 5 Day / 3 Hour Forecast <a href="https://openweathermap.org/forecast5">API</a>.
|
||||
*
|
||||
* @return requester for retrieving 5 day/3-hour weather forecast information.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = ALL)
|
||||
public FiveDayThreeHourStepForecastRequester forecast5Day3HourStep() {
|
||||
return new FiveDayThreeHourStepForecastRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Road Risk <a href="https://openweathermap.org/api/road-risk">API</a>.
|
||||
*
|
||||
* @return requester for retrieving road risk information.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = SPECIAL)
|
||||
public RoadRiskRequester roadRisk() {
|
||||
return new RoadRiskRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(getRequestSettings());
|
||||
}
|
||||
|
||||
@SubscriptionAvailability(plans = ALL)
|
||||
public GeocodingRequester geocoding() {
|
||||
return new GeocodingRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
private RequestSettings getRequestSettings() {
|
||||
return new RequestSettings(apiConfiguration);
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
|
||||
import com.github.prominence.openweathermap.api.constants.Unit;
|
||||
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
|
||||
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||
import com.github.prominence.openweathermap.api.model.response.Weather;
|
||||
import com.github.prominence.openweathermap.api.utils.JsonUtils;
|
||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class WeatherRequester extends BasicRequester<Weather> {
|
||||
|
||||
WeatherRequester(String authToken) {
|
||||
super(authToken);
|
||||
}
|
||||
|
||||
public WeatherRequester setLanguage(String language) {
|
||||
this.language = language;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WeatherRequester setUnitSystem(String unitSystem) {
|
||||
this.unitSystem = unitSystem;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WeatherRequester setAccuracy(String accuracy) {
|
||||
this.accuracy = accuracy;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected String getRequestType() {
|
||||
return "weather";
|
||||
}
|
||||
|
||||
protected Weather executeRequest(String requestSpecificParameters) throws InvalidAuthTokenException, DataNotFoundException {
|
||||
|
||||
Weather weather = null;
|
||||
|
||||
try {
|
||||
InputStream requestResult = RequestUtils.executeGetRequest(buildURL(requestSpecificParameters));
|
||||
weather = (Weather)JsonUtils.parseJson(requestResult, Weather.class);
|
||||
|
||||
weather.getWind().setUnit(Unit.getWindUnit(unitSystem));
|
||||
weather.getWeatherInfo().setTemperatureUnit(Unit.getTemperatureUnit(unitSystem));
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return weather;
|
||||
}
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.annotation;
|
||||
|
||||
import com.github.prominence.openweathermap.api.enums.SubscriptionPlan;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marker-type annotation to specify what type of license it needs to have to use API method.
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
public @interface SubscriptionAvailability {
|
||||
/**
|
||||
* Marks method with subscription plan it needs to have to use the method.
|
||||
* @return subscription plan.
|
||||
*/
|
||||
SubscriptionPlan[] plans();
|
||||
}
|
||||
+19
-27
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
@@ -20,42 +20,34 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
package com.github.prominence.openweathermap.api.conf;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Objects;
|
||||
@EqualsAndHashCode
|
||||
public final class TimeoutSettings {
|
||||
private final Integer connectionTimeout;
|
||||
private final Integer readTimeout;
|
||||
|
||||
public class Clouds {
|
||||
|
||||
@JSONField(name = "all")
|
||||
// Cloudiness, %
|
||||
private byte cloudiness;
|
||||
|
||||
public byte getCloudiness() {
|
||||
return cloudiness;
|
||||
public TimeoutSettings() {
|
||||
this(2000, 2000);
|
||||
}
|
||||
|
||||
public void setCloudiness(byte cloudiness) {
|
||||
this.cloudiness = cloudiness;
|
||||
public TimeoutSettings(Integer connectionTimeout, Integer readTimeout) {
|
||||
this.connectionTimeout = connectionTimeout;
|
||||
this.readTimeout = readTimeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Cloudiness: " + cloudiness + "%";
|
||||
public TimeoutSettings(TimeoutSettings from) {
|
||||
this.connectionTimeout = from.connectionTimeout;
|
||||
this.readTimeout = from.readTimeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Clouds clouds = (Clouds) o;
|
||||
return cloudiness == clouds.cloudiness;
|
||||
public Integer getConnectionTimeout() {
|
||||
return connectionTimeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(cloudiness);
|
||||
public Integer getReadTimeout() {
|
||||
return readTimeout;
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.constants;
|
||||
|
||||
public final class Language {
|
||||
|
||||
private Language() {}
|
||||
|
||||
public static final String ARABIC = "ar";
|
||||
public static final String BULGARIAN = "bg";
|
||||
public static final String CATALAN = "ca";
|
||||
public static final String CZECH = "cz";
|
||||
public static final String GERMAN = "de";
|
||||
public static final String GREEK = "el";
|
||||
public static final String ENGLISH = "en";
|
||||
public static final String PERSIAN = "fa";
|
||||
public static final String FINNISH = "fi";
|
||||
public static final String FRENCH = "fr";
|
||||
public static final String GALICIAN = "gl";
|
||||
public static final String CROATIAN = "hr";
|
||||
public static final String HUNGARIAN = "hu";
|
||||
public static final String ITALIAN = "it";
|
||||
public static final String JAPANESE = "ja";
|
||||
public static final String KOREAN = "kr";
|
||||
public static final String LATVIAN = "la";
|
||||
public static final String LITHUANIAN = "lt";
|
||||
public static final String MACEDONIAN = "mk";
|
||||
public static final String DUTCH = "nl";
|
||||
public static final String POLISH = "pl";
|
||||
public static final String PORTUGUESE = "pt";
|
||||
public static final String ROMANIAN ="ro";
|
||||
public static final String RUSSIAN = "ru";
|
||||
public static final String SWEDISH = "se";
|
||||
public static final String SLOVAK = "sk";
|
||||
public static final String SLOVENIAN = "sl";
|
||||
public static final String SPANISH = "en";
|
||||
public static final String TURKISH = "tr";
|
||||
public static final String UKRANIAN = "uk";
|
||||
public static final String VIETNAMESE = "vi";
|
||||
public static final String CHINESE_SIMPLIFIED = "zh_cn";
|
||||
public static final String CHINESE_TRADITIONAL = "zh_tw";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.context;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectReader;
|
||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
||||
import com.github.prominence.openweathermap.api.core.net.HttpClient;
|
||||
import com.github.prominence.openweathermap.api.core.net.HttpURLConnectionBasedHttpClient;
|
||||
import com.github.prominence.openweathermap.api.enums.ApiVariant;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class ApiConfiguration {
|
||||
@NonNull
|
||||
private final String apiKey;
|
||||
@NonNull
|
||||
private final Map<ApiVariant, String> baseUrls;
|
||||
@NonNull
|
||||
private final HttpClient httpClient;
|
||||
@NonNull
|
||||
private final TimeoutSettings defaultTimeoutSettings;
|
||||
private final ObjectReader objectReader;
|
||||
private final ObjectWriter objectWriter;
|
||||
|
||||
private ApiConfiguration(String apiKey, Map<ApiVariant, String> baseUrls, HttpClient httpClient,
|
||||
ObjectMapper objectMapper, TimeoutSettings defaultTimeoutSettings) {
|
||||
this.apiKey = apiKey;
|
||||
this.baseUrls = Collections.unmodifiableMap(baseUrls);
|
||||
this.httpClient = httpClient;
|
||||
this.defaultTimeoutSettings = defaultTimeoutSettings;
|
||||
this.objectReader = objectMapper.reader();
|
||||
this.objectWriter = objectMapper.writer();
|
||||
}
|
||||
|
||||
public static ApiConfigurationBuilder builder() {
|
||||
return new ApiConfigurationBuilder();
|
||||
}
|
||||
|
||||
public static class ApiConfigurationBuilder {
|
||||
private String apiKey;
|
||||
private Map<ApiVariant, String> baseUrls;
|
||||
private HttpClient httpClient = new HttpURLConnectionBasedHttpClient();
|
||||
private TimeoutSettings defaultTimeoutSettings = new TimeoutSettings();
|
||||
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
public ApiConfigurationBuilder() {
|
||||
baseUrls = Arrays.stream(ApiVariant.values())
|
||||
.collect(Collectors.toMap(Function.identity(), ApiVariant::getBaseUrl));
|
||||
}
|
||||
|
||||
public ApiConfigurationBuilder apiKey(@NonNull String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiConfigurationBuilder baseUrls(@NonNull Map<ApiVariant, String> baseUrls) {
|
||||
final List<ApiVariant> variants = Arrays.stream(ApiVariant.values()).collect(Collectors.toList());
|
||||
if (!baseUrls.keySet().containsAll(variants)) {
|
||||
throw new IllegalArgumentException("Not all API variants were found: " + baseUrls.keySet() + " , expected: " + variants);
|
||||
}
|
||||
this.baseUrls = new HashMap<>(baseUrls);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiConfigurationBuilder httpClient(@NonNull HttpClient httpClient) {
|
||||
this.httpClient = httpClient;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiConfigurationBuilder objectMapper(@NonNull ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiConfigurationBuilder defaultTimeoutSettings(@NonNull TimeoutSettings defaultTimeoutSettings) {
|
||||
this.defaultTimeoutSettings = new TimeoutSettings(defaultTimeoutSettings);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiConfiguration build() {
|
||||
return new ApiConfiguration(apiKey, baseUrls, httpClient, objectMapper, defaultTimeoutSettings);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ApiConfiguration.ApiConfigurationBuilder(apiKey=" + this.apiKey + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.context;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
public class ApiConfigurationHolder {
|
||||
|
||||
private static ApiConfiguration configuration = ApiConfiguration.builder()
|
||||
.apiKey(System.getenv("OPENWEATHER_API_KEY"))
|
||||
.build();
|
||||
public static ApiConfiguration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public static void setConfiguration(@NonNull ApiConfiguration configuration) {
|
||||
ApiConfigurationHolder.configuration = configuration;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.core.net;
|
||||
|
||||
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
||||
|
||||
public interface HttpClient {
|
||||
void setTimeoutSettings(TimeoutSettings timeoutSettings);
|
||||
|
||||
String executeGetRequest(String url);
|
||||
String executePostRequest(String url, String body);
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.core.net;
|
||||
|
||||
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
||||
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class HttpURLConnectionBasedHttpClient implements HttpClient {
|
||||
private static final Logger logger = LoggerFactory.getLogger(HttpURLConnectionBasedHttpClient.class);
|
||||
|
||||
private TimeoutSettings timeoutSettings;
|
||||
|
||||
@Override
|
||||
public void setTimeoutSettings(TimeoutSettings timeoutSettings) {
|
||||
this.timeoutSettings = timeoutSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String executeGetRequest(String url) {
|
||||
return doExecute(url, RequestExecutor.Method.GET, null);
|
||||
}
|
||||
|
||||
private String doExecute(String url, RequestExecutor.Method method, String body) {
|
||||
InputStream resultStream = null;
|
||||
try {
|
||||
HttpURLConnection connection = getConnection(url);
|
||||
configureTimeouts(connection);
|
||||
configureConnection(connection, method, body);
|
||||
|
||||
resultStream = evaluateResponse(connection);
|
||||
logger.debug("Executing OpenWeatherMap API request: " + url);
|
||||
return convertInputStreamToString(resultStream);
|
||||
} catch (IllegalStateException | IOException ex) {
|
||||
logger.error("An error occurred during OpenWeatherMap API response parsing: ", ex);
|
||||
throw new NoDataFoundException(ex);
|
||||
} finally {
|
||||
closeQuietly(resultStream);
|
||||
}
|
||||
}
|
||||
|
||||
HttpURLConnection getConnection(String url) throws IOException {
|
||||
return (HttpURLConnection) new URL(url).openConnection();
|
||||
}
|
||||
|
||||
private void closeQuietly(InputStream resultStream) {
|
||||
if (resultStream != null) {
|
||||
try {
|
||||
resultStream.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private InputStream evaluateResponse(HttpURLConnection connection) throws IOException {
|
||||
final int responseCode = connection.getResponseCode();
|
||||
switch (responseCode) {
|
||||
case HttpURLConnection.HTTP_OK:
|
||||
return connection.getInputStream();
|
||||
case HttpURLConnection.HTTP_UNAUTHORIZED:
|
||||
throw new InvalidAuthTokenException();
|
||||
case HttpURLConnection.HTTP_NOT_FOUND:
|
||||
case HttpURLConnection.HTTP_BAD_REQUEST:
|
||||
throw new NoDataFoundException();
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + responseCode);
|
||||
}
|
||||
}
|
||||
|
||||
private void configureTimeouts(HttpURLConnection connection) {
|
||||
Optional.ofNullable(timeoutSettings)
|
||||
.ifPresent(ts -> {
|
||||
Optional.ofNullable(ts.getConnectionTimeout())
|
||||
.ifPresent(connection::setConnectTimeout);
|
||||
Optional.ofNullable(ts.getReadTimeout())
|
||||
.ifPresent(connection::setReadTimeout);
|
||||
});
|
||||
}
|
||||
|
||||
private void configureConnection(HttpURLConnection connection, RequestExecutor.Method method, String body) throws IOException {
|
||||
connection.setRequestMethod(method.name());
|
||||
connection.setRequestProperty("Content-Type", "application/json; utf-8");
|
||||
connection.setRequestProperty("Accept", "application/json");
|
||||
addOptionalBodyContent(connection, body);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String executePostRequest(String url, String body) {
|
||||
return doExecute(url, RequestExecutor.Method.POST, body);
|
||||
}
|
||||
|
||||
private void addOptionalBodyContent(HttpURLConnection connection, String body) throws IOException {
|
||||
if (body != null) {
|
||||
connection.setDoOutput(true);
|
||||
try (OutputStream os = connection.getOutputStream()) {
|
||||
byte[] input = body.getBytes(StandardCharsets.UTF_8);
|
||||
os.write(input, 0, input.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the input stream line-by-line and returns its content in <code>String</code> representation.
|
||||
*
|
||||
* @param inputStream input stream to convert.
|
||||
* @return converted <code>InputStream</code> content.
|
||||
* @throws IllegalArgumentException in case if input stream is unable to be read.
|
||||
*/
|
||||
private String convertInputStreamToString(InputStream inputStream) {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
|
||||
return reader.lines().collect(Collectors.joining(System.lineSeparator()));
|
||||
} catch (IOException ex) {
|
||||
logger.error("Error during response reading: ", ex);
|
||||
throw new IllegalArgumentException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.core.net;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
import com.github.prominence.openweathermap.api.enums.ApiVariant;
|
||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class RequestExecutor {
|
||||
|
||||
private final RequestSettings requestSettings;
|
||||
|
||||
public RequestExecutor(RequestSettings requestSettings) {
|
||||
this.requestSettings = requestSettings;
|
||||
}
|
||||
|
||||
public String getResponse(ApiVariant variant) {
|
||||
return getResponse(variant, Method.GET);
|
||||
}
|
||||
|
||||
public String getResponse(ApiVariant variant, Method httpMethod) {
|
||||
return getResponse(selectRequestUrl(variant), httpMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes call to provided API url and retrieves response in <code>String</code> representation.
|
||||
*
|
||||
* @param url the url to make API request.
|
||||
* @param httpMethod HTTP method to execute.
|
||||
* @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.
|
||||
*/
|
||||
private String getResponse(String url, Method httpMethod) {
|
||||
final HttpClient httpClient = requestSettings.getApiConfiguration().getHttpClient();
|
||||
httpClient.setTimeoutSettings(requestSettings.getTimeoutSettings());
|
||||
|
||||
if (httpMethod == Method.GET) {
|
||||
return httpClient.executeGetRequest(url);
|
||||
} else {
|
||||
return httpClient.executePostRequest(url, getSerializedPayload());
|
||||
}
|
||||
}
|
||||
|
||||
private String selectRequestUrl(ApiVariant variant) {
|
||||
StringBuilder requestUrlBuilder = new StringBuilder(requestSettings.getApiConfiguration().getBaseUrls().get(variant));
|
||||
requestUrlBuilder.append(requestSettings.getUrlAppender());
|
||||
requestUrlBuilder.append('?');
|
||||
String parameters = requestSettings.getRequestParameters().entrySet().stream()
|
||||
.map(entry -> entry.getKey() + "=" + entry.getValue())
|
||||
.collect(Collectors.joining("&"));
|
||||
requestUrlBuilder.append(parameters);
|
||||
return requestUrlBuilder.toString();
|
||||
}
|
||||
|
||||
private String getSerializedPayload() {
|
||||
final ObjectWriter objectWriter = requestSettings.getApiConfiguration().getObjectWriter();
|
||||
try {
|
||||
return objectWriter.writeValueAsString(requestSettings.getPayloadObject());
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Method {
|
||||
GET,
|
||||
POST
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.air.pollution.Concentration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ConcentrationDeserializer extends JsonDeserializer<Concentration> {
|
||||
|
||||
@Override
|
||||
public Concentration deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(BigDecimal.class))
|
||||
.map(Concentration::new)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Optional;
|
||||
|
||||
public class EpochSecondsDeserializer extends JsonDeserializer<OffsetDateTime> {
|
||||
|
||||
@Override
|
||||
public OffsetDateTime deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(Long.class))
|
||||
.map(Instant::ofEpochSecond)
|
||||
.map((Instant instant) -> OffsetDateTime.ofInstant(instant, ZoneOffset.UTC))
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PercentageZeroToOneDeserializer extends JsonDeserializer<Integer> {
|
||||
@Override
|
||||
public Integer deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(BigDecimal.class))
|
||||
.map(v -> v.multiply(BigDecimal.valueOf(100)))
|
||||
.map(v -> v.setScale(0, RoundingMode.HALF_EVEN))
|
||||
.map(BigDecimal::intValue)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationIntensity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PrecipitationIntensityDeserializer extends JsonDeserializer<PrecipitationIntensity> {
|
||||
|
||||
@Override
|
||||
public PrecipitationIntensity deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(BigDecimal.class))
|
||||
.map(PrecipitationIntensity::new)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class RequiredPercentageDeserializer extends JsonDeserializer<Integer> {
|
||||
@Override
|
||||
public Integer deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(Integer.class))
|
||||
.filter(v -> v <= 100)
|
||||
.filter(v -> v >= 0)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Invalid data found for percentage"));
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureValue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TemperatureValueDeserializer extends JsonDeserializer<TemperatureValue> {
|
||||
|
||||
@Override
|
||||
public TemperatureValue deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(BigDecimal.class))
|
||||
.map(TemperatureValue::new)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.generic.visibility.Visibility;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
public class VisibilityDeserializer extends JsonDeserializer<Visibility> {
|
||||
|
||||
@Override
|
||||
public Visibility deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(BigDecimal.class))
|
||||
.map(Visibility::new)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.WindSpeed;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
public class WindSpeedDeserializer extends JsonDeserializer<WindSpeed> {
|
||||
|
||||
@Override
|
||||
public WindSpeed deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(BigDecimal.class))
|
||||
.map(WindSpeed::new)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ZoneIdDeserializer extends JsonDeserializer<ZoneId> {
|
||||
|
||||
@Override
|
||||
public ZoneId deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(String.class))
|
||||
.map(ZoneId::of)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
+13
-21
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
@@ -20,30 +20,22 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.utils;
|
||||
package com.github.prominence.openweathermap.api.deserializer;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class JsonUtils {
|
||||
public class ZoneOffsetDeserializer extends JsonDeserializer<ZoneOffset> {
|
||||
|
||||
private JsonUtils() {}
|
||||
|
||||
public static Object parseJson(InputStream inputStream, Class clazz) throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
|
||||
reader.close();
|
||||
|
||||
return JSON.parseObject(result.toString(), clazz);
|
||||
@Override
|
||||
public ZoneOffset deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(Integer.class))
|
||||
.map(ZoneOffset::ofTotalSeconds)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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 com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@JsonCreator
|
||||
public static AirQualityIndex getByIndex(@JsonProperty("aqi") int index) {
|
||||
return Arrays.stream(values())
|
||||
.filter(airQualityIndex -> airQualityIndex.getValue() == index)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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 ApiVariant {
|
||||
|
||||
BASE("https://api.openweathermap.org/"),
|
||||
PRO("https://pro.openweathermap.org/");
|
||||
|
||||
private final String baseUrl;
|
||||
|
||||
ApiVariant(String baseUrl) {
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
public String getBaseUrl() {
|
||||
return baseUrl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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 com.fasterxml.jackson.annotation.JsonCreator;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Enumeration for time of a day representation.
|
||||
*/
|
||||
public enum DayTime {
|
||||
/**
|
||||
* Day value.
|
||||
*/
|
||||
DAY("d"),
|
||||
|
||||
/**
|
||||
* Night value.
|
||||
*/
|
||||
NIGHT("n");
|
||||
|
||||
private final String value;
|
||||
|
||||
DayTime(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns time of a day value.
|
||||
*
|
||||
* @return string value
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the appropriate day time based on the short form value.
|
||||
*
|
||||
* @param value the short form value (d/n).
|
||||
* @return day time
|
||||
*/
|
||||
@JsonCreator
|
||||
public static DayTime findByValue(String value) {
|
||||
return Arrays.stream(values())
|
||||
.filter(dayTime -> dayTime.getValue().equals(value))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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 com.fasterxml.jackson.annotation.JsonCreator;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public enum EventLevel {
|
||||
/**
|
||||
* Unknown event severity.
|
||||
*/
|
||||
UNKNOWN(0),
|
||||
/**
|
||||
* Green alert.
|
||||
*/
|
||||
GREEN(1),
|
||||
/**
|
||||
* Yellow alert.
|
||||
*/
|
||||
YELLOW(2),
|
||||
/**
|
||||
* Orange alert.
|
||||
*/
|
||||
ORANGE(3),
|
||||
/**
|
||||
* Red alert.
|
||||
*/
|
||||
RED(4);
|
||||
|
||||
private final int value;
|
||||
|
||||
EventLevel(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the appropriate event level based on the numerical level.
|
||||
*
|
||||
* @param value the numerical level.
|
||||
* @return event level
|
||||
*/
|
||||
@JsonCreator
|
||||
public static EventLevel findByValue(int value) {
|
||||
return Arrays.stream(values())
|
||||
.filter(eventLevel -> eventLevel.getValue() == value)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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;
|
||||
|
||||
/**
|
||||
* An enumeration which lists all available languages for API usage.
|
||||
* Usually it could be specified to get response with some fields translated into desired language.
|
||||
*/
|
||||
public enum Language {
|
||||
/**
|
||||
* Afrikaans language.
|
||||
*/
|
||||
AFRIKAANS("af"),
|
||||
|
||||
/**
|
||||
* Albanian language.
|
||||
*/
|
||||
ALBANIAN("al"),
|
||||
|
||||
/**
|
||||
* Arabic language.
|
||||
*/
|
||||
ARABIC("ar"),
|
||||
|
||||
/**
|
||||
* Azerbaijani language.
|
||||
*/
|
||||
AZERBAIJANI("az"),
|
||||
|
||||
/**
|
||||
* Bulgarian language.
|
||||
*/
|
||||
BULGARIAN("bg"),
|
||||
|
||||
/**
|
||||
* Catalan language.
|
||||
*/
|
||||
CATALAN("ca"),
|
||||
|
||||
/**
|
||||
* Czech language.
|
||||
*/
|
||||
CZECH("cz"),
|
||||
|
||||
/**
|
||||
* Danish language
|
||||
*/
|
||||
DANISH("da"),
|
||||
|
||||
/**
|
||||
* German language.
|
||||
*/
|
||||
GERMAN("de"),
|
||||
|
||||
/**
|
||||
* Greek language.
|
||||
*/
|
||||
GREEK("el"),
|
||||
|
||||
/**
|
||||
* English language.
|
||||
*/
|
||||
ENGLISH("en"),
|
||||
|
||||
/**
|
||||
* Basque language.
|
||||
*/
|
||||
BASQUE("eu"),
|
||||
|
||||
/**
|
||||
* Persian language.
|
||||
*/
|
||||
PERSIAN("fa"),
|
||||
|
||||
/**
|
||||
* Finnish language.
|
||||
*/
|
||||
FINNISH("fi"),
|
||||
|
||||
/**
|
||||
* French language.
|
||||
*/
|
||||
FRENCH("fr"),
|
||||
|
||||
/**
|
||||
* Galician language.
|
||||
*/
|
||||
GALICIAN("gl"),
|
||||
|
||||
/**
|
||||
* Hebrew language.
|
||||
*/
|
||||
HEBREW("he"),
|
||||
|
||||
/**
|
||||
* Hindi language.
|
||||
*/
|
||||
HINDI("hi"),
|
||||
|
||||
/**
|
||||
* Croatian language.
|
||||
*/
|
||||
CROATIAN("hr"),
|
||||
|
||||
/**
|
||||
* Hungarian language.
|
||||
*/
|
||||
HUNGARIAN("hu"),
|
||||
|
||||
/**
|
||||
* Indonesian language.
|
||||
*/
|
||||
INDONESIAN("id"),
|
||||
|
||||
/**
|
||||
* Italian language.
|
||||
*/
|
||||
ITALIAN("it"),
|
||||
|
||||
/**
|
||||
* Japanese language.
|
||||
*/
|
||||
JAPANESE("ja"),
|
||||
|
||||
/**
|
||||
* Korean language.
|
||||
*/
|
||||
KOREAN("kr"),
|
||||
|
||||
/**
|
||||
* Latvian language.
|
||||
*/
|
||||
LATVIAN("la"),
|
||||
|
||||
/**
|
||||
* Lithuanian language.
|
||||
*/
|
||||
LITHUANIAN("lt"),
|
||||
|
||||
/**
|
||||
* Macedonian language.
|
||||
*/
|
||||
MACEDONIAN("mk"),
|
||||
|
||||
/**
|
||||
* Norwegian language.
|
||||
*/
|
||||
NORWEGIAN("no"),
|
||||
|
||||
/**
|
||||
* Dutch language.
|
||||
*/
|
||||
DUTCH("nl"),
|
||||
|
||||
/**
|
||||
* Polish language.
|
||||
*/
|
||||
POLISH("pl"),
|
||||
|
||||
/**
|
||||
* Portuguese language.
|
||||
*/
|
||||
PORTUGUESE("pt"),
|
||||
|
||||
/**
|
||||
* Português Brasil language.
|
||||
*/
|
||||
PORTUGUES_BRAZIL("pt_br"),
|
||||
|
||||
/**
|
||||
* Romanian language.
|
||||
*/
|
||||
ROMANIAN ("ro"),
|
||||
|
||||
/**
|
||||
* Russian language.
|
||||
*/
|
||||
RUSSIAN("ru"),
|
||||
|
||||
/**
|
||||
* Swedish language.
|
||||
*/
|
||||
SWEDISH("se"),
|
||||
|
||||
/**
|
||||
* Slovak language.
|
||||
*/
|
||||
SLOVAK("sk"),
|
||||
|
||||
/**
|
||||
* Slovenian language.
|
||||
*/
|
||||
SLOVENIAN("sl"),
|
||||
|
||||
/**
|
||||
* Spanish language.
|
||||
*/
|
||||
SPANISH("es"),
|
||||
|
||||
/**
|
||||
* Serbian language.
|
||||
*/
|
||||
SERBIAN("sr"),
|
||||
|
||||
/**
|
||||
* Thai language.
|
||||
*/
|
||||
THAI("th"),
|
||||
|
||||
/**
|
||||
* Turkish language.
|
||||
*/
|
||||
TURKISH("tr"),
|
||||
|
||||
/**
|
||||
* Ukrainian language.
|
||||
*/
|
||||
UKRAINIAN("uk"),
|
||||
|
||||
/**
|
||||
* Vietnamese language.
|
||||
*/
|
||||
VIETNAMESE("vi"),
|
||||
|
||||
/**
|
||||
* Chinese simplified language.
|
||||
*/
|
||||
CHINESE_SIMPLIFIED("zh_cn"),
|
||||
|
||||
/**
|
||||
* Chinese traditional language.
|
||||
*/
|
||||
CHINESE_TRADITIONAL("zh_tw"),
|
||||
|
||||
/**
|
||||
* Zulu language.
|
||||
*/
|
||||
ZULU("zu");
|
||||
|
||||
private final String value;
|
||||
|
||||
Language(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns language's value.
|
||||
* @return value.
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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;
|
||||
} else {
|
||||
return INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean equals(double d1, double d2) {
|
||||
return Math.abs(d1 - d2) < precision;
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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;
|
||||
|
||||
/**
|
||||
* The enum One call result options.
|
||||
*/
|
||||
public enum OneCallResultOptions {
|
||||
/**
|
||||
* Current one call result options.
|
||||
*/
|
||||
CURRENT("current"),
|
||||
/**
|
||||
* Minutely one call result options.
|
||||
*/
|
||||
MINUTELY("minutely"),
|
||||
/**
|
||||
* Hourly one call result options.
|
||||
*/
|
||||
HOURLY("hourly"),
|
||||
/**
|
||||
* Daily one call result options.
|
||||
*/
|
||||
DAILY("daily"),
|
||||
/**
|
||||
* Alerts one call result options.
|
||||
*/
|
||||
ALERTS("alerts");
|
||||
|
||||
private final String value;
|
||||
|
||||
OneCallResultOptions(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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 ResponseType {
|
||||
JSON("json"),
|
||||
HTML("html"),
|
||||
XML("xml");
|
||||
|
||||
private final String value;
|
||||
|
||||
ResponseType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns language's value.
|
||||
* @return value.
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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 com.fasterxml.jackson.annotation.JsonCreator;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public enum RoadState {
|
||||
NO_REPORT(0),
|
||||
DRY(1),
|
||||
MOIST(2),
|
||||
MOIST_AND_CHEMICALLY_TREATED(3),
|
||||
WET(4),
|
||||
WET_AND_CHEMICALLY_TREATED(5),
|
||||
ICE(6),
|
||||
FROST(7),
|
||||
SNOW(8),
|
||||
SNOW_OR_ICE_WATCH(9),
|
||||
SNOW_OR_ICE_WARNING(10),
|
||||
WET_ABOVE_FREEZING(11),
|
||||
WET_BELOW_FREEZING(12),
|
||||
ABSORPTION(13),
|
||||
ABSORPTION_AT_DEWPOINT(14),
|
||||
DEW(15),
|
||||
BLACK_ICE_WARNING(16),
|
||||
OTHER(17),
|
||||
SLUSH(18);
|
||||
|
||||
private final int value;
|
||||
|
||||
RoadState(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the appropriate road state based on the numerical code.
|
||||
*
|
||||
* @param value the numerical code.
|
||||
* @return road state
|
||||
*/
|
||||
@JsonCreator
|
||||
public static RoadState findByValue(int value) {
|
||||
return Arrays.stream(values()).filter(roadState -> roadState.getValue() == value).findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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;
|
||||
|
||||
/**
|
||||
* An enumeration with all available subscription plans.
|
||||
* More information <a href="https://openweathermap.org/price">at official website</a>.
|
||||
*/
|
||||
public enum SubscriptionPlan {
|
||||
/**
|
||||
* An alias that represents any of paid plans: startup, developer, professional or enterprise.
|
||||
*/
|
||||
PAID,
|
||||
|
||||
/**
|
||||
* Startup subscription plan.
|
||||
*/
|
||||
STARTUP,
|
||||
|
||||
/**
|
||||
* Developer subscription plan.
|
||||
*/
|
||||
DEVELOPER,
|
||||
|
||||
/**
|
||||
* Professional subscription plan.
|
||||
*/
|
||||
PROFESSIONAL,
|
||||
|
||||
/**
|
||||
* Enterprise subscription plan.
|
||||
*/
|
||||
ENTERPRISE,
|
||||
|
||||
/**
|
||||
* Special subscription plan. You should contact a manager to get an access.
|
||||
*/
|
||||
SPECIAL,
|
||||
|
||||
|
||||
/**
|
||||
* All existing subscription plans.
|
||||
*/
|
||||
ALL,
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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;
|
||||
|
||||
/**
|
||||
* An enumeration for supported unit systems with helper methods.
|
||||
*/
|
||||
public enum UnitSystem {
|
||||
/**
|
||||
* Metric units: Celsius, meter/sec, hPa, mm(rain, snow).
|
||||
*/
|
||||
METRIC("metric"),
|
||||
|
||||
/**
|
||||
* Imperial units: Fahrenheit, miles/hour, hPa, mm(rain, snow).
|
||||
*/
|
||||
IMPERIAL("imperial"),
|
||||
|
||||
/**
|
||||
* OpenWeatherMap standard units: Kelvin, meter/sec, hPa, mm(rain, snow).
|
||||
*/
|
||||
STANDARD("standard");
|
||||
|
||||
private final String value;
|
||||
|
||||
UnitSystem(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns unit system value.
|
||||
* @return value unit system.
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,398 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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 com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents weather condition and related information.
|
||||
* More details <a href="https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2">here</a>.
|
||||
*/
|
||||
public enum WeatherCondition {
|
||||
// Group 2xx: Thunderstorm
|
||||
|
||||
/**
|
||||
* The thunderstorm with light rain.
|
||||
*/
|
||||
THUNDERSTORM_LIGHT_RAIN(200, "Thunderstorm", "thunderstorm with light rain", "11"),
|
||||
/**
|
||||
* The thunderstorm with rain.
|
||||
*/
|
||||
THUNDERSTORM_RAIN(201, "Thunderstorm", "thunderstorm with rain", "11"),
|
||||
/**
|
||||
* The thunderstorm with heavy rain.
|
||||
*/
|
||||
THUNDERSTORM_HEAVY_RAIN(202, "Thunderstorm", "thunderstorm with heavy rain", "11"),
|
||||
/**
|
||||
* The light thunderstorm.
|
||||
*/
|
||||
THUNDERSTORM_LIGHT(210, "Thunderstorm", "light thunderstorm", "11"),
|
||||
/**
|
||||
* The thunderstorm.
|
||||
*/
|
||||
THUNDERSTORM(211, "Thunderstorm", "thunderstorm", "11"),
|
||||
/**
|
||||
* The heavy thunderstorm.
|
||||
*/
|
||||
THUNDERSTORM_HEAVY(212, "Thunderstorm", "heavy thunderstorm", "11"),
|
||||
/**
|
||||
* The ragged thunderstorm.
|
||||
*/
|
||||
THUNDERSTORM_RAGGED(221, "Thunderstorm", "ragged thunderstorm", "11"),
|
||||
/**
|
||||
* The thunderstorm with light drizzle.
|
||||
*/
|
||||
THUNDERSTORM_LIGHT_DRIZZLE(230, "Thunderstorm", "thunderstorm with light drizzle", "11"),
|
||||
/**
|
||||
* The thunderstorm with drizzle.
|
||||
*/
|
||||
THUNDERSTORM_DRIZZLE(231, "Thunderstorm", "thunderstorm with drizzle", "11"),
|
||||
/**
|
||||
* The thunderstorm with heavy drizzle.
|
||||
*/
|
||||
THUNDERSTORM_HEAVY_DRIZZLE(232, "Thunderstorm", "thunderstorm with heavy drizzle", "11"),
|
||||
|
||||
// Group 3xx: Drizzle
|
||||
|
||||
/**
|
||||
* The light intensity drizzle.
|
||||
*/
|
||||
DRIZZLE_LIGHT(300, "Drizzle", "light intensity drizzle", "09"),
|
||||
/**
|
||||
* The drizzle.
|
||||
*/
|
||||
DRIZZLE(301, "Drizzle", "drizzle", "09"),
|
||||
/**
|
||||
* The heavy intensity drizzle.
|
||||
*/
|
||||
DRIZZLE_HEAVY(302, "Drizzle", "heavy intensity drizzle", "09"),
|
||||
/**
|
||||
* The light intensity drizzle rain.
|
||||
*/
|
||||
DRIZZLE_LIGHT_RAIN(310, "Drizzle", "light intensity drizzle rain", "09"),
|
||||
/**
|
||||
* The drizzle rain.
|
||||
*/
|
||||
DRIZZLE_RAIN(311, "Drizzle", "drizzle rain", "09"),
|
||||
/**
|
||||
* The heavy intensity drizzle rain.
|
||||
*/
|
||||
DRIZZLE_HEAVY_RAIN(312, "Drizzle", "heavy intensity drizzle rain", "09"),
|
||||
/**
|
||||
* The shower rain and drizzle.
|
||||
*/
|
||||
DRIZZLE_SHOWER_RAIN(313, "Drizzle", "shower rain and drizzle", "09"),
|
||||
/**
|
||||
* The heavy shower rain and drizzle.
|
||||
*/
|
||||
DRIZZLE_HEAVY_SHOWER_RAIN(314, "Drizzle", "heavy shower rain and drizzle", "09"),
|
||||
/**
|
||||
* The shower drizzle.
|
||||
*/
|
||||
DRIZZLE_SHOWER(321, "Drizzle", "shower drizzle", "09"),
|
||||
|
||||
// Group 5xx: Rain
|
||||
|
||||
/**
|
||||
* The light rain.
|
||||
*/
|
||||
RAIN_LIGHT(500, "Rain", "light rain", "10"),
|
||||
/**
|
||||
* The moderate rain.
|
||||
*/
|
||||
RAIN_MODERATE(501, "Rain", "moderate rain", "10"),
|
||||
/**
|
||||
* The heavy intensity rain.
|
||||
*/
|
||||
RAIN_HEAVY(502, "Rain", "heavy intensity rain", "10"),
|
||||
/**
|
||||
* The very heavy rain.
|
||||
*/
|
||||
RAIN_VERY_HEAVY(503, "Rain", "very heavy rain", "10"),
|
||||
/**
|
||||
* The very heavy rain.
|
||||
*/
|
||||
RAIN_EXTREME(504, "Rain", "very heavy rain", "10"),
|
||||
/**
|
||||
* The freezing rain.
|
||||
*/
|
||||
RAIN_FREEZING(511, "Rain", "freezing rain", "10"),
|
||||
/**
|
||||
* The light intensity shower rain.
|
||||
*/
|
||||
RAIN_LIGHT_SHOWER(520, "Rain", "light intensity shower rain", "10"),
|
||||
/**
|
||||
* The shower rain.
|
||||
*/
|
||||
RAIN_SHOWER(521, "Rain", "shower rain", "10"),
|
||||
/**
|
||||
* The heavy intensity shower rain.
|
||||
*/
|
||||
RAIN_HEAVY_SHOWER(522, "Rain", "heavy intensity shower rain", "10"),
|
||||
/**
|
||||
* The ragged shower rain.
|
||||
*/
|
||||
RAIN_RAGGED_SHOWER(531, "Rain", "ragged shower rain", "10"),
|
||||
|
||||
// Group 6xx: Snow
|
||||
|
||||
/**
|
||||
* The light snow.
|
||||
*/
|
||||
SNOW_LIGHT(600, "Snow", "light snow", "13"),
|
||||
/**
|
||||
* The snow.
|
||||
*/
|
||||
SNOW(601, "Snow", "snow", "13"),
|
||||
/**
|
||||
* The heavy snow.
|
||||
*/
|
||||
SNOW_HEAVY(602, "Snow", "heavy snow", "13"),
|
||||
/**
|
||||
* The sleet.
|
||||
*/
|
||||
SNOW_SLEET(611, "Snow", "sleet", "13"),
|
||||
/**
|
||||
* The light shower sleet.
|
||||
*/
|
||||
SNOW_LIGHT_SHOWER_SLEET(612, "Snow", "light shower sleet", "13"),
|
||||
/**
|
||||
* The shower sleet.
|
||||
*/
|
||||
SNOW_SHOWER_SLEET(613, "Snow", "shower sleet", "13"),
|
||||
/**
|
||||
* The light rain and snow.
|
||||
*/
|
||||
SNOW_LIGHT_RAIN_AND_SNOW(615, "Snow", "light rain and snow", "13"),
|
||||
/**
|
||||
* The rain and snow.
|
||||
*/
|
||||
SNOW_RAIN_AND_SNOW(616, "Snow", "rain and snow", "13"),
|
||||
/**
|
||||
* The light shower snow.
|
||||
*/
|
||||
SNOW_LIGHT_SHOWER_SNOW(620, "Snow", "light shower snow", "13"),
|
||||
/**
|
||||
* The shower snow.
|
||||
*/
|
||||
SNOW_SHOWER_SNOW(621, "Snow", "shower snow", "13"),
|
||||
/**
|
||||
* The heavy shower snow.
|
||||
*/
|
||||
SNOW_HEAVY_SHOWER_SNOW(622, "Snow", "heavy shower snow", "13"),
|
||||
|
||||
// Group 7xx: Atmosphere
|
||||
|
||||
/**
|
||||
* The mist.
|
||||
*/
|
||||
MIST(701, "Mist", "mist", "50"),
|
||||
/**
|
||||
* The smoke.
|
||||
*/
|
||||
SMOKE(711, "Smoke", "smoke", "50"),
|
||||
/**
|
||||
* The haze.
|
||||
*/
|
||||
HAZE(721, "Haze", "haze", "50"),
|
||||
/**
|
||||
* The sand/dust whirls.
|
||||
*/
|
||||
DUST_WHIRLS(731, "Dust", "sand/dust whirls", "50"),
|
||||
/**
|
||||
* The fog.
|
||||
*/
|
||||
FOG(741, "Fog", "fog", "50"),
|
||||
/**
|
||||
* The sand.
|
||||
*/
|
||||
SAND(751, "Sand", "sand", "50"),
|
||||
/**
|
||||
* The dust.
|
||||
*/
|
||||
DUST(761, "Dust", "dust", "50"),
|
||||
/**
|
||||
* The volcanic ash.
|
||||
*/
|
||||
ASH(762, "Ash", "volcanic ash", "50"),
|
||||
/**
|
||||
* The squall.
|
||||
*/
|
||||
SQUALL(771, "Squall", "squalls", "50"),
|
||||
/**
|
||||
* The tornado.
|
||||
*/
|
||||
TORNADO(781, "Tornado", "tornado", "50"),
|
||||
|
||||
// Group 800: Clear
|
||||
|
||||
/**
|
||||
* The clear sky.
|
||||
*/
|
||||
CLEAR(800, "Clear", "clear sky", "01"),
|
||||
|
||||
// Group 80x: Clouds
|
||||
|
||||
/**
|
||||
* A few clouds: 11-25%.
|
||||
*/
|
||||
CLOUDS_FEW(801, "Clouds", "few clouds: 11-25%", "02"),
|
||||
/**
|
||||
* A scattered clouds: 25-50%.
|
||||
*/
|
||||
CLOUDS_SCATTERED(802, "Clouds", "scattered clouds: 25-50%", "03"),
|
||||
/**
|
||||
* A broken clouds: 51-84%.
|
||||
*/
|
||||
CLOUDS_BROKEN(803, "Clouds", "broken clouds: 51-84%", "04"),
|
||||
/**
|
||||
* An overcast clouds: 85-100%.
|
||||
*/
|
||||
CLOUDS_OVERCAST(804, "Clouds", "overcast clouds: 85-100%", "04");
|
||||
|
||||
|
||||
private final int id;
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final String iconId;
|
||||
|
||||
WeatherCondition(int id, String name, String description, String iconId) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.iconId = iconId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets description.
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets icon id based on part of day.
|
||||
*
|
||||
* @param partOfDay The part of day we need the icon for.
|
||||
* @return the icon id
|
||||
*/
|
||||
public String getIconId(DayTime partOfDay) {
|
||||
return iconId + partOfDay.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets day icon id.
|
||||
*
|
||||
* @return the day icon id
|
||||
*/
|
||||
public String getDayIconId() {
|
||||
return getIconId(DayTime.DAY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets night icon id.
|
||||
*
|
||||
* @return the night icon id
|
||||
*/
|
||||
public String getNightIconId() {
|
||||
return getIconId(DayTime.NIGHT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets day icon url.
|
||||
*
|
||||
* @param secure Determines whether we need to use secure channel (HTTPS) for loading the image.
|
||||
* @return the day icon url
|
||||
*/
|
||||
public String getDayIconUrl(boolean secure) {
|
||||
return getIconUrl(getDayIconId(), secure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets night icon url.
|
||||
*
|
||||
* @param secure Determines whether we need to use secure channel (HTTPS) for loading the image.
|
||||
* @return the night icon url
|
||||
*/
|
||||
public String getNightIconUrl(boolean secure) {
|
||||
return getIconUrl(getNightIconId(), secure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets icon url.
|
||||
*
|
||||
* @param iconId the icon id
|
||||
* @param secure Determines whether we need to use secure channel (HTTPS) for loading the image.
|
||||
* @return the icon url
|
||||
*/
|
||||
public static String getIconUrl(String iconId, boolean secure) {
|
||||
String scheme = "http";
|
||||
if (secure) {
|
||||
scheme = "https";
|
||||
}
|
||||
return scheme + "://openweathermap.org/img/w/" + iconId + ".png";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets {@link WeatherCondition} by id.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the by id
|
||||
*/
|
||||
@JsonCreator
|
||||
public static WeatherCondition getById(@JsonProperty("id") int id) {
|
||||
final Optional<WeatherCondition> optionalWeatherCondition =
|
||||
Arrays.stream(values()).filter(weatherCondition -> weatherCondition.getId() == id).findFirst();
|
||||
return optionalWeatherCondition.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Weather condition(" + id + "): " + name + '(' + description + ')';
|
||||
}
|
||||
}
|
||||
+4
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
@@ -22,10 +22,8 @@
|
||||
|
||||
package com.github.prominence.openweathermap.api.exception;
|
||||
|
||||
public class DataNotFoundException extends Exception {
|
||||
|
||||
public DataNotFoundException() {
|
||||
super("Data for provided parameters wasn't found. Please, check your request.");
|
||||
public class ApiPayloadParseException extends RuntimeException {
|
||||
public ApiPayloadParseException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
+11
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
@@ -22,10 +22,16 @@
|
||||
|
||||
package com.github.prominence.openweathermap.api.exception;
|
||||
|
||||
public class InvalidAuthTokenException extends Exception {
|
||||
|
||||
/**
|
||||
* An exception that could be thrown in case of your API key is invalid or your subscription plan does not cover requested functionality.
|
||||
* Subscription plans information you can find <a href="https://openweathermap.org/price">here</a>.
|
||||
* API Keys could be checked in <a href="https://home.openweathermap.org/api_keys/">your profile</a>.
|
||||
*/
|
||||
public class InvalidAuthTokenException extends RuntimeException {
|
||||
/**
|
||||
* Creates {@link InvalidAuthTokenException} exception with default message.
|
||||
*/
|
||||
public InvalidAuthTokenException() {
|
||||
super("Check you authentication token! You can get it here: https://home.openweathermap.org/api_keys/.");
|
||||
super("Authentication token wasn't set or requested functionality is not permitted for your subscription plan. Please, check https://home.openweathermap.org/api_keys/ and https://openweathermap.org/price.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.exception;
|
||||
|
||||
/**
|
||||
* An exception that could be thrown in several cases:
|
||||
* <ul>
|
||||
* <li>There is no data found for your query(wrong coordinates somewhere in the sea, some distant place, etc.);</li>
|
||||
* <li>Request is malformed. An occasion to report an <a href="https://github.com/Prominence/openweathermap-java-api/issues">issue</a>;</li>
|
||||
* <li>Any other unpredictable problems.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class NoDataFoundException extends RuntimeException {
|
||||
/**
|
||||
* Creates {@link NoDataFoundException} with default message.
|
||||
*/
|
||||
public NoDataFoundException() {
|
||||
super("Data for provided parameters wasn't found. Please, check requested location.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link NoDataFoundException} with message from another throwable.
|
||||
* @param throwable source throwable.
|
||||
*/
|
||||
public NoDataFoundException(Throwable throwable) {
|
||||
super(throwable.getMessage(), throwable.getCause());
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Coordinates {
|
||||
|
||||
@JSONField(name = "lat")
|
||||
// City geo location, latitude
|
||||
private float latitude;
|
||||
@JSONField(name = "lon")
|
||||
// City geo location, longitude
|
||||
private float longitude;
|
||||
|
||||
public Coordinates(float latitude, float longitude) {
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public float getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(float latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public float getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(float longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "latitude=" + latitude + ", longitude=" + longitude;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Coordinates that = (Coordinates) o;
|
||||
return Double.compare(that.latitude, latitude) == 0 &&
|
||||
Double.compare(that.longitude, longitude) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(latitude, longitude);
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Objects;
|
||||
|
||||
public class WeatherState {
|
||||
|
||||
@JSONField(name = "id")
|
||||
// Weather condition id
|
||||
long conditionId;
|
||||
|
||||
@JSONField(name = "main")
|
||||
// Group of weather parameters (Rain, Snow, Extreme etc.)
|
||||
String weatherGroup;
|
||||
|
||||
@JSONField(name = "description")
|
||||
// Weather condition within the group
|
||||
String description;
|
||||
|
||||
@JSONField(name = "icon")
|
||||
// Weather icon id
|
||||
String iconId;
|
||||
|
||||
public long getConditionId() {
|
||||
return conditionId;
|
||||
}
|
||||
|
||||
public void setConditionId(long conditionId) {
|
||||
this.conditionId = conditionId;
|
||||
}
|
||||
|
||||
public String getWeatherGroup() {
|
||||
return weatherGroup;
|
||||
}
|
||||
|
||||
public void setWeatherGroup(String weatherGroup) {
|
||||
this.weatherGroup = weatherGroup;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getIconId() {
|
||||
return iconId;
|
||||
}
|
||||
|
||||
public void setIconId(String iconId) {
|
||||
this.iconId = iconId;
|
||||
}
|
||||
|
||||
public URL getWeatherIconUrl() {
|
||||
URL iconUrl = null;
|
||||
try {
|
||||
iconUrl = new URL("http://openweathermap.org/img/w/" + iconId + ".png");
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return iconUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Weather: " + description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
WeatherState weatherState = (WeatherState) o;
|
||||
return conditionId == weatherState.conditionId &&
|
||||
Objects.equals(weatherGroup, weatherState.weatherGroup) &&
|
||||
Objects.equals(description, weatherState.description) &&
|
||||
Objects.equals(iconId, weatherState.iconId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(conditionId, weatherGroup, description, iconId);
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Wind {
|
||||
|
||||
@JSONField(name = "speed")
|
||||
// Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour.
|
||||
private float speed;
|
||||
|
||||
private String unit;
|
||||
|
||||
@JSONField(name = "deg")
|
||||
// Wind direction, degrees (meteorological)
|
||||
private short degrees;
|
||||
|
||||
public float getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public void setSpeed(float speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public void setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public short getDegrees() {
|
||||
return degrees;
|
||||
}
|
||||
|
||||
public void setDegrees(short degrees) {
|
||||
this.degrees = degrees;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Wind: " + speed + ' ' + unit + ", " + degrees + " degrees";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Wind wind = (Wind) o;
|
||||
return Float.compare(wind.speed, speed) == 0 &&
|
||||
degrees == wind.degrees;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(speed, degrees);
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.OffsetDateTime;
|
||||
|
||||
/**
|
||||
* Interface of air pollution concentration measurements.
|
||||
*/
|
||||
public interface AirPollutionConcentration {
|
||||
/**
|
||||
* The date time when the measurement happened.
|
||||
*
|
||||
* @return datetime
|
||||
*/
|
||||
OffsetDateTime getMeasurementTime();
|
||||
|
||||
/**
|
||||
* The air quality index as an (overview).
|
||||
*
|
||||
* @return index
|
||||
*/
|
||||
AirQualityIndex getAirQualityIndex();
|
||||
|
||||
/**
|
||||
* The concentration of CO in the air.
|
||||
*
|
||||
* @return CO
|
||||
*/
|
||||
Concentration getCarbonMonoxide();
|
||||
|
||||
/**
|
||||
* The concentration of NO in the air.
|
||||
*
|
||||
* @return NO
|
||||
*/
|
||||
Concentration getNitrogenMonoxide();
|
||||
|
||||
/**
|
||||
* The concentration of NO2 in the air.
|
||||
*
|
||||
* @return NO2
|
||||
*/
|
||||
Concentration getNitrogenDioxide();
|
||||
|
||||
/**
|
||||
* The concentration of O3 in the air.
|
||||
*
|
||||
* @return O3
|
||||
*/
|
||||
Concentration getOzone();
|
||||
|
||||
/**
|
||||
* The concentration of SO2 in the air.
|
||||
*
|
||||
* @return SO2
|
||||
*/
|
||||
Concentration getSulphurDioxide();
|
||||
|
||||
/**
|
||||
* The concentration of pine particles matter in the air.
|
||||
*
|
||||
* @return fine particles
|
||||
*/
|
||||
Concentration getFineParticlesMatter();
|
||||
|
||||
/**
|
||||
* The concentration of coarse particulate matter in the air.
|
||||
*
|
||||
* @return coarse particles
|
||||
*/
|
||||
Concentration getCoarseParticulateMatter();
|
||||
|
||||
/**
|
||||
* The concentration of NH3 in the air.
|
||||
*
|
||||
* @return NH3
|
||||
*/
|
||||
Concentration getAmmonia();
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic.location.CoordinateAware;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Interface of air pollution overview.
|
||||
*/
|
||||
public interface AirPollutionDetails extends CoordinateAware {
|
||||
|
||||
/**
|
||||
* The pollution details.
|
||||
* @return pollution
|
||||
*/
|
||||
List<AirPollutionConcentration> getAirPollutionConcentration();
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.Coordinates;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The type representing Air pollution data.
|
||||
*/
|
||||
@Data
|
||||
public class AirPollutionDetailsModel implements AirPollutionDetails {
|
||||
@JsonProperty("coord")
|
||||
private Coordinates coordinates;
|
||||
@JsonProperty("list")
|
||||
private List<AirPollutionRecord> airPollutionRecords;
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public List<AirPollutionConcentration> getAirPollutionConcentration() {
|
||||
return airPollutionRecords.stream()
|
||||
.map(AirPollutionConcentration.class::cast)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.ConcentrationDeserializer;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* The type Air pollution record.
|
||||
*/
|
||||
@Data
|
||||
public class AirPollutionMeasurements {
|
||||
|
||||
@JsonDeserialize(using = ConcentrationDeserializer.class)
|
||||
@JsonProperty("co")
|
||||
private Concentration carbonMonoxide;
|
||||
@JsonDeserialize(using = ConcentrationDeserializer.class)
|
||||
@JsonProperty("no")
|
||||
private Concentration nitrogenMonoxide;
|
||||
@JsonDeserialize(using = ConcentrationDeserializer.class)
|
||||
@JsonProperty("no2")
|
||||
private Concentration nitrogenDioxide;
|
||||
@JsonDeserialize(using = ConcentrationDeserializer.class)
|
||||
@JsonProperty("o3")
|
||||
private Concentration ozone;
|
||||
@JsonDeserialize(using = ConcentrationDeserializer.class)
|
||||
@JsonProperty("so2")
|
||||
private Concentration sulphurDioxide;
|
||||
@JsonDeserialize(using = ConcentrationDeserializer.class)
|
||||
@JsonProperty("pm2_5")
|
||||
private Concentration fineParticlesMatter;
|
||||
@JsonDeserialize(using = ConcentrationDeserializer.class)
|
||||
@JsonProperty("pm10")
|
||||
private Concentration coarseParticulateMatter;
|
||||
@JsonDeserialize(using = ConcentrationDeserializer.class)
|
||||
@JsonProperty("nh3")
|
||||
private Concentration ammonia;
|
||||
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.EpochSecondsDeserializer;
|
||||
import com.github.prominence.openweathermap.api.enums.AirQualityIndex;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The type representing an Air pollution record.
|
||||
*/
|
||||
@Data
|
||||
public class AirPollutionRecord implements AirPollutionConcentration {
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("dt")
|
||||
private OffsetDateTime measurementTime;
|
||||
@JsonProperty("main")
|
||||
private AirQualityIndex airQualityIndex;
|
||||
@JsonProperty("components")
|
||||
private AirPollutionMeasurements components;
|
||||
|
||||
@Override
|
||||
public OffsetDateTime getMeasurementTime() {
|
||||
return measurementTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AirQualityIndex getAirQualityIndex() {
|
||||
return airQualityIndex;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Concentration getCarbonMonoxide() {
|
||||
return Optional.ofNullable(components).map(AirPollutionMeasurements::getCarbonMonoxide).orElse(null);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Concentration getNitrogenMonoxide() {
|
||||
return Optional.ofNullable(components).map(AirPollutionMeasurements::getNitrogenMonoxide).orElse(null);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Concentration getNitrogenDioxide() {
|
||||
return Optional.ofNullable(components).map(AirPollutionMeasurements::getNitrogenDioxide).orElse(null);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Concentration getOzone() {
|
||||
return Optional.ofNullable(components).map(AirPollutionMeasurements::getOzone).orElse(null);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Concentration getSulphurDioxide() {
|
||||
return Optional.ofNullable(components).map(AirPollutionMeasurements::getSulphurDioxide).orElse(null);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Concentration getFineParticlesMatter() {
|
||||
return Optional.ofNullable(components).map(AirPollutionMeasurements::getFineParticlesMatter).orElse(null);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Concentration getCoarseParticulateMatter() {
|
||||
return Optional.ofNullable(components).map(AirPollutionMeasurements::getCoarseParticulateMatter).orElse(null);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Concentration getAmmonia() {
|
||||
return Optional.ofNullable(components).map(AirPollutionMeasurements::getAmmonia).orElse(null);
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
/**
|
||||
* Entity for air pollution concentration measurement.
|
||||
*/
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
public class Concentration {
|
||||
private static final int DECIMAL_PLACES = 10;
|
||||
@NonNull
|
||||
private final BigDecimal value;
|
||||
|
||||
/**
|
||||
* Returns the measured value in micrograms/m^3.
|
||||
*
|
||||
* @return value
|
||||
*/
|
||||
@JsonIgnore
|
||||
public BigDecimal asMicrogramsPerCubicMeters() {
|
||||
return value.setScale(DECIMAL_PLACES, RoundingMode.HALF_EVEN);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.github.prominence.openweathermap.api.enums.DayTime;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class MetaData {
|
||||
@JsonProperty("pod")
|
||||
private DayTime partOfDay;
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.climatic;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.BaseLocation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Root object for 30 days long daily forecasts.
|
||||
*/
|
||||
public interface ThirtyDaysDailyForecast {
|
||||
|
||||
/**
|
||||
* The location where the forecast belongs to.
|
||||
* @return location
|
||||
*/
|
||||
@JsonIgnore
|
||||
BaseLocation getLocation();
|
||||
|
||||
/**
|
||||
* The forecasts.
|
||||
* @return days
|
||||
*/
|
||||
@JsonIgnore
|
||||
List<WeatherForecastDay> getWeatherForecasts();
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.climatic;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.BaseLocation;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.BaseLocationModel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Represents information about forecast for different timestamps.
|
||||
*/
|
||||
@Data
|
||||
public class ThirtyDaysDailyForecastModel implements ThirtyDaysDailyForecast {
|
||||
@JsonProperty("cod")
|
||||
private long cod;
|
||||
@JsonProperty("message")
|
||||
private BigDecimal message;
|
||||
@JsonProperty("city")
|
||||
private BaseLocationModel locationModel;
|
||||
@JsonProperty("list")
|
||||
private List<WeatherForecast> forecasts;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BaseLocation getLocation() {
|
||||
return locationModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public List<WeatherForecastDay> getWeatherForecasts() {
|
||||
return forecasts.stream().map(WeatherForecastDay.class::cast).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.climatic;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.EpochSecondsDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.RequiredPercentageDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.WindSpeedDeserializer;
|
||||
import com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.CloudCoverage;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.Clouds;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationValues;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.BaseAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.DailyTemperature;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureDailyBasic;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureDailyDetailed;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureValue;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.BasicWind;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.WindSpeed;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents weather forecast information for a particular timestamp.
|
||||
*/
|
||||
@Data
|
||||
public class WeatherForecast implements WeatherForecastDay, DailyTemperature, BaseAtmosphericPressure, BasicWind, Humidity,
|
||||
PrecipitationValues, SunlightStages {
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("dt")
|
||||
private OffsetDateTime forecastTime;
|
||||
@JsonProperty("temp")
|
||||
private TemperatureDailyDetailed temperature;
|
||||
@JsonProperty("feels_like")
|
||||
private TemperatureDailyBasic feelsLike;
|
||||
@JsonProperty("weather")
|
||||
private List<WeatherCondition> weatherStates = new ArrayList<>();
|
||||
@JsonDeserialize(using = RequiredPercentageDeserializer.class)
|
||||
@JsonProperty("humidity")
|
||||
private int humidityPercentage;
|
||||
@JsonProperty("pressure")
|
||||
private BigDecimal pressure;
|
||||
@JsonDeserialize(using = RequiredPercentageDeserializer.class)
|
||||
@JsonProperty("clouds")
|
||||
private int clouds;
|
||||
@JsonDeserialize(using = WindSpeedDeserializer.class)
|
||||
@JsonProperty("speed")
|
||||
private WindSpeed speed;
|
||||
@JsonProperty("deg")
|
||||
private Integer directionDegrees;
|
||||
@JsonProperty("rain")
|
||||
private BigDecimal rain;
|
||||
@JsonProperty("snow")
|
||||
private BigDecimal snow;
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("sunrise")
|
||||
private OffsetDateTime sunriseTime;
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("sunset")
|
||||
private OffsetDateTime sunsetTime;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DailyTemperature getTemperature() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BasicWind getWind() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getMorning() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyBasic::getMorning).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getDay() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyBasic::getDay).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getEve() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyBasic::getEve).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getNight() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyBasic::getNight).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getMin() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyDetailed::getMin).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getMax() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyDetailed::getMax).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getMorningFeelsLike() {
|
||||
return Optional.ofNullable(feelsLike).map(TemperatureDailyBasic::getMorning).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getDayFeelsLike() {
|
||||
return Optional.ofNullable(feelsLike).map(TemperatureDailyBasic::getDay).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getEveFeelsLike() {
|
||||
return Optional.ofNullable(feelsLike).map(TemperatureDailyBasic::getEve).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getNightFeelsLike() {
|
||||
return Optional.ofNullable(feelsLike).map(TemperatureDailyBasic::getNight).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Humidity getHumidity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BaseAtmosphericPressure getAtmosphericPressure() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public CloudCoverage getCloudCoverage() {
|
||||
return new Clouds(this.clouds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public PrecipitationValues getPrecipitation() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public SunlightStages getSunlightStages() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.climatic;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
import com.github.prominence.openweathermap.api.model.generic.TimeAware;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.CloudCoverage;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationValues;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.BaseAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.DailyTemperature;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.BasicWind;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Contains forecast information for one day of the 30 day long climatic forecasts.
|
||||
*/
|
||||
public interface WeatherForecastDay extends TimeAware {
|
||||
/**
|
||||
* The temperature forecast.
|
||||
*
|
||||
* @return temps
|
||||
*/
|
||||
@JsonIgnore
|
||||
DailyTemperature getTemperature();
|
||||
|
||||
/**
|
||||
* The humidity forecast.
|
||||
*
|
||||
* @return humidity
|
||||
*/
|
||||
@JsonIgnore
|
||||
Humidity getHumidity();
|
||||
|
||||
/**
|
||||
* The atmospheric pressure forecast.
|
||||
*
|
||||
* @return pressure
|
||||
*/
|
||||
@JsonIgnore
|
||||
BaseAtmosphericPressure getAtmosphericPressure();
|
||||
|
||||
/**
|
||||
* The forecasted wind conditions.
|
||||
*
|
||||
* @return wind
|
||||
*/
|
||||
@JsonIgnore
|
||||
BasicWind getWind();
|
||||
|
||||
/**
|
||||
* The expected weather states.
|
||||
*
|
||||
* @return weather states
|
||||
*/
|
||||
List<WeatherCondition> getWeatherStates();
|
||||
|
||||
/**
|
||||
* The forecasted cloud coverage.
|
||||
*
|
||||
* @return clouds
|
||||
*/
|
||||
@JsonIgnore
|
||||
CloudCoverage getCloudCoverage();
|
||||
|
||||
/**
|
||||
* The forecasted precipitation.
|
||||
*
|
||||
* @return precipitation
|
||||
*/
|
||||
@JsonIgnore
|
||||
PrecipitationValues getPrecipitation();
|
||||
|
||||
/**
|
||||
* Information about sunlight stages.
|
||||
*
|
||||
* @return sunlight
|
||||
*/
|
||||
@JsonIgnore
|
||||
SunlightStages getSunlightStages();
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.daily;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
import com.github.prominence.openweathermap.api.model.generic.TimeAware;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.CloudCoverage;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationForecast;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.BaseAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.DailyTemperature;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.DetailedWindInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Interface for weather forecast data used by the SixteenDaysDailyForecast.
|
||||
*/
|
||||
public interface DailyWeather extends TimeAware {
|
||||
|
||||
/**
|
||||
* The temperature data,
|
||||
*
|
||||
* @return temp
|
||||
*/
|
||||
@JsonIgnore
|
||||
DailyTemperature getTemperature();
|
||||
|
||||
/**
|
||||
* The humidity.
|
||||
*
|
||||
* @return humidity
|
||||
*/
|
||||
@JsonIgnore
|
||||
Humidity getHumidity();
|
||||
|
||||
/**
|
||||
* The atmospheric pressure.
|
||||
*
|
||||
* @return pressure
|
||||
*/
|
||||
@JsonIgnore
|
||||
BaseAtmosphericPressure getAtmosphericPressure();
|
||||
|
||||
/**
|
||||
* The wind conditions.
|
||||
*
|
||||
* @return wind
|
||||
*/
|
||||
@JsonIgnore
|
||||
DetailedWindInfo getWind();
|
||||
|
||||
/**
|
||||
* The weather states.
|
||||
*
|
||||
* @return weather
|
||||
*/
|
||||
List<WeatherCondition> getWeatherStates();
|
||||
|
||||
/**
|
||||
* The cloud coverage.
|
||||
*
|
||||
* @return louds
|
||||
*/
|
||||
@JsonIgnore
|
||||
CloudCoverage getCloudCoverage();
|
||||
|
||||
/**
|
||||
* The precipitation.
|
||||
*
|
||||
* @return precipitation
|
||||
*/
|
||||
@JsonIgnore
|
||||
PrecipitationForecast getPrecipitation();
|
||||
|
||||
/**
|
||||
* The sunlight stages.
|
||||
*
|
||||
* @return sunlight
|
||||
*/
|
||||
@JsonIgnore
|
||||
SunlightStages getSunlightStages();
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.daily;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.DetailedLocationInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the daily forecast for the next sixteen days
|
||||
*/
|
||||
public interface SixteenDaysDailyForecast {
|
||||
/**
|
||||
* Information about the location.
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@JsonIgnore
|
||||
DetailedLocationInfo getLocation();
|
||||
|
||||
/**
|
||||
* The daily forecasts.
|
||||
*
|
||||
* @return forecasts
|
||||
*/
|
||||
@JsonIgnore
|
||||
List<DailyWeather> getWeatherForecasts();
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.daily;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.DetailedLocationInfo;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.DetailedLocationModel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Represents information about forecast for different timestamps.
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(value = {"cnt"})
|
||||
public class SixteenDaysDailyForecastModel implements SixteenDaysDailyForecast {
|
||||
@JsonProperty("cod")
|
||||
private long cod;
|
||||
@JsonProperty("message")
|
||||
private BigDecimal message;
|
||||
@JsonProperty("city")
|
||||
private DetailedLocationModel locationModel;
|
||||
@JsonProperty("list")
|
||||
private List<WeatherForecast> forecasts;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DetailedLocationInfo getLocation() {
|
||||
return locationModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public List<DailyWeather> getWeatherForecasts() {
|
||||
return forecasts.stream().map(DailyWeather.class::cast).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.daily;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.EpochSecondsDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.PercentageZeroToOneDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.RequiredPercentageDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.WindSpeedDeserializer;
|
||||
import com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.CloudCoverage;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.Clouds;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationForecast;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.BaseAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.DailyTemperature;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureDailyBasic;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureDailyDetailed;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureValue;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.DetailedWindInfo;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.WindSpeed;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents weather forecast information for a particular timestamp.
|
||||
*/
|
||||
@Data
|
||||
public class WeatherForecast
|
||||
implements DailyWeather, DailyTemperature, BaseAtmosphericPressure, DetailedWindInfo, Humidity, PrecipitationForecast, SunlightStages {
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("dt")
|
||||
private OffsetDateTime forecastTime;
|
||||
@JsonProperty("temp")
|
||||
private TemperatureDailyDetailed temperature;
|
||||
@JsonProperty("feels_like")
|
||||
private TemperatureDailyBasic feelsLike;
|
||||
@JsonProperty("weather")
|
||||
private List<WeatherCondition> weatherStates = new ArrayList<>();
|
||||
@JsonDeserialize(using = RequiredPercentageDeserializer.class)
|
||||
@JsonProperty("humidity")
|
||||
private int humidityPercentage;
|
||||
@JsonProperty("pressure")
|
||||
private BigDecimal pressure;
|
||||
@JsonDeserialize(using = RequiredPercentageDeserializer.class)
|
||||
@JsonProperty("clouds")
|
||||
private int clouds;
|
||||
@JsonDeserialize(using = WindSpeedDeserializer.class)
|
||||
@JsonProperty("speed")
|
||||
private WindSpeed speed;
|
||||
@JsonProperty("deg")
|
||||
private Integer directionDegrees;
|
||||
@JsonDeserialize(using = WindSpeedDeserializer.class)
|
||||
@JsonProperty("gust")
|
||||
private WindSpeed gust;
|
||||
@JsonProperty("rain")
|
||||
private BigDecimal rain;
|
||||
@JsonProperty("snow")
|
||||
private BigDecimal snow;
|
||||
@JsonDeserialize(using = PercentageZeroToOneDeserializer.class)
|
||||
@JsonProperty("pop")
|
||||
private Integer probabilityOfPrecipitation;
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("sunrise")
|
||||
private OffsetDateTime sunriseTime;
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("sunset")
|
||||
private OffsetDateTime sunsetTime;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DailyTemperature getTemperature() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DetailedWindInfo getWind() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getMorning() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyBasic::getMorning).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getDay() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyBasic::getDay).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getEve() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyBasic::getEve).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getNight() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyBasic::getNight).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getMin() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyDetailed::getMin).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getMax() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyDetailed::getMax).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getMorningFeelsLike() {
|
||||
return Optional.ofNullable(feelsLike).map(TemperatureDailyBasic::getMorning).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getDayFeelsLike() {
|
||||
return Optional.ofNullable(feelsLike).map(TemperatureDailyBasic::getDay).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getEveFeelsLike() {
|
||||
return Optional.ofNullable(feelsLike).map(TemperatureDailyBasic::getEve).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getNightFeelsLike() {
|
||||
return Optional.ofNullable(feelsLike).map(TemperatureDailyBasic::getNight).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Humidity getHumidity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BaseAtmosphericPressure getAtmosphericPressure() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public CloudCoverage getCloudCoverage() {
|
||||
return new Clouds(this.clouds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public PrecipitationForecast getPrecipitation() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public SunlightStages getSunlightStages() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.free;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.DetailedLocationInfo;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the 3 hours forecast for the next five days
|
||||
*/
|
||||
public interface FiveDaysThreeHoursForecast {
|
||||
/**
|
||||
* Information about the location.
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@JsonIgnore
|
||||
DetailedLocationInfo getLocation();
|
||||
|
||||
/**
|
||||
* The expected sunlight stages.
|
||||
*
|
||||
* @return sunlight
|
||||
*/
|
||||
@JsonIgnore
|
||||
SunlightStages getSunlightStages();
|
||||
|
||||
/**
|
||||
* The 3-hourly forecasts.
|
||||
*
|
||||
* @return forecasts
|
||||
*/
|
||||
@JsonIgnore
|
||||
List<ThreeHourWeather> getWeatherForecasts();
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.free;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.DetailedLocationInfo;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Represents information about forecast for different timestamps.
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(value = {"cnt"})
|
||||
public class FiveDaysThreeHoursForecastModel implements FiveDaysThreeHoursForecast {
|
||||
|
||||
@JsonProperty("cod")
|
||||
private long cod;
|
||||
@JsonProperty("message")
|
||||
private BigDecimal message;
|
||||
@JsonProperty("city")
|
||||
private LocationModel locationModel;
|
||||
@JsonProperty("list")
|
||||
private List<WeatherForecast> forecasts;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DetailedLocationInfo getLocation() {
|
||||
return locationModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public SunlightStages getSunlightStages() {
|
||||
return locationModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public List<ThreeHourWeather> getWeatherForecasts() {
|
||||
return forecasts.stream().map(ThreeHourWeather.class::cast).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.free;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.EpochSecondsDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.DetailedLocationInfo;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.DetailedLocationModel;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
/**
|
||||
* Represents location information.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class LocationModel extends DetailedLocationModel implements DetailedLocationInfo, SunlightStages {
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("sunrise")
|
||||
private OffsetDateTime sunriseTime;
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("sunset")
|
||||
private OffsetDateTime sunsetTime;
|
||||
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.free;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Represents snow/rain information.
|
||||
*/
|
||||
@Data
|
||||
public class Precipitation {
|
||||
@JsonProperty("3h")
|
||||
private BigDecimal threeHourLevel;
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.free;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.prominence.openweathermap.api.enums.DayTime;
|
||||
import com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
import com.github.prominence.openweathermap.api.model.generic.TimeAware;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.CloudCoverage;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationForecast;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.DetailedAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureWithRange;
|
||||
import com.github.prominence.openweathermap.api.model.generic.visibility.Visibility;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.DetailedWindInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Weather forecasts for 3 hours.
|
||||
*/
|
||||
public interface ThreeHourWeather extends TimeAware {
|
||||
/**
|
||||
* The temperature forecast.
|
||||
*
|
||||
* @return temperature
|
||||
*/
|
||||
@JsonIgnore
|
||||
TemperatureWithRange getTemperature();
|
||||
|
||||
/**
|
||||
* The humidity forecast.
|
||||
*
|
||||
* @return humidity
|
||||
*/
|
||||
@JsonIgnore
|
||||
Humidity getHumidity();
|
||||
|
||||
/**
|
||||
* The atmospheric pressure forecast.
|
||||
*
|
||||
* @return pressure
|
||||
*/
|
||||
@JsonIgnore
|
||||
DetailedAtmosphericPressure getAtmosphericPressure();
|
||||
|
||||
/**
|
||||
* The wind forecast.
|
||||
*
|
||||
* @return wind
|
||||
*/
|
||||
@JsonIgnore
|
||||
DetailedWindInfo getWind();
|
||||
|
||||
/**
|
||||
* The weather states.
|
||||
*
|
||||
* @return states
|
||||
*/
|
||||
List<WeatherCondition> getWeatherStates();
|
||||
|
||||
/**
|
||||
* The forecasted cloud cover.
|
||||
*
|
||||
* @return clouds
|
||||
*/
|
||||
CloudCoverage getClouds();
|
||||
|
||||
/**
|
||||
* The precipitation forecast.
|
||||
*
|
||||
* @return precipitation
|
||||
*/
|
||||
@JsonIgnore
|
||||
PrecipitationForecast getThreeHoursPrecipitation();
|
||||
|
||||
/**
|
||||
* The visibility forecast.
|
||||
*
|
||||
* @return visibility
|
||||
*/
|
||||
Visibility getVisibility();
|
||||
|
||||
/**
|
||||
* The part of day.
|
||||
*
|
||||
* @return part of day
|
||||
*/
|
||||
@JsonIgnore
|
||||
DayTime getPartOfDay();
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.free;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.EpochSecondsDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.PercentageZeroToOneDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.VisibilityDeserializer;
|
||||
import com.github.prominence.openweathermap.api.enums.DayTime;
|
||||
import com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
import com.github.prominence.openweathermap.api.model.forecast.MetaData;
|
||||
import com.github.prominence.openweathermap.api.model.generic.MainMetrics;
|
||||
import com.github.prominence.openweathermap.api.model.generic.TimeAware;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.CloudCoverage;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.Clouds;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationForecast;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.DetailedAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureWithRange;
|
||||
import com.github.prominence.openweathermap.api.model.generic.visibility.Visibility;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.DetailedWindInfo;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.WindModel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents weather forecast information for a particular timestamp.
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(value = {"dt_txt"})
|
||||
public class WeatherForecast implements TimeAware, ThreeHourWeather, PrecipitationForecast {
|
||||
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("dt")
|
||||
private OffsetDateTime forecastTime;
|
||||
@JsonProperty("main")
|
||||
private MainMetrics mainMetrics;
|
||||
@JsonProperty("weather")
|
||||
private List<WeatherCondition> weatherStates = new ArrayList<>();
|
||||
@JsonProperty("clouds")
|
||||
private Clouds clouds;
|
||||
@JsonProperty("wind")
|
||||
private WindModel windModel;
|
||||
@JsonProperty("rain")
|
||||
private Precipitation rainModel;
|
||||
@JsonProperty("snow")
|
||||
private Precipitation snowModel;
|
||||
@JsonDeserialize(using = VisibilityDeserializer.class)
|
||||
@JsonProperty("visibility")
|
||||
private Visibility visibility;
|
||||
@JsonDeserialize(using = PercentageZeroToOneDeserializer.class)
|
||||
@JsonProperty("pop")
|
||||
private Integer probabilityOfPrecipitation;
|
||||
@JsonProperty("sys")
|
||||
private MetaData sysMeta;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureWithRange getTemperature() {
|
||||
return mainMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Humidity getHumidity() {
|
||||
return mainMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DetailedAtmosphericPressure getAtmosphericPressure() {
|
||||
return mainMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DetailedWindInfo getWind() {
|
||||
return windModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DayTime getPartOfDay() {
|
||||
return Optional.ofNullable(sysMeta).map(MetaData::getPartOfDay).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public PrecipitationForecast getThreeHoursPrecipitation() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BigDecimal getRain() {
|
||||
return Optional.ofNullable(rainModel)
|
||||
.map(Precipitation::getThreeHourLevel)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BigDecimal getSnow() {
|
||||
return Optional.ofNullable(snowModel)
|
||||
.map(Precipitation::getThreeHourLevel)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudCoverage getClouds() {
|
||||
return clouds;
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.hourly;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.BaseLocation;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the hourly forecast for the next four days
|
||||
*/
|
||||
public interface FourDaysHourlyForecast {
|
||||
|
||||
/**
|
||||
* Information about the location.
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@JsonIgnore
|
||||
BaseLocation getLocation();
|
||||
|
||||
/**
|
||||
* The expected sunlight stages.
|
||||
*
|
||||
* @return sunlight
|
||||
*/
|
||||
@JsonIgnore
|
||||
SunlightStages getSunlightStages();
|
||||
|
||||
/**
|
||||
* The hourly forecasts.
|
||||
*
|
||||
* @return hours
|
||||
*/
|
||||
@JsonIgnore
|
||||
List<HourlyWeather> getWeatherForecasts();
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.hourly;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.BaseLocation;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Represents information about forecast for different timestamps.
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(value = {"cnt"})
|
||||
public class FourDaysHourlyForecastModel implements FourDaysHourlyForecast {
|
||||
|
||||
@JsonProperty("cod")
|
||||
private long cod;
|
||||
@JsonProperty("message")
|
||||
private BigDecimal message;
|
||||
@JsonProperty("list")
|
||||
private List<HourlyWeatherForecast> forecasts;
|
||||
@JsonProperty("city")
|
||||
private LocationModel locationModel;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BaseLocation getLocation() {
|
||||
return locationModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public SunlightStages getSunlightStages() {
|
||||
return locationModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public List<HourlyWeather> getWeatherForecasts() {
|
||||
return forecasts.stream().map(HourlyWeather.class::cast).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.hourly;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.prominence.openweathermap.api.enums.DayTime;
|
||||
import com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
import com.github.prominence.openweathermap.api.model.generic.TimeAware;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.CloudCoverage;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationForecast;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.DetailedAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureWithRange;
|
||||
import com.github.prominence.openweathermap.api.model.generic.visibility.Visibility;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.DetailedWindInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Forecast details for a single hour.
|
||||
*/
|
||||
public interface HourlyWeather extends TimeAware {
|
||||
/**
|
||||
* The temperature forecast.
|
||||
*
|
||||
* @return temperature
|
||||
*/
|
||||
@JsonIgnore
|
||||
TemperatureWithRange getTemperature();
|
||||
|
||||
/**
|
||||
* The humidity forecast.
|
||||
*
|
||||
* @return humidity
|
||||
*/
|
||||
@JsonIgnore
|
||||
Humidity getHumidity();
|
||||
|
||||
/**
|
||||
* The atmospheric pressure forecast.
|
||||
*
|
||||
* @return pressure
|
||||
*/
|
||||
@JsonIgnore
|
||||
DetailedAtmosphericPressure getAtmosphericPressure();
|
||||
|
||||
/**
|
||||
* The wind forecast.
|
||||
*
|
||||
* @return wind
|
||||
*/
|
||||
DetailedWindInfo getWind();
|
||||
|
||||
/**
|
||||
* The weather states.
|
||||
*
|
||||
* @return states
|
||||
*/
|
||||
List<WeatherCondition> getWeatherStates();
|
||||
|
||||
/**
|
||||
* The forecasted cloud cover.
|
||||
*
|
||||
* @return clouds
|
||||
*/
|
||||
CloudCoverage getClouds();
|
||||
|
||||
/**
|
||||
* The precipitation forecast.
|
||||
*
|
||||
* @return precipitation
|
||||
*/
|
||||
@JsonIgnore
|
||||
PrecipitationForecast getHourlyPrecipitation();
|
||||
|
||||
/**
|
||||
* The visibility forecast.
|
||||
*
|
||||
* @return visibility
|
||||
*/
|
||||
Visibility getVisibility();
|
||||
|
||||
/**
|
||||
* The part of day.
|
||||
*
|
||||
* @return part of day
|
||||
*/
|
||||
@JsonIgnore
|
||||
DayTime getPartOfDay();
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.hourly;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.EpochSecondsDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.PercentageZeroToOneDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.VisibilityDeserializer;
|
||||
import com.github.prominence.openweathermap.api.enums.DayTime;
|
||||
import com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
import com.github.prominence.openweathermap.api.model.forecast.MetaData;
|
||||
import com.github.prominence.openweathermap.api.model.generic.MainMetrics;
|
||||
import com.github.prominence.openweathermap.api.model.generic.TimeAware;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.CloudCoverage;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.Clouds;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.BasePrecipitation;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationForecast;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.DetailedAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureWithRange;
|
||||
import com.github.prominence.openweathermap.api.model.generic.visibility.Visibility;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.DetailedWindInfo;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.WindModel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents weather forecast information for a particular timestamp.
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(value = {"dt_txt"})
|
||||
public class HourlyWeatherForecast implements TimeAware, HourlyWeather, PrecipitationForecast {
|
||||
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("dt")
|
||||
private OffsetDateTime forecastTime;
|
||||
@JsonProperty("main")
|
||||
private MainMetrics mainMetrics;
|
||||
@JsonProperty("weather")
|
||||
private List<WeatherCondition> weatherStates = new ArrayList<>();
|
||||
@JsonProperty("clouds")
|
||||
private Clouds clouds;
|
||||
@JsonProperty("wind")
|
||||
private WindModel windModel;
|
||||
@JsonProperty("rain")
|
||||
private BasePrecipitation rainModel;
|
||||
@JsonProperty("snow")
|
||||
private BasePrecipitation snowModel;
|
||||
@JsonDeserialize(using = VisibilityDeserializer.class)
|
||||
@JsonProperty("visibility")
|
||||
private Visibility visibility;
|
||||
@JsonDeserialize(using = PercentageZeroToOneDeserializer.class)
|
||||
@JsonProperty("pop")
|
||||
private Integer probabilityOfPrecipitation;
|
||||
@JsonProperty("sys")
|
||||
private MetaData sysMeta;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureWithRange getTemperature() {
|
||||
return mainMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Humidity getHumidity() {
|
||||
return mainMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DetailedAtmosphericPressure getAtmosphericPressure() {
|
||||
return mainMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DetailedWindInfo getWind() {
|
||||
return windModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public PrecipitationForecast getHourlyPrecipitation() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BigDecimal getRain() {
|
||||
return Optional.ofNullable(getRainModel()).map(BasePrecipitation::getOneHourLevel).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BigDecimal getSnow() {
|
||||
return Optional.ofNullable(getSnowModel()).map(BasePrecipitation::getOneHourLevel).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudCoverage getClouds() {
|
||||
return clouds;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DayTime getPartOfDay() {
|
||||
return Optional.ofNullable(sysMeta).map(MetaData::getPartOfDay).orElse(null);
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.forecast.hourly;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.EpochSecondsDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.BaseLocation;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.BaseLocationModel;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
/**
|
||||
* Represents location information.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class LocationModel extends BaseLocationModel implements BaseLocation, SunlightStages {
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("sunrise")
|
||||
private OffsetDateTime sunriseTime;
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("sunset")
|
||||
private OffsetDateTime sunsetTime;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.RequiredPercentageDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.TemperatureValueDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.DetailedAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureValue;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureWithRange;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Contains Temperature and AtmosphericPressure.
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(value = {"temp_kf"})
|
||||
public class MainMetrics implements TemperatureWithRange, Humidity, DetailedAtmosphericPressure {
|
||||
@JsonDeserialize(using = TemperatureValueDeserializer.class)
|
||||
@JsonProperty("temp")
|
||||
private TemperatureValue temperature;
|
||||
@JsonDeserialize(using = TemperatureValueDeserializer.class)
|
||||
@JsonProperty("temp_max")
|
||||
private TemperatureValue max;
|
||||
@JsonDeserialize(using = TemperatureValueDeserializer.class)
|
||||
@JsonProperty("temp_min")
|
||||
private TemperatureValue min;
|
||||
@JsonDeserialize(using = TemperatureValueDeserializer.class)
|
||||
@JsonProperty("feels_like")
|
||||
private TemperatureValue feelsLike;
|
||||
@JsonDeserialize(using = RequiredPercentageDeserializer.class)
|
||||
@JsonProperty("humidity")
|
||||
private int humidityPercentage;
|
||||
@JsonProperty("pressure")
|
||||
private BigDecimal pressure;
|
||||
@JsonProperty("sea_level")
|
||||
private BigDecimal seaLevel;
|
||||
@JsonProperty("grnd_level")
|
||||
private BigDecimal groundLevel;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
/**
|
||||
* Indicates that the implementation keeps track of the forecast time.
|
||||
*/
|
||||
public interface TimeAware {
|
||||
/**
|
||||
* Returns the time when the data was calculated.
|
||||
*
|
||||
* @return timestamp
|
||||
*/
|
||||
OffsetDateTime getForecastTime();
|
||||
}
|
||||
+4
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
@@ -20,13 +20,9 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.constants;
|
||||
package com.github.prominence.openweathermap.api.model.generic.clouds;
|
||||
|
||||
public final class Accuracy {
|
||||
|
||||
private Accuracy() {}
|
||||
|
||||
public static final String LIKE = "like";
|
||||
public static final String ACCURATE = "accurate";
|
||||
public interface CloudCoverage {
|
||||
|
||||
Integer getCoveragePercentage();
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic.clouds;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The Clouds type represents cloudiness value percentage.
|
||||
* Its value can only be an integer in [0, 100] range.
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Clouds implements CloudCoverage {
|
||||
@JsonProperty("all")
|
||||
private Integer coveragePercentage;
|
||||
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic.location;
|
||||
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
/**
|
||||
* Contains basic location information.
|
||||
*/
|
||||
public interface BaseLocation extends CoordinateAware {
|
||||
|
||||
/**
|
||||
* The time zone of the location.
|
||||
*
|
||||
* @return time zone
|
||||
*/
|
||||
ZoneOffset getTimeZone();
|
||||
|
||||
/**
|
||||
* The Id of the city.
|
||||
*
|
||||
* @return city Id
|
||||
*/
|
||||
long getCityId();
|
||||
|
||||
/**
|
||||
* The name of the city.
|
||||
*
|
||||
* @return city name
|
||||
*/
|
||||
String getCityName();
|
||||
|
||||
/**
|
||||
* The country code of the location.
|
||||
*
|
||||
* @return country code
|
||||
*/
|
||||
String getCountryCode();
|
||||
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic.location;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.ZoneOffsetDeserializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
/**
|
||||
* Represents location information.
|
||||
*/
|
||||
@Data
|
||||
public class BaseLocationModel implements BaseLocation {
|
||||
@JsonProperty("id")
|
||||
private long cityId;
|
||||
@JsonProperty("name")
|
||||
private String cityName;
|
||||
@JsonProperty("coord")
|
||||
private Coordinates coordinates;
|
||||
@JsonProperty("country")
|
||||
private String countryCode;
|
||||
@JsonDeserialize(using = ZoneOffsetDeserializer.class)
|
||||
@JsonProperty("timezone")
|
||||
private ZoneOffset timeZone;
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic.location;
|
||||
|
||||
/**
|
||||
* Indicates that the object can provide coordinate information.
|
||||
*/
|
||||
public interface CoordinateAware {
|
||||
|
||||
/**
|
||||
* The coordinates of the data source.
|
||||
*
|
||||
* @return coordinated
|
||||
*/
|
||||
Coordinates getCoordinates();
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic.location;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Represents some location by its latitude and longitude.
|
||||
*/
|
||||
@Data
|
||||
public class Coordinates {
|
||||
@JsonProperty("lat")
|
||||
private final double latitude;
|
||||
@JsonProperty("lon")
|
||||
private final double longitude;
|
||||
|
||||
@JsonCreator
|
||||
public Coordinates(@JsonProperty("lat") double latitude, @JsonProperty("lon") double longitude) {
|
||||
if (latitude < -90 || latitude > 90) {
|
||||
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
|
||||
}
|
||||
if (longitude < -180 || longitude > 180) {
|
||||
throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0].");
|
||||
}
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
}
|
||||
}
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic.location;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents coordinate rectangle by its bottom-left and top-right coordinates.
|
||||
*/
|
||||
public class CoordinatesRectangle {
|
||||
private final double longitudeLeft;
|
||||
private final double latitudeBottom;
|
||||
private final double longitudeRight;
|
||||
private final double latitudeTop;
|
||||
|
||||
private CoordinatesRectangle(double longitudeLeft, double latitudeBottom, double longitudeRight, double latitudeTop) {
|
||||
this.longitudeLeft = longitudeLeft;
|
||||
this.latitudeBottom = latitudeBottom;
|
||||
this.longitudeRight = longitudeRight;
|
||||
this.latitudeTop = latitudeTop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for {@link CoordinatesRectangle} creation with correctness check.
|
||||
* @param longitudeLeft left longitude
|
||||
* @param latitudeBottom bottom latitude
|
||||
* @param longitudeRight right longitude
|
||||
* @param latitudeTop tip latitude
|
||||
* @return coordinate rectangle object.
|
||||
*/
|
||||
public static CoordinatesRectangle withValues(double longitudeLeft, double latitudeBottom, double longitudeRight, double latitudeTop) {
|
||||
if (latitudeBottom < -90 || latitudeTop < -90 || latitudeBottom > 90 || latitudeTop > 90) {
|
||||
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
|
||||
}
|
||||
if (longitudeLeft < -180 || longitudeRight < -180 || longitudeLeft > 180 || longitudeRight > 180) {
|
||||
throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0].");
|
||||
}
|
||||
return new CoordinatesRectangle(longitudeLeft, latitudeBottom, longitudeRight, latitudeTop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns left longitude value.
|
||||
* @return left longitude
|
||||
*/
|
||||
public double getLongitudeLeft() {
|
||||
return longitudeLeft;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns bottom latitude value.
|
||||
* @return bottom latitude
|
||||
*/
|
||||
public double getLatitudeBottom() {
|
||||
return latitudeBottom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns right longitude value.
|
||||
* @return right longitude
|
||||
*/
|
||||
public double getLongitudeRight() {
|
||||
return longitudeRight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns top latitude value.
|
||||
* @return top latitude
|
||||
*/
|
||||
public double getLatitudeTop() {
|
||||
return latitudeTop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatted coordinate rectangle string.
|
||||
* @return formatted string
|
||||
*/
|
||||
public String getFormattedRequestString() {
|
||||
return longitudeLeft + "," + latitudeBottom + "," + longitudeRight + "," + latitudeTop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof CoordinatesRectangle)) return false;
|
||||
CoordinatesRectangle rectangle = (CoordinatesRectangle) o;
|
||||
return Double.compare(rectangle.longitudeLeft, longitudeLeft) == 0 &&
|
||||
Double.compare(rectangle.latitudeBottom, latitudeBottom) == 0 &&
|
||||
Double.compare(rectangle.longitudeRight, longitudeRight) == 0 &&
|
||||
Double.compare(rectangle.latitudeTop, latitudeTop) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(longitudeLeft, latitudeBottom, longitudeRight, latitudeTop);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Rectangle: " + getFormattedRequestString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for CoordinateRectangle class.
|
||||
*/
|
||||
public static class Builder {
|
||||
private Double longitudeLeft;
|
||||
private Double latitudeBottom;
|
||||
private Double longitudeRight;
|
||||
private Double latitudeTop;
|
||||
|
||||
/**
|
||||
* Creates Builder object.
|
||||
*/
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets left longitude with correctness check.
|
||||
* @param longitudeLeft left longitude
|
||||
* @return builder object
|
||||
*/
|
||||
public Builder setLongitudeLeft(double longitudeLeft) {
|
||||
if (longitudeLeft < -180 || longitudeLeft > 180) {
|
||||
throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0].");
|
||||
}
|
||||
this.longitudeLeft = longitudeLeft;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets bottom latitude with correctness check.
|
||||
* @param latitudeBottom bottom latitude
|
||||
* @return builder object
|
||||
*/
|
||||
public Builder setLatitudeBottom(double latitudeBottom) {
|
||||
if (latitudeBottom < -90 || latitudeBottom > 90) {
|
||||
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
|
||||
}
|
||||
this.latitudeBottom = latitudeBottom;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets right longitude with correctness check.
|
||||
* @param longitudeRight right longitude
|
||||
* @return builder object
|
||||
*/
|
||||
public Builder setLongitudeRight(double longitudeRight) {
|
||||
if (longitudeRight < -180 || longitudeRight > 180) {
|
||||
throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0].");
|
||||
}
|
||||
this.longitudeRight = longitudeRight;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets top latitude with correctness check.
|
||||
* @param latitudeTop top latitude
|
||||
* @return builder object
|
||||
*/
|
||||
public Builder setLatitudeTop(double latitudeTop) {
|
||||
if (latitudeTop < -90 || latitudeTop > 90) {
|
||||
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
|
||||
}
|
||||
this.latitudeTop = latitudeTop;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds {@link CoordinatesRectangle} object with correctness check.
|
||||
* @return {@link CoordinatesRectangle} built object.
|
||||
*/
|
||||
public CoordinatesRectangle build() {
|
||||
if (longitudeLeft == null || latitudeBottom == null || longitudeRight == null || latitudeTop == null) {
|
||||
throw new IllegalStateException("Not all fields were set.");
|
||||
}
|
||||
return new CoordinatesRectangle(longitudeLeft, latitudeBottom, longitudeRight, latitudeTop);
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic.location;
|
||||
|
||||
/**
|
||||
* Location information containing additional details about population.
|
||||
*/
|
||||
public interface DetailedLocationInfo extends BaseLocation {
|
||||
|
||||
/**
|
||||
* The number of people living at this location.
|
||||
*
|
||||
* @return population
|
||||
*/
|
||||
Long getPopulation();
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user