From 0231668181a240e279da256e02e119548593f454 Mon Sep 17 00:00:00 2001 From: DadiBit <38182988+DadiBit@users.noreply.github.com> Date: Tue, 6 Jun 2023 18:25:27 +0200 Subject: [PATCH] refactor: separated current weather class --- .../main/kotlin/com/openmeteo/api/Forecast.kt | 3 +- .../kotlin/com/openmeteo/api/Historical.kt | 3 +- .../openmeteo/api/common/CurrentWeather.kt | 40 +++++++++++++++++++ .../com/openmeteo/api/common/Response.kt | 23 +---------- 4 files changed, 45 insertions(+), 24 deletions(-) create mode 100644 lib/src/main/kotlin/com/openmeteo/api/common/CurrentWeather.kt diff --git a/lib/src/main/kotlin/com/openmeteo/api/Forecast.kt b/lib/src/main/kotlin/com/openmeteo/api/Forecast.kt index 413367b..9982c17 100644 --- a/lib/src/main/kotlin/com/openmeteo/api/Forecast.kt +++ b/lib/src/main/kotlin/com/openmeteo/api/Forecast.kt @@ -1,5 +1,6 @@ package com.openmeteo.api +import com.openmeteo.api.common.CurrentWeather import com.openmeteo.api.common.Options import com.openmeteo.api.common.http.Endpoint import com.openmeteo.api.common.time.Date @@ -64,7 +65,7 @@ object Forecast : Endpoint( override val hourlyUnits: Map = mapOf(), @SerialName("hourly") override val hourlyValues: Map> = mapOf(), - override val currentWeather: R.CurrentWeather.CurrentWeather? = null, + override val currentWeather: CurrentWeather? = null, ) : R.Coordinate, R.Elevation, R.GenerationTimed, R.TimeZone, R.Daily, R.Hourly, R.CurrentWeather @Serializable diff --git a/lib/src/main/kotlin/com/openmeteo/api/Historical.kt b/lib/src/main/kotlin/com/openmeteo/api/Historical.kt index 75d9f27..e462df3 100644 --- a/lib/src/main/kotlin/com/openmeteo/api/Historical.kt +++ b/lib/src/main/kotlin/com/openmeteo/api/Historical.kt @@ -1,5 +1,6 @@ package com.openmeteo.api +import com.openmeteo.api.common.CurrentWeather import com.openmeteo.api.common.Options import com.openmeteo.api.common.http.Endpoint import com.openmeteo.api.common.time.Date @@ -57,7 +58,7 @@ object Historical : Endpoint( override val hourlyUnits: Map = mapOf(), @SerialName("hourly") override val hourlyValues: Map> = mapOf(), - override val currentWeather: R.CurrentWeather.CurrentWeather? = null, + override val currentWeather: CurrentWeather? = null, ) : R.Coordinate, R.Elevation, R.GenerationTimed, R.TimeZone, R.Daily, R.Hourly, R.CurrentWeather @Serializable diff --git a/lib/src/main/kotlin/com/openmeteo/api/common/CurrentWeather.kt b/lib/src/main/kotlin/com/openmeteo/api/common/CurrentWeather.kt new file mode 100644 index 0000000..4489b74 --- /dev/null +++ b/lib/src/main/kotlin/com/openmeteo/api/common/CurrentWeather.kt @@ -0,0 +1,40 @@ +package com.openmeteo.api.common + +import com.openmeteo.api.common.time.Time +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * + */ +@Serializable +open class CurrentWeather( + /** + * + */ + val time: Time, + /** + * + */ + val temperature: Float, + /** + * + */ + @SerialName("windspeed") + val windSpeed: Float, + /** + * + */ + @SerialName("winddirection") + val windDirection: Float, + /** + * + */ + @SerialName("weathercode") + val weatherCode: WeatherCode, + /** + * Whether the time step has daylight + */ + @Serializable(with = IntAsBoolean::class) + val isDay: Boolean, +) diff --git a/lib/src/main/kotlin/com/openmeteo/api/common/Response.kt b/lib/src/main/kotlin/com/openmeteo/api/common/Response.kt index 5d8394a..515be7d 100644 --- a/lib/src/main/kotlin/com/openmeteo/api/common/Response.kt +++ b/lib/src/main/kotlin/com/openmeteo/api/common/Response.kt @@ -1,9 +1,6 @@ package com.openmeteo.api.common -import com.openmeteo.api.common.time.Time import com.openmeteo.api.common.units.Unit -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable interface Response { @@ -48,28 +45,10 @@ interface Response { * Resource which may contain the current weather status. */ interface CurrentWeather : Response { - /** * The current weather. */ - val currentWeather: CurrentWeather? - - @Serializable - open class CurrentWeather( - val time: Time, - val temperature: Float, - @SerialName("windspeed") - val windSpeed: Float, - @SerialName("winddirection") - val windDirection: Float, - @SerialName("weathercode") - val weatherCode: WeatherCode, - /** - * Whether the time step has daylight - */ - @Serializable(with = IntAsBoolean::class) - val isDay: Boolean, - ) + val currentWeather: com.openmeteo.api.common.CurrentWeather? } /**