-
Notifications
You must be signed in to change notification settings - Fork 2
/
Marine.kt
119 lines (109 loc) · 4.63 KB
/
Marine.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package com.openmeteo.api
import com.openmeteo.api.common.CellSelection
import com.openmeteo.api.common.Options
import com.openmeteo.api.common.http.Endpoint
import com.openmeteo.api.common.query.City
import com.openmeteo.api.common.time.Date
import com.openmeteo.api.common.time.Timezone
import com.openmeteo.api.common.units.LengthUnit
import com.openmeteo.api.common.units.Units
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import java.net.URL
import com.openmeteo.api.common.Response as R
import com.openmeteo.api.common.query.Query as Q
object Marine : Endpoint(
URL("https://marine-api.open-meteo.com/v1/marine")
) {
operator fun invoke(query: Query, context: URL = this.context) =
query<Response, Query>(query, context)
@Deprecated(
"Hardcoded Cities are deprecated: use the geocoding API instead!",
ReplaceWith(
"""
GeocodingSearch.first(...).getOrNull()
?.let { Marine(it.latitude, it.longitude, apikey, context, query) }
""",
"com.openmeteo.api.GeocodingSearch"
),
DeprecationLevel.WARNING
)
inline operator fun invoke(
city: City,
apikey: String? = null,
context: URL = this.context,
query: Query.() -> Unit,
) = this(city.latitude, city.longitude, apikey, context, query)
inline operator fun invoke(
latitude: Float,
longitude: Float,
apikey: String? = null,
context: URL = this.context,
query: Query.() -> Unit,
) = Query(latitude, longitude, apikey = apikey).let {
it.query()
this(it, context)
}
@Serializable
open class Query(
override var latitude: Float,
override var longitude: Float,
override var daily: String? = null,
override var hourly: String? = null,
@SerialName("start_date")
override var startDate: Date? = null,
@SerialName("end_date")
override var endDate: Date? = null,
@SerialName("past_days")
override var pastDays: Int? = null,
override var timezone: Timezone? = null,
override var cellSelection: CellSelection? = null,
@SerialName("length_unit")
override var lengthUnit: LengthUnit? = null,
override var apikey: String? = null,
) : Q.Coordinate, Q.Daily, Q.Hourly, Q.TimeFormat, Q.Timezone, Q.PastDays,
Q.DateRange, Q.CellSelection, Q.LengthUnit, Q.CommercialLicense
@Serializable
open class Response(
override val latitude: Float,
override val longitude: Float,
override val utcOffsetSeconds: Int,
override val timezone: Timezone,
override val timezoneAbbreviation: String,
override val generationtimeMs: Float,
override val dailyUnits: Map<String, Units> = mapOf(),
@SerialName("daily")
override val dailyValues: Map<String, Array<Double?>> = mapOf(),
override val hourlyUnits: Map<String, Units> = mapOf(),
@SerialName("hourly")
override val hourlyValues: Map<String, Array<Double?>> = mapOf(),
) : R.Coordinate, R.GenerationTimed, R.TimeZone, R.Daily, R.Hourly
@Serializable
object Hourly : Options.Hourly, Options.Listable<Hourly>() {
const val waveHeight = "wave_height"
const val waveDirection = "wave_direction"
const val wavePeriod = "wave_period"
const val windWaveHeight = "wind_wave_height"
const val windWaveDirection = "wind_wave_direction"
const val windWavePeriod = "wind_wave_period"
const val windWavePeakPeriod = "wind_wave_peak_period"
const val swellWaveHeight = "swell_wave_height"
const val swellWaveDirection = "swell_wave_direction"
const val swellWavePeriod = "swell_wave_period"
const val swellWavePeakPeriod = "swell_wave_peak_period"
}
@Serializable
object Daily : Options.Daily, Options.Listable<Daily>() {
const val waveHeightMax = "wave_height_max"
const val waveDirectionDominant = "wave_direction_dominant"
const val wavePeriodMax = "wave_period_max"
const val windWaveHeightMax = "wind_wave_height_max"
const val windWaveDirectionDominant = "wind_wave_direction_dominant"
const val windWavePeriodMax = "wind_wave_period_max"
const val windWavePeakPeriodMax = "wind_wave_peak_period_max"
const val swellWaveHeightMax = "swell_wave_height_max"
const val swellWaveDirectionDominant = "swell_wave_direction_dominant"
const val swellWavePeriodMax = "swell_wave_period_max"
const val swellWavePeakPeriodMax = "swell_wave_peak_period_max"
}
}