mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-01-10 11:56:44 +03:00
Adjusted to use 17 source and 8 target version. Code refactoring. Docs improvements.
This commit is contained in:
parent
5ca31780da
commit
8ca55b15f7
12
build.gradle
12
build.gradle
@ -17,12 +17,22 @@ dependencies {
|
|||||||
implementation 'org.slf4j:slf4j-api:1.7.36'
|
implementation 'org.slf4j:slf4j-api:1.7.36'
|
||||||
testImplementation 'org.junit.platform:junit-platform-runner:1.8.2'
|
testImplementation 'org.junit.platform:junit-platform-runner:1.8.2'
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
|
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
|
||||||
|
|
||||||
|
annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:0.4.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'com.github.prominence'
|
group = 'com.github.prominence'
|
||||||
version = '3.0.0-SNAPSHOT'
|
version = '3.0.0-SNAPSHOT'
|
||||||
description = 'Java OpenWeatherMap API'
|
description = 'Java OpenWeatherMap API'
|
||||||
java.sourceCompatibility = JavaVersion.VERSION_17
|
|
||||||
|
configure([tasks.compileJava]) {
|
||||||
|
sourceCompatibility = 17 // for the IDE support
|
||||||
|
options.release = 8
|
||||||
|
|
||||||
|
javaCompiler = javaToolchains.compilerFor {
|
||||||
|
languageVersion = JavaLanguageVersion.of(17)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
isReleaseVersion = !version.endsWith("SNAPSHOT")
|
isReleaseVersion = !version.endsWith("SNAPSHOT")
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:1.0')
|
implementation 'com.github.prominence:openweathermap-api:1.0'
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to use:
|
### How to use:
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:1.1')
|
implementation 'com.github.prominence:openweathermap-api:1.1'
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to use:
|
### How to use:
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:1.2')
|
implementation 'com.github.prominence:openweathermap-api:1.2'
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to use:
|
### How to use:
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:2.0.0')
|
implementation 'com.github.prominence:openweathermap-api:2.0.0'
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to use:
|
### How to use:
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:2.0.1')
|
implementation 'com.github.prominence:openweathermap-api:2.0.1'
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to use:
|
### How to use:
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:2.1.0')
|
implementation 'com.github.prominence:openweathermap-api:2.1.0'
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to use:
|
### How to use:
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:2.1.1')
|
implementation 'com.github.prominence:openweathermap-api:2.1.1'
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to use:
|
### How to use:
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:2.2.0')
|
implementation 'com.github.prominence:openweathermap-api:2.2.0'
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to use:
|
### How to use:
|
||||||
|
|||||||
@ -21,7 +21,7 @@ Other:
|
|||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:2.3.0')
|
implementation 'com.github.prominence:openweathermap-api:2.3.0'
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to use:
|
### How to use:
|
||||||
|
|||||||
@ -52,14 +52,10 @@ public enum UnitSystem {
|
|||||||
* @return wind unit.
|
* @return wind unit.
|
||||||
*/
|
*/
|
||||||
public String getWindUnit() {
|
public String getWindUnit() {
|
||||||
switch (this) {
|
return switch (this) {
|
||||||
case IMPERIAL:
|
case IMPERIAL -> "miles/hour";
|
||||||
return "miles/hour";
|
case STANDARD, METRIC -> "meter/sec";
|
||||||
case STANDARD:
|
};
|
||||||
case METRIC:
|
|
||||||
default:
|
|
||||||
return "meter/sec";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,15 +63,11 @@ public enum UnitSystem {
|
|||||||
* @return temperature unit.
|
* @return temperature unit.
|
||||||
*/
|
*/
|
||||||
public String getTemperatureUnit() {
|
public String getTemperatureUnit() {
|
||||||
switch (this) {
|
return switch (this) {
|
||||||
case METRIC:
|
case METRIC -> "°C";
|
||||||
return "°C";
|
case IMPERIAL -> "°F";
|
||||||
case IMPERIAL:
|
case STANDARD -> "K";
|
||||||
return "°F";
|
};
|
||||||
case STANDARD:
|
|
||||||
default:
|
|
||||||
return "K";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -44,7 +44,7 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
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 String OWM_URL_BASE = "https://api.openweathermap.org/data/2.5/";
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(RequestUtils.class);
|
private static final Logger logger = LoggerFactory.getLogger(RequestUtils.class);
|
||||||
|
|
||||||
@ -120,18 +120,13 @@ public final class RequestUtils {
|
|||||||
|
|
||||||
connection.setRequestMethod("GET");
|
connection.setRequestMethod("GET");
|
||||||
|
|
||||||
switch (connection.getResponseCode()) {
|
resultStream = switch (connection.getResponseCode()) {
|
||||||
case HttpURLConnection.HTTP_OK:
|
case HttpURLConnection.HTTP_OK -> connection.getInputStream();
|
||||||
resultStream = connection.getInputStream();
|
case HttpURLConnection.HTTP_UNAUTHORIZED -> throw new InvalidAuthTokenException();
|
||||||
break;
|
case HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST ->
|
||||||
case HttpURLConnection.HTTP_UNAUTHORIZED:
|
throw new NoDataFoundException();
|
||||||
throw new InvalidAuthTokenException();
|
default -> throw new IllegalStateException("Unexpected value: " + connection.getResponseCode());
|
||||||
case HttpURLConnection.HTTP_NOT_FOUND:
|
};
|
||||||
case HttpURLConnection.HTTP_BAD_REQUEST:
|
|
||||||
throw new NoDataFoundException();
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("Unexpected value: " + connection.getResponseCode());
|
|
||||||
}
|
|
||||||
} catch (IllegalStateException | IOException ex) {
|
} catch (IllegalStateException | IOException ex) {
|
||||||
logger.error("An error occurred during OpenWeatherMap API response parsing: ", ex);
|
logger.error("An error occurred during OpenWeatherMap API response parsing: ", ex);
|
||||||
throw new NoDataFoundException(ex);
|
throw new NoDataFoundException(ex);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user