commonMain.com.adamratzman.spotify.endpoints.public.TrackApi.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spotify-api-kotlin-jvm Show documentation
Show all versions of spotify-api-kotlin-jvm Show documentation
A Kotlin wrapper for the Spotify Web API.
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2021; Original author: Adam Ratzman */
package com.adamratzman.spotify.endpoints.public
import com.adamratzman.spotify.GenericSpotifyApi
import com.adamratzman.spotify.SpotifyException.BadRequestException
import com.adamratzman.spotify.http.SpotifyEndpoint
import com.adamratzman.spotify.http.encodeUrl
import com.adamratzman.spotify.models.AudioAnalysis
import com.adamratzman.spotify.models.AudioFeatures
import com.adamratzman.spotify.models.AudioFeaturesResponse
import com.adamratzman.spotify.models.PlayableUri
import com.adamratzman.spotify.models.Track
import com.adamratzman.spotify.models.TrackList
import com.adamratzman.spotify.models.serialization.toObject
import com.adamratzman.spotify.utils.Market
import com.adamratzman.spotify.utils.catch
/**
* Endpoints for retrieving information about one or more tracks from the Spotify catalog.
*
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/tracks/)**
*/
public class TrackApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
/**
* Get Spotify catalog information for a single track identified by its unique Spotify ID.
*
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/tracks/get-track/)**
*
* @param track The id or uri for the track.
* @param market Provide this parameter if you want to apply [Track Relinking](https://github.com/adamint/spotify-web-api-kotlin#track-relinking)
*
* @return possibly-null Track. This behavior is *the same* as in [getTracks]
*/
public suspend fun getTrack(track: String, market: Market? = null): Track? = catch {
get(
endpointBuilder("/tracks/${PlayableUri(track).id.encodeUrl()}").with(
"market",
market?.name
).toString()
).toObject(Track.serializer(), api, json)
}
/**
* Get Spotify catalog information for multiple tracks based on their Spotify IDs.
*
* **[Api Reference](https://developer.spotify.com/documentation/web-api/reference/tracks/get-several-tracks/)**
*
* @param tracks The id or uri for the tracks. Maximum **50**.
* @param market Provide this parameter if you want to apply [Track Relinking](https://github.com/adamint/spotify-web-api-kotlin#track-relinking)
*
* @return List of possibly-null full [Track] objects.
*/
public suspend fun getTracks(vararg tracks: String, market: Market? = null): List