Skip to content

Commit 4a9a780

Browse files
committed
update PlayerApi#getRecentlyPlayed
Signed-off-by: Adam Ratzman <[email protected]>
1 parent 763b16e commit 4a9a780

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ apply plugin: 'kotlin'
2222
apply plugin: 'org.jetbrains.dokka'
2323

2424
group 'com.adamratzman'
25-
version '2.1.0'
25+
version '2.1.1'
2626

2727
archivesBaseName = 'spotify-api-kotlin'
2828

src/main/kotlin/com/adamratzman/spotify/endpoints/client/ClientPlayerAPI.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,22 @@ class ClientPlayerAPI(api: SpotifyAPI) : SpotifyEndpoint(api) {
5555

5656
/**
5757
* Get tracks from the current user’s recently played tracks.
58+
*
59+
* @param limit The number of objects to return. Default: 20. Minimum: 1. Maximum: 50.
60+
* @param before The timestamp (retrieved via cursor) **not including**, but before which, tracks will have been played. This can be combined with [limit]
61+
* @param after The timestamp (retrieved via cursor) **not including**, after which, the retrieval starts. This can be combined with [limit]
62+
*
5863
*/
59-
fun getRecentlyPlayed(): SpotifyRestActionPaging<PlayHistory, CursorBasedPagingObject<PlayHistory>> {
64+
fun getRecentlyPlayed(
65+
limit: Int? = null,
66+
before: String? = null,
67+
after: String? = null
68+
): SpotifyRestActionPaging<PlayHistory, CursorBasedPagingObject<PlayHistory>> {
6069
return toActionPaging(Supplier {
61-
get(EndpointBuilder("/me/player/recently-played").toString()).toCursorBasedPagingObject<PlayHistory>(
70+
get(
71+
EndpointBuilder("/me/player/recently-played")
72+
.with("limit", limit).with("before", before).with("after", after).toString()
73+
).toCursorBasedPagingObject<PlayHistory>(
6274
endpoint = this
6375
)
6476
})

src/main/kotlin/com/adamratzman/spotify/utils/Endpoints.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ abstract class SpotifyEndpoint(val api: SpotifyAPI) {
112112
HttpHeader("Authorization", "Bearer ${api.token.accessToken}")
113113
)
114114

115-
fun <T> toAction(supplier: Supplier<T>) = SpotifyRestAction(api, supplier)
116-
fun <Z, T : AbstractPagingObject<Z>> toActionPaging(supplier: Supplier<T>) = SpotifyRestActionPaging(api, supplier)
115+
internal fun <T> toAction(supplier: Supplier<T>) = SpotifyRestAction(api, supplier)
116+
internal fun <Z, T : AbstractPagingObject<Z>> toActionPaging(supplier: Supplier<T>) = SpotifyRestActionPaging(api, supplier)
117117
}
118118

119119
internal class EndpointBuilder(private val path: String) {

src/main/kotlin/com/adamratzman/spotify/utils/Helpers.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,9 @@ import java.net.URLEncoder
1010
import java.util.Base64
1111

1212
/**
13-
* The cursor to use as key to find the next page of items.
14-
*
15-
* @property after nullable cursor value
16-
*/
17-
data class Cursor(val after: String?)
18-
19-
/**
20-
*
13+
* The cursor to use as key to find the next (or previous) page of items.
2114
*/
15+
data class Cursor(val before: String? = null, val after: String? = null)
2216

2317
abstract class RelinkingAvailableResponse(@Json(ignored = true) val linkedTrack: LinkedTrack? = null) : Linkable() {
2418
fun isRelinked() = linkedTrack != null

0 commit comments

Comments
 (0)