Skip to content

Commit adb3578

Browse files
committed
Make images nullable (change in spotify responses?)
1 parent 153f23b commit adb3578

File tree

11 files changed

+21
-16
lines changed

11 files changed

+21
-16
lines changed

build.gradle.kts

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.databind.json.JsonMapper
44
import org.jetbrains.dokka.gradle.DokkaTask
5+
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
56
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
67
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
78
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackOutput.Target
@@ -46,7 +47,7 @@ version = libraryVersion
4647

4748
android {
4849
namespace = "com.adamratzman.spotify"
49-
compileSdk = 30
50+
compileSdk = 31
5051
compileOptions {
5152
sourceCompatibility = JavaVersion.VERSION_17
5253
targetCompatibility = JavaVersion.VERSION_17
@@ -56,7 +57,7 @@ android {
5657
}
5758
defaultConfig {
5859
minSdk = 23
59-
setCompileSdkVersion(30)
60+
setCompileSdkVersion(31)
6061
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
6162
}
6263

@@ -81,6 +82,10 @@ val dokkaJar: TaskProvider<Jar> by tasks.registering(Jar::class) {
8182
}
8283

8384
kotlin {
85+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
86+
compilerOptions {
87+
freeCompilerArgs.add("-Xexpect-actual-classes")
88+
}
8489
explicitApiWarning()
8590
jvmToolchain(17)
8691

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ kotlinxCoroutinesVersion=1.7.3
2121
androidBuildToolsVersion=8.2.2
2222
androidSpotifyAuthVersion=2.1.1
2323
androidCryptoVersion=1.1.0-alpha06
24-
androidxCompatVersion=1.6.1
24+
androidxCompatVersion=1.7.0-alpha03
2525

2626
sparkVersion=2.9.4

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public data class SimpleAlbum(
4141
override val uri: SpotifyUri,
4242

4343
val artists: List<SimpleArtist>,
44-
val images: List<SpotifyImage>,
44+
val images: List<SpotifyImage>? = null,
4545
val name: String,
4646
val type: String,
4747
val restrictions: Restrictions? = null,
@@ -142,7 +142,7 @@ public data class Album(
142142
val artists: List<SimpleArtist>,
143143
val copyrights: List<SpotifyCopyright>,
144144
val genres: List<String>,
145-
val images: List<SpotifyImage>,
145+
val images: List<SpotifyImage>? = null,
146146
val label: String,
147147
val name: String,
148148
val popularity: Double,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public data class Artist(
5959

6060
val followers: Followers,
6161
val genres: List<String>,
62-
val images: List<SpotifyImage>,
62+
val images: List<SpotifyImage>? = null,
6363
val name: String? = null,
6464
val popularity: Double,
6565
val type: String

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public data class Episode(
9696
@SerialName("external_urls") override val externalUrlsString: Map<String, String>,
9797
override val href: String,
9898
override val id: String,
99-
val images: List<SpotifyImage>,
99+
val images: List<SpotifyImage>? = null,
100100
@SerialName("is_externally_hosted") val isExternallyHosted: Boolean,
101101
@SerialName("is_playable") val isPlayable: Boolean,
102102
@Deprecated("This field is deprecated and might be removed in the future. Please use the languages field instead")
@@ -148,7 +148,7 @@ public data class SimpleEpisode(
148148
@SerialName("external_urls") override val externalUrlsString: Map<String, String>,
149149
override val href: String,
150150
override val id: String,
151-
val images: List<SpotifyImage>,
151+
val images: List<SpotifyImage>? = null,
152152
@SerialName("is_externally_hosted") val isExternallyHosted: Boolean,
153153
@SerialName("is_playable") val isPlayable: Boolean,
154154
@Deprecated("This field is deprecated and might be removed in the future. Please use the languages field instead")

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public data class SimplePlaylist(
3939
override val uri: SpotifyUri,
4040

4141
val collaborative: Boolean,
42-
val images: List<SpotifyImage>,
42+
val images: List<SpotifyImage>? = null,
4343
val name: String,
4444
val description: String? = null,
4545
val owner: SpotifyPublicUser,
@@ -126,7 +126,7 @@ public data class Playlist(
126126
val description: String? = null,
127127
val followers: Followers,
128128
@SerialName("primary_color") val primaryColor: String? = null,
129-
val images: List<SpotifyImage>,
129+
val images: List<SpotifyImage>? = null,
130130
val name: String,
131131
val owner: SpotifyPublicUser,
132132
val public: Boolean? = null,

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public interface ISpotifyUri {
7676
*/
7777
@Serializable(with = SpotifyUriSerializer::class)
7878
public sealed class SpotifyUri(input: String, public val type: String, allowColon: Boolean = false) : ISpotifyUri {
79-
public override val uri: String
80-
public override val id: String
79+
public final override val uri: String
80+
public final override val id: String
8181

8282
init {
8383
input.replace(" ", "").also {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public data class SpotifyUserInformation(
4040
@SerialName("display_name") val displayName: String? = null,
4141
val email: String? = null,
4242
val followers: Followers,
43-
val images: List<SpotifyImage>,
43+
val images: List<SpotifyImage>? = null,
4444
val product: String? = null,
4545
@SerialName("explicit_content") val explicitContentSettings: ExplicitContentSettings? = null,
4646
val type: String

src/commonMain/kotlin/com.adamratzman.spotify/utils/Utils.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal suspend inline fun <T> catch(catchInternalServerError: Boolean = false,
2121
return try {
2222
function()
2323
} catch (e: SpotifyException.BadRequestException) {
24-
if (e.statusCode !in listOf(400, 404)) throw e
24+
if (e.statusCode !in listOf(400, 404) && (e.statusCode !in 500..599) || catchInternalServerError) throw e
2525
// we should only ignore the exception if it's 400 or 404. Otherwise, it's a larger issue
2626
null
2727
}

src/commonTest/kotlin/com.adamratzman/spotify/priv/ClientPlaylistApiTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class ClientPlaylistApiTest : AbstractTest<SpotifyClientApi>() {
130130
assertTrue(updatedPlaylist.public == false)
131131
assertEquals("test playlist", updatedPlaylist.name)
132132
//assertEquals("description 2", fullPlaylist.description) <-- spotify is flaky about actually having description set
133-
assertTrue(updatedPlaylist.tracks.total == 2 && updatedPlaylist.images.isNotEmpty())
133+
assertTrue(updatedPlaylist.tracks.total == 2 && updatedPlaylist.images?.isNotEmpty() == true)
134134

135135
api.playlists.reorderClientPlaylistPlayables(updatedPlaylist.id, 1, insertionPoint = 0)
136136

src/jsMain/kotlin/com/adamratzman/spotify/webplayer/WebPlaybackSdk.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import kotlin.js.Promise
1313
public external interface Album {
1414
public var uri: String
1515
public var name: String
16-
public var images: Array<Image>
16+
public var images: Array<Image>?
1717
}
1818

1919
public external interface Artist {

0 commit comments

Comments
 (0)