Skip to content

Commit

Permalink
refactor: separated current weather class
Browse files Browse the repository at this point in the history
  • Loading branch information
DadiBit committed Jun 6, 2023
1 parent c0c6052 commit 0231668
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 24 deletions.
3 changes: 2 additions & 1 deletion lib/src/main/kotlin/com/openmeteo/api/Forecast.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -64,7 +65,7 @@ object Forecast : Endpoint(
override val hourlyUnits: Map<String, Unit> = mapOf(),
@SerialName("hourly")
override val hourlyValues: Map<String, Array<Double?>> = 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
Expand Down
3 changes: 2 additions & 1 deletion lib/src/main/kotlin/com/openmeteo/api/Historical.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -57,7 +58,7 @@ object Historical : Endpoint(
override val hourlyUnits: Map<String, Unit> = mapOf(),
@SerialName("hourly")
override val hourlyValues: Map<String, Array<Double?>> = 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
Expand Down
40 changes: 40 additions & 0 deletions lib/src/main/kotlin/com/openmeteo/api/common/CurrentWeather.kt
Original file line number Diff line number Diff line change
@@ -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,
)
23 changes: 1 addition & 22 deletions lib/src/main/kotlin/com/openmeteo/api/common/Response.kt
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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?
}

/**
Expand Down

0 comments on commit 0231668

Please sign in to comment.