mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-01-09 19:46:41 +03:00
Added javadocs and refactoring.
This commit is contained in:
parent
7003935869
commit
4c7b553b81
@ -29,6 +29,9 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marker-type annotation to specify what type of license it needs to have to use API method.
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
public @interface SubscriptionAvailability {
|
||||
|
||||
@ -22,8 +22,11 @@
|
||||
|
||||
package com.github.prominence.openweathermap.api.enums;
|
||||
|
||||
/**
|
||||
* An enumeration which lists all available languages for API usage.
|
||||
* Usually it could be specified to get response with some fields translated into desired language.
|
||||
*/
|
||||
public enum Language {
|
||||
|
||||
ARABIC("ar"),
|
||||
BULGARIAN("bg"),
|
||||
CATALAN("ca"),
|
||||
|
||||
@ -22,6 +22,10 @@
|
||||
|
||||
package com.github.prominence.openweathermap.api.enums;
|
||||
|
||||
/**
|
||||
* An enumeration with all available subscription plans.
|
||||
* More information <a href="https://openweathermap.org/price">at official website</a>.
|
||||
*/
|
||||
public enum SubscriptionPlan {
|
||||
FREE,
|
||||
STARTUP,
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
|
||||
package com.github.prominence.openweathermap.api.enums;
|
||||
|
||||
@Deprecated
|
||||
public enum TimeFrame {
|
||||
YEAR,
|
||||
MONTH,
|
||||
|
||||
@ -22,8 +22,10 @@
|
||||
|
||||
package com.github.prominence.openweathermap.api.enums;
|
||||
|
||||
/**
|
||||
* An enumeration for supported unit systems with helper methods.
|
||||
*/
|
||||
public enum UnitSystem {
|
||||
|
||||
METRIC("metric"),
|
||||
IMPERIAL("imperial"),
|
||||
STANDARD("standard");
|
||||
@ -34,8 +36,8 @@ public enum UnitSystem {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static String getWindUnit(UnitSystem type) {
|
||||
switch (type) {
|
||||
public String getWindUnit() {
|
||||
switch (this) {
|
||||
case IMPERIAL:
|
||||
return "miles/hour";
|
||||
case STANDARD:
|
||||
@ -45,8 +47,8 @@ public enum UnitSystem {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTemperatureUnit(UnitSystem type) {
|
||||
switch (type) {
|
||||
public String getTemperatureUnit() {
|
||||
switch (this) {
|
||||
case METRIC:
|
||||
return "℃";
|
||||
case IMPERIAL:
|
||||
|
||||
@ -22,10 +22,13 @@
|
||||
|
||||
package com.github.prominence.openweathermap.api.exception;
|
||||
|
||||
/**
|
||||
* An exception that could be thrown in case of your API key is invalid or your subscription plan does not cover requested functionality.
|
||||
* Subscription plans information you can find <a href="https://openweathermap.org/price">here</a>.
|
||||
* API Keys could be checked in <a href="https://home.openweathermap.org/api_keys/">your profile</a>.
|
||||
*/
|
||||
public class InvalidAuthTokenException extends RuntimeException {
|
||||
|
||||
public InvalidAuthTokenException() {
|
||||
super("Authentication token wasn't set or requested functionality is not permitted for your subscription plan. Please, check https://home.openweathermap.org/api_keys/ and https://openweathermap.org/price.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -22,8 +22,15 @@
|
||||
|
||||
package com.github.prominence.openweathermap.api.exception;
|
||||
|
||||
/**
|
||||
* An exception that could be thrown in several cases:
|
||||
* <ul>
|
||||
* <li>There is no data found for your query(wrong coordinates somewhere in the sea, some distant place, etc.);</li>
|
||||
* <li>Request is malformed. An occasion to report an <a href="https://github.com/Prominence/openweathermap-java-api/issues">issue</a>;</li>
|
||||
* <li>Any other unpredictable problems.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class NoDataFoundException extends RuntimeException {
|
||||
|
||||
public NoDataFoundException() {
|
||||
super("Data for provided parameters wasn't found. Please, check requested location.");
|
||||
}
|
||||
@ -31,5 +38,4 @@ public class NoDataFoundException extends RuntimeException {
|
||||
public NoDataFoundException(Throwable throwable) {
|
||||
super(throwable.getMessage(), throwable.getCause());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ public class FiveDayThreeHourStepForecastResponseMapper {
|
||||
|
||||
private Temperature parseTemperature(JsonNode rootNode) {
|
||||
final double tempValue = rootNode.get("temp").asDouble();
|
||||
Temperature temperature = Temperature.forValue(tempValue, UnitSystem.getTemperatureUnit(unitSystem));
|
||||
Temperature temperature = Temperature.forValue(tempValue, unitSystem.getTemperatureUnit());
|
||||
|
||||
final JsonNode tempMaxNode = rootNode.get("temp_max");
|
||||
if (tempMaxNode != null) {
|
||||
@ -192,7 +192,7 @@ public class FiveDayThreeHourStepForecastResponseMapper {
|
||||
final JsonNode windNode = root.get("wind");
|
||||
double speed = windNode.get("speed").asDouble();
|
||||
|
||||
Wind wind = Wind.forValue(speed, UnitSystem.getWindUnit(unitSystem));
|
||||
Wind wind = Wind.forValue(speed, unitSystem.getWindUnit());
|
||||
final JsonNode degNode = windNode.get("deg");
|
||||
if (degNode != null) {
|
||||
wind.setDegrees(degNode.asDouble());
|
||||
|
||||
@ -147,7 +147,7 @@ public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
|
||||
final JsonNode mainNode = rootNode.get("main");
|
||||
|
||||
final double tempValue = mainNode.get("temp").asDouble();
|
||||
temperature = Temperature.forValue(tempValue, UnitSystem.getTemperatureUnit(unitSystem));
|
||||
temperature = Temperature.forValue(tempValue, unitSystem.getTemperatureUnit());
|
||||
|
||||
final JsonNode feelsLikeNode = mainNode.get("feels_like");
|
||||
if (feelsLikeNode != null) {
|
||||
@ -191,7 +191,7 @@ public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
|
||||
final JsonNode windNode = rootNode.get("wind");
|
||||
double speed = windNode.get("speed").asDouble();
|
||||
|
||||
Wind wind = Wind.forValue(speed, UnitSystem.getWindUnit(unitSystem));
|
||||
Wind wind = Wind.forValue(speed, unitSystem.getWindUnit());
|
||||
|
||||
final JsonNode degNode = windNode.get("deg");
|
||||
if (degNode != null) {
|
||||
|
||||
@ -53,7 +53,6 @@ public final class RequestUtils {
|
||||
* @return <code>InputStream</code> instance containing http response body.
|
||||
* @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 IllegalStateException in case of unexpected response or error.
|
||||
*/
|
||||
private static InputStream executeRequest(URL requestUrl) {
|
||||
InputStream resultStream;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user