initial commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package com.icegps.shared
|
||||
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.cio.CIO
|
||||
import io.ktor.client.plugins.HttpTimeout
|
||||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.client.plugins.logging.LogLevel
|
||||
import io.ktor.client.plugins.logging.Logger
|
||||
import io.ktor.client.plugins.logging.Logging
|
||||
import io.ktor.client.plugins.logging.SIMPLE
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
/**
|
||||
* @author tabidachinokaze
|
||||
* @date 2025/11/20
|
||||
*/
|
||||
@Suppress("FunctionName")
|
||||
fun SharedHttpClient(json: Json): HttpClient {
|
||||
return HttpClient(CIO) {
|
||||
install(ContentNegotiation) {
|
||||
json(
|
||||
json = json,
|
||||
contentType = ContentType.Text.Html
|
||||
)
|
||||
json(
|
||||
json = json,
|
||||
contentType = ContentType.Application.Json
|
||||
)
|
||||
}
|
||||
install(Logging) {
|
||||
this.level = LogLevel.ALL
|
||||
this.logger = Logger.SIMPLE
|
||||
}
|
||||
install(HttpTimeout) {
|
||||
requestTimeoutMillis = 1000 * 60 * 10
|
||||
connectTimeoutMillis = 1000 * 60 * 5
|
||||
socketTimeoutMillis = 1000 * 60 * 10
|
||||
}
|
||||
}
|
||||
}
|
||||
17
icegps-shared/src/main/java/com/icegps/shared/SharedJson.kt
Normal file
17
icegps-shared/src/main/java/com/icegps/shared/SharedJson.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.icegps.shared
|
||||
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.modules.SerializersModule
|
||||
|
||||
/**
|
||||
* @author tabidachinokaze
|
||||
* @date 2025/11/20
|
||||
*/
|
||||
@Suppress("FunctionName")
|
||||
fun SharedJson(): Json {
|
||||
return Json {
|
||||
ignoreUnknownKeys = true
|
||||
serializersModule = SerializersModule {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.icegps.shared.api
|
||||
|
||||
import com.icegps.shared.model.IGeoPoint
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class LookupResponse(
|
||||
@SerialName("results")
|
||||
val results: List<Result>
|
||||
) {
|
||||
@Serializable
|
||||
data class Result(
|
||||
@SerialName("longitude")
|
||||
override val longitude: Double,
|
||||
@SerialName("latitude")
|
||||
override val latitude: Double,
|
||||
@SerialName("elevation")
|
||||
override val altitude: Double,
|
||||
) : IGeoPoint
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.icegps.shared.api
|
||||
|
||||
import com.icegps.shared.model.IGeoPoint
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.body
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.request.parameter
|
||||
import io.ktor.http.appendPathSegments
|
||||
|
||||
/**
|
||||
* @author tabidachinokaze
|
||||
* @date 2025/11/20
|
||||
*/
|
||||
interface OpenElevationApi {
|
||||
suspend fun lookup(values: List<IGeoPoint>): List<IGeoPoint>
|
||||
}
|
||||
|
||||
class OpenElevation(
|
||||
private val client: HttpClient
|
||||
) : OpenElevationApi {
|
||||
private val baseUrl: String = "https://api.open-elevation.com/api/v1/"
|
||||
|
||||
// curl 'https://api.open-elevation.com/api/v1/lookup?locations=10,10|20,20|41.161758,-8.583933'
|
||||
override suspend fun lookup(values: List<IGeoPoint>): List<IGeoPoint> {
|
||||
val response = client.get(baseUrl) {
|
||||
url {
|
||||
appendPathSegments("lookup")
|
||||
parameter(
|
||||
"locations",
|
||||
values.joinToString("|") { "${it.latitude},${it.longitude}" })
|
||||
}
|
||||
}
|
||||
return response.body<LookupResponse>().results
|
||||
}
|
||||
}
|
||||
7
icegps-shared/src/main/java/com/icegps/shared/ktx/Any.kt
Normal file
7
icegps-shared/src/main/java/com/icegps/shared/ktx/Any.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
package com.icegps.shared.ktx
|
||||
|
||||
/**
|
||||
* @author tabidachinokaze
|
||||
* @date 2025/11/22
|
||||
*/
|
||||
val Any.TAG: String get() = this::class.java.simpleName
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.icegps.shared.model
|
||||
|
||||
/**
|
||||
* @author tabidachinokaze
|
||||
* @date 2025/11/22
|
||||
*/
|
||||
data class GeoPoint(
|
||||
override val longitude: Double,
|
||||
override val latitude: Double,
|
||||
override val altitude: Double
|
||||
) : IGeoPoint
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.icegps.shared.model
|
||||
|
||||
/**
|
||||
* @author tabidachinokaze
|
||||
* @date 2025/11/22
|
||||
*/
|
||||
interface IGeoPoint {
|
||||
val longitude: Double
|
||||
val latitude: Double
|
||||
val altitude: Double
|
||||
}
|
||||
Reference in New Issue
Block a user