Skip to content

Commit 0925e31

Browse files
authored
Merge pull request #24 from molikuner/inlineUris
Clean classes for URIs
2 parents 5b75359 + 37366f9 commit 0925e31

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

src/main/kotlin/com/adamratzman/spotify/utils/SpotifyUris.kt

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,25 @@ private fun String.remove(type: String): String {
2020
throw SpotifyUriException("Illegal Spotify ID/URI: '$this' isn't convertible to '$type' id")
2121
}
2222

23-
abstract class SpotifyUri(tmp: String, val input: String = tmp.replace(" ", "")) {
24-
abstract val uri: String
25-
abstract val id: String
23+
sealed class SpotifyUri(input: String, type: String) {
24+
val uri: String
25+
val id: String
26+
27+
init {
28+
input.replace(" ", "").also {
29+
this.uri = it.add(type)
30+
this.id = it.remove(type)
31+
}
32+
}
2633
}
2734

28-
class AlbumURI(input: String) : SpotifyUri(input) {
29-
override val uri: String = super.input.add("album")
30-
override val id: String = super.input.remove("album")
31-
}
35+
class AlbumURI(input: String) : SpotifyUri(input, "album")
3236

33-
class ArtistURI(input: String) : SpotifyUri(input) {
34-
override val uri: String = super.input.add("artist")
35-
override val id: String = super.input.remove("artist")
36-
}
37+
class ArtistURI(input: String) : SpotifyUri(input, "artist")
3738

38-
class TrackURI(input: String) : SpotifyUri(input) {
39-
override val uri: String = super.input.add("track")
40-
override val id: String = super.input.remove("track")
41-
}
39+
class TrackURI(input: String) : SpotifyUri(input, "track")
4240

43-
class UserURI(input: String) : SpotifyUri(input) {
44-
override val uri: String = super.input.add("user")
45-
override val id: String = super.input.remove("user")
46-
}
41+
class UserURI(input: String) : SpotifyUri(input, "user")
4742

48-
class PlaylistURI(input: String) : SpotifyUri(input) {
49-
override val uri: String = super.input.add("playlist")
50-
override val id: String = super.input.remove("playlist")
51-
}
43+
class PlaylistURI(input: String) : SpotifyUri(input, "playlist")
5244

0 commit comments

Comments
 (0)