commonMain.com.bselzer.gw2.v2.client.instance.RecipeClient.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of v2-client Show documentation
Show all versions of v2-client Show documentation
Ktor client for v2 endpoints of the Guild Wars 2 API.
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) })
}