Skip to content

Commit 0b1c201

Browse files
committed
feat: OpenMeteo class meteoFrance implementation
1 parent 9b4d720 commit 0b1c201

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

lib/src/main/kotlin/com/openmeteo/api/OpenMeteo.kt

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ import com.openmeteo.api.historical.HistoricalHourly
3535
import com.openmeteo.api.marine.Marine
3636
import com.openmeteo.api.marine.MarineDaily
3737
import com.openmeteo.api.marine.MarineHourly
38+
import com.openmeteo.api.meteofrance.MeteoFrance
39+
import com.openmeteo.api.meteofrance.MeteoFranceHourly
40+
import com.openmeteo.api.meteofrance.MeteoFranceDaily
3841
import kotlinx.serialization.SerialName
3942

4043
class OpenMeteo(
@@ -69,6 +72,7 @@ class OpenMeteo(
6972
val gfs: Endpoint = Endpoint(Gfs.context),
7073
val historical: Endpoint = Endpoint(Historical.context),
7174
val marine: Endpoint = Endpoint(Marine.context),
75+
val meteoFrance: Endpoint = Endpoint(MeteoFrance.context),
7276
)
7377

7478
var coordinates
@@ -110,6 +114,9 @@ class OpenMeteo(
110114
operator fun invoke(query: Marine.Query) =
111115
endpoints.marine.query<Marine.Response>(query)
112116

117+
operator fun invoke(query: MeteoFrance.Query) =
118+
endpoints.meteoFrance.query<MeteoFrance.Response>(query)
119+
113120
fun airQuality(
114121
hourly: Iterable<AirQualityHourly>? = null,
115122
domains: AirQualityDomains? = null,
@@ -256,6 +263,27 @@ class OpenMeteo(
256263
)
257264
)
258265

266+
fun meteoFrance(
267+
hourly: Iterable<MeteoFranceHourly>? = null,
268+
daily: Iterable<MeteoFranceDaily>? = null,
269+
currentWeather: Boolean? = null,
270+
temperatureUnit: TemperatureUnit? = null,
271+
windSpeedUnit: WindSpeedUnit? = null,
272+
precipitationUnit: PrecipitationUnit? = null,
273+
timeZone: TimeZone? = null,
274+
startDate: Date? = null,
275+
endDate: Date? = null,
276+
pastDays: Int? = null,
277+
latitude: Float = this.latitude,
278+
longitude: Float = this.longitude,
279+
) = invoke(
280+
MeteoFrance.Query(
281+
latitude, longitude, hourly, daily, currentWeather,
282+
temperatureUnit, windSpeedUnit, precipitationUnit, timeZone, startDate,
283+
endDate, pastDays
284+
)
285+
)
286+
259287
fun currentWeather(
260288
temperatureUnit: TemperatureUnit? = null,
261289
windSpeedUnit: WindSpeedUnit? = null,
@@ -382,6 +410,16 @@ class OpenMeteo(
382410
).getOrThrow()
383411
}
384412

413+
val meteoFranceHourly = separate<MeteoFranceHourly>(hourly)
414+
val meteoFranceDaily = separate<MeteoFranceDaily>(daily)
415+
val meteoFranceResponse = (meteoFranceHourly ?: meteoFranceDaily)?.let {
416+
meteoFrance(
417+
meteoFranceHourly, meteoFranceDaily, currentWeather,
418+
temperatureUnit, windSpeedUnit, precipitationUnit, timeZone,
419+
startDate, endDate, pastDays, latitude, longitude
420+
).getOrThrow()
421+
}
422+
385423
val hourlyResponses: List<ResponseHourly> = listOfNotNull(
386424
airQualityResponse,
387425
dwdResponse,
@@ -390,6 +428,7 @@ class OpenMeteo(
390428
gfsResponse,
391429
historicalResponse,
392430
marineResponse,
431+
meteoFranceResponse,
393432
)
394433

395434
val dailyResponses: List<ResponseDaily> = listOfNotNull(
@@ -398,6 +437,7 @@ class OpenMeteo(
398437
gfsResponse,
399438
historicalResponse,
400439
marineResponse,
440+
meteoFranceResponse,
401441
)
402442

403443
val responses = (hourlyResponses + dailyResponses)
@@ -410,10 +450,12 @@ class OpenMeteo(
410450
val elevation = dwdResponse?.elevation
411451
?: forecastResponse?.elevation
412452
?: gfsResponse?.elevation
453+
?: meteoFranceResponse?.elevation
413454

414455
val currentWeather0 = dwdResponse?.currentWeather
415456
?: forecastResponse?.currentWeather
416457
?: gfsResponse?.currentWeather
458+
?: meteoFranceResponse?.currentWeather
417459

418460
val utcOffsetSeconds = hourlyResponses[0].utcOffsetSeconds
419461
val timeZone0 = hourlyResponses[0].timeZone
@@ -435,8 +477,6 @@ class OpenMeteo(
435477
.map { it.dailyValues }
436478
.reduce { acc, map -> acc + map }
437479

438-
439-
440480
AnyResponse(
441481
latitude,
442482
longitude,

0 commit comments

Comments
 (0)