Skip to content

Commit ec0e1c1

Browse files
committed
lint
1 parent 1f7d72a commit ec0e1c1

File tree

8 files changed

+88
-90
lines changed

8 files changed

+88
-90
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import com.adamratzman.spotify.utils.TimeUnit
77
import com.adamratzman.spotify.utils.getCurrentTimeMs
88
import com.adamratzman.spotify.utils.runBlocking
99
import com.adamratzman.spotify.utils.schedule
10+
import kotlin.coroutines.CoroutineContext
11+
import kotlin.coroutines.resume
12+
import kotlin.coroutines.resumeWithException
13+
import kotlin.coroutines.suspendCoroutine
14+
import kotlin.jvm.JvmOverloads
1015
import kotlinx.coroutines.CancellationException
1116
import kotlinx.coroutines.CoroutineScope
1217
import kotlinx.coroutines.Dispatchers
@@ -21,11 +26,6 @@ import kotlinx.coroutines.flow.flow
2126
import kotlinx.coroutines.flow.flowOn
2227
import kotlinx.coroutines.launch
2328
import kotlinx.coroutines.withContext
24-
import kotlin.coroutines.CoroutineContext
25-
import kotlin.coroutines.resume
26-
import kotlin.coroutines.resumeWithException
27-
import kotlin.coroutines.suspendCoroutine
28-
import kotlin.jvm.JvmOverloads
2929

3030
/**
3131
* Provides a uniform interface to retrieve, whether synchronously or asynchronously, [T] from Spotify
@@ -114,11 +114,11 @@ open class SpotifyRestAction<T> internal constructor(protected val api: SpotifyA
114114
*/
115115
@JvmOverloads
116116
fun queueAfter(
117-
quantity: Int,
118-
timeUnit: TimeUnit = TimeUnit.SECONDS,
119-
scope: CoroutineScope = GlobalScope,
120-
failure: (Throwable) -> Unit = { throw it },
121-
consumer: (T) -> Unit
117+
quantity: Int,
118+
timeUnit: TimeUnit = TimeUnit.SECONDS,
119+
scope: CoroutineScope = GlobalScope,
120+
failure: (Throwable) -> Unit = { throw it },
121+
consumer: (T) -> Unit
122122
): SpotifyRestAction<T> {
123123
val runAt = getCurrentTimeMs() + timeUnit.toMillis(quantity.toLong())
124124
queue({ exception ->

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ class ClientFollowingApi(api: SpotifyApi<*, *>) : FollowingApi(api) {
151151
* with full [Artist] objects
152152
*/
153153
fun getFollowedArtists(
154-
limit: Int? = api.defaultLimit,
155-
after: String? = null
154+
limit: Int? = api.defaultLimit,
155+
after: String? = null
156156
): SpotifyRestActionPaging<Artist, CursorBasedPagingObject<Artist>> {
157157
return toActionPaging {
158158
get(

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

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ class ClientPlaylistApi(api: SpotifyApi<*, *>) : PlaylistApi(api) {
6464
* @return The created [Playlist] object with no tracks
6565
*/
6666
fun createClientPlaylist(
67-
name: String,
68-
description: String? = null,
69-
public: Boolean? = null,
70-
collaborative: Boolean? = null,
71-
user: String = (api as SpotifyClientApi).userId
67+
name: String,
68+
description: String? = null,
69+
public: Boolean? = null,
70+
collaborative: Boolean? = null,
71+
user: String = (api as SpotifyClientApi).userId
7272
): SpotifyRestAction<Playlist> {
7373
if (name.isEmpty()) throw BadRequestException(ErrorObject(400, "Name cannot be empty"))
7474
return toAction {
@@ -120,7 +120,7 @@ class ClientPlaylistApi(api: SpotifyApi<*, *>) : PlaylistApi(api) {
120120
*
121121
* @throws BadRequestException if any invalid track ids is provided or the playlist is not found
122122
*/
123-
fun addTracksToClientPlaylist(playlist: String, vararg tracks: String, position: Int? = null): SpotifyRestAction<Unit> {
123+
fun addTracksToClientPlaylist(playlist: String, vararg tracks: String, position: Int? = null): SpotifyRestAction<Unit> {
124124
checkBulkRequesting(100, tracks.size)
125125
return toAction {
126126
bulkRequest(100, tracks.toList()) { chunk ->
@@ -135,7 +135,6 @@ class ClientPlaylistApi(api: SpotifyApi<*, *>) : PlaylistApi(api) {
135135

136136
Unit
137137
}
138-
139138
}
140139

141140
/**
@@ -155,11 +154,11 @@ class ClientPlaylistApi(api: SpotifyApi<*, *>) : PlaylistApi(api) {
155154
* @throws BadRequestException if the playlist is not found or parameters exceed the max length
156155
*/
157156
fun changeClientPlaylistDetails(
158-
playlist: String,
159-
name: String? = null,
160-
public: Boolean? = null,
161-
collaborative: Boolean? = null,
162-
description: String? = null
157+
playlist: String,
158+
name: String? = null,
159+
public: Boolean? = null,
160+
collaborative: Boolean? = null,
161+
description: String? = null
163162
): SpotifyRestAction<Unit> {
164163
val body = jsonMap()
165164
if (name != null) body += json { "name" to name }
@@ -190,8 +189,8 @@ class ClientPlaylistApi(api: SpotifyApi<*, *>) : PlaylistApi(api) {
190189
* @throws BadRequestException if the filters provided are illegal
191190
*/
192191
fun getClientPlaylists(
193-
limit: Int? = api.defaultLimit,
194-
offset: Int? = null
192+
limit: Int? = api.defaultLimit,
193+
offset: Int? = null
195194
): SpotifyRestActionPaging<SimplePlaylist, PagingObject<SimplePlaylist>> {
196195
require(!(limit != null && limit !in 1..50)) { "Limit must be between 1 and 50. Provided $limit" }
197196
require(!(offset != null && offset !in 0..100000)) { "Offset must be between 0 and 100,000. Provided $limit" }
@@ -257,11 +256,11 @@ class ClientPlaylistApi(api: SpotifyApi<*, *>) : PlaylistApi(api) {
257256
* @throws BadRequestException if the playlist is not found or illegal filters are applied
258257
*/
259258
fun reorderClientPlaylistTracks(
260-
playlist: String,
261-
reorderRangeStart: Int,
262-
reorderRangeLength: Int? = null,
263-
insertionPoint: Int,
264-
snapshotId: String? = null
259+
playlist: String,
260+
reorderRangeStart: Int,
261+
reorderRangeLength: Int? = null,
262+
insertionPoint: Int,
263+
snapshotId: String? = null
265264
): SpotifyRestAction<PlaylistSnapshot> {
266265
return toAction {
267266
val body = jsonMap()
@@ -352,12 +351,12 @@ class ClientPlaylistApi(api: SpotifyApi<*, *>) : PlaylistApi(api) {
352351
* @throws BadRequestException if invalid data is provided
353352
*/
354353
fun uploadClientPlaylistCover(
355-
playlist: String,
356-
imagePath: String? = null,
357-
imageFile: File? = null,
358-
image: BufferedImage? = null,
359-
imageData: String? = null,
360-
imageUrl: String? = null
354+
playlist: String,
355+
imagePath: String? = null,
356+
imageFile: File? = null,
357+
image: BufferedImage? = null,
358+
imageData: String? = null,
359+
imageUrl: String? = null
361360
): SpotifyRestAction<Unit> {
362361
return toAction {
363362
val data = imageData ?: when {
@@ -389,10 +388,10 @@ class ClientPlaylistApi(api: SpotifyApi<*, *>) : PlaylistApi(api) {
389388
* @param snapshotId The playlist snapshot against which to apply this action. **recommended to have**
390389
*/
391390
fun removeTrackFromClientPlaylist(
392-
playlist: String,
393-
track: String,
394-
positions: SpotifyTrackPositions,
395-
snapshotId: String? = null
391+
playlist: String,
392+
track: String,
393+
positions: SpotifyTrackPositions,
394+
snapshotId: String? = null
396395
) = removeTracksFromClientPlaylist(playlist, track to positions, snapshotId = snapshotId)
397396

398397
/**
@@ -408,9 +407,9 @@ class ClientPlaylistApi(api: SpotifyApi<*, *>) : PlaylistApi(api) {
408407
* @param snapshotId The playlist snapshot against which to apply this action. **recommended to have**
409408
*/
410409
fun removeTrackFromClientPlaylist(
411-
playlist: String,
412-
track: String,
413-
snapshotId: String? = null
410+
playlist: String,
411+
track: String,
412+
snapshotId: String? = null
414413
) = removeTracksFromClientPlaylist(playlist, track, snapshotId = snapshotId)
415414

416415
/**
@@ -426,9 +425,9 @@ class ClientPlaylistApi(api: SpotifyApi<*, *>) : PlaylistApi(api) {
426425
* @param snapshotId The playlist snapshot against which to apply this action. **recommended to have**
427426
*/
428427
fun removeTracksFromClientPlaylist(
429-
playlist: String,
430-
vararg tracks: String,
431-
snapshotId: String? = null
428+
playlist: String,
429+
vararg tracks: String,
430+
snapshotId: String? = null
432431
) = removePlaylistTracksImpl(playlist, tracks.map { it to null }.toTypedArray(), snapshotId)
433432

434433
/**
@@ -444,17 +443,17 @@ class ClientPlaylistApi(api: SpotifyApi<*, *>) : PlaylistApi(api) {
444443
* @param snapshotId The playlist snapshot against which to apply this action. **recommended to have**
445444
*/
446445
fun removeTracksFromClientPlaylist(
447-
playlist: String,
448-
vararg tracks: Pair<String, SpotifyTrackPositions>,
449-
snapshotId: String? = null
446+
playlist: String,
447+
vararg tracks: Pair<String, SpotifyTrackPositions>,
448+
snapshotId: String? = null
450449
) = removePlaylistTracksImpl(playlist, tracks.toList().toTypedArray(), snapshotId)
451450

452451
private fun removePlaylistTracksImpl(
453-
playlist: String,
454-
tracks: Array<Pair<String, SpotifyTrackPositions?>>,
455-
snapshotId: String?
452+
playlist: String,
453+
tracks: Array<Pair<String, SpotifyTrackPositions?>>,
454+
snapshotId: String?
456455
): SpotifyRestAction<PlaylistSnapshot> {
457-
checkBulkRequesting(100,tracks.size)
456+
checkBulkRequesting(100, tracks.size)
458457
if (snapshotId != null && tracks.size > 100) throw BadRequestException("You cannot provide both the snapshot id and attempt bulk requesting")
459458

460459
return toAction {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ class AlbumApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
8787
* @return [PagingObject] of [SimpleTrack] objects
8888
*/
8989
fun getAlbumTracks(
90-
album: String,
91-
limit: Int? = api.defaultLimit,
92-
offset: Int? = null,
93-
market: Market? = null
90+
album: String,
91+
limit: Int? = api.defaultLimit,
92+
offset: Int? = null,
93+
market: Market? = null
9494
): SpotifyRestActionPaging<SimpleTrack, PagingObject<SimpleTrack>> {
9595
return toActionPaging {
9696
get(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ open class FollowingApi(api: SpotifyApi<*, *>) : SpotifyEndpoint(api) {
3535
* @throws [BadRequestException] if the playlist is not found OR any user in the list does not exist
3636
*/
3737
fun areFollowingPlaylist(
38-
playlist: String,
39-
vararg users: String
38+
playlist: String,
39+
vararg users: String
4040
): SpotifyRestAction<List<Boolean>> {
4141
checkBulkRequesting(5, users.size)
4242

src/commonMain/kotlin/com.adamratzman.spotify/http/Endpoints.kt

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import com.adamratzman.spotify.models.ErrorResponse
1414
import com.adamratzman.spotify.models.serialization.toObject
1515
import com.adamratzman.spotify.utils.ConcurrentHashMap
1616
import com.adamratzman.spotify.utils.getCurrentTimeMs
17+
import kotlin.math.ceil
1718
import kotlinx.coroutines.TimeoutCancellationException
1819
import kotlinx.coroutines.withTimeout
19-
import kotlin.math.ceil
2020

2121
abstract class SpotifyEndpoint(val api: SpotifyApi<*, *>) {
2222
val cache = SpotifyCache()
@@ -48,20 +48,20 @@ abstract class SpotifyEndpoint(val api: SpotifyApi<*, *>) {
4848
}
4949

5050
internal suspend fun delete(
51-
url: String,
52-
body: String? = null,
53-
contentType: String? = null
51+
url: String,
52+
body: String? = null,
53+
contentType: String? = null
5454
): String {
5555
return execute(url, body, HttpRequestMethod.DELETE, contentType = contentType)
5656
}
5757

5858
private suspend fun execute(
59-
url: String,
60-
body: String? = null,
61-
method: HttpRequestMethod = HttpRequestMethod.GET,
62-
retry202: Boolean = true,
63-
contentType: String? = null,
64-
attemptedRefresh: Boolean = false
59+
url: String,
60+
body: String? = null,
61+
method: HttpRequestMethod = HttpRequestMethod.GET,
62+
retry202: Boolean = true,
63+
contentType: String? = null,
64+
attemptedRefresh: Boolean = false
6565
): String {
6666
if (getCurrentTimeMs() >= api.expireTime) {
6767
if (!api.automaticRefresh) throw SpotifyException.AuthenticationException("The access token has expired.")
@@ -112,10 +112,10 @@ abstract class SpotifyEndpoint(val api: SpotifyApi<*, *>) {
112112
}
113113

114114
private fun handleResponse(
115-
document: HttpResponse,
116-
cacheState: CacheState?,
117-
spotifyRequest: SpotifyRequest,
118-
retry202: Boolean
115+
document: HttpResponse,
116+
cacheState: CacheState?,
117+
spotifyRequest: SpotifyRequest,
118+
retry202: Boolean
119119
): String? {
120120
val statusCode = document.responseCode
121121

@@ -147,10 +147,10 @@ abstract class SpotifyEndpoint(val api: SpotifyApi<*, *>) {
147147
}
148148

149149
private fun createConnection(
150-
url: String,
151-
body: String? = null,
152-
method: HttpRequestMethod = HttpRequestMethod.GET,
153-
contentType: String? = null
150+
url: String,
151+
body: String? = null,
152+
method: HttpRequestMethod = HttpRequestMethod.GET,
153+
contentType: String? = null
154154
) = HttpConnection(
155155
url,
156156
method,
@@ -224,10 +224,10 @@ class SpotifyCache {
224224
}
225225

226226
data class SpotifyRequest(
227-
val url: String,
228-
val method: HttpRequestMethod,
229-
val body: String?,
230-
val api: SpotifyApi<*, *>
227+
val url: String,
228+
val method: HttpRequestMethod,
229+
val body: String?,
230+
val api: SpotifyApi<*, *>
231231
)
232232

233233
data class CacheState(val data: String, val eTag: String?, val expireBy: Long = 0) {

src/commonTest/kotlin/com.adamratzman/spotify/private/ClientPlaylistAPITest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import com.adamratzman.spotify.SpotifyException
66
import com.adamratzman.spotify.api
77
import com.adamratzman.spotify.endpoints.client.SpotifyTrackPositions
88
import com.adamratzman.spotify.utils.runBlocking
9+
import kotlin.test.assertEquals
10+
import kotlin.test.assertFailsWith
11+
import kotlin.test.assertTrue
912
import kotlinx.coroutines.GlobalScope
1013
import kotlinx.coroutines.async
1114
import kotlinx.coroutines.awaitAll
1215
import org.spekframework.spek2.Spek
1316
import org.spekframework.spek2.style.specification.describe
14-
import kotlin.test.assertEquals
15-
import kotlin.test.assertFailsWith
16-
import kotlin.test.assertTrue
1717

1818
class ClientPlaylistAPITest : Spek({
1919
describe("Client playlist test") {
@@ -40,16 +40,16 @@ class ClientPlaylistAPITest : Spek({
4040
).awaitAll().flatten()
4141
}.mapNotNull { it.track?.uri?.uri }
4242

43-
api.allowBulkRequests=true
43+
api.allowBulkRequests = true
4444

45-
val getSize = {cp.getClientPlaylist(createdPlaylist.id).complete()!!.tracks.total}
46-
val sizeBefore = getSize()
45+
val getSize = { cp.getClientPlaylist(createdPlaylist.id).complete()!!.tracks.total }
46+
val sizeBefore = getSize()
4747
cp.addTracksToClientPlaylist(createdPlaylist.id, *tracks.toTypedArray()).complete()
4848
assertEquals(sizeBefore + tracks.size, getSize())
4949
cp.removeTracksFromClientPlaylist(createdPlaylist.id, *tracks.toTypedArray()).complete()
5050
assertEquals(sizeBefore, getSize())
5151

52-
api.allowBulkRequests=false
52+
api.allowBulkRequests = false
5353
}
5454

5555
it("edit playlists") {

src/commonTest/kotlin/com.adamratzman/spotify/public/PublicFollowingAPITest.kt

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

44
import com.adamratzman.spotify.SpotifyException
55
import com.adamratzman.spotify.api
6-
import com.adamratzman.spotify.stackTrace
76
import kotlin.test.assertEquals
87
import kotlin.test.assertFailsWith
98
import org.spekframework.spek2.Spek

0 commit comments

Comments
 (0)