mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-01-09 19:46:41 +03:00
Checked visibility. Removed unused exceptions' constructors. Renamed sunruse/sunset methods and variables. Updated documentation.
This commit is contained in:
parent
c5cbf79efb
commit
b0cbf1135d
26
README.md
26
README.md
@ -56,18 +56,18 @@ Available requests:
|
||||
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||
| `getBase()` | Returns `String` with some internal information. Example: `cmc stations` - from official documentation. |
|
||||
| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, pressure and humidity. |
|
||||
| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, pressure and humidity. |
|
||||
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
|
||||
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
|
||||
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
||||
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
||||
| `getDataCalculationTime()`| Returns `long` value that represents data calculation timestamp. |
|
||||
| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset times. |
|
||||
| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset time. |
|
||||
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||
| `getCountry()` | An alias for `getWeatherSystemInfo().getCountry()`. |
|
||||
| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. |
|
||||
| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. |
|
||||
| `getDataCalculationDate()`| Returns data calculation time in `Date` representation. |
|
||||
| `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. |
|
||||
| `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. |
|
||||
@ -121,20 +121,20 @@ Available requests:
|
||||
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||
| `getCityInfo()` | Returns `HourlyForecast.CityInfo` instance that contains information about city. |
|
||||
| `getCityInfo()` | Returns `HourlyForecast.CityInfo` instance that contains information about city. |
|
||||
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
|
||||
| `getForecasts()` | Returns `List<HourlyForecast.ForecastInfo>` collection with all forecast information. |
|
||||
| `getForecasts()` | Returns `List<HourlyForecast.ForecastInfo>` collection with all forecast information. |
|
||||
| `getAverageTemperature()` | Returns average temperature from forecasts. |
|
||||
| `getMinimumTemperature()` | Returns minimum temperature from forecasts. |
|
||||
| `getMaximumTemperature()` | Returns maximum temperature from forecasts. |
|
||||
| `getByMinimumTemperature()` | Returns `HourlyForecast.ForecastInfo` for the time where temperature is minimal. |
|
||||
| `getByMaximumTemperature()` | Returns `HourlyForecast.ForecastInfo` for the time where temperature is maximal. |
|
||||
| `getByMinimumTemperature()` | Returns `HourlyForecast.ForecastInfo` for the time where temperature is minimal. |
|
||||
| `getByMaximumTemperature()` | Returns `HourlyForecast.ForecastInfo` for the time where temperature is maximal. |
|
||||
| `getAveragePressure()` | Returns average pressure from forecasts. |
|
||||
| `getMinimumPressure()` | Returns minimum pressure from forecasts. |
|
||||
| `getMaximumPressure()` | Returns maximum pressure from forecasts. |
|
||||
| `getByMinimumPressure()` | Returns `HourlyForecast.ForecastInfo` for the time where pressure is minimal. |
|
||||
| `getByMaximumPressure()` | Returns `HourlyForecast.ForecastInfo` for the time where pressure is maximal. |
|
||||
| `getByMinimumPressure()` | Returns `HourlyForecast.ForecastInfo` for the time where pressure is minimal. |
|
||||
| `getByMaximumPressure()` | Returns `HourlyForecast.ForecastInfo` for the time where pressure is maximal. |
|
||||
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||
|
||||
`toString()` output example:
|
||||
@ -190,13 +190,13 @@ Forecasts:
|
||||
|-----------------------------|------------------------------------------------------------------------------------------------------------------|
|
||||
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
|
||||
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
|
||||
| `getMainInfo()` | Returns `HourlyForecast.MainInfo` instance that contains information about temperature, pressure and humidity. |
|
||||
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||
| `getMainInfo()` | Returns `HourlyForecast.MainInfo` instance that contains information about temperature, pressure and humidity. |
|
||||
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
|
||||
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
|
||||
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
||||
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
||||
| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. |
|
||||
| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. |
|
||||
| `getDt_txt()` | Returns `String` value that represents data calculation time. |
|
||||
| `toString()` | Returns pretty string for the whole available weather information. |
|
||||
|
||||
|
||||
@ -22,7 +22,9 @@
|
||||
|
||||
package by.prominence.openweathermap.api.constants;
|
||||
|
||||
public class Accuracy {
|
||||
public final class Accuracy {
|
||||
|
||||
private Accuracy() {}
|
||||
|
||||
public static final String LIKE = "like";
|
||||
public static final String ACCURATE = "accurate";
|
||||
|
||||
@ -22,7 +22,9 @@
|
||||
|
||||
package by.prominence.openweathermap.api.constants;
|
||||
|
||||
public class Language {
|
||||
public final class Language {
|
||||
|
||||
private Language() {}
|
||||
|
||||
public static final String ARABIC = "ar";
|
||||
public static final String BULGARIAN = "bg";
|
||||
|
||||
@ -22,7 +22,9 @@
|
||||
|
||||
package by.prominence.openweathermap.api.constants;
|
||||
|
||||
public class System {
|
||||
public final class System {
|
||||
|
||||
private System() {}
|
||||
|
||||
public static final String OPEN_WEATHER_API_VERSION = "2.5";
|
||||
public static final String OPEN_WEATHER_API_URL = "http://api.openweathermap.org/data/" + OPEN_WEATHER_API_VERSION + "/";
|
||||
|
||||
@ -22,7 +22,9 @@
|
||||
|
||||
package by.prominence.openweathermap.api.constants;
|
||||
|
||||
public class Unit {
|
||||
public final class Unit {
|
||||
|
||||
private Unit() {}
|
||||
|
||||
public static final String METRIC_SYSTEM = "metric";
|
||||
public static final String IMPERIAL_SYSTEM = "imperial";
|
||||
|
||||
@ -28,7 +28,4 @@ public class DataNotFoundException extends Exception {
|
||||
super("Data for provided parameters wasn't found. Please, check your request.");
|
||||
}
|
||||
|
||||
public DataNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,10 +25,7 @@ package by.prominence.openweathermap.api.exception;
|
||||
public class InvalidAuthTokenException extends Exception {
|
||||
|
||||
public InvalidAuthTokenException() {
|
||||
super("Check you authentication token! You can get it here: https://home.openweathermap.org/api_keys/. Please, notice that some requests requires non-free subscription plan.");
|
||||
super("Check you authentication token! You can get it here: https://home.openweathermap.org/api_keys/.");
|
||||
}
|
||||
|
||||
public InvalidAuthTokenException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ public class Rain {
|
||||
|
||||
@JSONField(name = "3h")
|
||||
// Rain volume for the last 3 hours
|
||||
byte rainVolumeLast3Hrs;
|
||||
private byte rainVolumeLast3Hrs;
|
||||
|
||||
public byte getRainVolumeLast3Hrs() {
|
||||
return rainVolumeLast3Hrs;
|
||||
|
||||
@ -174,10 +174,10 @@ public class HourlyForecast implements OpenWeatherResponse {
|
||||
|
||||
public static class CityInfo {
|
||||
|
||||
// CityInfo ID
|
||||
// City ID
|
||||
private long id;
|
||||
|
||||
// CityInfo name
|
||||
// City name
|
||||
private String name;
|
||||
|
||||
@JSONField(name = "coord")
|
||||
|
||||
@ -424,11 +424,11 @@ public class Weather implements OpenWeatherResponse {
|
||||
|
||||
@JSONField(name = "sunrise")
|
||||
// Sunrise time, unix, UTC
|
||||
private long sunrise;
|
||||
private long sunriseTimestamp;
|
||||
|
||||
@JSONField(name = "sunset")
|
||||
// Sunset time, unix, UTC
|
||||
private long sunset;
|
||||
private long sunsetTimestamp;
|
||||
|
||||
public short getType() {
|
||||
return type;
|
||||
@ -462,20 +462,28 @@ public class Weather implements OpenWeatherResponse {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public long getSunrise() {
|
||||
return sunrise;
|
||||
public long getSunriseTimestamp() {
|
||||
return sunriseTimestamp;
|
||||
}
|
||||
|
||||
public void setSunrise(long sunrise) {
|
||||
this.sunrise = sunrise;
|
||||
public void setSunriseTimestamp(long sunriseTimestamp) {
|
||||
this.sunriseTimestamp = sunriseTimestamp;
|
||||
}
|
||||
|
||||
public long getSunset() {
|
||||
return sunset;
|
||||
public Date getSunriseDate() {
|
||||
return new Date(sunriseTimestamp * 1000);
|
||||
}
|
||||
|
||||
public void setSunset(long sunset) {
|
||||
this.sunset = sunset;
|
||||
public long getSunsetTimestamp() {
|
||||
return sunsetTimestamp;
|
||||
}
|
||||
|
||||
public void setSunsetTimestamp(long sunsetTimestamp) {
|
||||
this.sunsetTimestamp = sunsetTimestamp;
|
||||
}
|
||||
|
||||
public Date getSunsetDate() {
|
||||
return new Date(sunsetTimestamp * 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -487,14 +495,14 @@ public class Weather implements OpenWeatherResponse {
|
||||
stringBuilder.append(country);
|
||||
stringBuilder.append('\n');
|
||||
}
|
||||
if (sunrise > 0) {
|
||||
if (sunriseTimestamp > 0) {
|
||||
stringBuilder.append("Sunrise: ");
|
||||
stringBuilder.append(new Date(sunrise * 1000));
|
||||
stringBuilder.append(getSunriseDate());
|
||||
stringBuilder.append('\n');
|
||||
}
|
||||
if (sunset > 0) {
|
||||
if (sunsetTimestamp > 0) {
|
||||
stringBuilder.append("Sunset: ");
|
||||
stringBuilder.append(new Date(sunset * 1000));
|
||||
stringBuilder.append(getSunsetDate());
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
@ -509,14 +517,14 @@ public class Weather implements OpenWeatherResponse {
|
||||
id == that.id &&
|
||||
Double.compare(that.message, message) == 0 &&
|
||||
Objects.equals(country, that.country) &&
|
||||
Objects.equals(sunrise, that.sunrise) &&
|
||||
Objects.equals(sunset, that.sunset);
|
||||
Objects.equals(sunriseTimestamp, that.sunriseTimestamp) &&
|
||||
Objects.equals(sunsetTimestamp, that.sunsetTimestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(type, id, message, country, sunrise, sunset);
|
||||
return Objects.hash(type, id, message, country, sunriseTimestamp, sunsetTimestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,9 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class JsonUtils {
|
||||
public final class JsonUtils {
|
||||
|
||||
private JsonUtils() {}
|
||||
|
||||
public static Object parseJson(InputStream inputStream, Class clazz) throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
|
||||
@ -30,7 +30,9 @@ import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
public class RequestUtils {
|
||||
public final class RequestUtils {
|
||||
|
||||
private RequestUtils() {}
|
||||
|
||||
public static InputStream executeGetRequest(URL requestUrl) throws InvalidAuthTokenException, DataNotFoundException {
|
||||
InputStream resultStream = null;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user