Skip to content

Commit 6542663

Browse files
committed
update documentation to reflect current online docs
1 parent d1c652e commit 6542663

17 files changed

+357
-154
lines changed

src/main/kotlin/com/adamratzman/spotify/SpotifyAPI.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class SpotifyAppAPI internal constructor(clientId: String, clientSecret: String,
110110
tracks,
111111
following
112112
)
113+
114+
override fun equals(other: Any?) = other is SpotifyAppAPI && other.token == this.token
113115
}
114116

115117
class SpotifyClientAPI internal constructor(
@@ -202,6 +204,8 @@ class SpotifyClientAPI internal constructor(
202204
fun getAuthorizationUrl(vararg scopes: SpotifyScope): String {
203205
return getAuthUrlFull(*scopes, clientId = clientId, redirectUri = redirectUri)
204206
}
207+
208+
override fun equals(other: Any?) = other is SpotifyClientAPI && other.token == this.token
205209
}
206210

207211
internal fun getAuthUrlFull(vararg scopes: SpotifyScope, clientId: String, redirectUri: String): String {

src/main/kotlin/com/adamratzman/spotify/SpotifyLogger.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ package com.adamratzman.spotify
44
class SpotifyLogger(var enabled: Boolean) {
55
val redString = "\u001B[31m"
66
val resetString = "\u001B[0m"
7+
78
fun logInfo(message: String) {
89
if (enabled) println("Spotify Logger Info: $message")
910
}
11+
1012
fun logWarning(message: String) {
1113
if (enabled) println("${redString}Spotify Logger Warning: $message$resetString")
1214
}

src/main/kotlin/com/adamratzman/spotify/SpotifyRestAction.kt

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ import java.util.concurrent.CompletableFuture
66
import java.util.concurrent.TimeUnit
77
import java.util.function.Supplier
88

9-
open class SpotifyRestAction<T>(protected val api: SpotifyAPI, private val supplier: Supplier<T>) {
9+
/**
10+
* Provides a uniform interface to retrieve, whether synchronously or asynchronously, [T] from Spotify
11+
*/
12+
open class SpotifyRestAction<T> internal constructor(protected val api: SpotifyAPI, private val supplier: Supplier<T>) {
13+
14+
/**
15+
* Invoke [supplier] and synchronously retrieve [T]
16+
*/
1017
fun complete(): T {
1118
return try {
1219
supplier.get()
@@ -15,10 +22,24 @@ open class SpotifyRestAction<T>(protected val api: SpotifyAPI, private val suppl
1522
}
1623
}
1724

25+
/**
26+
* Invoke [supplier] asynchronously with no consumer
27+
*/
1828
fun queue() = queue({}, { throw it })
1929

30+
/**
31+
* Invoke [supplier] asynchronously and consume [consumer] with the [T] value returned
32+
*
33+
* @param consumer to be invoked with [T] after successful completion of [supplier]
34+
*/
2035
fun queue(consumer: (T) -> Unit) = queue(consumer, {})
2136

37+
/**
38+
* Invoke [supplier] asynchronously and consume [consumer] with the [T] value returned
39+
*
40+
* @param failure Consumer to invoke when an exception is thrown by [supplier]
41+
* @param consumer to be invoked with [T] after successful completion of [supplier]
42+
*/
2243
fun queue(consumer: ((T) -> Unit), failure: ((Throwable) -> Unit)) {
2344
api.executor.execute {
2445
try {
@@ -30,8 +51,18 @@ open class SpotifyRestAction<T>(protected val api: SpotifyAPI, private val suppl
3051
}
3152
}
3253

54+
/**
55+
* Return [supplier] as a [CompletableFuture]
56+
*/
3357
fun asFuture() = CompletableFuture.supplyAsync(supplier)
3458

59+
/**
60+
* Invoke [supplier] asynchronously immediately and invoke [consumer] after the specified quantity of time
61+
*
62+
* @param quantity amount of time
63+
* @param timeUnit the unit that [quantity] is in
64+
* @param consumer to be invoked with [T] after successful completion of [supplier]
65+
*/
3566
fun queueAfter(quantity: Int, timeUnit: TimeUnit = TimeUnit.SECONDS, consumer: (T) -> Unit) {
3667
val runAt = System.currentTimeMillis() + timeUnit.toMillis(quantity.toLong())
3768
queue { result ->
@@ -43,7 +74,26 @@ open class SpotifyRestAction<T>(protected val api: SpotifyAPI, private val suppl
4374
}
4475

4576
class SpotifyRestActionPaging<Z, T : AbstractPagingObject<Z>>(api: SpotifyAPI, supplier: Supplier<T>) :
46-
SpotifyRestAction<T>(api, supplier) {
77+
SpotifyRestAction<T>(api, supplier) {
78+
79+
/**
80+
* Synchronously retrieve all [AbstractPagingObject] associated with this rest action
81+
*/
4782
fun getAll() = api.tracks.toAction(Supplier { complete().getAllImpl() })
83+
84+
/**
85+
* Synchronously retrieve all [Z] associated with this rest action
86+
*/
4887
fun getAllItems() = api.tracks.toAction(Supplier { complete().getAllImpl().toList().map { it.items }.flatten() })
88+
89+
/**
90+
* Consume each [Z] by [consumer] as it is retrieved
91+
*/
92+
fun streamAllItems(consumer: (Z) -> Unit): SpotifyRestAction<Unit> {
93+
return api.tracks.toAction(
94+
Supplier {
95+
complete().getAllImpl().toList().forEach { it.items.forEach { item -> consumer(item) } }
96+
}
97+
)
98+
}
4999
}

src/main/kotlin/com/adamratzman/spotify/SpotifyScope.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
/* Spotify Web API - Kotlin Wrapper; MIT License, 2019; Original author: Adam Ratzman */
22
package com.adamratzman.spotify
33

4+
/**
5+
* Scopes provide Spotify users using third-party apps the confidence
6+
* that only the information they choose to share will be shared, and nothing more.
7+
*
8+
* Each represents a distinct privilege and may be required by one or more endpoints as discussed
9+
* on the [Spotify Authorization Documentation](https://developer.spotify.com/documentation/general/guides/scopes/)
10+
*
11+
* @property uri the scope id
12+
*/
413
enum class SpotifyScope(val uri: String) {
514
PLAYLIST_READ_PRIVATE("playlist-read-private"),
615
PLAYLIST_READ_COLLABORATIVE("playlist-read-collaborative"),

src/main/kotlin/com/adamratzman/spotify/models/Albums.kt

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
/* Spotify Web API - Kotlin Wrapper; MIT License, 2019; Original author: Adam Ratzman */
22
package com.adamratzman.spotify.models
33

4+
import com.adamratzman.spotify.utils.match
45
import com.beust.klaxon.Json
56

67
/**
8+
* Simplified Album object that can be used to retrieve a full [Album]
9+
*
710
* @property albumGroup Optional. The field is present when getting an artist’s albums. Possible values
811
* are “album”, “single”, “compilation”, “appears_on”. Compare to album_type this field represents relationship
912
* between the artist and the album.
@@ -36,27 +39,35 @@ data class SimpleAlbum(
3639
val images: List<SpotifyImage>,
3740
val name: String,
3841
val type: String,
42+
val restrictions: Restrictions? = null,
3943
@Json(name = "uri", ignored = false) private val _uri: String,
40-
@Json(ignored = true) val uri: AlbumURI = AlbumURI(_uri),
4144
@Json(name = "release_date") val releaseDate: String,
4245
@Json(name = "release_date_precision") val releaseDatePrecision: String,
4346
@Json(name = "total_tracks") val totalTracks: Int? = null,
44-
@Json(name = "album_group", ignored = false) private val albumGroupString: String? = null,
45-
val restrictions: Restrictions? = null,
46-
@Json(ignored = true) val albumGroup: AlbumResultType? = albumGroupString?.let { _ ->
47-
AlbumResultType.values().find { it.id == albumGroupString }
48-
}
47+
@Json(name = "album_group", ignored = false) private val albumGroupString: String? = null
4948
) : Linkable() {
49+
@Json(ignored = true) val uri: AlbumURI = AlbumURI(_uri)
50+
5051
@Json(ignored = true)
5152
val albumType: AlbumResultType = _albumType.let { _ ->
5253
AlbumResultType.values().first { it.id.equals(_albumType, true) }
5354
}
5455

56+
@Json(ignored = true) val albumGroup: AlbumResultType? = albumGroupString?.let { _ ->
57+
AlbumResultType.values().find { it.id == albumGroupString }
58+
}
59+
60+
/**
61+
* Converts this [SimpleAlbum] into a full [Album] object with the given
62+
* market
63+
*
64+
* @param market Provide this parameter if you want the list of returned items to be relevant to a particular country.
65+
*/
5566
fun toFullAlbum(market: Market? = null) = api.albums.getAlbum(id, market)
5667
}
5768

5869
/**
59-
* Album type
70+
* Album search type
6071
*/
6172
enum class AlbumResultType(internal val id: String) {
6273
ALBUM("album"),
@@ -66,6 +77,8 @@ enum class AlbumResultType(internal val id: String) {
6677
}
6778

6879
/**
80+
* Represents an Album on Spotify
81+
*
6982
* @property albumType The type of the album: one of "album" , "single" , or "compilation".
7083
* @property artists The artists of the album. Each artist object includes a link in href to more detailed
7184
* information about the artist.
@@ -115,22 +128,41 @@ data class Album(
115128
val tracks: PagingObject<SimpleTrack>,
116129
val type: String,
117130
@Json(name = "uri", ignored = false) private val _uri: String,
118-
@Json(ignored = true) val uri: AlbumURI = AlbumURI(_uri),
119131
@Json(name = "total_tracks") val totalTracks: Int,
120-
val restrictions: Restrictions? = null,
132+
val restrictions: Restrictions? = null
133+
) {
134+
@Json(ignored = true) val uri: AlbumURI = AlbumURI(_uri)
135+
121136
@Json(ignored = true) val albumType: AlbumResultType = AlbumResultType.values().first { it.id == _albumType }
122-
)
137+
}
123138

124139
/**
125-
* Describes an album's copyright
140+
* Describes an album's copyright information
126141
*
127142
* @property text The copyright text for this album.
128143
* @property type The type of copyright: C = the copyright,
129144
* P = the sound recording (performance) copyright.
130145
*/
131146
data class SpotifyCopyright(
132-
val text: String,
133-
val type: String
134-
)
147+
@Json(name="text") private val _text: String,
148+
@Json(name="type") private val _type: String
149+
) {
150+
@Json(ignored = true) val text = _text
151+
.removePrefix("(P)")
152+
.removePrefix("(C)")
153+
.trim()
154+
@Json(ignored = true) val type = CopyrightType.values().match(_type)!!
155+
}
156+
157+
internal data class AlbumsResponse(val albums: List<Album?>)
158+
159+
/**
160+
* Copyright statement type of an Album
161+
*/
162+
enum class CopyrightType(val identifier: String): ResultEnum {
163+
COPYRIGHT("C"),
164+
SOUND_PERFORMANCE_COPYRIGHT("P")
165+
;
135166

136-
internal data class AlbumsResponse(val albums: List<Album?>)
167+
override fun retrieveIdentifier() = identifier
168+
}

src/main/kotlin/com/adamratzman/spotify/models/Artists.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ package com.adamratzman.spotify.models
44
import com.beust.klaxon.Json
55

66
/**
7+
* Simplified Artist object that can be used to retrieve a full [Artist]
8+
*
79
* @property externalUrls Known external URLs for this artist.
810
* @property href A link to the Web API endpoint providing full details of the artist.
911
* @property id The Spotify ID for the artist.
@@ -17,13 +19,19 @@ data class SimpleArtist(
1719
val id: String,
1820
val name: String,
1921
val type: String,
20-
@Json(name = "uri", ignored = false) private val _uri: String,
21-
@Json(ignored = true) val uri: ArtistURI = ArtistURI(_uri)
22+
@Json(name = "uri", ignored = false) private val _uri: String
2223
) : Linkable() {
24+
@Json(ignored = true) val uri: ArtistURI = ArtistURI(_uri)
25+
26+
/**
27+
* Converts this [SimpleArtist] into a full [Artist] object
28+
*/
2329
fun toFullArtist() = api.artists.getArtist(id)
2430
}
2531

2632
/**
33+
* Represents an Artist (distinct from a regular user) on Spotify
34+
*
2735
* @property externalUrls Known external URLs for this artist.
2836
* @property followers Information about the followers of the artist.
2937
* @property genres A list of the genres the artist is associated with. For example: "Prog Rock" ,
@@ -47,8 +55,9 @@ data class Artist(
4755
val name: String,
4856
val popularity: Int,
4957
val type: String,
50-
@Json(name = "uri", ignored = false) private val _uri: String,
58+
@Json(name = "uri", ignored = false) private val _uri: String
59+
) {
5160
@Json(ignored = true) val uri: ArtistURI = ArtistURI(_uri)
52-
)
61+
}
5362

5463
internal data class ArtistList(val artists: List<Artist?>)

src/main/kotlin/com/adamratzman/spotify/models/Authentication.kt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@ import com.adamratzman.spotify.SpotifyScope
55
import com.beust.klaxon.Json
66

77
/**
8-
* Represents a Spotify Token, retrieved through instantiating a new [SpotifyAPI]
8+
* Represents a Spotify Token, retrieved through instantiating a [SpotifyAPI]
9+
*
10+
* @property accessToken An access token that can be provided in subsequent calls,
11+
* for example to Spotify Web API services.
12+
* @property tokenType How the access token may be used: always “Bearer”.
13+
* @property expiresIn The time period (in seconds) for which the access token is valid.
14+
* @property refreshToken A token that can be sent to the Spotify Accounts service in place of an authorization code,
15+
* null if the token was created using a method that does not support token refresh
16+
* @property scopes A list of scopes granted access for this [accessToken]. An
17+
* empty list means that the token can only be used to acces public information.
918
*/
1019
data class Token(
11-
@Json(name = "access_token") val accessToken: String,
12-
@Json(name = "token_type") val tokenType: String,
13-
@Json(name = "expires_in")val expiresIn: Int,
14-
@Json(name = "refresh_token") val refreshToken: String? = null,
15-
@Json(ignored = false) private val scopeString: String? = null,
16-
@Json(ignored = true) val scopes: List<SpotifyScope>? = scopeString?.let { str ->
17-
str.split(" ").mapNotNull { scope -> SpotifyScope.values().find { it.uri == scope } }
18-
}
20+
@Json(name = "access_token") val accessToken: String,
21+
@Json(name = "token_type") val tokenType: String,
22+
@Json(name = "expires_in") val expiresIn: Int,
23+
@Json(name = "refresh_token") val refreshToken: String? = null,
24+
@Json(ignored = false) private val scopeString: String? = null,
25+
@Json(ignored = true) val scopes: List<SpotifyScope> = scopeString?.let { str ->
26+
str.split(" ").mapNotNull { scope -> SpotifyScope.values().find { it.uri.equals(scope, true) } }
27+
} ?: listOf()
1928
)

src/main/kotlin/com/adamratzman/spotify/models/Browse.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ package com.adamratzman.spotify.models
1010
* @property name The name of the category.
1111
*/
1212
data class SpotifyCategory(
13-
val href: String,
14-
val icons: List<SpotifyImage>,
15-
val id: String,
16-
val name: String
13+
val href: String,
14+
val icons: List<SpotifyImage>,
15+
val id: String,
16+
val name: String
1717
)
1818

1919
/**
@@ -29,12 +29,12 @@ data class SpotifyCategory(
2929
* @property type The entity type of this seed. One of artist , track or genre.
3030
*/
3131
data class RecommendationSeed(
32-
val initialPoolSize: Int,
33-
val afterFilteringSize: Int,
34-
val afterRelinkingSize: Int?,
35-
val href: String?,
36-
val id: String,
37-
val type: String
32+
val initialPoolSize: Int,
33+
val afterFilteringSize: Int,
34+
val afterRelinkingSize: Int?,
35+
val href: String?,
36+
val id: String,
37+
val type: String
3838
)
3939

4040
/**

src/main/kotlin/com/adamratzman/spotify/models/Library.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ package com.adamratzman.spotify.models
44
import com.beust.klaxon.Json
55

66
/**
7+
* Represents an album saved in a user's library
8+
*
79
* @property addedAt The date and time the album was saved.
8-
* @property track Information about the album.
10+
* @property album Information about the album.
911
*/
1012
data class SavedAlbum(
1113
@Json(name = "added_at") val addedAt: String,
1214
val album: Album
1315
)
1416

1517
/**
18+
* Represents a track saved in a user's library
19+
*
1620
* @property addedAt The date and time the track was saved.
1721
* @property track The track object.
1822
*/

src/main/kotlin/com/adamratzman/spotify/models/Market.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package com.adamratzman.spotify.models
44
/**
55
* Represents Spotify markets (countries + distinctive territories)
66
*
7-
* @param country the readable country/territory name of the market
7+
* @property country the readable country/territory name of the market
88
*/
99
enum class Market(val country: String) {
1010
AD("Andorra"),

0 commit comments

Comments
 (0)