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

commonMain.com.bselzer.gw2.v2.client.instance.HomeClient.kt Maven / Gradle / Ivy

The newest version!
package com.bselzer.gw2.v2.client.instance

import com.bselzer.gw2.v2.model.home.cat.Cat
import com.bselzer.gw2.v2.model.home.cat.CatId
import com.bselzer.gw2.v2.model.home.node.Node
import com.bselzer.gw2.v2.model.home.node.NodeId
import io.ktor.client.*

/**
 * The home instance client.
 */
class HomeClient(httpClient: HttpClient, configuration: Gw2ClientConfiguration) : BaseClient(httpClient, configuration) {
    private companion object {
        const val HOME = "home"
        const val CATS = "cats"
        const val NODES = "nodes"
    }

    /**
     * @return the ids of the available cats
     * @see the wiki
     */
    suspend fun catIds(): List = getIds(path = "${HOME}/${CATS}")

    /**
     * @return the cat associated with the [id]
     * @see the wiki
     */
    suspend fun cat(id: CatId): Cat = getSingleById(id, "${HOME}/${CATS}", instance = { Cat(id = it) })

    /**
     * @return the cats associated with the [ids]
     * @see the wiki
     */
    suspend fun cats(ids: Collection): List = chunkedIds(ids, "${HOME}/${CATS}", instance = { Cat(id = it) })

    /**
     * @return all the cats
     * @see the wiki
     */
    suspend fun cats(): List = allIds("${HOME}/${CATS}")

    /**
     * @return the ids of the available nodes
     * @see the wiki
     */
    suspend fun nodeIds(): List = getIds(path = "${HOME}/${NODES}")

    /**
     * @return the node associated with the [id]
     * @see the wiki
     */
    suspend fun node(id: NodeId): Node = getSingleById(id, "${HOME}/${NODES}", instance = { Node(id = it) })

    /**
     * @return the nodes associated with the [ids]
     * @see the wiki
     */
    suspend fun nodes(ids: Collection): List = chunkedIds(ids, "${HOME}/${NODES}", instance = { Node(id = it) })

    /**
     * @return all the nodes
     * @see the wiki
     */
    suspend fun nodes(): List = allIds("${HOME}/${NODES}")
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy