mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-01-09 03:26:45 +03:00
Version 2.0.1 (#13)
* Added method for weather icon id retrieval. Small internal changes in models. * Changed temperature unit signs.
This commit is contained in:
parent
4c1b079e05
commit
f5d202aee3
4
.github/workflows/codeql-analysis.yml
vendored
4
.github/workflows/codeql-analysis.yml
vendored
@ -13,10 +13,10 @@ name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
branches: [ dev ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ master ]
|
||||
branches: [ dev ]
|
||||
schedule:
|
||||
- cron: '27 20 * * 1'
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ Paid:
|
||||
<dependency>
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
@ -105,6 +105,7 @@ You are able to set preferable options(via chain methods) and execute appropriat
|
||||
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getState()` | Returns short weather description. Example: `Clear`. |
|
||||
| `getDescription()` | Returns weather description. Example: `clear sky`. |
|
||||
| `getWeatherIconId()` | Returns a weather state ID. Examples: `01d`, `01n`, `11n`, etc. |
|
||||
| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. |
|
||||
| `getCalculatedOn()` | Returns `LocalDateTime` object with data calculation time. |
|
||||
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||
@ -188,6 +189,7 @@ A forecast for Minsk with 15 timestamps.
|
||||
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getState()` | Returns short weather description. Example: `Clear`. |
|
||||
| `getDescription()` | Returns weather description. Example: `clear sky`. |
|
||||
| `getWeatherIconId()` | Returns a weather state ID. Examples: `01d`, `01n`, `11n`, etc. |
|
||||
| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. |
|
||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||
|
||||
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.github.prominence</groupId>
|
||||
<artifactId>openweathermap-api</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Java OpenWeatherMap API</name>
|
||||
|
||||
@ -69,9 +69,9 @@ public enum UnitSystem {
|
||||
public String getTemperatureUnit() {
|
||||
switch (this) {
|
||||
case METRIC:
|
||||
return "℃";
|
||||
return "°C";
|
||||
case IMPERIAL:
|
||||
return "℉";
|
||||
return "°F";
|
||||
case STANDARD:
|
||||
default:
|
||||
return "K";
|
||||
|
||||
@ -33,7 +33,7 @@ import java.util.Objects;
|
||||
public class WeatherForecast {
|
||||
private String state;
|
||||
private String description;
|
||||
private String weatherIconUrl;
|
||||
private String weatherIconId;
|
||||
|
||||
private LocalDateTime forecastTime;
|
||||
|
||||
@ -113,22 +113,34 @@ public class WeatherForecast {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets weather icon ID.
|
||||
*
|
||||
* @return the weather icon ID
|
||||
*/
|
||||
public String getWeatherIconId() {
|
||||
return weatherIconId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets weather icon ID.
|
||||
*
|
||||
* @param weatherIconId the weather icon ID
|
||||
*/
|
||||
public void setWeatherIconId(String weatherIconId) {
|
||||
this.weatherIconId = weatherIconId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets weather icon url.
|
||||
*
|
||||
* @return the weather icon url
|
||||
*/
|
||||
public String getWeatherIconUrl() {
|
||||
return weatherIconUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets weather icon url.
|
||||
*
|
||||
* @param weatherIconUrl the weather icon url
|
||||
*/
|
||||
public void setWeatherIconUrl(String weatherIconUrl) {
|
||||
this.weatherIconUrl = weatherIconUrl;
|
||||
if (weatherIconId != null) {
|
||||
return "https://openweathermap.org/img/w/" + weatherIconId + ".png";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -318,7 +330,7 @@ public class WeatherForecast {
|
||||
WeatherForecast that = (WeatherForecast) o;
|
||||
return Objects.equals(state, that.state) &&
|
||||
Objects.equals(description, that.description) &&
|
||||
Objects.equals(weatherIconUrl, that.weatherIconUrl) &&
|
||||
Objects.equals(weatherIconId, that.weatherIconId) &&
|
||||
Objects.equals(forecastTime, that.forecastTime) &&
|
||||
Objects.equals(temperature, that.temperature) &&
|
||||
Objects.equals(atmosphericPressure, that.atmosphericPressure) &&
|
||||
@ -333,7 +345,7 @@ public class WeatherForecast {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(state, description, weatherIconUrl, forecastTime, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, forecastTimeISO, dayTime);
|
||||
return Objects.hash(state, description, weatherIconId, forecastTime, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, forecastTimeISO, dayTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -33,7 +33,7 @@ import java.util.Objects;
|
||||
public class Weather {
|
||||
private String state;
|
||||
private String description;
|
||||
private String weatherIconUrl;
|
||||
private String weatherIconId;
|
||||
|
||||
private LocalDateTime calculatedOn;
|
||||
|
||||
@ -112,22 +112,34 @@ public class Weather {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets weather icon ID.
|
||||
*
|
||||
* @return the weather icon ID
|
||||
*/
|
||||
public String getWeatherIconId() {
|
||||
return weatherIconId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets weather icon ID.
|
||||
*
|
||||
* @param weatherIconId the weather icon ID
|
||||
*/
|
||||
public void setWeatherIconId(String weatherIconId) {
|
||||
this.weatherIconId = weatherIconId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets weather icon url.
|
||||
*
|
||||
* @return the weather icon url
|
||||
*/
|
||||
public String getWeatherIconUrl() {
|
||||
return weatherIconUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets weather icon url.
|
||||
*
|
||||
* @param weatherIconUrl the weather icon url
|
||||
*/
|
||||
public void setWeatherIconUrl(String weatherIconUrl) {
|
||||
this.weatherIconUrl = weatherIconUrl;
|
||||
if (weatherIconId != null) {
|
||||
return "http://openweathermap.org/img/w/" + weatherIconId + ".png";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -299,7 +311,7 @@ public class Weather {
|
||||
Weather weather = (Weather) o;
|
||||
return Objects.equals(state, weather.state) &&
|
||||
Objects.equals(description, weather.description) &&
|
||||
Objects.equals(weatherIconUrl, weather.weatherIconUrl) &&
|
||||
Objects.equals(weatherIconId, weather.weatherIconId) &&
|
||||
Objects.equals(calculatedOn, weather.calculatedOn) &&
|
||||
Objects.equals(temperature, weather.temperature) &&
|
||||
Objects.equals(atmosphericPressure, weather.atmosphericPressure) &&
|
||||
@ -313,7 +325,7 @@ public class Weather {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(state, description, weatherIconUrl, calculatedOn, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, location);
|
||||
return Objects.hash(state, description, weatherIconId, calculatedOn, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, location);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -138,7 +138,7 @@ public class FiveDayThreeHourStepForecastResponseMapper {
|
||||
weatherNode.get("main").asText(),
|
||||
weatherNode.get("description").asText()
|
||||
);
|
||||
weatherForecast.setWeatherIconUrl("https://openweathermap.org/img/w/" + weatherNode.get("icon").asText() + ".png");
|
||||
weatherForecast.setWeatherIconId(weatherNode.get("icon").asText());
|
||||
|
||||
JsonNode mainNode = rootNode.get("main");
|
||||
weatherForecast.setTemperature(parseTemperature(mainNode));
|
||||
|
||||
@ -117,7 +117,7 @@ public class CurrentWeatherResponseMapper {
|
||||
private Weather getSingle(JsonNode rootNode) {
|
||||
JsonNode weatherState = rootNode.get("weather").get(0);
|
||||
Weather weather = Weather.forValue(weatherState.get("main").asText(), weatherState.get("description").asText());
|
||||
weather.setWeatherIconUrl("http://openweathermap.org/img/w/" + weatherState.get("icon").asText() + ".png");
|
||||
weather.setWeatherIconId(weatherState.get("icon").asText());
|
||||
|
||||
weather.setTemperature(parseTemperature(rootNode));
|
||||
weather.setAtmosphericPressure(parsePressure(rootNode));
|
||||
|
||||
@ -73,11 +73,15 @@ public class WeatherForecastUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetIconUrl_thenValueIsSet() {
|
||||
public void whenSetIconId_thenValueIsSet() {
|
||||
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||
weatherForecast.setWeatherIconUrl("test");
|
||||
Assert.assertNull(weatherForecast.getWeatherIconId());
|
||||
Assert.assertNull(weatherForecast.getWeatherIconUrl());
|
||||
|
||||
Assert.assertEquals("test", weatherForecast.getWeatherIconUrl());
|
||||
weatherForecast.setWeatherIconId("02n");
|
||||
|
||||
Assert.assertEquals("02n", weatherForecast.getWeatherIconId());
|
||||
Assert.assertNotNull(weatherForecast.getWeatherIconUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -258,11 +262,11 @@ public class WeatherForecastUnitTest {
|
||||
|
||||
Assert.assertTrue(one.equals(two));
|
||||
|
||||
one.setWeatherIconUrl("1");
|
||||
one.setWeatherIconId("1");
|
||||
|
||||
Assert.assertFalse(one.equals(two));
|
||||
|
||||
two.setWeatherIconUrl("1");
|
||||
two.setWeatherIconId("1");
|
||||
|
||||
Assert.assertTrue(one.equals(two));
|
||||
|
||||
|
||||
@ -76,11 +76,15 @@ public class WeatherUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetIconUrl_thenValueIsSet() {
|
||||
public void whenSetIconId_thenValueIsSet() {
|
||||
final Weather weather = Weather.forValue("state", "desc");
|
||||
weather.setWeatherIconUrl("test");
|
||||
Assert.assertNull(weather.getWeatherIconId());
|
||||
Assert.assertNull(weather.getWeatherIconUrl());
|
||||
|
||||
Assert.assertEquals("test", weather.getWeatherIconUrl());
|
||||
weather.setWeatherIconId("11d");
|
||||
|
||||
Assert.assertEquals("11d", weather.getWeatherIconId());
|
||||
Assert.assertNotNull(weather.getWeatherIconUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -235,11 +239,11 @@ public class WeatherUnitTest {
|
||||
|
||||
Assert.assertTrue(one.equals(two));
|
||||
|
||||
one.setWeatherIconUrl("1");
|
||||
one.setWeatherIconId("1");
|
||||
|
||||
Assert.assertFalse(one.equals(two));
|
||||
|
||||
two.setWeatherIconUrl("1");
|
||||
two.setWeatherIconId("1");
|
||||
|
||||
Assert.assertTrue(one.equals(two));
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user