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

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

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

import com.bselzer.gw2.v2.client.extension.language
import com.bselzer.gw2.v2.client.model.Language
import com.bselzer.gw2.v2.model.story.Story
import com.bselzer.gw2.v2.model.story.StoryId
import com.bselzer.gw2.v2.model.story.season.StorySeason
import com.bselzer.gw2.v2.model.story.season.StorySeasonId
import io.ktor.client.*

/**
 * The story client.
 * @see the wiki
 */
class StoryClient(httpClient: HttpClient, configuration: Gw2ClientConfiguration) : BaseClient(httpClient, configuration) {
    private companion object {
        const val STORIES = "stories"
        const val SEASONS = "seasons"
    }

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

    /**
     * @return the story associated with the [id]
     * @see the wiki
     */
    suspend fun story(id: StoryId, language: Language? = null): Story = getSingleById(id, STORIES, instance = { Story(id = it) }) {
        language(language)
    }

    /**
     * @return the stories associated with the [ids]
     * @see the wiki
     */
    suspend fun stories(ids: Collection, language: Language? = null): List = chunkedIds(ids, STORIES, instance = { Story(id = it) }) {
        language(language)
    }

    /**
     * @return all the stories
     * @see the wiki
     */
    suspend fun stories(language: Language? = null): List = allIds(STORIES) {
        language(language)
    }

    /**
     * @return the ids of the available seasons
     * @see the wiki
     */
    suspend fun seasonIds(): List = getIds(path = "${STORIES}/${SEASONS}")

    /**
     * @return the season associated with the [id]
     * @see the wiki
     */
    suspend fun season(id: StorySeasonId, language: Language? = null): StorySeason = getSingleById(id, "${STORIES}/${SEASONS}", instance = { StorySeason(id = it) }) {
        language(language)
    }

    /**
     * @return the seasons associated with the [ids]
     * @see the wiki
     */
    suspend fun seasons(ids: Collection, language: Language? = null): List =
        chunkedIds(ids, "${STORIES}/${SEASONS}", instance = { StorySeason(id = it) }) {
            language(language)
        }

    /**
     * @return all the seasons
     * @see the wiki
     */
    suspend fun seasons(language: Language? = null): List = allIds("${STORIES}/${SEASONS}") {
        language(language)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy