mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-03 19:26:43 +03:00
Compare commits
35 Commits
2.2.0
...
2553f13fbe
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 |
@@ -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
|
||||||
@@ -13,10 +13,10 @@ name: "CodeQL"
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [ dev ]
|
||||||
pull_request:
|
pull_request:
|
||||||
# The branches below must be a subset of the branches above
|
# The branches below must be a subset of the branches above
|
||||||
branches: [ master ]
|
branches: [ dev ]
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '27 20 * * 1'
|
- cron: '27 20 * * 1'
|
||||||
|
|
||||||
|
|||||||
+2
-21
@@ -1,24 +1,5 @@
|
|||||||
# 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
|
*.iml
|
||||||
.idea/
|
.idea/
|
||||||
|
.gradle
|
||||||
|
build/
|
||||||
target/
|
target/
|
||||||
@@ -8,6 +8,9 @@ Free:
|
|||||||
* One Call API
|
* One Call API
|
||||||
* Air pollution
|
* Air pollution
|
||||||
|
|
||||||
|
Other:
|
||||||
|
* Request timeout settings
|
||||||
|
|
||||||
### Will be implemented later:
|
### Will be implemented later:
|
||||||
|
|
||||||
Free:
|
Free:
|
||||||
@@ -24,16 +27,48 @@ Paid:
|
|||||||
|
|
||||||
```xml
|
```xml
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.prominence</groupId>
|
<groupId>com.github.prominence</groupId>
|
||||||
<artifactId>openweathermap-api</artifactId>
|
<artifactId>openweathermap-api</artifactId>
|
||||||
<version>2.2.0</version>
|
<version>3.0.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</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:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:2.2.0')
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
...
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
@@ -45,14 +80,15 @@ compile('com.github.prominence:openweathermap-api:2.2.0')
|
|||||||
* [OpenWeatherMap Java API - 2.1.0](docs/Release_2.1.0.md)
|
* [OpenWeatherMap Java API - 2.1.0](docs/Release_2.1.0.md)
|
||||||
* [OpenWeatherMap Java API - 2.1.1](docs/Release_2.1.1.md)
|
* [OpenWeatherMap Java API - 2.1.1](docs/Release_2.1.1.md)
|
||||||
* [OpenWeatherMap Java API - 2.2.0](docs/Release_2.2.0.md)
|
* [OpenWeatherMap Java API - 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)
|
* [OpenWeatherMap Java API - SNAPSHOT](docs/SNAPSHOT.md)
|
||||||
|
|
||||||
### License
|
### License
|
||||||
MIT
|
MIT
|
||||||
|
|
||||||
[ci-shield]: https://travis-ci.org/Prominence/openweathermap-java-api.svg?branch=master
|
[ci-shield]: https://travis-ci.org/Prominence/openweathermap-java-api.svg?branch=dev
|
||||||
[ci-link]: https://travis-ci.org/Prominence/openweathermap-java-api
|
[ci-link]: https://travis-ci.org/Prominence/openweathermap-java-api
|
||||||
|
|
||||||
|
|
||||||
[codecov-shield]: https://codecov.io/gh/Prominence/openweathermap-java-api/branch/master/graph/badge.svg
|
[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
|
[codecov-link]: https://codecov.io/gh/Prominence/openweathermap-java-api
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java-library'
|
||||||
|
id 'maven-publish'
|
||||||
|
id 'signing'
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
maven {
|
||||||
|
url = uri('https://repo.maven.apache.org/maven2/')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.2.2'
|
||||||
|
implementation 'org.slf4j:slf4j-api:1.7.36'
|
||||||
|
testImplementation 'org.junit.platform:junit-platform-runner:1.8.2'
|
||||||
|
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'com.github.prominence'
|
||||||
|
version = '3.0.0-SNAPSHOT'
|
||||||
|
description = 'Java OpenWeatherMap API'
|
||||||
|
java.sourceCompatibility = JavaVersion.VERSION_11
|
||||||
|
|
||||||
|
ext {
|
||||||
|
isReleaseVersion = !version.endsWith("SNAPSHOT")
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
withSourcesJar()
|
||||||
|
withJavadocJar()
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = ossrhUsername
|
||||||
|
password = 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
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
compile('com.github.prominence:openweathermap-api:2.3.0')
|
||||||
|
```
|
||||||
|
|
||||||
|
### How to use:
|
||||||
|
|
||||||
|
Firstly, you need to create the instance of `OpenWeatherMapClient` class:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapClient openWeatherClient = new OpenWeatherMapClient(API_TOKEN);
|
||||||
|
```
|
||||||
|
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
||||||
|
|
||||||
|
Currently, available APIs are:
|
||||||
|
* `currentWeather()`
|
||||||
|
* `forecast5Day3HourStep()`
|
||||||
|
* `oneCall()`
|
||||||
|
* `airPollution()`
|
||||||
|
|
||||||
|
Also, it is possible to set timeouts for the requests on `openWeatherClient` object:
|
||||||
|
```java
|
||||||
|
openWeatherClient.setReadTimeout(1000);
|
||||||
|
openWeatherClient.setConnectTimeout(1000);
|
||||||
|
```
|
||||||
|
Timeout settings are passed to the requesters as a copy.
|
||||||
|
|
||||||
|
Default(more or less) customization points:
|
||||||
|
```java
|
||||||
|
...
|
||||||
|
// response language
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
...
|
||||||
|
// response units of measure
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
Available output forms:
|
||||||
|
* `asJava()`
|
||||||
|
* `asJSON()`
|
||||||
|
|
||||||
|
Additional output forms, available for several APIs:
|
||||||
|
* `asXML()`
|
||||||
|
* `asHTML()`
|
||||||
|
|
||||||
|
_All response forms can be in **sync** and **async** variants._
|
||||||
|
|
||||||
|
#### Current weather data
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final String weatherJson = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final Weather weather = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final List<Weather> weatherList = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.multiple()
|
||||||
|
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
|
||||||
|
.language(Language.GERMAN)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<String> weatherXmlFuture = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byZipCodeAndCountry("220015", "by")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.weather.Weather`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getCalculationTime()` | Returns `LocalDateTime` object with data calculation time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()`| Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last one hour and/or the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last one hour and/or the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||||
|
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset` and `coordinate`. |
|
||||||
|
| `toString()` | Returns informative string for the whole available weather information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
Location: Minsk(BY), Weather: clear sky, -4.22 ℃, 1020.0 hPa, Clouds: 0%
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 5 day / 3-hour forecast
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final Forecast forecast = openWeatherClient
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.count(15)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String forecastJson = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityName("New York", "NY", "US")
|
||||||
|
.language(Language.SPANISH)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.count(15)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
CompletableFuture<String> forecastFuture = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityId(350001514)
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.count(15)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String forecastXml = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byZipCodeInUSA("10005")
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.forecast.free.Forecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset`, `coordinate` and `population`. |
|
||||||
|
| `getWeatherForecasts()` | Returns list of `WeatherForecast` objects with forecast information. |
|
||||||
|
| `toString()` | Returns informative string for the whole available forecast information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
A forecast for Minsk with 15 timestamps.
|
||||||
|
```
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.forecast.WeatherForecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||||
|
| `getForecastTimeISO()` | Returns String with time of data forecasted, ISO, UTC. |
|
||||||
|
| `getDayTime()` | Returns enumerations representing the part of day(day, night). |
|
||||||
|
| `toString()` | Returns informative string for the forecast of particular timestamp. |
|
||||||
|
|
||||||
|
#### One Call API
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final CurrentWeatherData currentWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CurrentWeatherData currentWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.exclude(OneCallResultOptions.CURRENT, OneCallResultOptions.MINUTELY)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<CurrentWeatherData> currentWeatherDataFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String responseJson = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final HistoricalWeatherData historicalWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String responseJson = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<HistoricalWeatherData> historicalWeatherDataFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<String> responseJsonFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|--------------------------------------------------------------------------------|
|
||||||
|
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||||
|
| `getTimezone()` | Returns location timezone object. |
|
||||||
|
| `getTimezoneOffset()` | Returns zone offset. |
|
||||||
|
| `getCurrent()` | Returns `Current` object with current weather state if available. |
|
||||||
|
| `getMinutelyList()` | Returns list of `Minutely` objects if available. |
|
||||||
|
| `getHourlyList()` | Returns list of `Houlry` objects if available. |
|
||||||
|
| `getDailyList()` | Returns list of `Daily` objects if available. |
|
||||||
|
| `getAlerts()` | Returns list of `Alert` objects if available. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.Current`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Minutely`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getPrecipitationVolume()` | Returns precipitation volume. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Hourly`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
||||||
|
| `getProbabilityOfPrecipitationPercentage()` | Returns probability of precipitation percentage. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Daily`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getMoonriseTime()` | Returns `LocalDateTime` object with moonrise time. |
|
||||||
|
| `getMoonsetTime()` | Returns `LocalDateTime` object with moonset time. |
|
||||||
|
| `getMoonPhase()` | Returns `MoonPhase` object with `MoonType` info and value. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `DailyTemperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
||||||
|
| `getProbabilityOfPrecipitationPercentage()` | Returns probability of precipitation percentage. |
|
||||||
|
| `getRain()` | Returns `DailyRain` object. Available fields: `value`. |
|
||||||
|
| `getSnow()` | Returns `DailySnow` object. Available fields: `value`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Alert`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|------------------------------|--------------------------------------------------------|
|
||||||
|
| `getSenderName()` | Returns alert sender name. |
|
||||||
|
| `getEventName()` | Returns alert event name. |
|
||||||
|
| `getStartTime()` | Returns `LocalDateTime` when event should start. |
|
||||||
|
| `getEndTime()` | Returns `LocalDateTime` when event should end. |
|
||||||
|
| `getDescription()` | Returns alert description. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------|
|
||||||
|
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||||
|
| `getTimezone()` | Returns location timezone object. |
|
||||||
|
| `getTimezoneOffset()` | Returns zone offset. |
|
||||||
|
| `getHistoricalWeather()` | Returns `HistoricalWeather` object with historical weather state. |
|
||||||
|
| `getHourlyList()` | Returns list of `HourlyHistorical` objects. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeather`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HourlyHistorical`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
#### Air Pollution API
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final AirPollutionDetails airPollutionDetails = openWeatherClient
|
||||||
|
.airPollution()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final AirPollutionDetails airPollutionDetails = openWeatherClient
|
||||||
|
.airPollution()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------------------|
|
||||||
|
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||||
|
| `getAirPollutionRecords()` | Returns list of `AirPollutionRecord` objects. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionRecord`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with air pollution forecast time. |
|
||||||
|
| `getAirQualityIndex()` | Returns `AirQualityIndex` object. |
|
||||||
|
| `getCO()` | Returns carbon monoxide concentration value in μg/m^3.s. |
|
||||||
|
| `getCarbonMonoxide()` | An alias for `getCO()` method. |
|
||||||
|
| `getNO()` | Returns nitrogen monoxide concentration value in μg/m^3. |
|
||||||
|
| `getNitrogenMonoxide()` | An alias for `getNO()` method. |
|
||||||
|
| `getNO2()` | Returns nitrogen dioxide concentration value in μg/m^3. |
|
||||||
|
| `getNitrogenDioxide()` | An alias for `getNO2()` method. |
|
||||||
|
| `getO3()` | Returns ozone concentration value in μg/m^3. |
|
||||||
|
| `getOzone()` | An alias for `getO3()` method. |
|
||||||
|
| `getSO2()` | Returns sulphur dioxide concentration value in μg/m^3. |
|
||||||
|
| `getSulphurDioxide()` | An alias for `getSO2()` method. |
|
||||||
|
| `getPM2_5()` | Returns fine particles matter concentration value in μg/m^3. |
|
||||||
|
| `getFineParticlesMatter()` | An alias for `getPM2_5()` method. |
|
||||||
|
| `getPM10()` | Returns coarse particulate matter concentration value in μg/m^3. |
|
||||||
|
| `getCoarseParticulateMatter()`| An alias for `getPM10()` method. |
|
||||||
|
| `getNH3()` | Returns ammonia concentration value in μg/m^3. |
|
||||||
|
| `getAmmonia()` | An alias for `getNH3()` method. |
|
||||||
|
|
||||||
|
### Constants and options
|
||||||
|
|
||||||
|
#### Language
|
||||||
|
| Constant | Description |
|
||||||
|
|------------------------------|-------------------------------|
|
||||||
|
| Language.AFRIKAANS | Afrikaans language. |
|
||||||
|
| Language.ALBANIAN | ALBANIAN language. |
|
||||||
|
| Language.ARABIC | Arabic language. |
|
||||||
|
| Language.AZERBAIJANI | Azerbaijani language. |
|
||||||
|
| Language.BULGARIAN | Bulgarian language. |
|
||||||
|
| Language.CATALAN | Catalan language. |
|
||||||
|
| Language.CZECH | Czech language. |
|
||||||
|
| Language.DANISH | Danish language. |
|
||||||
|
| Language.GERMAN | German language. |
|
||||||
|
| Language.GREEK | Greek language. |
|
||||||
|
| Language.ENGLISH | English language. |
|
||||||
|
| Language.BASQUE | Basque language. |
|
||||||
|
| Language.PERSIAN | Persian (Farsi) language. |
|
||||||
|
| Language.FINNISH | Finnish language. |
|
||||||
|
| Language.FRENCH | French language. |
|
||||||
|
| Language.GALICIAN | Galician language. |
|
||||||
|
| Language.HEBREW | Hebrew language. |
|
||||||
|
| Language.HINDI | Hindi language. |
|
||||||
|
| Language.CROATIAN | Croatian language. |
|
||||||
|
| Language.HUNGARIAN | Hungarian language. |
|
||||||
|
| Language.INDONESIAN | Indonesian language. |
|
||||||
|
| Language.ITALIAN | Italian language. |
|
||||||
|
| Language.JAPANESE | Japanese language. |
|
||||||
|
| Language.KOREAN | Korean language. |
|
||||||
|
| Language.LATVIAN | Latvian language. |
|
||||||
|
| Language.LITHUANIAN | Lithuanian language. |
|
||||||
|
| Language.MACEDONIAN | Macedonian language. |
|
||||||
|
| Language.NORWEGIAN | Norwegian language. |
|
||||||
|
| Language.DUTCH | Dutch language. |
|
||||||
|
| Language.POLISH | Polish language. |
|
||||||
|
| Language.PORTUGUESE | Portuguese language. |
|
||||||
|
| Language.PORTUGUES_BRAZIL | Português Brasil language. |
|
||||||
|
| Language.ROMANIAN | Romanian language. |
|
||||||
|
| Language.RUSSIAN | Russian language. |
|
||||||
|
| Language.SWEDISH | Swedish language. |
|
||||||
|
| Language.SLOVAK | Slovak language. |
|
||||||
|
| Language.SLOVENIAN | Slovenian language. |
|
||||||
|
| Language.SPANISH | Spanish language. |
|
||||||
|
| Language.SERBIAN | Serbian language. |
|
||||||
|
| Language.THAI | Thai language. |
|
||||||
|
| Language.TURKISH | Turkish language. |
|
||||||
|
| Language.UKRAINIAN | Ukrainian language. |
|
||||||
|
| Language.VIETNAMESE | Vietnamese language. |
|
||||||
|
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||||
|
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||||
|
| Language.ZULU | Zulu language. |
|
||||||
|
|
||||||
|
#### Unit
|
||||||
|
| Constant | Description |
|
||||||
|
|----------------------|------------------------------------------------|
|
||||||
|
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
|
||||||
|
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
|
||||||
|
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow). |
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
* com.fasterxml.jackson.core:jackson-databind:2.13.2.2
|
||||||
|
* org.slf4j:slf4j-api:1.7.36 (*compile*)
|
||||||
|
* org.junit.jupiter:junit-jupiter-engine:5.8.2 (*test*)
|
||||||
|
* org.junit.platform:junit-platform-runner:1.8.2 (*test*)
|
||||||
+118
-72
@@ -4,20 +4,56 @@
|
|||||||
* One Call API
|
* One Call API
|
||||||
* Air Pollution
|
* Air Pollution
|
||||||
|
|
||||||
|
|
||||||
|
Other:
|
||||||
|
* Request timeout settings
|
||||||
|
|
||||||
### Maven coordinates:
|
### Maven coordinates:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.prominence</groupId>
|
<groupId>com.github.prominence</groupId>
|
||||||
<artifactId>openweathermap-api</artifactId>
|
<artifactId>openweathermap-api</artifactId>
|
||||||
<version>2.1.1-SNAPSHOT</version>
|
<version>3.0.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</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:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:2.1.1-SNAPSHOT')
|
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:
|
### How to use:
|
||||||
@@ -34,6 +70,13 @@ Currently, available APIs are:
|
|||||||
* `oneCall()`
|
* `oneCall()`
|
||||||
* `airPollution()`
|
* `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:
|
Default(more or less) customization points:
|
||||||
```java
|
```java
|
||||||
...
|
...
|
||||||
@@ -352,22 +395,25 @@ You are able to set preferable options(via chain methods) and execute appropriat
|
|||||||
|
|
||||||
`com.github.prominence.openweathermap.api.model.onecall.current.Daily`'s useful public methods(setters are not listed):
|
`com.github.prominence.openweathermap.api.model.onecall.current.Daily`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
|-----------------------------------------------|---------------------------------------------------------------------------------------------------|
|
|---------------------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
| `getMoonriseTime()` | Returns `LocalDateTime` object with moonrise time. |
|
||||||
| `getTemperature()` | Returns `DailyTemperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
| `getMoonsetTime()` | Returns `LocalDateTime` object with moonset time. |
|
||||||
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
| `getMoonPhase()` | Returns `MoonPhase` object with `MoonType` info and value. |
|
||||||
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
| `getTemperature()` | Returns `DailyTemperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
| `getUvIndex()` | Returns UV index value. |
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
| `getProbabilityOfPrecipitationPercentage()` | Returns probability of precipitation percentage. |
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
| `getRain()` | Returns `DailyRain` object. Available fields: `value`. |
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
| `getSnow()` | Returns `DailySnow` object. Available fields: `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):
|
`com.github.prominence.openweathermap.api.model.onecall.current.Alert`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
@@ -475,54 +521,54 @@ final AirPollutionDetails airPollutionDetails = openWeatherClient
|
|||||||
### Constants and options
|
### Constants and options
|
||||||
|
|
||||||
#### Language
|
#### Language
|
||||||
| Constant | Description |
|
| Constant | Description |
|
||||||
|-----------------------------------|-------------------------------|
|
|------------------------------|-------------------------------|
|
||||||
| Language.AFRIKAANS | Afrikaans language. |
|
| Language.AFRIKAANS | Afrikaans language. |
|
||||||
| Language.ALBANIAN | ALBANIAN language. |
|
| Language.ALBANIAN | ALBANIAN language. |
|
||||||
| Language.ARABIC | Arabic language. |
|
| Language.ARABIC | Arabic language. |
|
||||||
| Language.AZERBAIJANI | Azerbaijani language. |
|
| Language.AZERBAIJANI | Azerbaijani language. |
|
||||||
| Language.BULGARIAN | Bulgarian language. |
|
| Language.BULGARIAN | Bulgarian language. |
|
||||||
| Language.CATALAN | Catalan language. |
|
| Language.CATALAN | Catalan language. |
|
||||||
| Language.CZECH | Czech language. |
|
| Language.CZECH | Czech language. |
|
||||||
| Language.DANISH | Danish language. |
|
| Language.DANISH | Danish language. |
|
||||||
| Language.GERMAN | German language. |
|
| Language.GERMAN | German language. |
|
||||||
| Language.GREEK | Greek language. |
|
| Language.GREEK | Greek language. |
|
||||||
| Language.ENGLISH | English language. |
|
| Language.ENGLISH | English language. |
|
||||||
| Language.BASQUE | Basque language. |
|
| Language.BASQUE | Basque language. |
|
||||||
| Language.PERSIAN | Persian (Farsi) language. |
|
| Language.PERSIAN | Persian (Farsi) language. |
|
||||||
| Language.FINNISH | Finnish language. |
|
| Language.FINNISH | Finnish language. |
|
||||||
| Language.FRENCH | French language. |
|
| Language.FRENCH | French language. |
|
||||||
| Language.GALICIAN | Galician language. |
|
| Language.GALICIAN | Galician language. |
|
||||||
| Language.HEBREW | Hebrew language. |
|
| Language.HEBREW | Hebrew language. |
|
||||||
| Language.HINDI | Hindi language. |
|
| Language.HINDI | Hindi language. |
|
||||||
| Language.CROATIAN | Croatian language. |
|
| Language.CROATIAN | Croatian language. |
|
||||||
| Language.HUNGARIAN | Hungarian language. |
|
| Language.HUNGARIAN | Hungarian language. |
|
||||||
| Language.INDONESIAN | Indonesian language. |
|
| Language.INDONESIAN | Indonesian language. |
|
||||||
| Language.ITALIAN | Italian language. |
|
| Language.ITALIAN | Italian language. |
|
||||||
| Language.JAPANESE | Japanese language. |
|
| Language.JAPANESE | Japanese language. |
|
||||||
| Language.KOREAN | Korean language. |
|
| Language.KOREAN | Korean language. |
|
||||||
| Language.LATVIAN | Latvian language. |
|
| Language.LATVIAN | Latvian language. |
|
||||||
| Language.LITHUANIAN | Lithuanian language. |
|
| Language.LITHUANIAN | Lithuanian language. |
|
||||||
| Language.MACEDONIAN | Macedonian language. |
|
| Language.MACEDONIAN | Macedonian language. |
|
||||||
| Language.NORWEGIAN | Norwegian language. |
|
| Language.NORWEGIAN | Norwegian language. |
|
||||||
| Language.DUTCH | Dutch language. |
|
| Language.DUTCH | Dutch language. |
|
||||||
| Language.POLISH | Polish language. |
|
| Language.POLISH | Polish language. |
|
||||||
| Language.PORTUGUESE | Portuguese language. |
|
| Language.PORTUGUESE | Portuguese language. |
|
||||||
| Language.PORTUGUES_BRAZIL | Português Brasil language. |
|
| Language.PORTUGUES_BRAZIL | Português Brasil language. |
|
||||||
| Language.ROMANIAN | Romanian language. |
|
| Language.ROMANIAN | Romanian language. |
|
||||||
| Language.RUSSIAN | Russian language. |
|
| Language.RUSSIAN | Russian language. |
|
||||||
| Language.SWEDISH | Swedish language. |
|
| Language.SWEDISH | Swedish language. |
|
||||||
| Language.SLOVAK | Slovak language. |
|
| Language.SLOVAK | Slovak language. |
|
||||||
| Language.SLOVENIAN | Slovenian language. |
|
| Language.SLOVENIAN | Slovenian language. |
|
||||||
| Language.SPANISH | Spanish language. |
|
| Language.SPANISH | Spanish language. |
|
||||||
| Language.SERBIAN | Serbian language. |
|
| Language.SERBIAN | Serbian language. |
|
||||||
| Language.THAI | Thai language. |
|
| Language.THAI | Thai language. |
|
||||||
| Language.TURKISH | Turkish language. |
|
| Language.TURKISH | Turkish language. |
|
||||||
| Language.UKRANIAN | Ukrainian language. |
|
| Language.UKRAINIAN | Ukrainian language. |
|
||||||
| Language.VIETNAMESE | Vietnamese language. |
|
| Language.VIETNAMESE | Vietnamese language. |
|
||||||
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||||
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||||
| Language.ZULU | Zulu language. |
|
| Language.ZULU | Zulu language. |
|
||||||
|
|
||||||
#### Unit
|
#### Unit
|
||||||
| Constant | Description |
|
| Constant | Description |
|
||||||
@@ -532,7 +578,7 @@ final AirPollutionDetails airPollutionDetails = openWeatherClient
|
|||||||
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow). |
|
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow). |
|
||||||
|
|
||||||
### Dependencies
|
### Dependencies
|
||||||
* com.fasterxml.jackson.core:jackson-databind:2.12.2
|
* com.fasterxml.jackson.core:jackson-databind:2.13.2.2
|
||||||
* org.slf4j:slf4j-api:1.7.30 (*compile*)
|
* org.slf4j:slf4j-api:1.7.36 (*compile*)
|
||||||
* org.junit.jupiter:junit-jupiter-engine:5.7.1 (*test*)
|
* org.junit.jupiter:junit-jupiter-engine:5.8.2 (*test*)
|
||||||
* org.junit.platform:junit-platform-runner:1.7.1 (*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
|
||||||
@@ -1,187 +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>2.2.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>https://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>
|
|
||||||
<version>3.8.1</version>
|
|
||||||
<configuration>
|
|
||||||
<source>8</source>
|
|
||||||
<target>8</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<version>3.2.0</version>
|
|
||||||
<configuration>
|
|
||||||
<excludes>
|
|
||||||
<exclude>**/test/*</exclude>
|
|
||||||
</excludes>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.sonatype.plugins</groupId>
|
|
||||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
|
||||||
<version>1.6.8</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>3.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>3.2.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>8</source>
|
|
||||||
</configuration>
|
|
||||||
<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.6</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>sign-artifacts</id>
|
|
||||||
<phase>verify</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>sign</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.jacoco</groupId>
|
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
|
||||||
<version>0.8.6</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>prepare-agent</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>report</id>
|
|
||||||
<phase>test</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>report</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<version>2.22.2</version>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
|
||||||
<artifactId>jackson-databind</artifactId>
|
|
||||||
<version>2.12.2</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>1.7.30</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
|
||||||
<version>5.7.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.platform</groupId>
|
|
||||||
<artifactId>junit-platform-runner</artifactId>
|
|
||||||
<version>1.7.1</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = 'openweathermap-api'
|
||||||
@@ -23,16 +23,14 @@
|
|||||||
package com.github.prominence.openweathermap.api;
|
package com.github.prominence.openweathermap.api;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.annotation.SubscriptionAvailability;
|
import com.github.prominence.openweathermap.api.annotation.SubscriptionAvailability;
|
||||||
|
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequester;
|
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequester;
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequesterImpl;
|
|
||||||
import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThreeHourStepForecastRequester;
|
import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThreeHourStepForecastRequester;
|
||||||
import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThreeHourStepForecastRequesterImpl;
|
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherRequester;
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherRequesterImpl;
|
|
||||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester;
|
||||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequesterImpl;
|
|
||||||
|
|
||||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.*;
|
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.ALL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main public API client to communicate with OpenWeatherMap services.
|
* The main public API client to communicate with OpenWeatherMap services.
|
||||||
@@ -40,6 +38,7 @@ import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.*;
|
|||||||
*/
|
*/
|
||||||
public class OpenWeatherMapClient {
|
public class OpenWeatherMapClient {
|
||||||
private final String apiKey;
|
private final String apiKey;
|
||||||
|
private final TimeoutSettings timeoutSettings = new TimeoutSettings();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created OpenWeatherMap client object.
|
* Created OpenWeatherMap client object.
|
||||||
@@ -49,13 +48,21 @@ public class OpenWeatherMapClient {
|
|||||||
this.apiKey = apiKey;
|
this.apiKey = apiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setConnectionTimeout(int connectionTimeout) {
|
||||||
|
timeoutSettings.setConnectionTimeout(connectionTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReadTimeout(int readTimeout) {
|
||||||
|
timeoutSettings.setReadTimeout(readTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current Weather <a href="https://openweathermap.org/current">API</a>.
|
* Current Weather <a href="https://openweathermap.org/current">API</a>.
|
||||||
* @return requester for retrieving current weather information.
|
* @return requester for retrieving current weather information.
|
||||||
*/
|
*/
|
||||||
@SubscriptionAvailability(plans = ALL)
|
@SubscriptionAvailability(plans = ALL)
|
||||||
public CurrentWeatherRequester currentWeather() {
|
public CurrentWeatherRequester currentWeather() {
|
||||||
return new CurrentWeatherRequesterImpl(apiKey);
|
return new CurrentWeatherRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,7 +71,7 @@ public class OpenWeatherMapClient {
|
|||||||
*/
|
*/
|
||||||
@SubscriptionAvailability(plans = ALL)
|
@SubscriptionAvailability(plans = ALL)
|
||||||
public FiveDayThreeHourStepForecastRequester forecast5Day3HourStep() {
|
public FiveDayThreeHourStepForecastRequester forecast5Day3HourStep() {
|
||||||
return new FiveDayThreeHourStepForecastRequesterImpl(apiKey);
|
return new FiveDayThreeHourStepForecastRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,7 +81,7 @@ public class OpenWeatherMapClient {
|
|||||||
*/
|
*/
|
||||||
@SubscriptionAvailability(plans = ALL)
|
@SubscriptionAvailability(plans = ALL)
|
||||||
public OneCallWeatherRequester oneCall() {
|
public OneCallWeatherRequester oneCall() {
|
||||||
return new OneCallWeatherRequesterImpl(apiKey);
|
return new OneCallWeatherRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,6 +91,6 @@ public class OpenWeatherMapClient {
|
|||||||
*/
|
*/
|
||||||
@SubscriptionAvailability(plans = ALL)
|
@SubscriptionAvailability(plans = ALL)
|
||||||
public AirPollutionRequester airPollution() {
|
public AirPollutionRequester airPollution() {
|
||||||
return new AirPollutionRequesterImpl(apiKey);
|
return new AirPollutionRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-24
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,31 +20,39 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request;
|
package com.github.prominence.openweathermap.api.conf;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
public class TimeoutSettings {
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
private Integer connectionTimeout;
|
||||||
|
private Integer readTimeout;
|
||||||
|
|
||||||
/**
|
public TimeoutSettings() {
|
||||||
* The interface Request customizer.
|
this(2000, 2000);
|
||||||
*
|
}
|
||||||
* @param <T> the type parameter
|
|
||||||
*/
|
|
||||||
public interface RequestCustomizer<T extends RequestCustomizer<?>> {
|
|
||||||
|
|
||||||
/**
|
public TimeoutSettings(Integer connectionTimeout, Integer readTimeout) {
|
||||||
* Customize language.
|
this.connectionTimeout = connectionTimeout;
|
||||||
*
|
this.readTimeout = readTimeout;
|
||||||
* @param language the language
|
}
|
||||||
* @return the request customizer
|
|
||||||
*/
|
|
||||||
T language(Language language);
|
|
||||||
|
|
||||||
/**
|
public TimeoutSettings(TimeoutSettings from) {
|
||||||
* Customize unit system.
|
this.connectionTimeout = from.connectionTimeout;
|
||||||
*
|
this.readTimeout = from.readTimeout;
|
||||||
* @param unitSystem the unit system
|
}
|
||||||
* @return the request customizer
|
|
||||||
*/
|
public Integer getConnectionTimeout() {
|
||||||
T unitSystem(UnitSystem unitSystem);
|
return connectionTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnectionTimeout(Integer connectionTimeout) {
|
||||||
|
this.connectionTimeout = connectionTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getReadTimeout() {
|
||||||
|
return readTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReadTimeout(Integer readTimeout) {
|
||||||
|
this.readTimeout = readTimeout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -233,9 +233,9 @@ public enum Language {
|
|||||||
TURKISH("tr"),
|
TURKISH("tr"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ukranian language.
|
* Ukrainian language.
|
||||||
*/
|
*/
|
||||||
UKRANIAN("uk"),
|
UKRAINIAN("uk"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vietnamese language.
|
* Vietnamese language.
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.enums;
|
||||||
|
|
||||||
|
public enum MoonType {
|
||||||
|
NEW_MOON,
|
||||||
|
WAXING_CRESCENT,
|
||||||
|
FIRST_QUARTER_MOON,
|
||||||
|
WAXING_GIBBOUS,
|
||||||
|
FULL_MOON,
|
||||||
|
WANING_GIBBOUS,
|
||||||
|
LAST_QUARTER_MOON,
|
||||||
|
WANING_CRESCENT,
|
||||||
|
INVALID;
|
||||||
|
|
||||||
|
private static final double precision = 0.000001d;
|
||||||
|
|
||||||
|
public static MoonType valueOf(double numericValue) {
|
||||||
|
if (equals(numericValue, 0) || equals(numericValue, 1)) {
|
||||||
|
return NEW_MOON;
|
||||||
|
} else if (equals(numericValue, 0.25)) {
|
||||||
|
return FIRST_QUARTER_MOON;
|
||||||
|
} else if (equals(numericValue, 0.5)) {
|
||||||
|
return FULL_MOON;
|
||||||
|
} else if (equals(numericValue, 0.75)) {
|
||||||
|
return LAST_QUARTER_MOON;
|
||||||
|
} else if (numericValue > 0 && numericValue < 0.25) {
|
||||||
|
return WAXING_CRESCENT;
|
||||||
|
} else if (numericValue > 0.25 && numericValue < 0.5) {
|
||||||
|
return WAXING_GIBBOUS;
|
||||||
|
} else if (numericValue > 0.5 && numericValue < 0.75) {
|
||||||
|
return WANING_GIBBOUS;
|
||||||
|
} else if (numericValue > 0.75 && numericValue < 1) {
|
||||||
|
return WANING_CRESCENT;
|
||||||
|
}
|
||||||
|
return INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean equals(double d1, double d2) {
|
||||||
|
return Math.abs(d1 - d2) < precision;
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
-10
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,15 +20,23 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request;
|
package com.github.prominence.openweathermap.api.enums;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
public enum ResponseType {
|
||||||
|
HTML("html"),
|
||||||
|
XML("xml");
|
||||||
|
|
||||||
/**
|
private final String value;
|
||||||
* The interface Async request terminator.
|
|
||||||
*
|
ResponseType(String value) {
|
||||||
* @param <T> the type parameter
|
this.value = value;
|
||||||
* @param <S> the type parameter
|
}
|
||||||
*/
|
|
||||||
public interface AsyncRequestTerminator<T, S> extends RequestTerminator<CompletableFuture<T>, CompletableFuture<S>> {
|
/**
|
||||||
|
* Returns language's value.
|
||||||
|
* @return value.
|
||||||
|
*/
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+18
-20
@@ -1,28 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright (c) 2022 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
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
* in the Software without restriction, including without limitation the rights
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* * in the Software without restriction, including without limitation the rights
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* furnished to do so, subject to the following conditions:
|
||||||
* * 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.
|
|
||||||
*
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
package com.github.prominence.openweathermap.api.mapper;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather;
|
package com.github.prominence.openweathermap.api.mapper;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
package com.github.prominence.openweathermap.api.mapper;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
+14
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall;
|
package com.github.prominence.openweathermap.api.mapper;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
@@ -200,6 +200,18 @@ public class OneCallWeatherResponseMapper {
|
|||||||
daily.setForecastTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(dailyNode.get("dt").asInt()), TimeZone.getDefault().toZoneId()));
|
daily.setForecastTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(dailyNode.get("dt").asInt()), TimeZone.getDefault().toZoneId()));
|
||||||
daily.setSunriseTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(dailyNode.get("sunrise").asInt()), TimeZone.getDefault().toZoneId()));
|
daily.setSunriseTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(dailyNode.get("sunrise").asInt()), TimeZone.getDefault().toZoneId()));
|
||||||
daily.setSunsetTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(dailyNode.get("sunset").asInt()), TimeZone.getDefault().toZoneId()));
|
daily.setSunsetTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(dailyNode.get("sunset").asInt()), TimeZone.getDefault().toZoneId()));
|
||||||
|
final JsonNode moonriseTimeNode = dailyNode.get("moonrise");
|
||||||
|
if (moonriseTimeNode != null) {
|
||||||
|
daily.setMoonriseTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(moonriseTimeNode.asInt()), TimeZone.getDefault().toZoneId()));
|
||||||
|
}
|
||||||
|
final JsonNode moonsetTimeNode = dailyNode.get("moonset");
|
||||||
|
if (moonsetTimeNode != null) {
|
||||||
|
daily.setMoonsetTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(moonsetTimeNode.asInt()), TimeZone.getDefault().toZoneId()));
|
||||||
|
}
|
||||||
|
final JsonNode moonPhaseNode = dailyNode.get("moon_phase");
|
||||||
|
if (moonPhaseNode != null) {
|
||||||
|
daily.setMoonPhase(new MoonPhase(moonPhaseNode.asDouble()));
|
||||||
|
}
|
||||||
|
|
||||||
daily.setWeatherState(parseWeatherState(dailyNode.get("weather").get(0)));
|
daily.setWeatherState(parseWeatherState(dailyNode.get("weather").get(0)));
|
||||||
daily.setTemperature(parseDailyTemperature(dailyNode));
|
daily.setTemperature(parseDailyTemperature(dailyNode));
|
||||||
+63
-2
@@ -39,6 +39,10 @@ public class Daily {
|
|||||||
private LocalDateTime sunriseTime;
|
private LocalDateTime sunriseTime;
|
||||||
private LocalDateTime sunsetTime;
|
private LocalDateTime sunsetTime;
|
||||||
|
|
||||||
|
private LocalDateTime moonriseTime;
|
||||||
|
private LocalDateTime moonsetTime;
|
||||||
|
private MoonPhase moonPhase;
|
||||||
|
|
||||||
private WeatherState weatherState;
|
private WeatherState weatherState;
|
||||||
private DailyTemperature temperature;
|
private DailyTemperature temperature;
|
||||||
private AtmosphericPressure atmosphericPressure;
|
private AtmosphericPressure atmosphericPressure;
|
||||||
@@ -104,6 +108,60 @@ public class Daily {
|
|||||||
this.sunsetTime = sunsetTime;
|
this.sunsetTime = sunsetTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets moonrise time.
|
||||||
|
*
|
||||||
|
* @return the moonrise time
|
||||||
|
*/
|
||||||
|
public LocalDateTime getMoonriseTime() {
|
||||||
|
return moonriseTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets moonrise time.
|
||||||
|
*
|
||||||
|
* @param moonriseTime the moonrise time
|
||||||
|
*/
|
||||||
|
public void setMoonriseTime(LocalDateTime moonriseTime) {
|
||||||
|
this.moonriseTime = moonriseTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets moonset time.
|
||||||
|
*
|
||||||
|
* @return the moonset time
|
||||||
|
*/
|
||||||
|
public LocalDateTime getMoonsetTime() {
|
||||||
|
return moonsetTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets moonset time.
|
||||||
|
*
|
||||||
|
* @param moonsetTime the moonset time
|
||||||
|
*/
|
||||||
|
public void setMoonsetTime(LocalDateTime moonsetTime) {
|
||||||
|
this.moonsetTime = moonsetTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets moon phase.
|
||||||
|
*
|
||||||
|
* @return the moon phase
|
||||||
|
*/
|
||||||
|
public MoonPhase getMoonPhase() {
|
||||||
|
return moonPhase;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets moon phase.
|
||||||
|
*
|
||||||
|
* @param moonPhase the moon phase
|
||||||
|
*/
|
||||||
|
public void setMoonPhase(MoonPhase moonPhase) {
|
||||||
|
this.moonPhase = moonPhase;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets weather state.
|
* Gets weather state.
|
||||||
*
|
*
|
||||||
@@ -311,6 +369,9 @@ public class Daily {
|
|||||||
return Objects.equals(forecastTime, daily.forecastTime) &&
|
return Objects.equals(forecastTime, daily.forecastTime) &&
|
||||||
Objects.equals(sunriseTime, daily.sunriseTime) &&
|
Objects.equals(sunriseTime, daily.sunriseTime) &&
|
||||||
Objects.equals(sunsetTime, daily.sunsetTime) &&
|
Objects.equals(sunsetTime, daily.sunsetTime) &&
|
||||||
|
Objects.equals(moonriseTime, daily.moonriseTime) &&
|
||||||
|
Objects.equals(moonsetTime, daily.moonsetTime) &&
|
||||||
|
Objects.equals(moonPhase, daily.moonPhase) &&
|
||||||
Objects.equals(weatherState, daily.weatherState) &&
|
Objects.equals(weatherState, daily.weatherState) &&
|
||||||
Objects.equals(temperature, daily.temperature) &&
|
Objects.equals(temperature, daily.temperature) &&
|
||||||
Objects.equals(atmosphericPressure, daily.atmosphericPressure) &&
|
Objects.equals(atmosphericPressure, daily.atmosphericPressure) &&
|
||||||
@@ -325,7 +386,7 @@ public class Daily {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(forecastTime, sunriseTime, sunsetTime, weatherState, temperature, atmosphericPressure, humidity, wind, clouds, uvIndex, probabilityOfPrecipitation, rain, snow);
|
return Objects.hash(forecastTime, sunriseTime, sunsetTime, moonriseTime, moonsetTime, moonPhase, weatherState, temperature, atmosphericPressure, humidity, wind, clouds, uvIndex, probabilityOfPrecipitation, rain, snow);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -355,7 +416,7 @@ public class Daily {
|
|||||||
}
|
}
|
||||||
if (clouds != null) {
|
if (clouds != null) {
|
||||||
stringBuilder.append(" Clouds: ");
|
stringBuilder.append(" Clouds: ");
|
||||||
stringBuilder.append(clouds.toString());
|
stringBuilder.append(clouds);
|
||||||
stringBuilder.append('.');
|
stringBuilder.append('.');
|
||||||
}
|
}
|
||||||
if (rain != null) {
|
if (rain != null) {
|
||||||
|
|||||||
+38
-21
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,27 +20,44 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request;
|
package com.github.prominence.openweathermap.api.model.onecall.current;
|
||||||
|
|
||||||
/**
|
import com.github.prominence.openweathermap.api.enums.MoonType;
|
||||||
* The interface Request terminator.
|
|
||||||
*
|
|
||||||
* @param <T> the type parameter
|
|
||||||
* @param <S> the type parameter
|
|
||||||
*/
|
|
||||||
public interface RequestTerminator<T, S> {
|
|
||||||
|
|
||||||
/**
|
import java.util.Objects;
|
||||||
* Java object response format.
|
|
||||||
*
|
|
||||||
* @return the java object
|
|
||||||
*/
|
|
||||||
T asJava();
|
|
||||||
|
|
||||||
/**
|
public class MoonPhase {
|
||||||
* JSON response format.
|
private final double value;
|
||||||
*
|
private final MoonType type;
|
||||||
* @return the JSON string
|
|
||||||
*/
|
public MoonPhase(Double value) {
|
||||||
S asJSON();
|
this.value = value;
|
||||||
|
this.type = MoonType.valueOf(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MoonType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
MoonPhase moonPhase = (MoonPhase) o;
|
||||||
|
return Double.compare(moonPhase.value, value) == 0 && type == moonPhase.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(value, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return type.name() + "(" + value + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.ResponseType;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class RequestSettings {
|
||||||
|
|
||||||
|
private static final String LANG_PARAM = "lang";
|
||||||
|
private static final String UNITS_PARAM = "units";
|
||||||
|
private static final String MODE_PARAM = "mode";
|
||||||
|
private static final String API_KEY_PARAM_NAME = "appid";
|
||||||
|
|
||||||
|
private final TimeoutSettings timeoutSettings;
|
||||||
|
|
||||||
|
private final Map<String, String> requestParameters = new HashMap<>(8);
|
||||||
|
|
||||||
|
private final StringBuilder urlAppenderBuilder = new StringBuilder("");
|
||||||
|
|
||||||
|
private Language language = Language.ENGLISH;
|
||||||
|
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
||||||
|
|
||||||
|
public RequestSettings(String apiKey, TimeoutSettings timeoutSettings) {
|
||||||
|
this.putRequestParameter(API_KEY_PARAM_NAME, apiKey);
|
||||||
|
// make a copy
|
||||||
|
this.timeoutSettings = new TimeoutSettings(timeoutSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimeoutSettings getTimeoutSettings() {
|
||||||
|
return timeoutSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnitSystem getUnitSystem() {
|
||||||
|
return unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUnitSystem(UnitSystem unitSystem) {
|
||||||
|
this.putRequestParameter(UNITS_PARAM, unitSystem.getValue());
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Language getLanguage() {
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLanguage(Language language) {
|
||||||
|
this.putRequestParameter(LANG_PARAM, language.getValue());
|
||||||
|
this.language = language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResponseType(ResponseType responseType) {
|
||||||
|
this.putRequestParameter(MODE_PARAM, responseType.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void putRequestParameter(String key, String value) {
|
||||||
|
this.requestParameters.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeRequestParameter(String key) {
|
||||||
|
this.requestParameters.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getRequestParameters() {
|
||||||
|
return requestParameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void appendToURL(String appendix) {
|
||||||
|
urlAppenderBuilder.append(appendix);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringBuilder getUrlAppender() {
|
||||||
|
return urlAppenderBuilder;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Request url builder.
|
|
||||||
*/
|
|
||||||
public class RequestUrlBuilder {
|
|
||||||
|
|
||||||
private static final String API_KEY_PARAM_NAME = "appid";
|
|
||||||
|
|
||||||
private final StringBuilder builder = new StringBuilder("http://api.openweathermap.org/data/2.5/");
|
|
||||||
private final Map<String, Object> requestParameters = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Request url builder.
|
|
||||||
*
|
|
||||||
* @param key the API key
|
|
||||||
*/
|
|
||||||
public RequestUrlBuilder(String key) {
|
|
||||||
requestParameters.put(API_KEY_PARAM_NAME, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Appends value.
|
|
||||||
*
|
|
||||||
* @param value the value
|
|
||||||
*/
|
|
||||||
public void append(String value) {
|
|
||||||
builder.append(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds request parameter.
|
|
||||||
*
|
|
||||||
* @param key the key
|
|
||||||
* @param value the value
|
|
||||||
*/
|
|
||||||
public void addRequestParameter(String key, Object value) {
|
|
||||||
requestParameters.put(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Applies customization.
|
|
||||||
*
|
|
||||||
* @param language the language
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
public void applyCustomization(Language language, UnitSystem unitSystem) {
|
|
||||||
if (language != null) {
|
|
||||||
addRequestParameter("lang", language.getValue());
|
|
||||||
}
|
|
||||||
if (unitSystem != null && unitSystem != UnitSystem.STANDARD) {
|
|
||||||
addRequestParameter("units", unitSystem.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds url string.
|
|
||||||
*
|
|
||||||
* @return the string
|
|
||||||
*/
|
|
||||||
public String buildUrl() {
|
|
||||||
final String joinedParameters = requestParameters.entrySet().stream()
|
|
||||||
.map(entry -> entry.getKey() + "=" + entry.getValue())
|
|
||||||
.collect(Collectors.joining("&"));
|
|
||||||
builder.append('?');
|
|
||||||
builder.append(joinedParameters);
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+29
-3
@@ -24,11 +24,37 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.AirPollutionResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
||||||
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Current air pollution async request terminator.
|
* The type Air pollution async request terminator.
|
||||||
*/
|
*/
|
||||||
public interface AirPollutionAsyncRequestTerminator extends AsyncRequestTerminator<AirPollutionDetails, String> {
|
public class AirPollutionAsyncRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Air pollution async request terminator.
|
||||||
|
*
|
||||||
|
* @param requestSettings request settings object.
|
||||||
|
*/
|
||||||
|
public AirPollutionAsyncRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<AirPollutionDetails> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new AirPollutionResponseMapper().mapToAirPollution(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-61
@@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Air pollution async request terminator.
|
|
||||||
*/
|
|
||||||
public class AirPollutionAsyncRequestTerminatorImpl implements AirPollutionAsyncRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Air pollution async request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
public AirPollutionAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<AirPollutionDetails> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new AirPollutionResponseMapper().mapToAirPollution(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+18
-11
@@ -24,21 +24,28 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Current air pollution request customizer.
|
* The Air Pollution request customizer.
|
||||||
*/
|
*/
|
||||||
public interface AirPollutionRequestCustomizer {
|
public class AirPollutionRequestCustomizer {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* Retrieve current air pollution request terminator.
|
|
||||||
*
|
|
||||||
* @return the current air pollution request terminator
|
|
||||||
*/
|
|
||||||
AirPollutionRequestTerminator retrieve();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve async current air pollution async request terminator.
|
* Instantiates a new Air pollution request customizer.
|
||||||
*
|
*
|
||||||
* @return the current air pollution async request terminator
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
AirPollutionAsyncRequestTerminator retrieveAsync();
|
public AirPollutionRequestCustomizer(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AirPollutionRequestTerminator retrieve() {
|
||||||
|
return new AirPollutionRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AirPollutionAsyncRequestTerminator retrieveAsync() {
|
||||||
|
return new AirPollutionAsyncRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-45
@@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
|
|
||||||
public class AirPollutionRequestCustomizerImpl implements AirPollutionRequestCustomizer {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
public AirPollutionRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AirPollutionRequestTerminator retrieve() {
|
|
||||||
return new AirPollutionRequestTerminatorImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AirPollutionAsyncRequestTerminator retrieveAsync() {
|
|
||||||
return new AirPollutionAsyncRequestTerminatorImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+27
-3
@@ -24,11 +24,35 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.AirPollutionResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Current air pollution request terminator.
|
* The type Air pollution request terminator.
|
||||||
*/
|
*/
|
||||||
public interface AirPollutionRequestTerminator extends RequestTerminator<AirPollutionDetails, String> {
|
public class AirPollutionRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Air pollution request terminator.
|
||||||
|
*
|
||||||
|
* @param requestSettings request settings object.
|
||||||
|
*/
|
||||||
|
public AirPollutionRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AirPollutionDetails asJava() {
|
||||||
|
return new AirPollutionResponseMapper().mapToAirPollution(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-59
@@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Air pollution request terminator.
|
|
||||||
*/
|
|
||||||
public class AirPollutionRequestTerminatorImpl implements AirPollutionRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Air pollution request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
public AirPollutionRequestTerminatorImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AirPollutionDetails asJava() {
|
|
||||||
return new AirPollutionResponseMapper().mapToAirPollution(getRawResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+42
-37
@@ -1,53 +1,58 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* * Copyright (c) 2021 Alexey Zinchenko
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* *
|
||||||
* in the Software without restriction, including without limitation the rights
|
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* * of this software and associated documentation files (the "Software"), to deal
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* * in the Software without restriction, including without limitation the rights
|
||||||
* furnished to do so, subject to the following conditions:
|
* * 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.
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.current.CurrentAirPollutionRequester;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.forecast.ForecastAirPollutionRequester;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.historical.HistoricalAirPollutionRequester;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Air pollution requester.
|
* The type Air pollution requester.
|
||||||
*/
|
*/
|
||||||
public interface AirPollutionRequester {
|
public class AirPollutionRequester {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* Current current air pollution requester.
|
|
||||||
*
|
|
||||||
* @return the current air pollution requester
|
|
||||||
*/
|
|
||||||
CurrentAirPollutionRequester current();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forecast forecast air pollution requester.
|
* Instantiates a new Air pollution requester.
|
||||||
*
|
*
|
||||||
* @return the forecast air pollution requester
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
ForecastAirPollutionRequester forecast();
|
public AirPollutionRequester(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public CurrentAirPollutionRequester current() {
|
||||||
* Historical historical air pollution requester.
|
requestSettings.appendToURL("air_pollution");
|
||||||
*
|
return new CurrentAirPollutionRequester(requestSettings);
|
||||||
* @return the historical air pollution requester
|
}
|
||||||
*/
|
|
||||||
HistoricalAirPollutionRequester historical();
|
public ForecastAirPollutionRequester forecast() {
|
||||||
|
requestSettings.appendToURL("air_pollution/forecast");
|
||||||
|
return new ForecastAirPollutionRequester(requestSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HistoricalAirPollutionRequester historical() {
|
||||||
|
requestSettings.appendToURL("air_pollution/history");
|
||||||
|
return new HistoricalAirPollutionRequester(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-67
@@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.current.CurrentAirPollutionRequester;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.current.CurrentAirPollutionRequesterImpl;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.forecast.ForecastAirPollutionRequester;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.forecast.ForecastAirPollutionRequesterImpl;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.historical.HistoricalAirPollutionRequester;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.historical.HistoricalAirPollutionRequesterImpl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Air pollution requester.
|
|
||||||
*/
|
|
||||||
public class AirPollutionRequesterImpl implements AirPollutionRequester {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Air pollution requester.
|
|
||||||
*
|
|
||||||
* @param apiKey the api key
|
|
||||||
*/
|
|
||||||
public AirPollutionRequesterImpl(String apiKey) {
|
|
||||||
urlBuilder = new RequestUrlBuilder(apiKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CurrentAirPollutionRequester current() {
|
|
||||||
urlBuilder.append("air_pollution");
|
|
||||||
return new CurrentAirPollutionRequesterImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ForecastAirPollutionRequester forecast() {
|
|
||||||
urlBuilder.append("air_pollution/forecast");
|
|
||||||
return new ForecastAirPollutionRequesterImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HistoricalAirPollutionRequester historical() {
|
|
||||||
urlBuilder.append("air_pollution/history");
|
|
||||||
return new HistoricalAirPollutionRequesterImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+18
-9
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,20 +20,29 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution.current;
|
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Current air pollution requester.
|
* The type Current air pollution requester.
|
||||||
*/
|
*/
|
||||||
public interface CurrentAirPollutionRequester {
|
public class CurrentAirPollutionRequester {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By coordinate current air pollution request customizer.
|
* Instantiates a new Current air pollution requester.
|
||||||
*
|
*
|
||||||
* @param coordinate the coordinate
|
* @param requestSettings request settings object.
|
||||||
* @return the current air pollution request customizer
|
|
||||||
*/
|
*/
|
||||||
AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate);
|
public CurrentAirPollutionRequester(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate) {
|
||||||
|
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||||
|
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||||
|
return new AirPollutionRequestCustomizer(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+14
-16
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,31 +20,29 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type One call current weather requester.
|
* The type Forecast air pollution requester.
|
||||||
*/
|
*/
|
||||||
public class OneCallCurrentWeatherRequesterImpl implements OneCallCurrentWeatherRequester {
|
public class ForecastAirPollutionRequester {
|
||||||
private final RequestUrlBuilder urlBuilder;
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new One call current weather requester.
|
* Instantiates a new Forecast air pollution requester.
|
||||||
*
|
*
|
||||||
* @param urlBuilder the url builder
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
public OneCallCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
|
public ForecastAirPollutionRequester(RequestSettings requestSettings) {
|
||||||
this.urlBuilder = urlBuilder;
|
this.requestSettings = requestSettings;
|
||||||
urlBuilder.append("onecall");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate) {
|
||||||
public OneCallCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate) {
|
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||||
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||||
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
return new AirPollutionRequestCustomizer(requestSettings);
|
||||||
return new OneCallCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+16
-17
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,32 +20,31 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type One call historical weather requester.
|
* The type Historical air pollution requester.
|
||||||
*/
|
*/
|
||||||
public class OneCallHistoricalWeatherRequesterImpl implements OneCallHistoricalWeatherRequester {
|
public class HistoricalAirPollutionRequester {
|
||||||
private final RequestUrlBuilder urlBuilder;
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new One call historical weather requester.
|
* Instantiates a new Historical air pollution requester.
|
||||||
*
|
*
|
||||||
* @param urlBuilder the url builder
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
public OneCallHistoricalWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
|
public HistoricalAirPollutionRequester(RequestSettings requestSettings) {
|
||||||
this.urlBuilder = urlBuilder;
|
this.requestSettings = requestSettings;
|
||||||
urlBuilder.append("onecall/timemachine");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public AirPollutionRequestCustomizer byCoordinateAndPeriod(Coordinate coordinate, long startUnixTime, long endUnixTime) {
|
||||||
public OneCallHistoricalWeatherRequestCustomizer byCoordinateAndTimestamp(Coordinate coordinate, long unixTime) {
|
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||||
urlBuilder.addRequestParameter("lat", coordinate.getLatitude());
|
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||||
urlBuilder.addRequestParameter("lon", coordinate.getLongitude());
|
requestSettings.putRequestParameter("start", String.valueOf(startUnixTime));
|
||||||
urlBuilder.addRequestParameter("dt", unixTime);
|
requestSettings.putRequestParameter("end", String.valueOf(endUnixTime));
|
||||||
return new OneCallHistoricalWeatherRequestCustomizerImpl(urlBuilder);
|
return new AirPollutionRequestCustomizer(requestSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-53
@@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution.current;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizerImpl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Current air pollution requester.
|
|
||||||
*/
|
|
||||||
public class CurrentAirPollutionRequesterImpl implements CurrentAirPollutionRequester {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Current air pollution requester.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
public CurrentAirPollutionRequesterImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate) {
|
|
||||||
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
|
||||||
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
|
||||||
return new AirPollutionRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-41
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution.forecast;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The interface Forecast air pollution requester.
|
|
||||||
*/
|
|
||||||
public interface ForecastAirPollutionRequester {
|
|
||||||
/**
|
|
||||||
* By coordinate forecast air pollution request customizer.
|
|
||||||
*
|
|
||||||
* @param coordinate the coordinate
|
|
||||||
* @return the forecast air pollution request customizer
|
|
||||||
*/
|
|
||||||
AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate);
|
|
||||||
}
|
|
||||||
-53
@@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution.forecast;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizerImpl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Forecast air pollution requester.
|
|
||||||
*/
|
|
||||||
public class ForecastAirPollutionRequesterImpl implements ForecastAirPollutionRequester {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Forecast air pollution requester.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
public ForecastAirPollutionRequesterImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AirPollutionRequestCustomizer byCoordinate(Coordinate coordinate) {
|
|
||||||
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
|
||||||
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
|
||||||
return new AirPollutionRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-43
@@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution.historical;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The interface Historical air pollution requester.
|
|
||||||
*/
|
|
||||||
public interface HistoricalAirPollutionRequester {
|
|
||||||
/**
|
|
||||||
* By coordinate historical air pollution request customizer.
|
|
||||||
*
|
|
||||||
* @param coordinate the coordinate
|
|
||||||
* @param startUnixTime the start unix time
|
|
||||||
* @param endUnixTime the end unix time
|
|
||||||
* @return the historical air pollution request customizer
|
|
||||||
*/
|
|
||||||
AirPollutionRequestCustomizer byCoordinateAndPeriod(Coordinate coordinate, long startUnixTime, long endUnixTime);
|
|
||||||
}
|
|
||||||
-55
@@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* * Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
* *
|
|
||||||
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* * of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* * in the Software without restriction, including without limitation the rights
|
|
||||||
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* * copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* * furnished to do so, subject to the following conditions:
|
|
||||||
* *
|
|
||||||
* * The above copyright notice and this permission notice shall be included in all
|
|
||||||
* * copies or substantial portions of the Software.
|
|
||||||
* *
|
|
||||||
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* * SOFTWARE.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution.historical;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizer;
|
|
||||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequestCustomizerImpl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Historical air pollution requester.
|
|
||||||
*/
|
|
||||||
public class HistoricalAirPollutionRequesterImpl implements HistoricalAirPollutionRequester {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Historical air pollution requester.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
public HistoricalAirPollutionRequesterImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AirPollutionRequestCustomizer byCoordinateAndPeriod(Coordinate coordinate, long startUnixTime, long endUnixTime) {
|
|
||||||
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
|
||||||
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
|
||||||
urlBuilder.addRequestParameter("start", String.valueOf(startUnixTime));
|
|
||||||
urlBuilder.addRequestParameter("end", String.valueOf(endUnixTime));
|
|
||||||
return new AirPollutionRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+29
-7
@@ -22,21 +22,43 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.ResponseType;
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.FiveDayThreeHourStepForecastResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
||||||
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The forecast async request terminator interface.
|
* Async request terminator.
|
||||||
*/
|
*/
|
||||||
public interface FiveDayThreeHourStepForecastAsyncRequestTerminator extends AsyncRequestTerminator<Forecast, String> {
|
public class FiveDayThreeHourStepForecastAsyncRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XML response format.
|
* Instantiates a new async request terminator.
|
||||||
*
|
*
|
||||||
* @return the completable future
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
CompletableFuture<String> asXML();
|
FiveDayThreeHourStepForecastAsyncRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<Forecast> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new FiveDayThreeHourStepForecastResponseMapper(requestSettings.getUnitSystem()).mapToForecast(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<String> asXML() {
|
||||||
|
requestSettings.setResponseType(ResponseType.XML);
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-69
@@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Async request terminator.
|
|
||||||
*/
|
|
||||||
public class FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl implements FiveDayThreeHourStepForecastAsyncRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new async request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Forecast> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new FiveDayThreeHourStepForecastResponseMapper(unitSystem).mapToForecast(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<String> asXML() {
|
|
||||||
urlBuilder.addRequestParameter("mode", "xml");
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+33
-19
@@ -22,31 +22,45 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The forecast request customizer interface.
|
* The forecast request customizer.
|
||||||
*/
|
*/
|
||||||
public interface FiveDayThreeHourStepForecastRequestCustomizer extends RequestCustomizer<FiveDayThreeHourStepForecastRequestCustomizer> {
|
public class FiveDayThreeHourStepForecastRequestCustomizer {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* Count customizer.
|
|
||||||
*
|
|
||||||
* @param numberOfTimestamps the number of timestamps
|
|
||||||
* @return forecast request customizer
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer count(int numberOfTimestamps);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve forecast request terminator.
|
* Instantiates a new forecast request customizer.
|
||||||
*
|
*
|
||||||
* @return forecast request terminator
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
FiveDayThreeHourStepForecastRequestTerminator retrieve();
|
FiveDayThreeHourStepForecastRequestCustomizer(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public FiveDayThreeHourStepForecastRequestCustomizer language(Language language) {
|
||||||
* Retrieve forecast async request terminator.
|
requestSettings.setLanguage(language);
|
||||||
*
|
return this;
|
||||||
* @return forecast async request terminator
|
}
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastAsyncRequestTerminator retrieveAsync();
|
public FiveDayThreeHourStepForecastRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
requestSettings.setUnitSystem(unitSystem);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer count(int numberOfTimestamps) {
|
||||||
|
requestSettings.putRequestParameter("cnt", Integer.toString(numberOfTimestamps));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FiveDayThreeHourStepForecastRequestTerminator retrieve() {
|
||||||
|
return new FiveDayThreeHourStepForecastRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FiveDayThreeHourStepForecastAsyncRequestTerminator retrieveAsync() {
|
||||||
|
return new FiveDayThreeHourStepForecastAsyncRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-84
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The forecast request customizer.
|
|
||||||
*/
|
|
||||||
public class FiveDayThreeHourStepForecastRequestCustomizerImpl implements FiveDayThreeHourStepForecastRequestCustomizer {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
private Language language;
|
|
||||||
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
|
||||||
private int count = -1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new forecast request customizer.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer language(Language language) {
|
|
||||||
this.language = language;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer count(int numberOfTimestamps) {
|
|
||||||
count = numberOfTimestamps;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestTerminator retrieve() {
|
|
||||||
applyCustomization();
|
|
||||||
return new FiveDayThreeHourStepForecastRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastAsyncRequestTerminator retrieveAsync() {
|
|
||||||
applyCustomization();
|
|
||||||
return new FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyCustomization() {
|
|
||||||
urlBuilder.applyCustomization(language, unitSystem);
|
|
||||||
if (count >= 0) {
|
|
||||||
urlBuilder.addRequestParameter("cnt", count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+29
-7
@@ -22,19 +22,41 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.ResponseType;
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.FiveDayThreeHourStepForecastResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The forecast request terminator interface.
|
* The forecast request terminator.
|
||||||
*/
|
*/
|
||||||
public interface FiveDayThreeHourStepForecastRequestTerminator extends RequestTerminator<Forecast, String> {
|
public class FiveDayThreeHourStepForecastRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XML response format.
|
* Instantiates a new forecast request terminator.
|
||||||
*
|
*
|
||||||
* @return the XML string
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
String asXML();
|
FiveDayThreeHourStepForecastRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Forecast asJava() {
|
||||||
|
return new FiveDayThreeHourStepForecastResponseMapper(requestSettings.getUnitSystem()).mapToForecast(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asXML() {
|
||||||
|
requestSettings.setResponseType(ResponseType.XML);
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-67
@@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The forecast request terminator.
|
|
||||||
*/
|
|
||||||
public class FiveDayThreeHourStepForecastRequestTerminatorImpl implements FiveDayThreeHourStepForecastRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new forecast request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Forecast asJava() {
|
|
||||||
return new FiveDayThreeHourStepForecastResponseMapper(unitSystem).mapToForecast(getRawResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String asXML() {
|
|
||||||
urlBuilder.addRequestParameter("mode", "xml");
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+40
-52
@@ -23,69 +23,57 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface for <a href="https://openweathermap.org/forecast5">API</a> methods.
|
* The forecast requester.
|
||||||
*/
|
*/
|
||||||
public interface FiveDayThreeHourStepForecastRequester {
|
public class FiveDayThreeHourStepForecastRequester {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By city name forecast request customizer.
|
* Instantiates a new forecast requester.
|
||||||
*
|
*
|
||||||
* @param cityName the city name
|
* @param requestSettings request settings object.
|
||||||
* @return the forecast request customizer
|
|
||||||
*/
|
*/
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName);
|
public FiveDayThreeHourStepForecastRequester(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
this.requestSettings.appendToURL("forecast");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName) {
|
||||||
* By city name forecast request customizer.
|
requestSettings.putRequestParameter("q", cityName);
|
||||||
*
|
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||||
* @param cityName the city name
|
}
|
||||||
* @param stateCode the state code
|
|
||||||
* @return the forecast request customizer
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode);
|
|
||||||
|
|
||||||
/**
|
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode) {
|
||||||
* By city name forecast request customizer.
|
requestSettings.putRequestParameter("q", cityName + "," + stateCode);
|
||||||
*
|
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||||
* @param cityName the city name
|
}
|
||||||
* @param stateCode the state code
|
|
||||||
* @param countryCode the country code
|
|
||||||
* @return the forecast request customizer
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode, String countryCode);
|
|
||||||
|
|
||||||
/**
|
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode, String countryCode) {
|
||||||
* By city id forecast request customizer.
|
requestSettings.putRequestParameter("q", cityName + "," + stateCode + "," + countryCode);
|
||||||
*
|
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||||
* @param cityId the city id
|
}
|
||||||
* @return the forecast request customizer
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer byCityId(long cityId);
|
|
||||||
|
|
||||||
/**
|
public FiveDayThreeHourStepForecastRequestCustomizer byCityId(long cityId) {
|
||||||
* By coordinate forecast request customizer.
|
requestSettings.putRequestParameter("id", Long.toString(cityId));
|
||||||
*
|
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||||
* @param coordinate the coordinate
|
}
|
||||||
* @return the forecast request customizer
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer byCoordinate(Coordinate coordinate);
|
|
||||||
|
|
||||||
/**
|
public FiveDayThreeHourStepForecastRequestCustomizer byCoordinate(Coordinate coordinate) {
|
||||||
* By zip code and country forecast request customizer.
|
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||||
*
|
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||||
* @param zipCode the zip code
|
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||||
* @param countryCode the country code
|
}
|
||||||
* @return the forecast request customizer
|
|
||||||
*/
|
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode);
|
|
||||||
|
|
||||||
/**
|
public FiveDayThreeHourStepForecastRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode) {
|
||||||
* By zip code in USA forecast request customizer.
|
requestSettings.putRequestParameter("zip", zipCode + "," + countryCode);
|
||||||
*
|
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||||
* @param zipCode the zip code
|
}
|
||||||
* @return the forecast request customizer
|
|
||||||
*/
|
public FiveDayThreeHourStepForecastRequestCustomizer byZipCodeInUSA(String zipCode) {
|
||||||
FiveDayThreeHourStepForecastRequestCustomizer byZipCodeInUSA(String zipCode);
|
requestSettings.putRequestParameter("zip", zipCode);
|
||||||
|
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-86
@@ -1,86 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The forecast requester.
|
|
||||||
*/
|
|
||||||
public class FiveDayThreeHourStepForecastRequesterImpl implements FiveDayThreeHourStepForecastRequester {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new forecast requester.
|
|
||||||
*
|
|
||||||
* @param apiKey the api key
|
|
||||||
*/
|
|
||||||
public FiveDayThreeHourStepForecastRequesterImpl(String apiKey) {
|
|
||||||
urlBuilder = new RequestUrlBuilder(apiKey);
|
|
||||||
urlBuilder.append("forecast");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName) {
|
|
||||||
urlBuilder.addRequestParameter("q", cityName);
|
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode) {
|
|
||||||
urlBuilder.addRequestParameter("q", cityName + "," + stateCode);
|
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode, String countryCode) {
|
|
||||||
urlBuilder.addRequestParameter("q", cityName + "," + stateCode + "," + countryCode);
|
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byCityId(long cityId) {
|
|
||||||
urlBuilder.addRequestParameter("id", cityId);
|
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byCoordinate(Coordinate coordinate) {
|
|
||||||
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
|
||||||
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode) {
|
|
||||||
urlBuilder.addRequestParameter("zip", zipCode + "," + countryCode);
|
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FiveDayThreeHourStepForecastRequestCustomizer byZipCodeInUSA(String zipCode) {
|
|
||||||
urlBuilder.addRequestParameter("zip", zipCode);
|
|
||||||
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+17
-11
@@ -22,24 +22,30 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall;
|
package com.github.prominence.openweathermap.api.request.onecall;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.current.OneCallCurrentWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.onecall.current.OneCallCurrentWeatherRequester;
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.historical.OneCallHistoricalWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.onecall.historical.OneCallHistoricalWeatherRequester;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call weather requester.
|
* The type One call weather requester.
|
||||||
*/
|
*/
|
||||||
public interface OneCallWeatherRequester {
|
public class OneCallWeatherRequester {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* Current one call current weather requester.
|
|
||||||
*
|
|
||||||
* @return the one call current weather requester
|
|
||||||
*/
|
|
||||||
OneCallCurrentWeatherRequester current();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Historical one call historical weather requester.
|
* Instantiates a new One call weather requester.
|
||||||
*
|
*
|
||||||
* @return the one call historical weather requester
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
OneCallHistoricalWeatherRequester historical();
|
public OneCallWeatherRequester(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallCurrentWeatherRequester current() {
|
||||||
|
return new OneCallCurrentWeatherRequester(requestSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallHistoricalWeatherRequester historical() {
|
||||||
|
return new OneCallHistoricalWeatherRequester(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-55
@@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.current.OneCallCurrentWeatherRequester;
|
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.current.OneCallCurrentWeatherRequesterImpl;
|
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.historical.OneCallHistoricalWeatherRequester;
|
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.historical.OneCallHistoricalWeatherRequesterImpl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type One call weather requester.
|
|
||||||
*/
|
|
||||||
public class OneCallWeatherRequesterImpl implements OneCallWeatherRequester {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call weather requester.
|
|
||||||
*
|
|
||||||
* @param apiKey the api key
|
|
||||||
*/
|
|
||||||
public OneCallWeatherRequesterImpl(String apiKey) {
|
|
||||||
urlBuilder = new RequestUrlBuilder(apiKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallCurrentWeatherRequester current() {
|
|
||||||
return new OneCallCurrentWeatherRequesterImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallHistoricalWeatherRequester historical() {
|
|
||||||
return new OneCallHistoricalWeatherRequesterImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+29
-3
@@ -22,11 +22,37 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
package com.github.prominence.openweathermap.api.request.onecall.current;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
||||||
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call current weather async request terminator.
|
* The type One call current weather async request terminator.
|
||||||
*/
|
*/
|
||||||
public interface OneCallCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<CurrentWeatherData, String> {
|
public class OneCallCurrentWeatherAsyncRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new One call current weather async request terminator.
|
||||||
|
*
|
||||||
|
* @param requestSettings request settings object.
|
||||||
|
*/
|
||||||
|
OneCallCurrentWeatherAsyncRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<CurrentWeatherData> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new OneCallWeatherResponseMapper(requestSettings.getUnitSystem()).mapToCurrent(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-64
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type One call current weather async request terminator.
|
|
||||||
*/
|
|
||||||
public class OneCallCurrentWeatherAsyncRequestTerminatorImpl implements OneCallCurrentWeatherAsyncRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call current weather async request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
OneCallCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<CurrentWeatherData> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new OneCallWeatherResponseMapper(unitSystem).mapToCurrent(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+40
-19
@@ -22,32 +22,53 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
package com.github.prominence.openweathermap.api.request.onecall.current;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
import com.github.prominence.openweathermap.api.enums.OneCallResultOptions;
|
import com.github.prominence.openweathermap.api.enums.OneCallResultOptions;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call current weather request customizer.
|
* The type One call current weather request customizer.
|
||||||
*/
|
*/
|
||||||
public interface OneCallCurrentWeatherRequestCustomizer extends RequestCustomizer<OneCallCurrentWeatherRequestCustomizer> {
|
public class OneCallCurrentWeatherRequestCustomizer {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* Exclude one call current weather request customizer.
|
|
||||||
*
|
|
||||||
* @param excludeOptions the exclude options
|
|
||||||
* @return the one call current weather request customizer
|
|
||||||
*/
|
|
||||||
OneCallCurrentWeatherRequestCustomizer exclude(OneCallResultOptions... excludeOptions);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve one call current weather request terminator.
|
* Instantiates a new One call current weather request customizer.
|
||||||
*
|
*
|
||||||
* @return the one call current weather request terminator
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
OneCallCurrentWeatherRequestTerminator retrieve();
|
OneCallCurrentWeatherRequestCustomizer(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public OneCallCurrentWeatherRequestCustomizer language(Language language) {
|
||||||
* Retrieve async one call current weather async request terminator.
|
requestSettings.setLanguage(language);
|
||||||
*
|
return this;
|
||||||
* @return the one call current weather async request terminator
|
}
|
||||||
*/
|
|
||||||
OneCallCurrentWeatherAsyncRequestTerminator retrieveAsync();
|
public OneCallCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
this.requestSettings.setUnitSystem(unitSystem);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallCurrentWeatherRequestCustomizer exclude(OneCallResultOptions... excludeOptions) {
|
||||||
|
if (excludeOptions != null && excludeOptions.length > 0) {
|
||||||
|
requestSettings.putRequestParameter("exclude", Stream.of(excludeOptions).map(OneCallResultOptions::getValue).collect(Collectors.joining(",")));
|
||||||
|
} else {
|
||||||
|
requestSettings.removeRequestParameter("exclude");
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallCurrentWeatherRequestTerminator retrieve() {
|
||||||
|
return new OneCallCurrentWeatherRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
||||||
|
return new OneCallCurrentWeatherAsyncRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-88
@@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.OneCallResultOptions;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type One call current weather request customizer.
|
|
||||||
*/
|
|
||||||
public class OneCallCurrentWeatherRequestCustomizerImpl implements OneCallCurrentWeatherRequestCustomizer {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
private Language language;
|
|
||||||
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
|
||||||
private OneCallResultOptions[] excludeOptions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call current weather request customizer.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
OneCallCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallCurrentWeatherRequestCustomizer language(Language language) {
|
|
||||||
this.language = language;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallCurrentWeatherRequestCustomizer exclude(OneCallResultOptions... excludeOptions) {
|
|
||||||
this.excludeOptions = excludeOptions;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallCurrentWeatherRequestTerminator retrieve() {
|
|
||||||
applyCustomization();
|
|
||||||
return new OneCallCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
|
||||||
applyCustomization();
|
|
||||||
return new OneCallCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyCustomization() {
|
|
||||||
urlBuilder.applyCustomization(language, unitSystem);
|
|
||||||
if (excludeOptions != null) {
|
|
||||||
urlBuilder.addRequestParameter("exclude", Stream.of(excludeOptions).map(OneCallResultOptions::getValue).collect(Collectors.joining(",")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+26
-3
@@ -22,12 +22,35 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
package com.github.prominence.openweathermap.api.request.onecall.current;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call current weather request terminator.
|
* The type One call current weather request terminator.
|
||||||
*/
|
*/
|
||||||
public interface OneCallCurrentWeatherRequestTerminator extends RequestTerminator<CurrentWeatherData, String> {
|
public class OneCallCurrentWeatherRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new One call current weather request terminator.
|
||||||
|
*
|
||||||
|
* @param requestSettings request settings object.
|
||||||
|
*/
|
||||||
|
OneCallCurrentWeatherRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CurrentWeatherData asJava() {
|
||||||
|
return new OneCallWeatherResponseMapper(requestSettings.getUnitSystem()).mapToCurrent(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-62
@@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type One call current weather request terminator.
|
|
||||||
*/
|
|
||||||
public class OneCallCurrentWeatherRequestTerminatorImpl implements OneCallCurrentWeatherRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call current weather request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
OneCallCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CurrentWeatherData asJava() {
|
|
||||||
return new OneCallWeatherResponseMapper(unitSystem).mapToCurrent(getRawResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+17
-6
@@ -23,16 +23,27 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.onecall.current;
|
package com.github.prominence.openweathermap.api.request.onecall.current;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call current weather requester.
|
* The type One call current weather requester.
|
||||||
*/
|
*/
|
||||||
public interface OneCallCurrentWeatherRequester {
|
public class OneCallCurrentWeatherRequester {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By coordinate one call current weather request customizer.
|
* Instantiates a new One call current weather requester.
|
||||||
*
|
*
|
||||||
* @param coordinate the coordinate
|
* @param requestSettings request settings object.
|
||||||
* @return the one call current weather request customizer
|
|
||||||
*/
|
*/
|
||||||
OneCallCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate);
|
public OneCallCurrentWeatherRequester(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
this.requestSettings.appendToURL("onecall");
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate) {
|
||||||
|
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||||
|
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||||
|
return new OneCallCurrentWeatherRequestCustomizer(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-3
@@ -22,11 +22,37 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
||||||
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call historical weather async request terminator.
|
* The type One call historical weather async request terminator.
|
||||||
*/
|
*/
|
||||||
public interface OneCallHistoricalWeatherAsyncRequestTerminator extends AsyncRequestTerminator<HistoricalWeatherData, String> {
|
public class OneCallHistoricalWeatherAsyncRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new One call historical weather async request terminator.
|
||||||
|
*
|
||||||
|
* @param requestSettings request settings object.
|
||||||
|
*/
|
||||||
|
public OneCallHistoricalWeatherAsyncRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<HistoricalWeatherData> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new OneCallWeatherResponseMapper(requestSettings.getUnitSystem()).mapToHistorical(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-64
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type One call historical weather async request terminator.
|
|
||||||
*/
|
|
||||||
public class OneCallHistoricalWeatherAsyncRequestTerminatorImpl implements OneCallHistoricalWeatherAsyncRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call historical weather async request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
public OneCallHistoricalWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<HistoricalWeatherData> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new OneCallWeatherResponseMapper(unitSystem).mapToHistorical(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+29
-12
@@ -22,23 +22,40 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call historical weather request customizer.
|
* The type One call historical weather request customizer.
|
||||||
*/
|
*/
|
||||||
public interface OneCallHistoricalWeatherRequestCustomizer extends RequestCustomizer<OneCallHistoricalWeatherRequestCustomizer> {
|
public class OneCallHistoricalWeatherRequestCustomizer {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* Retrieve one call historical weather request terminator.
|
|
||||||
*
|
|
||||||
* @return the one call historical weather request terminator
|
|
||||||
*/
|
|
||||||
OneCallHistoricalWeatherRequestTerminator retrieve();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve async one call historical weather async request terminator.
|
* Instantiates a new One call historical weather request customizer.
|
||||||
*
|
*
|
||||||
* @return the one call historical weather async request terminator
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
OneCallHistoricalWeatherAsyncRequestTerminator retrieveAsync();
|
public OneCallHistoricalWeatherRequestCustomizer(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallHistoricalWeatherRequestCustomizer language(Language language) {
|
||||||
|
requestSettings.setLanguage(language);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallHistoricalWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
requestSettings.setUnitSystem(unitSystem);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallHistoricalWeatherRequestTerminator retrieve() {
|
||||||
|
return new OneCallHistoricalWeatherRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallHistoricalWeatherAsyncRequestTerminator retrieveAsync() {
|
||||||
|
return new OneCallHistoricalWeatherAsyncRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-70
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type One call historical weather request customizer.
|
|
||||||
*/
|
|
||||||
public class OneCallHistoricalWeatherRequestCustomizerImpl implements OneCallHistoricalWeatherRequestCustomizer {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
private Language language;
|
|
||||||
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call historical weather request customizer.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
public OneCallHistoricalWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallHistoricalWeatherRequestCustomizer language(Language language) {
|
|
||||||
this.language = language;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallHistoricalWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallHistoricalWeatherRequestTerminator retrieve() {
|
|
||||||
urlBuilder.applyCustomization(language, unitSystem);
|
|
||||||
return new OneCallHistoricalWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OneCallHistoricalWeatherAsyncRequestTerminator retrieveAsync() {
|
|
||||||
urlBuilder.applyCustomization(language, unitSystem);
|
|
||||||
return new OneCallHistoricalWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+27
-3
@@ -22,11 +22,35 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call historical weather request terminator.
|
* The type One call historical weather request terminator.
|
||||||
*/
|
*/
|
||||||
public interface OneCallHistoricalWeatherRequestTerminator extends RequestTerminator<HistoricalWeatherData, String> {
|
public class OneCallHistoricalWeatherRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new One call historical weather request terminator.
|
||||||
|
*
|
||||||
|
* @param requestSettings request settings object.
|
||||||
|
*/
|
||||||
|
public OneCallHistoricalWeatherRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HistoricalWeatherData asJava() {
|
||||||
|
return new OneCallWeatherResponseMapper(requestSettings.getUnitSystem()).mapToHistorical(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-62
@@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type One call historical weather request terminator.
|
|
||||||
*/
|
|
||||||
public class OneCallHistoricalWeatherRequestTerminatorImpl implements OneCallHistoricalWeatherRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new One call historical weather request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
public OneCallHistoricalWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HistoricalWeatherData asJava() {
|
|
||||||
return new OneCallWeatherResponseMapper(unitSystem).mapToHistorical(getRawResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+18
-7
@@ -23,17 +23,28 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
package com.github.prominence.openweathermap.api.request.onecall.historical;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface One call historical weather requester.
|
* The type One call historical weather requester.
|
||||||
*/
|
*/
|
||||||
public interface OneCallHistoricalWeatherRequester {
|
public class OneCallHistoricalWeatherRequester {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By coordinate and timestamp one call historical weather request customizer.
|
* Instantiates a new One call historical weather requester.
|
||||||
*
|
*
|
||||||
* @param coordinate the coordinate
|
* @param requestSettings request settings object.
|
||||||
* @param unixTime the unix time
|
|
||||||
* @return the one call historical weather request customizer
|
|
||||||
*/
|
*/
|
||||||
OneCallHistoricalWeatherRequestCustomizer byCoordinateAndTimestamp(Coordinate coordinate, long unixTime);
|
public OneCallHistoricalWeatherRequester(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
this.requestSettings.appendToURL("onecall/timemachine");
|
||||||
|
}
|
||||||
|
|
||||||
|
public OneCallHistoricalWeatherRequestCustomizer byCoordinateAndTimestamp(Coordinate coordinate, long unixTime) {
|
||||||
|
requestSettings.putRequestParameter("lat", Double.toString(coordinate.getLatitude()));
|
||||||
|
requestSettings.putRequestParameter("lon", Double.toString(coordinate.getLongitude()));
|
||||||
|
requestSettings.putRequestParameter("dt", Long.toString(unixTime));
|
||||||
|
return new OneCallHistoricalWeatherRequestCustomizer(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-11
@@ -22,25 +22,30 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather;
|
package com.github.prominence.openweathermap.api.request.weather;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsCurrentWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsCurrentWeatherRequester;
|
||||||
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequester;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface for <a href="https://openweathermap.org/current">API</a> methods.
|
* The type Current weather requester.
|
||||||
*/
|
*/
|
||||||
public interface CurrentWeatherRequester {
|
public class CurrentWeatherRequester {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Single location current weather requester.
|
* Instantiates a new Current weather requester.
|
||||||
*
|
*
|
||||||
* @return the single location current weather requester
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
SingleLocationCurrentWeatherRequester single();
|
public CurrentWeatherRequester(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public SingleLocationCurrentWeatherRequester single() {
|
||||||
* Multiple locations current weather requester.
|
return new SingleLocationCurrentWeatherRequester(requestSettings);
|
||||||
*
|
}
|
||||||
* @return the multiple locations current weather requester
|
|
||||||
*/
|
public MultipleLocationsCurrentWeatherRequester multiple() {
|
||||||
MultipleLocationsCurrentWeatherRequester multiple();
|
return new MultipleLocationsCurrentWeatherRequester(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-53
@@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsCurrentWeatherRequesterImpl;
|
|
||||||
import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsCurrentWeatherRequester;
|
|
||||||
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequesterImpl;
|
|
||||||
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequester;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Current weather requester.
|
|
||||||
*/
|
|
||||||
public class CurrentWeatherRequesterImpl implements CurrentWeatherRequester {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Current weather requester.
|
|
||||||
*
|
|
||||||
* @param apiKey the api key
|
|
||||||
*/
|
|
||||||
public CurrentWeatherRequesterImpl(String apiKey) {
|
|
||||||
urlBuilder = new RequestUrlBuilder(apiKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SingleLocationCurrentWeatherRequester single() {
|
|
||||||
return new SingleLocationCurrentWeatherRequesterImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MultipleLocationsCurrentWeatherRequester multiple() {
|
|
||||||
return new MultipleLocationsCurrentWeatherRequesterImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+31
-22
@@ -24,36 +24,45 @@ package com.github.prominence.openweathermap.api.request.weather.multiple;
|
|||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
|
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Multiple locations current weather requester.
|
* The type Multiple locations current weather requester.
|
||||||
*/
|
*/
|
||||||
public interface MultipleLocationsCurrentWeatherRequester {
|
public class MultipleLocationsCurrentWeatherRequester {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By rectangle multiple result current weather request customizer.
|
* Instantiates a new Multiple locations current weather requester.
|
||||||
*
|
*
|
||||||
* @param rectangle the rectangle
|
* @param requestSettings request settings object.
|
||||||
* @param zoom the zoom
|
|
||||||
* @return the multiple result current weather request customizer
|
|
||||||
*/
|
*/
|
||||||
MultipleResultCurrentWeatherRequestCustomizer byRectangle(CoordinateRectangle rectangle, int zoom);
|
public MultipleLocationsCurrentWeatherRequester(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public MultipleResultCurrentWeatherRequestCustomizer byRectangle(CoordinateRectangle rectangle, int zoom) {
|
||||||
* By cities in cycle multiple result current weather request customizer.
|
String coordinates = rectangle.getFormattedRequestString() + "," + zoom;
|
||||||
*
|
requestSettings.appendToURL("box/city");
|
||||||
* @param point the point
|
requestSettings.putRequestParameter("bbox", coordinates);
|
||||||
* @return the multiple result cities in circle current weather request customizer
|
|
||||||
*/
|
|
||||||
MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point);
|
|
||||||
|
|
||||||
/**
|
return new MultipleResultCurrentWeatherRequestCustomizer(requestSettings);
|
||||||
* By cities in cycle multiple result current weather request customizer.
|
}
|
||||||
*
|
|
||||||
* @param point the point
|
|
||||||
* @param citiesCount the cities count
|
|
||||||
* @return the multiple result cities in circle current weather request customizer
|
|
||||||
*/
|
|
||||||
MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point, int citiesCount);
|
|
||||||
|
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point, int citiesCount) {
|
||||||
|
requestSettings.appendToURL("find");
|
||||||
|
requestSettings.putRequestParameter("lat", Double.toString(point.getLatitude()));
|
||||||
|
requestSettings.putRequestParameter("lon", Double.toString(point.getLongitude()));
|
||||||
|
requestSettings.putRequestParameter("cnt", Integer.toString(citiesCount));
|
||||||
|
|
||||||
|
return new MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer(requestSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point) {
|
||||||
|
requestSettings.appendToURL("find");
|
||||||
|
requestSettings.putRequestParameter("lat", Double.toString(point.getLatitude()));
|
||||||
|
requestSettings.putRequestParameter("lon", Double.toString(point.getLongitude()));
|
||||||
|
|
||||||
|
return new MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-71
@@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Multiple locations current weather requester.
|
|
||||||
*/
|
|
||||||
public class MultipleLocationsCurrentWeatherRequesterImpl implements MultipleLocationsCurrentWeatherRequester {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Multiple locations current weather requester.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
public MultipleLocationsCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MultipleResultCurrentWeatherRequestCustomizer byRectangle(CoordinateRectangle rectangle, int zoom) {
|
|
||||||
String coordinates = rectangle.getFormattedRequestString() + "," + zoom;
|
|
||||||
urlBuilder.append("box/city");
|
|
||||||
urlBuilder.addRequestParameter("bbox", coordinates);
|
|
||||||
|
|
||||||
return new MultipleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point, int citiesCount) {
|
|
||||||
urlBuilder.append("find");
|
|
||||||
urlBuilder.addRequestParameter("lat", Double.toString(point.getLatitude()));
|
|
||||||
urlBuilder.addRequestParameter("lon", Double.toString(point.getLongitude()));
|
|
||||||
urlBuilder.addRequestParameter("cnt", Integer.toString(citiesCount));
|
|
||||||
|
|
||||||
return new MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point) {
|
|
||||||
urlBuilder.append("find");
|
|
||||||
urlBuilder.addRequestParameter("lat", Double.toString(point.getLatitude()));
|
|
||||||
urlBuilder.addRequestParameter("lon", Double.toString(point.getLongitude()));
|
|
||||||
|
|
||||||
return new MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+30
-6
@@ -22,20 +22,44 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.ResponseType;
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Multiple result current weather async request terminator.
|
* The type Multiple result current weather async request terminator.
|
||||||
*/
|
*/
|
||||||
public interface MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<List<Weather>, String> {
|
public class MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XML response format.
|
* Instantiates a new Multiple result current weather async request terminator.
|
||||||
*
|
*
|
||||||
* @return the completable future
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
CompletableFuture<String> asXML();
|
MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<List<Weather>> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(requestSettings.getUnitSystem()).getList(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<String> asXML() {
|
||||||
|
requestSettings.setResponseType(ResponseType.XML);
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-71
@@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Multiple result current weather async request terminator.
|
|
||||||
*/
|
|
||||||
public class MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl implements MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Multiple result current weather async request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<List<Weather>> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<String> asXML() {
|
|
||||||
urlBuilder.addRequestParameter("mode", "xml");
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+29
-12
@@ -22,23 +22,40 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Multiple result current weather request customizer.
|
* The type Multiple result current weather request customizer.
|
||||||
*/
|
*/
|
||||||
public interface MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer extends RequestCustomizer<MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer> {
|
public class MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* Retrieve multiple result current weather request terminator.
|
|
||||||
*
|
|
||||||
* @return the multiple result current weather request terminator
|
|
||||||
*/
|
|
||||||
MultipleResultCitiesInCircleCurrentWeatherRequestTerminator retrieve();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve async multiple result current weather async request terminator.
|
* Instantiates a new Multiple result current weather request customizer.
|
||||||
*
|
*
|
||||||
* @return the multiple result current weather async request terminator
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator retrieveAsync();
|
MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer language(Language language) {
|
||||||
|
requestSettings.setLanguage(language);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
requestSettings.setUnitSystem(unitSystem);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherRequestTerminator retrieve() {
|
||||||
|
return new MultipleResultCitiesInCircleCurrentWeatherRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
||||||
|
return new MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
-70
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Multiple result current weather request customizer.
|
|
||||||
*/
|
|
||||||
public class MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl implements MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
private Language language;
|
|
||||||
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Multiple result current weather request customizer.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer language(Language language) {
|
|
||||||
this.language = language;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MultipleResultCitiesInCircleCurrentWeatherRequestTerminator retrieve() {
|
|
||||||
urlBuilder.applyCustomization(language, unitSystem);
|
|
||||||
return new MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
|
||||||
urlBuilder.applyCustomization(language, unitSystem);
|
|
||||||
return new MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+30
-6
@@ -22,19 +22,43 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.ResponseType;
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Multiple result current weather request terminator.
|
* The type Multiple result current weather request terminator.
|
||||||
*/
|
*/
|
||||||
public interface MultipleResultCitiesInCircleCurrentWeatherRequestTerminator extends RequestTerminator<List<Weather>, String> {
|
public class MultipleResultCitiesInCircleCurrentWeatherRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XML response format.
|
* Instantiates a new Multiple result current weather request terminator.
|
||||||
*
|
*
|
||||||
* @return the XML string
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
String asXML();
|
MultipleResultCitiesInCircleCurrentWeatherRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Weather> asJava() {
|
||||||
|
return new CurrentWeatherResponseMapper(requestSettings.getUnitSystem()).getList(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asXML() {
|
||||||
|
requestSettings.setResponseType(ResponseType.XML);
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-70
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Multiple result current weather request terminator.
|
|
||||||
*/
|
|
||||||
public class MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl implements MultipleResultCitiesInCircleCurrentWeatherRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Multiple result current weather request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Weather> asJava() {
|
|
||||||
return new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String asXML() {
|
|
||||||
urlBuilder.addRequestParameter("mode", "xml");
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+28
-3
@@ -23,12 +23,37 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Multiple result current weather async request terminator.
|
* The type Multiple result current weather async request terminator.
|
||||||
*/
|
*/
|
||||||
public interface MultipleResultCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<List<Weather>, String> {
|
public class MultipleResultCurrentWeatherAsyncRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Multiple result current weather async request terminator.
|
||||||
|
*
|
||||||
|
* @param requestSettings request settings object.
|
||||||
|
*/
|
||||||
|
MultipleResultCurrentWeatherAsyncRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<List<Weather>> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(requestSettings.getUnitSystem()).getList(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-65
@@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Multiple result current weather async request terminator.
|
|
||||||
*/
|
|
||||||
public class MultipleResultCurrentWeatherAsyncRequestTerminatorImpl implements MultipleResultCurrentWeatherAsyncRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Multiple result current weather async request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
MultipleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<List<Weather>> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+29
-12
@@ -22,23 +22,40 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Multiple result current weather request customizer.
|
* The type Multiple result current weather request customizer.
|
||||||
*/
|
*/
|
||||||
public interface MultipleResultCurrentWeatherRequestCustomizer extends RequestCustomizer<MultipleResultCurrentWeatherRequestCustomizer> {
|
public class MultipleResultCurrentWeatherRequestCustomizer {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* Retrieve multiple result current weather request terminator.
|
|
||||||
*
|
|
||||||
* @return the multiple result current weather request terminator
|
|
||||||
*/
|
|
||||||
MultipleResultCurrentWeatherRequestTerminator retrieve();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve async multiple result current weather async request terminator.
|
* Instantiates a new Multiple result current weather request customizer.
|
||||||
*
|
*
|
||||||
* @return the multiple result current weather async request terminator
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
MultipleResultCurrentWeatherAsyncRequestTerminator retrieveAsync();
|
MultipleResultCurrentWeatherRequestCustomizer(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipleResultCurrentWeatherRequestCustomizer language(Language language) {
|
||||||
|
requestSettings.setLanguage(language);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipleResultCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
requestSettings.setUnitSystem(unitSystem);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipleResultCurrentWeatherRequestTerminator retrieve() {
|
||||||
|
return new MultipleResultCurrentWeatherRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipleResultCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
||||||
|
return new MultipleResultCurrentWeatherAsyncRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
-70
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Multiple result current weather request customizer.
|
|
||||||
*/
|
|
||||||
public class MultipleResultCurrentWeatherRequestCustomizerImpl implements MultipleResultCurrentWeatherRequestCustomizer {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
private Language language;
|
|
||||||
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Multiple result current weather request customizer.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
MultipleResultCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MultipleResultCurrentWeatherRequestCustomizer language(Language language) {
|
|
||||||
this.language = language;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MultipleResultCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MultipleResultCurrentWeatherRequestTerminator retrieve() {
|
|
||||||
urlBuilder.applyCustomization(language, unitSystem);
|
|
||||||
return new MultipleResultCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MultipleResultCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
|
||||||
urlBuilder.applyCustomization(language, unitSystem);
|
|
||||||
return new MultipleResultCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+27
-3
@@ -23,12 +23,36 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Multiple result current weather request terminator.
|
* The type Multiple result current weather request terminator.
|
||||||
*/
|
*/
|
||||||
public interface MultipleResultCurrentWeatherRequestTerminator extends RequestTerminator<List<Weather>, String> {
|
public class MultipleResultCurrentWeatherRequestTerminator {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Multiple result current weather request terminator.
|
||||||
|
*
|
||||||
|
* @param requestSettings request settings object.
|
||||||
|
*/
|
||||||
|
MultipleResultCurrentWeatherRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Weather> asJava() {
|
||||||
|
return new CurrentWeatherResponseMapper(requestSettings.getUnitSystem()).getList(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-64
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Multiple result current weather request terminator.
|
|
||||||
*/
|
|
||||||
public class MultipleResultCurrentWeatherRequestTerminatorImpl implements MultipleResultCurrentWeatherRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Multiple result current weather request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
MultipleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Weather> asJava() {
|
|
||||||
return new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+40
-52
@@ -23,69 +23,57 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface Single location current weather requester.
|
* The type Single location current weather requester.
|
||||||
*/
|
*/
|
||||||
public interface SingleLocationCurrentWeatherRequester {
|
public class SingleLocationCurrentWeatherRequester {
|
||||||
|
private final RequestSettings requestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By city name current weather request customizer.
|
* Instantiates a new Single location current weather requester.
|
||||||
*
|
*
|
||||||
* @param cityName the city name
|
* @param requestSettings request settings object.
|
||||||
* @return the single result current weather request customizer
|
|
||||||
*/
|
*/
|
||||||
SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName);
|
public SingleLocationCurrentWeatherRequester(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
this.requestSettings.appendToURL("weather");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName) {
|
||||||
* By city name current weather request customizer.
|
requestSettings.putRequestParameter("q", cityName);
|
||||||
*
|
return new SingleResultCurrentWeatherRequestCustomizer(requestSettings);
|
||||||
* @param cityName the city name
|
}
|
||||||
* @param countryCode the country code
|
|
||||||
* @return the single result current weather request customizer
|
|
||||||
*/
|
|
||||||
SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String countryCode);
|
|
||||||
|
|
||||||
/**
|
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String countryCode) {
|
||||||
* By city name current weather request customizer.
|
requestSettings.putRequestParameter("q", cityName + "," + countryCode);
|
||||||
*
|
return new SingleResultCurrentWeatherRequestCustomizer(requestSettings);
|
||||||
* @param cityName the city name
|
}
|
||||||
* @param stateCode the state code
|
|
||||||
* @param countryCode the country code
|
|
||||||
* @return the single result current weather request customizer
|
|
||||||
*/
|
|
||||||
SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String stateCode, String countryCode);
|
|
||||||
|
|
||||||
/**
|
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String stateCode, String countryCode) {
|
||||||
* By city id current weather request customizer.
|
requestSettings.putRequestParameter("q", cityName + "," + stateCode + "," + countryCode);
|
||||||
*
|
return new SingleResultCurrentWeatherRequestCustomizer(requestSettings);
|
||||||
* @param cityId the city id
|
}
|
||||||
* @return the single result current weather request customizer
|
|
||||||
*/
|
|
||||||
SingleResultCurrentWeatherRequestCustomizer byCityId(long cityId);
|
|
||||||
|
|
||||||
/**
|
public SingleResultCurrentWeatherRequestCustomizer byCityId(long cityId) {
|
||||||
* By coordinate current weather request customizer.
|
requestSettings.putRequestParameter("id", String.valueOf(cityId));
|
||||||
*
|
return new SingleResultCurrentWeatherRequestCustomizer(requestSettings);
|
||||||
* @param coordinate the coordinate
|
}
|
||||||
* @return the single result current weather request customizer
|
|
||||||
*/
|
|
||||||
SingleResultCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate);
|
|
||||||
|
|
||||||
/**
|
public SingleResultCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate) {
|
||||||
* By zip code and country current weather request customizer.
|
requestSettings.putRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||||
*
|
requestSettings.putRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||||
* @param zipCode the zip code
|
return new SingleResultCurrentWeatherRequestCustomizer(requestSettings);
|
||||||
* @param countryCode the country code
|
}
|
||||||
* @return the single result current weather request customizer
|
|
||||||
*/
|
|
||||||
SingleResultCurrentWeatherRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode);
|
|
||||||
|
|
||||||
/**
|
public SingleResultCurrentWeatherRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode) {
|
||||||
* By zip code in usa current weather request customizer.
|
requestSettings.putRequestParameter("zip", zipCode + "," + countryCode);
|
||||||
*
|
return new SingleResultCurrentWeatherRequestCustomizer(requestSettings);
|
||||||
* @param zipCode the zip code
|
}
|
||||||
* @return the single result current weather request customizer
|
|
||||||
*/
|
public SingleResultCurrentWeatherRequestCustomizer byZipCodeInUSA(String zipCode) {
|
||||||
SingleResultCurrentWeatherRequestCustomizer byZipCodeInUSA(String zipCode);
|
requestSettings.putRequestParameter("zip", zipCode);
|
||||||
|
return new SingleResultCurrentWeatherRequestCustomizer(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-81
@@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Single location current weather requester.
|
|
||||||
*/
|
|
||||||
public class SingleLocationCurrentWeatherRequesterImpl implements SingleLocationCurrentWeatherRequester {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Single location current weather requester.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
public SingleLocationCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
urlBuilder.append("weather");
|
|
||||||
}
|
|
||||||
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName) {
|
|
||||||
urlBuilder.addRequestParameter("q", cityName);
|
|
||||||
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String countryCode) {
|
|
||||||
urlBuilder.addRequestParameter("q", cityName + "," + countryCode);
|
|
||||||
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String stateCode, String countryCode) {
|
|
||||||
urlBuilder.addRequestParameter("q", cityName + "," + stateCode + "," + countryCode);
|
|
||||||
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer byCityId(long cityId) {
|
|
||||||
urlBuilder.addRequestParameter("id", cityId);
|
|
||||||
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate) {
|
|
||||||
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
|
||||||
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
|
||||||
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode) {
|
|
||||||
urlBuilder.addRequestParameter("zip", zipCode + "," + countryCode);
|
|
||||||
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer byZipCodeInUSA(String zipCode) {
|
|
||||||
urlBuilder.addRequestParameter("zip", zipCode);
|
|
||||||
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+34
-12
@@ -22,26 +22,48 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.ResponseType;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.CurrentWeatherResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current weather async request terminator interface.
|
* The type Single result current weather async request terminator.
|
||||||
*/
|
*/
|
||||||
public interface SingleResultCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<Weather, String> {
|
public class SingleResultCurrentWeatherAsyncRequestTerminator {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* XML response format.
|
|
||||||
*
|
|
||||||
* @return the completable future
|
|
||||||
*/
|
|
||||||
CompletableFuture<String> asXML();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTML response format.
|
* Instantiates a new Single result current weather async request terminator.
|
||||||
*
|
*
|
||||||
* @return the completable future
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
CompletableFuture<String> asHTML();
|
SingleResultCurrentWeatherAsyncRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<Weather> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(requestSettings.getUnitSystem()).getSingle(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<String> asXML() {
|
||||||
|
requestSettings.setResponseType(ResponseType.XML);
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<String> asHTML() {
|
||||||
|
requestSettings.setResponseType(ResponseType.HTML);
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-76
@@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Single result current weather async request terminator.
|
|
||||||
*/
|
|
||||||
public class SingleResultCurrentWeatherAsyncRequestTerminatorImpl implements SingleResultCurrentWeatherAsyncRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Single result current weather async request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
SingleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Weather> asJava() {
|
|
||||||
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(unitSystem).getSingle(getRawResponse()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<String> asJSON() {
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<String> asXML() {
|
|
||||||
urlBuilder.addRequestParameter("mode", "xml");
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<String> asHTML() {
|
|
||||||
urlBuilder.addRequestParameter("mode", "html");
|
|
||||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+28
-12
@@ -22,24 +22,40 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current weather request customizer interface.
|
* The type Single result current weather request customizer.
|
||||||
*/
|
*/
|
||||||
public interface SingleResultCurrentWeatherRequestCustomizer extends RequestCustomizer<SingleResultCurrentWeatherRequestCustomizer> {
|
public class SingleResultCurrentWeatherRequestCustomizer {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* Retrieve current weather request terminator.
|
|
||||||
*
|
|
||||||
* @return the single result current weather request terminator
|
|
||||||
*/
|
|
||||||
SingleResultCurrentWeatherRequestTerminator retrieve();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve current weather async request terminator.
|
* Instantiates a new Single result current weather request customizer.
|
||||||
*
|
*
|
||||||
* @return the single result current weather async request terminator
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
SingleResultCurrentWeatherAsyncRequestTerminator retrieveAsync();
|
SingleResultCurrentWeatherRequestCustomizer(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer language(Language language) {
|
||||||
|
requestSettings.setLanguage(language);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
requestSettings.setUnitSystem(unitSystem);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleResultCurrentWeatherRequestTerminator retrieve() {
|
||||||
|
return new SingleResultCurrentWeatherRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleResultCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
||||||
|
return new SingleResultCurrentWeatherAsyncRequestTerminator(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
-70
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.Language;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Single result current weather request customizer.
|
|
||||||
*/
|
|
||||||
public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleResultCurrentWeatherRequestCustomizer {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
|
|
||||||
private Language language;
|
|
||||||
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Single result current weather request customizer.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
*/
|
|
||||||
SingleResultCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer language(Language language) {
|
|
||||||
this.language = language;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SingleResultCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SingleResultCurrentWeatherRequestTerminator retrieve() {
|
|
||||||
urlBuilder.applyCustomization(language, unitSystem);
|
|
||||||
return new SingleResultCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SingleResultCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
|
||||||
urlBuilder.applyCustomization(language, unitSystem);
|
|
||||||
return new SingleResultCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+34
-12
@@ -22,24 +22,46 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.ResponseType;
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current weather request terminator interface.
|
* The type Single result current weather request terminator.
|
||||||
*/
|
*/
|
||||||
public interface SingleResultCurrentWeatherRequestTerminator extends RequestTerminator<Weather, String> {
|
public class SingleResultCurrentWeatherRequestTerminator {
|
||||||
/**
|
private final RequestSettings requestSettings;
|
||||||
* XML response format.
|
|
||||||
*
|
|
||||||
* @return the XML string
|
|
||||||
*/
|
|
||||||
String asXML();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTML response format.
|
* Instantiates a new Single result current weather request terminator.
|
||||||
*
|
*
|
||||||
* @return the HTML string
|
* @param requestSettings request settings object.
|
||||||
*/
|
*/
|
||||||
String asHTML();
|
SingleResultCurrentWeatherRequestTerminator(RequestSettings requestSettings) {
|
||||||
|
this.requestSettings = requestSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Weather asJava() {
|
||||||
|
return new CurrentWeatherResponseMapper(requestSettings.getUnitSystem()).getSingle(asJSON());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asXML() {
|
||||||
|
requestSettings.setResponseType(ResponseType.XML);
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String asHTML() {
|
||||||
|
requestSettings.setResponseType(ResponseType.HTML);
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(requestSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-74
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
|
||||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The type Single result current weather request terminator.
|
|
||||||
*/
|
|
||||||
public class SingleResultCurrentWeatherRequestTerminatorImpl implements SingleResultCurrentWeatherRequestTerminator {
|
|
||||||
private final RequestUrlBuilder urlBuilder;
|
|
||||||
private final UnitSystem unitSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Single result current weather request terminator.
|
|
||||||
*
|
|
||||||
* @param urlBuilder the url builder
|
|
||||||
* @param unitSystem the unit system
|
|
||||||
*/
|
|
||||||
SingleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
|
||||||
this.urlBuilder = urlBuilder;
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Weather asJava() {
|
|
||||||
return new CurrentWeatherResponseMapper(unitSystem).getSingle(asJSON());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String asJSON() {
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String asXML() {
|
|
||||||
urlBuilder.addRequestParameter("mode", "xml");
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String asHTML() {
|
|
||||||
urlBuilder.addRequestParameter("mode", "html");
|
|
||||||
return getRawResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRawResponse() {
|
|
||||||
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,8 +22,10 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.utils;
|
package com.github.prominence.openweathermap.api.utils;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
||||||
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
|
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
|
||||||
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -35,17 +37,32 @@ import java.net.HttpURLConnection;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for API calls execution.
|
* Utility class for API calls execution.
|
||||||
*/
|
*/
|
||||||
public final class RequestUtils {
|
public final class RequestUtils {
|
||||||
|
|
||||||
|
private static final String OWM_URL_BASE = "http://api.openweathermap.org/data/2.5/";
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(RequestUtils.class);
|
private static final Logger logger = LoggerFactory.getLogger(RequestUtils.class);
|
||||||
|
|
||||||
private RequestUtils() {
|
private RequestUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getResponse(RequestSettings requestSettings) {
|
||||||
|
StringBuilder requestUrlBuilder = new StringBuilder(OWM_URL_BASE);
|
||||||
|
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 getResponse(requestUrlBuilder.toString(), requestSettings.getTimeoutSettings());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes call to provided API url and retrieves response in <code>String</code> representation.
|
* Executes call to provided API url and retrieves response in <code>String</code> representation.
|
||||||
*
|
*
|
||||||
@@ -54,6 +71,18 @@ public final class RequestUtils {
|
|||||||
* @throws IllegalArgumentException in case if provided parameter isn't a valid url for {@link URL} instance.
|
* @throws IllegalArgumentException in case if provided parameter isn't a valid url for {@link URL} instance.
|
||||||
*/
|
*/
|
||||||
public static String getResponse(String url) {
|
public static String getResponse(String url) {
|
||||||
|
return getResponse(url, new TimeoutSettings());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes call to provided API url and retrieves response in <code>String</code> representation.
|
||||||
|
*
|
||||||
|
* @param url the url to make API request.
|
||||||
|
* @param timeoutSettings an object with timeout settings.
|
||||||
|
* @return response from the request in <code>String</code> representation.
|
||||||
|
* @throws IllegalArgumentException in case if provided parameter isn't a valid url for {@link URL} instance.
|
||||||
|
*/
|
||||||
|
public static String getResponse(String url, TimeoutSettings timeoutSettings) {
|
||||||
URL requestUrl;
|
URL requestUrl;
|
||||||
try {
|
try {
|
||||||
requestUrl = new URL(url);
|
requestUrl = new URL(url);
|
||||||
@@ -62,7 +91,7 @@ public final class RequestUtils {
|
|||||||
throw new IllegalArgumentException(ex);
|
throw new IllegalArgumentException(ex);
|
||||||
}
|
}
|
||||||
logger.debug("Executing OpenWeatherMap API request: " + url);
|
logger.debug("Executing OpenWeatherMap API request: " + url);
|
||||||
final InputStream requestInputStream = executeRequest(requestUrl);
|
final InputStream requestInputStream = executeRequest(requestUrl, timeoutSettings);
|
||||||
|
|
||||||
return convertInputStreamToString(requestInputStream);
|
return convertInputStreamToString(requestInputStream);
|
||||||
}
|
}
|
||||||
@@ -75,11 +104,20 @@ public final class RequestUtils {
|
|||||||
* @throws InvalidAuthTokenException in case if authentication token wasn't set or requested functionality is not permitted for its subscription plan.
|
* @throws InvalidAuthTokenException in case if authentication token wasn't set or requested functionality is not permitted for its subscription plan.
|
||||||
* @throws NoDataFoundException in case if there is no any data for requested location(s) or request is invalid.
|
* @throws NoDataFoundException in case if there is no any data for requested location(s) or request is invalid.
|
||||||
*/
|
*/
|
||||||
private static InputStream executeRequest(URL requestUrl) {
|
private static InputStream executeRequest(URL requestUrl, TimeoutSettings timeoutSettings) {
|
||||||
InputStream resultStream;
|
InputStream resultStream;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();
|
||||||
|
|
||||||
|
if (timeoutSettings.getConnectionTimeout() != null) {
|
||||||
|
connection.setConnectTimeout(timeoutSettings.getConnectionTimeout());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timeoutSettings.getReadTimeout() != null) {
|
||||||
|
connection.setReadTimeout(timeoutSettings.getReadTimeout());
|
||||||
|
}
|
||||||
|
|
||||||
connection.setRequestMethod("GET");
|
connection.setRequestMethod("GET");
|
||||||
|
|
||||||
switch (connection.getResponseCode()) {
|
switch (connection.getResponseCode()) {
|
||||||
|
|||||||
+100
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.onecall.current;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.MoonType;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
|
||||||
|
public class MoonPhaseUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getValue() {
|
||||||
|
final MoonPhase moonPhase = new MoonPhase(0.67);
|
||||||
|
|
||||||
|
assertEquals(0.67, moonPhase.getValue(), 0.000001);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getType() {
|
||||||
|
final MoonPhase newMoon1 = new MoonPhase(0d);
|
||||||
|
assertEquals(MoonType.NEW_MOON, newMoon1.getType());
|
||||||
|
|
||||||
|
final MoonPhase newMoon2 = new MoonPhase(1d);
|
||||||
|
assertEquals(MoonType.NEW_MOON, newMoon2.getType());
|
||||||
|
|
||||||
|
final MoonPhase firstQuarterMoon = new MoonPhase(0.25d);
|
||||||
|
assertEquals(MoonType.FIRST_QUARTER_MOON, firstQuarterMoon.getType());
|
||||||
|
|
||||||
|
final MoonPhase fullMoon = new MoonPhase(0.5d);
|
||||||
|
assertEquals(MoonType.FULL_MOON, fullMoon.getType());
|
||||||
|
|
||||||
|
final MoonPhase lastQuarterMoon = new MoonPhase(0.75d);
|
||||||
|
assertEquals(MoonType.LAST_QUARTER_MOON, lastQuarterMoon.getType());
|
||||||
|
|
||||||
|
final MoonPhase waxingCrescentMoon = new MoonPhase(0.1d);
|
||||||
|
assertEquals(MoonType.WAXING_CRESCENT, waxingCrescentMoon.getType());
|
||||||
|
|
||||||
|
final MoonPhase waxingGibbousMoon = new MoonPhase(0.4d);
|
||||||
|
assertEquals(MoonType.WAXING_GIBBOUS, waxingGibbousMoon.getType());
|
||||||
|
|
||||||
|
final MoonPhase waningGibbousMoon = new MoonPhase(0.623d);
|
||||||
|
assertEquals(MoonType.WANING_GIBBOUS, waningGibbousMoon.getType());
|
||||||
|
|
||||||
|
final MoonPhase waningCrescentMoon = new MoonPhase(0.9999d);
|
||||||
|
assertEquals(MoonType.WANING_CRESCENT, waningCrescentMoon.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getEquals() {
|
||||||
|
final MoonPhase phase1 = new MoonPhase(0d);
|
||||||
|
final MoonPhase phase2 = new MoonPhase(0.5d);
|
||||||
|
|
||||||
|
assertNotEquals(phase1, phase2);
|
||||||
|
|
||||||
|
final MoonPhase phase3 = new MoonPhase(0d);
|
||||||
|
|
||||||
|
assertEquals(phase1, phase3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getHashCode() {
|
||||||
|
final MoonPhase phase1 = new MoonPhase(0d);
|
||||||
|
final MoonPhase phase2 = new MoonPhase(0.5d);
|
||||||
|
|
||||||
|
assertNotEquals(phase1.hashCode(), phase2.hashCode());
|
||||||
|
|
||||||
|
final MoonPhase phase3 = new MoonPhase(0d);
|
||||||
|
|
||||||
|
assertEquals(phase1.hashCode(), phase3.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getToString() {
|
||||||
|
final MoonPhase phase2 = new MoonPhase(0.5d);
|
||||||
|
|
||||||
|
assertEquals("FULL_MOON(0.5)", phase2.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.air.pollution;
|
package com.github.prominence.openweathermap.api.request.air.pollution;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.AirPollutionResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|||||||
+1
@@ -23,6 +23,7 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.forecast.free;
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.FiveDayThreeHourStepForecastResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|||||||
+1
@@ -23,6 +23,7 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.onecall;
|
package com.github.prominence.openweathermap.api.request.onecall;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.OneCallWeatherResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
import com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData;
|
||||||
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
|||||||
+1
@@ -23,6 +23,7 @@
|
|||||||
package com.github.prominence.openweathermap.api.request.weather;
|
package com.github.prominence.openweathermap.api.request.weather;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.mapper.CurrentWeatherResponseMapper;
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user