Skip to content

Commit cce417d

Browse files
committed
feat(apix): geocoding get and search endpoints
1 parent 3407879 commit cce417d

2 files changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.openmeteo.apix.geocoding
2+
3+
import com.openmeteo.apix.common.http.Endpoint
4+
import com.openmeteo.apix.common.query.Query
5+
import com.openmeteo.apix.common.time.TimeZone
6+
import kotlinx.serialization.SerialName
7+
import kotlinx.serialization.Serializable
8+
import java.net.URL
9+
10+
open class GeocodingGet(
11+
val id: Int,
12+
context: URL = Companion.context,
13+
) : Endpoint(context) {
14+
15+
companion object {
16+
val context = URL("https://geocoding-api.open-meteo.com/v1/get")
17+
}
18+
19+
@Serializable
20+
open class Response(
21+
val id: Int,
22+
val name: String, // #2
23+
private val _3: String? = null,
24+
val latitude: Float, // #4
25+
val longitude: Float, // #5
26+
val ranking: Float, // #6
27+
val elevation: Float, // #7
28+
// https://www.geonames.org/export/codes.html enum?
29+
@SerialName("feature_code")
30+
val featureCode: String, // #8
31+
// https://en.wikipedia.org/wiki/List_of_FIPS_country_codes enum?
32+
@SerialName("country_code")
33+
val countryCode: String, // #9
34+
@SerialName("admin1_id")
35+
val admin1Id: Int? = null, // #10
36+
@SerialName("admin2_id")
37+
val admin2Id: Int? = null, // #11
38+
@SerialName("admin3_id")
39+
val admin3Id: Int? = null, // #12
40+
@SerialName("admin4_id")
41+
val admin4Id: Int? = null, // #13
42+
val timezone: TimeZone, // #14
43+
val population: Int, // #15
44+
private val _16: Int? = null,
45+
val postcodes: Array<String>, // #17
46+
@SerialName("country_id")
47+
val countryId: Int,
48+
val country: String,
49+
val admin1: String? = null,
50+
val admin2: String? = null,
51+
val admin3: String? = null,
52+
val admin4: String? = null,
53+
)
54+
55+
operator fun invoke() = invoke<Response>()
56+
operator fun invoke(query: Query) = invoke<Response>(query)
57+
58+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.openmeteo.apix.geocoding
2+
3+
import com.openmeteo.apix.common.http.ContentFormat
4+
import com.openmeteo.apix.common.http.Endpoint
5+
import com.openmeteo.apix.common.query.Query
6+
import com.openmeteo.apix.common.query.QueryContentFormat
7+
import com.openmeteo.apix.common.response.ResponseGenerationTimed
8+
import kotlinx.serialization.SerialName
9+
import kotlinx.serialization.Serializable
10+
import java.net.URL
11+
12+
open class GeocodingSearch(
13+
val name: String,
14+
@SerialName("count")
15+
val count: Int? = null,
16+
val language: String? = null,
17+
context: URL = Companion.context,
18+
) : Endpoint(context),
19+
QueryContentFormat {
20+
21+
override val format: ContentFormat = ContentFormat.ProtoBuf
22+
23+
companion object {
24+
val context = URL("https://geocoding-api.open-meteo.com/v1/search")
25+
}
26+
27+
init {
28+
count?.let { require(it in 1..100) }
29+
}
30+
31+
@Serializable
32+
open class Response(
33+
val results: Array<GeocodingGet.Response>,
34+
@SerialName("generationtime_ms")
35+
override val generationTimeMs: Float,
36+
) : ResponseGenerationTimed
37+
38+
operator fun invoke() = invoke<Response>()
39+
operator fun invoke(query: Query) = invoke<Response>(query)
40+
41+
}

0 commit comments

Comments
 (0)