Skip to content

Commit 0ce9f60

Browse files
authored
Merge pull request #230 from adamint/dev
fix paging object deserialization for SimpleAlbum
2 parents 937a860 + 06d146d commit 0ce9f60

File tree

8 files changed

+72
-25
lines changed

8 files changed

+72
-25
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ repositories {
3737
jcenter()
3838
}
3939
40-
implementation("com.adamratzman:spotify-api-kotlin-core:3.3.0")
40+
implementation("com.adamratzman:spotify-api-kotlin-core:3.3.01")
4141
```
4242

4343
Note that images and profiles are not supported on the Kotlin/JS target.
@@ -69,7 +69,7 @@ packagingOptions {
6969
```
7070

7171
## Documentation
72-
The `spotify-web-api-kotlin` JavaDocs are hosted at https://adamint.github.io/spotify-web-api-kotlin/spotify-web-api-kotlin/
72+
The `spotify-web-api-kotlin` JavaDocs are hosted [here](https://adamint.github.io/spotify-web-api-kotlin-docs/spotify-web-api-kotlin/).
7373

7474
## Have a question?
7575
If you have a question, you can:
@@ -97,7 +97,7 @@ By default, the SpotifyApi `Token` automatically regenerates when needed.
9797
This can be changed by overriding the `automaticRefresh` builder setting.
9898

9999
There are four exposed builders, depending on the level of control you need over api creation.
100-
Please see the [spotifyAppApi builder docs](https://adamint.github.io/spotify-web-api-kotlin/spotify-web-api-kotlin/com.adamratzman.spotify/spotify-app-api.html) for a full list of available builders.
100+
Please see the [spotifyAppApi builder docs](https://adamint.github.io/spotify-web-api-kotlin-docs/spotify-web-api-kotlin/com.adamratzman.spotify/spotify-app-api.html) for a full list of available builders.
101101

102102
You will need:
103103
- Spotify application client id
@@ -165,7 +165,7 @@ This library contains helpful methods that can be used to simplify the PKCE auth
165165
This includes `getSpotifyPkceCodeChallenge` (not available in the Kotlin/JS target), which SHA256 hashes and base64url encodes the code
166166
challenge, and `getPkceAuthorizationUrl`, which allows you to generate an easy authorization url for PKCE flow.
167167

168-
Please see the [spotifyClientPkceApi builder docs](https://adamint.github.io/spotify-web-api-kotlin/spotify-web-api-kotlin/com.adamratzman.spotify/spotify-client-pkce-api.html) for a full list of available builders.
168+
Please see the [spotifyClientPkceApi builder docs](https://adamint.github.io/spotify-web-api-kotlin-docs/spotify-web-api-kotlin/com.adamratzman.spotify/spotify-client-pkce-api.html) for a full list of available builders.
169169

170170
**Takeaway**: Use PKCE authorization flow in applications where you cannot secure the client secret.
171171

@@ -224,7 +224,7 @@ There are also several optional parameters, allowing you to set whether the auth
224224
for implicit grant flow, the state, and whether a re-authorization dialog should be shown to users.
225225

226226
There are several exposed builders, depending on the level of control you need over api creation.
227-
Please see the [spotifyClientApi builder docs](https://adamint.github.io/spotify-web-api-kotlin/spotify-web-api-kotlin/com.adamratzman.spotify/spotify-client-api.html) for a full list of available builders.
227+
Please see the [spotifyClientApi builder docs](https://adamint.github.io/spotify-web-api-kotlin-docs/spotify-web-api-kotlin/com.adamratzman.spotify/spotify-client-api.html) for a full list of available builders.
228228

229229
##### Example: You've redirected the user back to your web server and have an authorization code (code).
230230
In this example, automatic token refresh is turned on by default.
@@ -275,7 +275,7 @@ Some highlights about the flow are:
275275
- It is client-side
276276
- It does not require a client secret
277277

278-
Please see the [spotifyImplicitGrantApi builder docs](https://adamint.github.io/spotify-web-api-kotlin/spotify-web-api-kotlin/com.adamratzman.spotify/spotify-implicit-grant-api.html) for a full list of available builders.
278+
Please see the [spotifyImplicitGrantApi builder docs](https://adamint.github.io/spotify-web-api-kotlin-docs/spotify-web-api-kotlin/com.adamratzman.spotify/spotify-implicit-grant-api.html) for a full list of available builders.
279279

280280
The Kotlin/JS target contains the `parseSpotifyCallbackHashToToken` method, which will parse the hash
281281
for the current url into a Token object, with which you can then instantiate the api.

build.gradle.kts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,8 @@ buildscript {
3131
}
3232
}
3333

34-
dependencies {
35-
dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.4.20")
36-
}
37-
3834
group = "com.adamratzman"
39-
version = "3.3.0"
35+
version = "3.3.01"
4036

4137
tasks.withType<Test> {
4238
this.testLogging {
@@ -67,6 +63,7 @@ android {
6763
}
6864
}
6965
testOptions {
66+
this.unitTests.isReturnDefaultValues = true
7067
@Suppress("UNCHECKED_CAST")
7168
this.unitTests.all(closureOf<Test> {
7269
// this.useJUnitPlatform()
@@ -216,17 +213,14 @@ kotlin {
216213
}
217214

218215
dependencies {
219-
implementation("net.sourceforge.streamsupport:android-retrofuture:1.7.2")
220216
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
221-
implementation("io.coil-kt:coil:1.1.0")
222217
}
223218
}
224219

225220
val androidTest by getting {
226221
dependencies {
227222
implementation(kotlin("test-junit"))
228223
implementation("com.sparkjava:spark-core:2.9.3")
229-
implementation("org.mockito:mockito-core:3.3.3")
230224
runtimeOnly(kotlin("reflect"))
231225
}
232226
}
@@ -279,6 +273,18 @@ signing {
279273
tasks {
280274
val dokkaHtml by getting(DokkaTask::class) {
281275
outputDirectory.set(projectDir.resolve("docs"))
276+
277+
dokkaSourceSets {
278+
configureEach {
279+
skipDeprecated.set(true)
280+
281+
sourceLink {
282+
localDirectory.set(file("src"))
283+
remoteUrl.set(uri("https://github.com/adamint/spotify-web-api-kotlin/tree/master/src").toURL())
284+
remoteLineSuffix.set("#L")
285+
}
286+
}
287+
}
282288
}
283289

284290
spotless {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
2+
package com.adamratzman.spotify.utils
3+
4+
public actual val platform: Platform = Platform.ANDROID

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ public abstract class AbstractPagingObject<T : Any, Z : AbstractPagingObject<T,
116116
return (if (type == FORWARDS) next else previous)?.let { endpoint!!.get(it) }?.let { json ->
117117
when (itemClazz) {
118118
SimpleTrack::class -> json.toPagingObject(SimpleTrack.serializer(), null, endpointFinal, endpointFinal.api.json, true)
119-
SpotifyCategory::class -> json.toPagingObject(SpotifyCategory.serializer(), "categories", endpointFinal, endpointFinal.api.json, true)
120-
SimpleAlbum::class -> json.toPagingObject(SimpleAlbum.serializer(), "albums", endpointFinal, endpointFinal.api.json, true)
121-
SimplePlaylist::class -> json.toPagingObject(SimplePlaylist.serializer(), "playlists", endpointFinal, endpointFinal.api.json, true)
119+
SpotifyCategory::class -> json.toPagingObject(SpotifyCategory.serializer(), null, endpointFinal, endpointFinal.api.json, true)
120+
SimpleAlbum::class -> json.toPagingObject(SimpleAlbum.serializer(), null, endpointFinal, endpointFinal.api.json, true)
121+
SimplePlaylist::class -> json.toPagingObject(SimplePlaylist.serializer(), null, endpointFinal, endpointFinal.api.json, true)
122122
SavedTrack::class -> json.toPagingObject(SavedTrack.serializer(), null, endpointFinal, endpointFinal.api.json, true)
123123
SavedAlbum::class -> json.toPagingObject(SavedAlbum.serializer(), null, endpointFinal, endpointFinal.api.json, true)
124124
Artist::class -> json.toPagingObject(Artist.serializer(), null, endpointFinal, endpointFinal.api.json, true)
@@ -154,7 +154,6 @@ public abstract class AbstractPagingObject<T : Any, Z : AbstractPagingObject<T,
154154

155155
@Suppress("UNCHECKED_CAST")
156156
pagingObjects.add(this as Z)
157-
158157
var nxt = next?.let { getNext() }
159158
while (nxt != null) {
160159
pagingObjects.add(nxt)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
2+
package com.adamratzman.spotify.utils
3+
4+
/**
5+
* Actual platforms that this program can be run on.
6+
*/
7+
public enum class Platform {
8+
JVM,
9+
ANDROID,
10+
JS
11+
}
12+
13+
public expect val platform: Platform

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import com.adamratzman.spotify.models.Playlist
99
import com.adamratzman.spotify.models.SimplePlaylist
1010
import com.adamratzman.spotify.runBlockingTest
1111
import com.adamratzman.spotify.spotifyApi
12-
import kotlin.test.AfterTest
12+
import com.adamratzman.spotify.utils.Platform
13+
import com.adamratzman.spotify.utils.platform
1314
import kotlin.test.Test
1415
import kotlin.test.assertEquals
1516
import kotlin.test.assertTrue
1617
import kotlinx.coroutines.async
1718
import kotlinx.coroutines.awaitAll
19+
import kotlinx.coroutines.coroutineScope
1820

1921
class ClientPlaylistApiTest {
2022
lateinit var api: SpotifyClientApi
@@ -32,8 +34,18 @@ class ClientPlaylistApiTest {
3234

3335
private suspend fun tearDown() {
3436
if (::createdPlaylist.isInitialized) {
35-
api.playlists.deleteClientPlaylist(createdPlaylist.id)
36-
assertTrue(api.playlists.getClientPlaylist(createdPlaylist.id) == null)
37+
coroutineScope {
38+
api.playlists.getClientPlaylists().getAllItemsNotNull()
39+
.filter { it.name == "this is a test playlist" }
40+
.map {
41+
async {
42+
if (api.following.isFollowingPlaylist(it.id)) {
43+
api.playlists.deleteClientPlaylist(it.id)
44+
}
45+
}
46+
}
47+
.awaitAll()
48+
}
3749
}
3850
}
3951

@@ -94,10 +106,12 @@ class ClientPlaylistApiTest {
94106

95107
api.playlists.addTracksToClientPlaylist(createdPlaylist.id, "3WDIhWoRWVcaHdRwMEHkkS", "7FjZU7XFs7P9jHI9Z0yRhK")
96108

97-
api.playlists.uploadClientPlaylistCover(
98-
createdPlaylist.id,
99-
imageUrl = "https://developer.spotify.com/assets/WebAPI_intro.png"
100-
)
109+
if (platform != Platform.ANDROID) {
110+
api.playlists.uploadClientPlaylistCover(
111+
createdPlaylist.id,
112+
imageUrl = "https://developer.spotify.com/assets/WebAPI_intro.png"
113+
)
114+
}
101115

102116
var updatedPlaylist = api.playlists.getClientPlaylist(createdPlaylist.id)!!
103117
val fullPlaylist = updatedPlaylist.toFullPlaylist()!!
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
2+
package com.adamratzman.spotify.utils
3+
4+
public actual val platform: Platform = Platform.JS
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2020; Original author: Adam Ratzman */
2+
package com.adamratzman.spotify.utils
3+
4+
/**
5+
* The actual platform that this program is running on.
6+
*/
7+
public actual val platform: Platform = Platform.JVM

0 commit comments

Comments
 (0)