You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
+[The benefits of LinkedResults, PagingObjects, and Cursor-based Paging Objects](#the-benefits-of-linkedresults-pagingobjects-and-cursor-based-paging-objects)
@@ -293,7 +291,7 @@ val api = spotifyImplicitGrantApi(
293
291
null,
294
292
token
295
293
) // create api. there is no need to build it
296
-
println(api.personalization.getTopArtists(limit =1).complete()[0].name) // use it
294
+
println(api.personalization.getTopArtists(limit =1)[0].name) // use it
297
295
```
298
296
299
297
### SpotifyApiBuilder Block & setting API options
@@ -356,45 +354,13 @@ APIs available only in `SpotifyClientApi` and `SpotifyImplicitGrantApi` instance
356
354
## Tips
357
355
358
356
### Building the API
359
-
The easiest way to build the API is synchronously using .build() after a builder
360
-
361
-
```kotlin
362
-
spotifyAppApi(clientId, clientSecret).build()
363
-
```
364
-
365
-
You can also build the API asynchronously using Kotlin coroutines.
357
+
The easiest way to build the API is using .build() after a builder
366
358
```kotlin
367
359
runBlocking {
368
-
spotifyAppApi(clientId, clientSecret).buildAsyncAt(this) { api ->
369
-
// do things
370
-
}
360
+
val api = spotifyAppApi(clientId, clientSecret).build()
371
361
}
372
362
```
373
363
374
-
### What is the SpotifyRestAction class?
375
-
Abstracting requests into a `SpotifyRestAction` class allows for a lot of flexibility in sending and receiving requests.
376
-
This class includes options for asynchronous and blocking execution in all endpoints. However,
377
-
due to this, you **must** call one of the provided methods in order for the call
378
-
to execute! The `SpotifyRestAction` provides many methods and fields for use, including blocking and asynchronous ones. For example,
379
-
-`hasRun()` tells you whether the rest action has been *started*
380
-
-`hasCompleted()` tells you whether this rest action has been fully executed and *completed*
381
-
-`complete()` blocks the current thread and returns the result
382
-
-`suspendComplete(context: CoroutineContext = Dispatchers.Default)` switches to given context, invokes the supplier, and synchronously retrieves the result.
383
-
-`suspendQueue()` suspends the coroutine, invokes the supplier asynchronously, and resumes with the result
384
-
-`queue()` executes and immediately returns
385
-
-`queue(consumer: (T) -> Unit)` executes the provided callback as soon as the request
386
-
is asynchronously evaluated
387
-
-`queueAfter(quantity: Int, timeUnit: TimeUnit, consumer: (T) -> Unit)` executes the
388
-
provided callback after the provided time. As long as supplier execution is less than the provided
389
-
time, this will likely be accurate within a few milliseconds.
390
-
-`asFuture()` transforms the supplier into a `CompletableFuture` (only JVM)
391
-
392
-
### SpotifyRestPagingAction
393
-
Separate from, but a superset of SpotifyRestAction, this specialized implementation of RestActions includes extensions
394
-
for `AbstractPagingObject` (`PagingObject` and `CursorBasedPagingObject`). This class gives you the same functionality as SpotifyRestAction,
395
-
but you also have the ability to retrieve *all* of its items or linked PagingObjects, or a *subset* of its items or linked PagingObjects with one call, with
396
-
a single method call to `getAllItems()` or `getAllPagingObjects()`, or `getWithNext(total: Int, context: CoroutineContext = Dispatchers.Default)` or `getWithNextItems(total: Int, context: CoroutineContext = Dispatchers.Default)` respectively
397
-
398
364
## Notes
399
365
### The benefits of LinkedResults, PagingObjects, and Cursor-based Paging Objects
400
366
Spotify provides these three object models in order to simplify our lives as developers. So let's see what we
@@ -430,22 +396,17 @@ val api = spotifyAppApi(
430
396
System.getenv("SPOTIFY_CLIENT_SECRET")
431
397
).build()
432
398
433
-
// block and print out the names of the twenty most similar songs to the search
434
-
println(api.search.searchTrack("Début de la Suite").complete().joinToString { it.name })
435
-
436
-
// now, let's do it asynchronously
437
-
api.search.searchTrack("Début de la Suite").queue { tracks ->println(tracks.joinToString { track -> track.name }) }
399
+
// print out the names of the twenty most similar songs to the search
400
+
println(api.search.searchTrack("Début de la Suite").joinToString { it.name })
438
401
439
402
// simple, right? what about if we want to print out the featured playlists message from the "Overview" tab?
0 commit comments