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

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

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

import com.bselzer.gw2.v2.model.item.ItemId
import com.bselzer.gw2.v2.model.recipe.Recipe
import com.bselzer.gw2.v2.model.recipe.RecipeId
import io.ktor.client.*
import io.ktor.client.request.*

/**
 * The recipe client.
 * @see the wiki
 */
class RecipeClient(httpClient: HttpClient, configuration: Gw2ClientConfiguration) : BaseClient(httpClient, configuration) {
    private companion object {
        const val RECIPES = "recipes"
        const val SEARCH = "search"
    }

    /**
     * @return the ids of the available recipes
     * @see the wiki
     */
    suspend fun ids(): List = getIds(path = RECIPES)

    /**
     * @return the ids of the recipes that use the item with the given [itemId]
     * @see the wiki
     */
    suspend fun idsByInput(itemId: ItemId): List = getIds(path = "${RECIPES}/${SEARCH}") {
        parameter("input", itemId)
    }

    /**
     * @return the ids of the recipes that produce the item with the given [itemId]
     * @see the wiki
     */
    suspend fun idsByOutput(itemId: Int): List = getIds(path = "${RECIPES}/${SEARCH}") {
        parameter("output", itemId)
    }

    /**
     * @return the recipes associated with the [id]
     * @see the wiki
     */
    suspend fun recipe(id: RecipeId): Recipe = getSingleById(id, RECIPES, instance = { Recipe(id = it) })

    /**
     * @return the recipes associated with the [ids]
     * @see the wiki
     */
    suspend fun recipes(ids: Collection): List = chunkedIds(ids, RECIPES, instance = { Recipe(id = it) })
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy