Skip to content

Commit 1b2c9f8

Browse files
authored
Merge pull request #337 from adamint/dev/adamint/fix-incorrect-logic-has-scopes
Several bug fixes
2 parents 3c7b55d + d50cc64 commit 1b2c9f8

File tree

23 files changed

+49
-37
lines changed

23 files changed

+49
-37
lines changed

build.gradle.kts

Lines changed: 7 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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/commonJvmLikeTest/kotlin/com/adamratzman/spotify/CommonImpl.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ private suspend fun buildSpotifyApiInternal(): GenericSpotifyApi? {
3838

3939
val optionsCreator: (SpotifyApiOptions.() -> Unit) = {
4040
this.enableDebugMode = logHttp
41+
retryOnInternalServerErrorTimes = 0
4142
}
4243

4344
return when {

src/commonMain/kotlin/com.adamratzman.spotify/SpotifyApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ public open class SpotifyClientApi(
644644
if (token.scopes == null) {
645645
null
646646
} else {
647-
!isTokenValid(false).isValid &&
647+
isTokenValid(false).isValid &&
648648
token.scopes?.contains(scope) == true &&
649649
scopes.all { token.scopes?.contains(it) == true }
650650
}

src/commonMain/kotlin/com.adamratzman.spotify/endpoints/pub/EpisodeApi.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.adamratzman.spotify.endpoints.pub
33

44
import com.adamratzman.spotify.GenericSpotifyApi
55
import com.adamratzman.spotify.SpotifyAppApi
6+
import com.adamratzman.spotify.SpotifyClientApi
67
import com.adamratzman.spotify.SpotifyException.BadRequestException
78
import com.adamratzman.spotify.SpotifyScope
89
import com.adamratzman.spotify.http.SpotifyEndpoint
@@ -60,7 +61,7 @@ public open class EpisodeApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
6061
* Users can view the country that is associated with their account in the account settings. Required for [SpotifyAppApi], but **you may use [Market.FROM_TOKEN] to get the user market**
6162
*
6263
* @return List of possibly-null [Episode] objects.
63-
* @throws BadRequestException If any invalid show id is provided
64+
* @throws BadRequestException If any invalid show id is provided, if this is a [SpotifyClientApi]
6465
*/
6566
public suspend fun getEpisodes(vararg ids: String, market: Market): List<Episode?> {
6667
checkBulkRequesting(50, ids.size)

src/commonMain/kotlin/com.adamratzman.spotify/endpoints/pub/SearchApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
338338
market: Market,
339339
language: Language? = null
340340
): SpotifySearchResult =
341-
search(query, filters = filters, searchTypes = SearchType.values(), limit = limit, offset = offset, market = market)
341+
search(query, filters = filters, searchTypes = SearchType.entries.toTypedArray(), limit = limit, offset = offset, market = market, language = language)
342342

343343
protected fun build(
344344
query: String,

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

Lines changed: 6 additions & 6 deletions
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,
@@ -54,14 +54,14 @@ public data class SimpleAlbum(
5454

5555
val albumType: AlbumResultType
5656
get() = albumTypeString.let { _ ->
57-
AlbumResultType.values().first { it.id.equals(albumTypeString, true) }
57+
AlbumResultType.entries.first { it.id.equals(albumTypeString, true) }
5858
}
5959

6060
val releaseDate: ReleaseDate? get() = releaseDateString?.let { getReleaseDate(releaseDateString) }
6161

6262
val albumGroup: AlbumResultType?
6363
get() = albumGroupString?.let { _ ->
64-
AlbumResultType.values().find { it.id == albumGroupString }
64+
AlbumResultType.entries.find { it.id == albumGroupString }
6565
}
6666

6767
/**
@@ -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,
@@ -157,7 +157,7 @@ public data class Album(
157157

158158
val externalIds: List<ExternalId> get() = externalIdsString.map { ExternalId(it.key, it.value) }
159159

160-
val albumType: AlbumResultType get() = AlbumResultType.values().first { it.id == albumTypeString }
160+
val albumType: AlbumResultType get() = AlbumResultType.entries.first { it.id == albumTypeString }
161161

162162
val releaseDate: ReleaseDate get() = getReleaseDate(releaseDateString)
163163

@@ -181,7 +181,7 @@ public data class SpotifyCopyright(
181181
.removePrefix("(C)")
182182
.trim()
183183

184-
val type: CopyrightType get() = CopyrightType.values().match(typeString)!!
184+
val type: CopyrightType get() = CopyrightType.entries.toTypedArray().match(typeString)!!
185185
}
186186

187187
@Serializable

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

Lines changed: 1 addition & 1 deletion
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/Authentication.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public data class Token(
3333
val expiresAt: Long get() = getCurrentTimeMs() + expiresIn * 1000
3434

3535
val scopes: List<SpotifyScope>? get() = scopeString?.let { str ->
36-
str.split(" ").mapNotNull { scope -> SpotifyScope.values().find { it.uri.equals(scope, true) } }
36+
str.split(" ").mapNotNull { scope -> SpotifyScope.entries.find { it.uri.equals(scope, true) } }
3737
}
3838

3939
public fun shouldRefresh(): Boolean = getCurrentTimeMs() > expiresAt

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

Lines changed: 2 additions & 2 deletions
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")

0 commit comments

Comments
 (0)