All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.kryszak.gwatlin.clients.mapinfo.MapInfoClient.kt Maven / Gradle / Ivy

The newest version!
package io.github.kryszak.gwatlin.clients.mapinfo

import io.github.kryszak.gwatlin.api.mapinfo.model.*
import io.github.kryszak.gwatlin.api.mapinfo.model.Map
import io.github.kryszak.gwatlin.http.BaseHttpClient

internal class MapInfoClient : BaseHttpClient(
    "2022-03-23T19:00:00.000Z"
) {

    private val mapsEndpoint = "maps"
    private val continentsEndpoint = "continents"

    fun getMaps() = getRequest>(mapsEndpoint)

    fun getMaps(mapIds: Collection, language: io.github.kryszak.gwatlin.api.ApiLanguage?) =
        handleOneOrMultipleIds(mapIds, language, mapsEndpoint)

    fun getContinents() = getRequest>(continentsEndpoint)

    fun getContinents(continentIds: Collection, language: io.github.kryszak.gwatlin.api.ApiLanguage?) =
        handleOneOrMultipleIds(continentIds, language, continentsEndpoint)

    fun getFloors(continentId: Int) =
        getRequest>("$continentsEndpoint/$continentId/floors")

    fun getFloor(continentId: Int, floorId: Int, language: io.github.kryszak.gwatlin.api.ApiLanguage?) =
        getRequest("$continentsEndpoint/$continentId/floors/$floorId", language)

    fun getRegions(continentId: Int, floorId: Int) =
        getRequest>("$continentsEndpoint/$continentId/floors/$floorId/regions")

    fun getRegion(continentId: Int, floorId: Int, regionId: Int, language: io.github.kryszak.gwatlin.api.ApiLanguage?) =
        getRequest("$continentsEndpoint/$continentId/floors/$floorId/regions/$regionId", language)

    fun getMaps(continentId: Int, floorId: Int, regionId: Int) =
        getRequest>("$continentsEndpoint/$continentId/floors/$floorId/regions/$regionId/maps")

    fun getMap(
        continentId: Int,
        floorId: Int,
        regionId: Int,
        mapId: Int,
        language: io.github.kryszak.gwatlin.api.ApiLanguage?
    ) =
        getRequest(
            "$continentsEndpoint/$continentId/floors/$floorId/regions/$regionId/maps/$mapId", language
        )

    fun getSectors(continentId: Int, floorId: Int, regionId: Int, mapId: Int) =
        getRequest>(
            "$continentsEndpoint/$continentId/floors/$floorId/regions/$regionId/maps/$mapId/sectors"
        )

    fun getPointsOfInterest(continentId: Int, floorId: Int, regionId: Int, mapId: Int) =
        getRequest>(
            "$continentsEndpoint/$continentId/floors/$floorId/regions/$regionId/maps/$mapId/pois"
        )

    fun getTasks(continentId: Int, floorId: Int, regionId: Int, mapId: Int) =
        getRequest>(
            "$continentsEndpoint/$continentId/floors/$floorId/regions/$regionId/maps/$mapId/tasks"
        )

    private inline fun  handleOneOrMultipleIds(
        ids: Collection,
        language: io.github.kryszak.gwatlin.api.ApiLanguage?,
        endpoint: String
    ) = when {
        ids.isEmpty() -> emptyList()
        ids.size == 1 -> listOf(getRequest("$endpoint/${ids.first()}", language))
        else -> getRequest("$endpoint?ids=${ids.joinToString(",")}", language)
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy