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.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
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)
|
@Target(ElementType.METHOD)
|
||||||
@Retention(RetentionPolicy.CLASS)
|
@Retention(RetentionPolicy.CLASS)
|
||||||
public @interface SubscriptionAvailability {
|
public @interface SubscriptionAvailability {
|
||||||
|
|||||||
@ -22,8 +22,11 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.enums;
|
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 {
|
public enum Language {
|
||||||
|
|
||||||
ARABIC("ar"),
|
ARABIC("ar"),
|
||||||
BULGARIAN("bg"),
|
BULGARIAN("bg"),
|
||||||
CATALAN("ca"),
|
CATALAN("ca"),
|
||||||
|
|||||||
@ -22,6 +22,10 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.enums;
|
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 {
|
public enum SubscriptionPlan {
|
||||||
FREE,
|
FREE,
|
||||||
STARTUP,
|
STARTUP,
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.enums;
|
package com.github.prominence.openweathermap.api.enums;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public enum TimeFrame {
|
public enum TimeFrame {
|
||||||
YEAR,
|
YEAR,
|
||||||
MONTH,
|
MONTH,
|
||||||
|
|||||||
@ -22,8 +22,10 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.enums;
|
package com.github.prominence.openweathermap.api.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An enumeration for supported unit systems with helper methods.
|
||||||
|
*/
|
||||||
public enum UnitSystem {
|
public enum UnitSystem {
|
||||||
|
|
||||||
METRIC("metric"),
|
METRIC("metric"),
|
||||||
IMPERIAL("imperial"),
|
IMPERIAL("imperial"),
|
||||||
STANDARD("standard");
|
STANDARD("standard");
|
||||||
@ -34,8 +36,8 @@ public enum UnitSystem {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getWindUnit(UnitSystem type) {
|
public String getWindUnit() {
|
||||||
switch (type) {
|
switch (this) {
|
||||||
case IMPERIAL:
|
case IMPERIAL:
|
||||||
return "miles/hour";
|
return "miles/hour";
|
||||||
case STANDARD:
|
case STANDARD:
|
||||||
@ -45,8 +47,8 @@ public enum UnitSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTemperatureUnit(UnitSystem type) {
|
public String getTemperatureUnit() {
|
||||||
switch (type) {
|
switch (this) {
|
||||||
case METRIC:
|
case METRIC:
|
||||||
return "℃";
|
return "℃";
|
||||||
case IMPERIAL:
|
case IMPERIAL:
|
||||||
|
|||||||
@ -22,10 +22,13 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.exception;
|
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 class InvalidAuthTokenException extends RuntimeException {
|
||||||
|
|
||||||
public InvalidAuthTokenException() {
|
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.");
|
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;
|
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 class NoDataFoundException extends RuntimeException {
|
||||||
|
|
||||||
public NoDataFoundException() {
|
public NoDataFoundException() {
|
||||||
super("Data for provided parameters wasn't found. Please, check requested location.");
|
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) {
|
public NoDataFoundException(Throwable throwable) {
|
||||||
super(throwable.getMessage(), throwable.getCause());
|
super(throwable.getMessage(), throwable.getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -151,7 +151,7 @@ public class FiveDayThreeHourStepForecastResponseMapper {
|
|||||||
|
|
||||||
private Temperature parseTemperature(JsonNode rootNode) {
|
private Temperature parseTemperature(JsonNode rootNode) {
|
||||||
final double tempValue = rootNode.get("temp").asDouble();
|
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");
|
final JsonNode tempMaxNode = rootNode.get("temp_max");
|
||||||
if (tempMaxNode != null) {
|
if (tempMaxNode != null) {
|
||||||
@ -192,7 +192,7 @@ public class FiveDayThreeHourStepForecastResponseMapper {
|
|||||||
final JsonNode windNode = root.get("wind");
|
final JsonNode windNode = root.get("wind");
|
||||||
double speed = windNode.get("speed").asDouble();
|
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");
|
final JsonNode degNode = windNode.get("deg");
|
||||||
if (degNode != null) {
|
if (degNode != null) {
|
||||||
wind.setDegrees(degNode.asDouble());
|
wind.setDegrees(degNode.asDouble());
|
||||||
|
|||||||
@ -147,7 +147,7 @@ public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
|
|||||||
final JsonNode mainNode = rootNode.get("main");
|
final JsonNode mainNode = rootNode.get("main");
|
||||||
|
|
||||||
final double tempValue = mainNode.get("temp").asDouble();
|
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");
|
final JsonNode feelsLikeNode = mainNode.get("feels_like");
|
||||||
if (feelsLikeNode != null) {
|
if (feelsLikeNode != null) {
|
||||||
@ -191,7 +191,7 @@ public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
|
|||||||
final JsonNode windNode = rootNode.get("wind");
|
final JsonNode windNode = rootNode.get("wind");
|
||||||
double speed = windNode.get("speed").asDouble();
|
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");
|
final JsonNode degNode = windNode.get("deg");
|
||||||
if (degNode != null) {
|
if (degNode != null) {
|
||||||
|
|||||||
@ -53,7 +53,6 @@ public final class RequestUtils {
|
|||||||
* @return <code>InputStream</code> instance containing http response body.
|
* @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 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.
|
||||||
* @throws IllegalStateException in case of unexpected response or error.
|
|
||||||
*/
|
*/
|
||||||
private static InputStream executeRequest(URL requestUrl) {
|
private static InputStream executeRequest(URL requestUrl) {
|
||||||
InputStream resultStream;
|
InputStream resultStream;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user