Skip to content

Commit

Permalink
feat: Elevation invoke operator
Browse files Browse the repository at this point in the history
  • Loading branch information
DadiBit committed Jul 15, 2023
1 parent bcfd05c commit 1e06c92
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/main/kotlin/com/openmeteo/api/Elevation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.openmeteo.api

import com.openmeteo.api.common.Coordinate
import com.openmeteo.api.common.http.Endpoint
import com.openmeteo.api.common.query.City
import com.openmeteo.api.common.time.Date
import kotlinx.serialization.Serializable
import java.net.URL
import com.openmeteo.api.common.Response as R
Expand All @@ -14,6 +16,58 @@ object Elevation : Endpoint(
operator fun invoke(query: Query, context: URL = this.context) =
query<Response, Query>(query, context)

/**
* Quickly call the Elevation API.
*/
inline operator fun invoke(
latitude: Float,
longitude: Float,
context: URL = this.context,
query: Query.() -> Unit,
) = Query(latitude, longitude).let {
it.query()
this(it, context)
}

/**
* Quickly call the Elevation API.
*/
inline operator fun invoke(
latitudes: List<Float>,
longitudes: List<Float>,
context: URL = this.context,
query: Query.() -> Unit,
) = Query(latitudes, longitudes).let {
it.query()
this(it, context)
}

/**
* Quickly call the Elevation API.
* @param coordinates The list of coordinates
*/
inline operator fun invoke(
vararg coordinates: Coordinate,
context: URL = this.context,
query: Query.() -> Unit,
) = Query(*coordinates).let {
it.query()
this(it, context)
}

/**
* Quickly call the Elevation API.
* @param coordinates The list of coordinates pairs
*/
inline operator fun invoke(
vararg coordinates: Pair<Float, Float>,
context: URL = this.context,
query: Query.() -> Unit,
) = Query(*coordinates).let {
it.query()
this(it, context)
}

@Serializable
open class Query private constructor(
var latitude: String,
Expand Down

0 comments on commit 1e06c92

Please sign in to comment.