Skip to content

Commit e71b124

Browse files
committed
kotlin style changes
1 parent de002e4 commit e71b124

File tree

7 files changed

+19
-24
lines changed

7 files changed

+19
-24
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,11 +501,11 @@ class SpotifyApiOptionsBuilder(
501501
SpotifyApiOptions(
502502
true,
503503
200,
504-
false,
505-
true,
506-
true,
507-
true,
508-
json
504+
automaticRefresh = false,
505+
retryWhenRateLimited = true,
506+
enableLogger = true,
507+
testTokenValidity = true,
508+
json = json
509509
)
510510
else
511511
SpotifyApiOptions(

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ sealed class SpotifyApi<T : SpotifyApi<T, B>, B : ISpotifyApiBuilder<T, B>>(
9292
if (!isTokenValid().isValid)
9393
try {
9494
refreshToken()
95-
} catch (e: SpotifyException.BadRequestException) {
95+
} catch (e: BadRequestException) {
9696
throw SpotifyException.AuthenticationException(
9797
"Invalid token and refresh token supplied. Cannot refresh to a fresh token.",
9898
e
@@ -453,7 +453,7 @@ class SpotifyClientApi internal constructor(
453453

454454
logger.logInfo("Successfully refreshed the Spotify token")
455455
return currentToken
456-
} else throw SpotifyException.BadRequestException(
456+
} else throw BadRequestException(
457457
response.body.toObject(
458458
AuthenticationError.serializer(),
459459
this,
@@ -551,7 +551,7 @@ suspend fun getCredentialedToken(clientId: String, clientSecret: String, api: Sp
551551

552552
if (response.responseCode / 200 == 1) return response.body.toObject(Token.serializer(), null, json)
553553

554-
throw SpotifyException.BadRequestException(response.body.toObject(AuthenticationError.serializer(), null, json))
554+
throw BadRequestException(response.body.toObject(AuthenticationError.serializer(), null, json))
555555
}
556556

557557
internal suspend fun executeTokenRequest(

src/commonMain/kotlin/com.adamratzman.spotify/endpoints/client/ClientPlaylistApi.kt

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

44
import com.adamratzman.spotify.SpotifyApi
55
import com.adamratzman.spotify.SpotifyClientApi
6-
import com.adamratzman.spotify.SpotifyException
76
import com.adamratzman.spotify.SpotifyException.BadRequestException
87
import com.adamratzman.spotify.SpotifyRestAction
98
import com.adamratzman.spotify.SpotifyRestActionPaging
@@ -67,7 +66,7 @@ class ClientPlaylistApi(api: SpotifyApi<*, *>) : PlaylistApi(api) {
6766
collaborative: Boolean? = null,
6867
user: String = (api as SpotifyClientApi).userId
6968
): SpotifyRestAction<Playlist> {
70-
if (name.isEmpty()) throw SpotifyException.BadRequestException(ErrorObject(400, "Name cannot be empty"))
69+
if (name.isEmpty()) throw BadRequestException(ErrorObject(400, "Name cannot be empty"))
7170
return toAction {
7271
val body = jsonMap()
7372
body += json { "name" to name }

src/commonMain/kotlin/com.adamratzman.spotify/endpoints/public/BrowseApi.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package com.adamratzman.spotify.endpoints.public
33

44
import com.adamratzman.spotify.SpotifyApi
5-
import com.adamratzman.spotify.SpotifyException
65
import com.adamratzman.spotify.SpotifyException.BadRequestException
76
import com.adamratzman.spotify.SpotifyRestAction
87
import com.adamratzman.spotify.SpotifyRestActionPaging
@@ -25,9 +24,9 @@ import com.adamratzman.spotify.models.serialization.toObject
2524
import com.adamratzman.spotify.models.serialization.toPagingObject
2625
import com.adamratzman.spotify.utils.Market
2726
import com.adamratzman.spotify.utils.formatDate
27+
import kotlin.reflect.KClass
2828
import kotlinx.serialization.list
2929
import kotlinx.serialization.serializer
30-
import kotlin.reflect.KClass
3130

3231
@Deprecated("Endpoint name has been updated for kotlin convention consistency", ReplaceWith("BrowseApi"))
3332
typealias BrowseAPI = BrowseApi
@@ -294,7 +293,7 @@ class BrowseApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
294293
maxAttributes: Map<TuneableTrackAttribute<*>, Number> = mapOf()
295294
): SpotifyRestAction<RecommendationResponse> {
296295
if (seedArtists?.isEmpty() != false && seedGenres?.isEmpty() != false && seedTracks?.isEmpty() != false) {
297-
throw SpotifyException.BadRequestException(
296+
throw BadRequestException(
298297
ErrorObject(
299298
400,
300299
"At least one seed (genre, artist, track) must be provided."
@@ -325,7 +324,7 @@ sealed class TuneableTrackAttribute<T : Number>(
325324
val integerOnly: Boolean,
326325
val min: T?,
327326
val max: T?,
328-
internal val tClazz: KClass<T>
327+
private val tClazz: KClass<T>
329328
) {
330329
/**
331330
* A confidence measure from 0.0 to 1.0 of whether the track is acoustic.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ abstract class AbstractPagingObject<T : Any>(
253253

254254
@ExperimentalCoroutinesApi
255255
fun flowStartOrdered(): Flow<AbstractPagingObject<T>> =
256-
flow<AbstractPagingObject<T>> {
256+
flow {
257257
if (previous == null) return@flow
258258
flowBackward().toList().reversed().also {
259259
emitAll(it.asFlow())

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ package com.adamratzman.spotify.utils
44
import io.ktor.utils.io.core.String
55
import io.ktor.utils.io.core.toByteArray
66

7-
private val BASE64_ALPHABET: String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
8-
private val BASE64_MASK: Byte = 0x3f
9-
private val BASE64_PAD: Char = '='
10-
private val BASE64_INVERSE_ALPHABET = IntArray(256) {
11-
BASE64_ALPHABET.indexOf(it.toChar())
12-
}
7+
private const val BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
8+
private const val BASE64_MASK = 0x3f
9+
private const val BASE64_PAD = '='
1310

1411
private fun Int.toBase64(): Char = BASE64_ALPHABET[this]
1512

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
package com.adamratzman.spotify
33

44
actual class SpotifyLogger actual constructor(actual var enabled: Boolean) {
5-
val redString = "\u001B[31m"
6-
val orangeString = "\u001B[33m"
7-
val resetString = "\u001B[0m"
5+
private val redString = "\u001B[31m"
6+
private val orangeString = "\u001B[33m"
7+
private val resetString = "\u001B[0m"
88

99
actual fun logInfo(message: String) {
1010
if (enabled) println("Spotify Logger Info: $message")

0 commit comments

Comments
 (0)