Skip to content

Commit a2293d1

Browse files
committed
correctly classify javadoc jar in publication, fix user collection parsing
1 parent 57e7b80 commit a2293d1

File tree

3 files changed

+72
-11
lines changed

3 files changed

+72
-11
lines changed

build.gradle.kts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ val dokkaJar: TaskProvider<Jar> by tasks.registering(Jar::class) {
7373
group = JavaBasePlugin.DOCUMENTATION_GROUP
7474
description = "spotify-web-api-kotlin generated documentation"
7575
from(tasks.dokkaHtml)
76+
archiveClassifier.set("javadoc")
7677
}
7778

7879
kotlin {
@@ -151,10 +152,6 @@ kotlin {
151152
mavenPublication { setupPom(artifactId) }
152153
}*/
153154

154-
publishing {
155-
registerPublishing()
156-
}
157-
158155
targets {
159156
sourceSets {
160157
val kotlinxDatetimeVersion: String by project
@@ -298,6 +295,10 @@ kotlin {
298295
}
299296
}
300297

298+
publishing {
299+
registerPublishing()
300+
}
301+
301302
tasks {
302303
val dokkaHtml by getting(DokkaTask::class) {
303304
outputDirectory.set(projectDir.resolve("docs"))
@@ -354,7 +355,7 @@ tasks {
354355

355356
fun MavenPublication.setupPom(publicationName: String) {
356357
artifactId = artifactId.replace("-web", "")
357-
artifact(dokkaJar.get())
358+
artifact(dokkaJar.get()) // add javadocs to publication
358359

359360
pom {
360361
name.set(publicationName)

src/commonMain/kotlin/com.adamratzman.spotify/models/SpotifyUris.kt

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,20 @@ private fun String.matchType(type: String, allowColon: Boolean): String? {
2424
return match[1].takeIf { it.isNotBlank() || match[2].isEmpty() } ?: match[2].takeIf { it.isNotEmpty() }
2525
}
2626

27+
private fun String.matchesUserCollectionUri() = this.matches("^spotify:user:([^:]+):collection".toRegex())
28+
2729
private fun String.add(type: String, allowColon: Boolean): String {
28-
this.matchType(type, allowColon)?.let {
30+
if (type == UserCollectionUriType && matchesUserCollectionUri()) return this
31+
else this.matchType(type, allowColon)?.let {
2932
return "spotify:$type:${it.trim()}"
3033
}
3134
throw SpotifyUriException("Illegal Spotify ID/URI: '$this' isn't convertible to '$type' uri")
3235
}
3336

3437
private fun String.remove(type: String, allowColon: Boolean): String {
35-
this.matchType(type, allowColon)?.let {
38+
println(type)
39+
if (type == UserCollectionUriType && matchesUserCollectionUri()) return "collection"
40+
else this.matchType(type, allowColon)?.let {
3641
return it.trim()
3742
}
3843
throw SpotifyUriException("Illegal Spotify ID/URI: '$this' isn't convertible to '$type' id")
@@ -112,7 +117,7 @@ public sealed class SpotifyUri(input: String, public val type: String, allowColo
112117
val constructors = listOf(
113118
::ArtistUri,
114119
PlayableUri.Companion::invoke,
115-
ImmutableCollectionUri.Companion::invoke,
120+
CollectionUri.Companion::invoke,
116121
::UserUri,
117122
::PlaylistUri
118123
)
@@ -178,7 +183,7 @@ public sealed class CollectionUri(input: String, type: String, allowColon: Boole
178183
* Creates an abstract [CollectionUri] of given input. Prefers [PlaylistUri] if the input is ambiguous.
179184
*/
180185
public operator fun invoke(input: String): CollectionUri {
181-
val constructors = listOf(::PlaylistUri, ImmutableCollectionUri.Companion::invoke)
186+
val constructors = listOf(::PlaylistUri, ::UserCollectionUri, ImmutableCollectionUri.Companion::invoke)
182187
for (ctor in constructors) {
183188
safeInitiate(input, ctor)?.also { return it }
184189
}
@@ -372,9 +377,24 @@ public object ShowUriSerializer : KSerializer<ShowUri> by SimpleUriSerializer(::
372377
*/
373378
public fun String.toShowUri(): ShowUri = ShowUri(this)
374379

380+
private const val UserCollectionUriType = "UserCollectionUri"
381+
382+
/**
383+
* Represents a Spotify **User Collection URI** URI (spotify:user:XXXX:collection), parsed from either a Spotify ID or taken from an endpoint.
384+
* It appears that this URI corresponds to the user's saved tracks collection in their library.
385+
*/
386+
@Serializable(with = UserCollectionUriSerializer::class)
387+
public class UserCollectionUri(input: String) : CollectionUri(input, UserCollectionUriType), ContextUri
388+
public object UserCollectionUriSerializer : KSerializer<UserCollectionUri> by SimpleUriSerializer(::UserCollectionUri)
389+
375390
/**
376-
* Represents a Spotify **Context** URI (one of [AlbumUri], [ArtistUri], [PlaylistUri], or [ShowUri]),
377-
*/
391+
* Convert a show id or uri string to a [ShowUri] object
392+
*/
393+
public fun String.toUserCollectionUri(): UserCollectionUri = UserCollectionUri(this)
394+
395+
/**
396+
* Represents a Spotify **Context** URI (one of [AlbumUri], [ArtistUri], [PlaylistUri], [UserCollectionUri], or [ShowUri]),
397+
*/
378398
@Serializable(with = ContextUriSerializer::class)
379399
public interface ContextUri : ISpotifyUri {
380400
public companion object {

src/commonTest/kotlin/com.adamratzman/spotify/utilities/UrisTests.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.adamratzman.spotify.models.PlaylistUri
99
import com.adamratzman.spotify.models.SpotifyTrackUri
1010
import com.adamratzman.spotify.models.SpotifyUri
1111
import com.adamratzman.spotify.models.SpotifyUriException
12+
import com.adamratzman.spotify.models.UserCollectionUri
1213
import com.adamratzman.spotify.models.UserUri
1314
import kotlin.test.Test
1415
import kotlin.test.assertEquals
@@ -185,6 +186,45 @@ class UrisTests {
185186
)
186187
}
187188

189+
@Test
190+
fun testUserCollectionUri() {
191+
assertFailsWith<SpotifyUriException> {
192+
UserCollectionUri("a:invalid")
193+
}
194+
195+
assertFailsWith<SpotifyUriException> {
196+
UserCollectionUri("a:invalid").uri
197+
}
198+
199+
assertFailsWith<SpotifyUriException> {
200+
UserCollectionUri("a:invalid").id
201+
}
202+
203+
assertFailsWith<SpotifyUriException> {
204+
UserCollectionUri("spotify:user:testuser").uri
205+
}
206+
207+
assertEquals(
208+
"spotify:user:adamratzman1:collection",
209+
UserCollectionUri("spotify:user:adamratzman1:collection").uri
210+
)
211+
212+
assertEquals(
213+
"spotify:user:adamratzman1:collection",
214+
UserCollectionUri("spotify:user:adamratzman1:collection").uri
215+
)
216+
217+
assertEquals(
218+
UserCollectionUri::class,
219+
SpotifyUri("spotify:user:adamratzman1:collection")::class
220+
)
221+
222+
assertEquals(
223+
"collection",
224+
UserCollectionUri("spotify:user:adamratzman1:collection").id
225+
)
226+
}
227+
188228
@Test
189229
fun testPlaylistUri() {
190230
assertFailsWith<SpotifyUriException> {

0 commit comments

Comments
 (0)