mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-25 13:12:16 +03:00
Add getPlaylists api call.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
71d1609dd8
commit
e4728af320
@ -0,0 +1,50 @@
|
|||||||
|
package org.moire.ultrasonic.api.subsonic
|
||||||
|
|
||||||
|
import org.amshove.kluent.`should equal to`
|
||||||
|
import org.amshove.kluent.`should equal`
|
||||||
|
import org.amshove.kluent.`should not be`
|
||||||
|
import org.junit.Test
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Playlist
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integration test for [SubsonicAPIClient] for getPlaylists call.
|
||||||
|
*/
|
||||||
|
class SubsonicApiGetPlaylistsTest : SubsonicAPIClientTest() {
|
||||||
|
@Test
|
||||||
|
fun `Should parse error call`() {
|
||||||
|
val response = checkErrorCallParsed(mockWebServerRule) {
|
||||||
|
client.api.getPlaylists().execute()
|
||||||
|
}
|
||||||
|
|
||||||
|
response.playlists `should not be` null
|
||||||
|
response.playlists `should equal` emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should parse ok response`() {
|
||||||
|
mockWebServerRule.enqueueResponse("get_playlists_ok.json")
|
||||||
|
|
||||||
|
val response = client.api.getPlaylists().execute()
|
||||||
|
|
||||||
|
assertResponseSuccessful(response)
|
||||||
|
with(response.body().playlists) {
|
||||||
|
size `should equal to` 1
|
||||||
|
this[0] `should equal` Playlist(id = 0, name = "Aug 27, 2017 11:17 AM",
|
||||||
|
owner = "admin", public = false, songCount = 16, duration = 3573,
|
||||||
|
comment = "Some comment",
|
||||||
|
created = parseDate("2017-08-27T11:17:26.216Z"),
|
||||||
|
changed = parseDate("2017-08-27T11:17:26.218Z"),
|
||||||
|
coverArt = "pl-0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should pass username as a parameter`() {
|
||||||
|
val username = "SomeUsername"
|
||||||
|
|
||||||
|
mockWebServerRule.assertRequestParam(responseResourceName = "get_playlists_ok.json",
|
||||||
|
expectedParam = "username=$username") {
|
||||||
|
client.api.getPlaylists(username = username).execute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"subsonic-response" : {
|
||||||
|
"status" : "ok",
|
||||||
|
"version" : "1.15.0",
|
||||||
|
"playlists" : {
|
||||||
|
"playlist" : [ {
|
||||||
|
"id" : "0",
|
||||||
|
"name" : "Aug 27, 2017 11:17 AM",
|
||||||
|
"comment" : "Some comment",
|
||||||
|
"owner" : "admin",
|
||||||
|
"public" : false,
|
||||||
|
"songCount" : 16,
|
||||||
|
"duration" : 3573,
|
||||||
|
"created" : "2017-08-27T11:17:26.216Z",
|
||||||
|
"changed" : "2017-08-27T11:17:26.218Z",
|
||||||
|
"coverArt" : "pl-0"
|
||||||
|
} ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ import org.moire.ultrasonic.api.subsonic.response.GetArtistsResponse
|
|||||||
import org.moire.ultrasonic.api.subsonic.response.GetIndexesResponse
|
import org.moire.ultrasonic.api.subsonic.response.GetIndexesResponse
|
||||||
import org.moire.ultrasonic.api.subsonic.response.GetMusicDirectoryResponse
|
import org.moire.ultrasonic.api.subsonic.response.GetMusicDirectoryResponse
|
||||||
import org.moire.ultrasonic.api.subsonic.response.GetPlaylistResponse
|
import org.moire.ultrasonic.api.subsonic.response.GetPlaylistResponse
|
||||||
|
import org.moire.ultrasonic.api.subsonic.response.GetPlaylistsResponse
|
||||||
import org.moire.ultrasonic.api.subsonic.response.LicenseResponse
|
import org.moire.ultrasonic.api.subsonic.response.LicenseResponse
|
||||||
import org.moire.ultrasonic.api.subsonic.response.MusicFoldersResponse
|
import org.moire.ultrasonic.api.subsonic.response.MusicFoldersResponse
|
||||||
import org.moire.ultrasonic.api.subsonic.response.SearchResponse
|
import org.moire.ultrasonic.api.subsonic.response.SearchResponse
|
||||||
@ -87,4 +88,7 @@ interface SubsonicAPIDefinition {
|
|||||||
|
|
||||||
@GET("getPlaylist.view")
|
@GET("getPlaylist.view")
|
||||||
fun getPlaylist(@Query("id") id: Long): Call<GetPlaylistResponse>
|
fun getPlaylist(@Query("id") id: Long): Call<GetPlaylistResponse>
|
||||||
|
|
||||||
|
@GET("getPlaylists.view")
|
||||||
|
fun getPlaylists(@Query("username") username: String? = null): Call<GetPlaylistsResponse>
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ data class Playlist(
|
|||||||
val id: Long = -1,
|
val id: Long = -1,
|
||||||
val name: String = "",
|
val name: String = "",
|
||||||
val owner: String = "",
|
val owner: String = "",
|
||||||
|
val comment: String = "",
|
||||||
val public: Boolean = false,
|
val public: Boolean = false,
|
||||||
val songCount: Int = 0,
|
val songCount: Int = 0,
|
||||||
val duration: Long = 0,
|
val duration: Long = 0,
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package org.moire.ultrasonic.api.subsonic.response
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions
|
||||||
|
import org.moire.ultrasonic.api.subsonic.SubsonicError
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Playlist
|
||||||
|
|
||||||
|
class GetPlaylistsResponse(status: Status,
|
||||||
|
version: SubsonicAPIVersions,
|
||||||
|
error: SubsonicError?)
|
||||||
|
: SubsonicResponse(status, version, error) {
|
||||||
|
@JsonProperty("playlists")
|
||||||
|
private val playlistsWrapper: PlaylistsWrapper = PlaylistsWrapper()
|
||||||
|
|
||||||
|
val playlists: List<Playlist>
|
||||||
|
get() = playlistsWrapper.playlistList
|
||||||
|
}
|
||||||
|
|
||||||
|
private class PlaylistsWrapper(@JsonProperty("playlist") val playlistList: List<Playlist> = emptyList())
|
Loading…
x
Reference in New Issue
Block a user