Add getSongsByGenre api call.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2017-11-14 21:57:28 +01:00
parent 457181e074
commit 10e25e8597
4 changed files with 159 additions and 0 deletions

View File

@ -0,0 +1,82 @@
package org.moire.ultrasonic.api.subsonic
import org.amshove.kluent.`should equal to`
import org.amshove.kluent.`should equal`
import org.junit.Test
import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild
/**
* Integration test for [SubsonicAPIDefinition.getSongsByGenre] call.
*/
class SubsonicApiGetSongsByGenreTest : SubsonicAPIClientTest() {
@Test
fun `Should handle error response`() {
val response = checkErrorCallParsed(mockWebServerRule) {
client.api.getSongsByGenre("Metal").execute()
}
response.songsList `should equal` emptyList()
}
@Test
fun `Should handle ok response`() {
mockWebServerRule.enqueueResponse("get_songs_by_genre_ok.json")
val response = client.api.getSongsByGenre("Trance").execute()
assertResponseSuccessful(response)
response.body().songsList.size `should equal to` 2
with(response.body().songsList) {
this[0] `should equal` MusicDirectoryChild(id = 575, parent = 576, isDir = false,
title = "Time Machine (Vadim Zhukov Remix)", album = "668",
artist = "Tasadi", year = 2008, genre = "Trance", size = 22467672,
contentType = "audio/mpeg", suffix = "mp3", duration = 561, bitRate = 320,
path = "Tasadi/668/00 Time Machine (Vadim Zhukov Remix).mp3",
isVideo = false, playCount = 0, created = parseDate("2016-10-23T21:58:29.000Z"),
albumId = 0, artistId = 0, type = "music")
this[1] `should equal` MusicDirectoryChild(id = 621, parent = 622, isDir = false,
title = "My Heart (Vadim Zhukov Remix)", album = "668",
artist = "DJ Polyakov PPK Feat Kate Cameron", year = 2009, genre = "Trance",
size = 26805932, contentType = "audio/mpeg", suffix = "mp3", duration = 670,
bitRate = 320,
path = "DJ Polyakov PPK Feat Kate Cameron/668/00 My Heart (Vadim Zhukov Remix).mp3",
isVideo = false, playCount = 2, created = parseDate("2016-10-23T21:58:29.000Z"),
albumId = 5, artistId = 4, type = "music")
}
}
@Test
fun `Should pass genre in request param`() {
val genre = "Rock"
mockWebServerRule.assertRequestParam(expectedParam = "genre=$genre") {
client.api.getSongsByGenre(genre = genre).execute()
}
}
@Test
fun `Should pass count in request param`() {
val count = 494
mockWebServerRule.assertRequestParam(expectedParam = "count=$count") {
client.api.getSongsByGenre("Trance", count = count).execute()
}
}
@Test
fun `Should pass offset in request param`() {
val offset = 31
mockWebServerRule.assertRequestParam(expectedParam = "offset=$offset") {
client.api.getSongsByGenre("Trance", offset = offset).execute()
}
}
@Test
fun `Should pass music folder id in request param`() {
val musicFolderId = 1010L
mockWebServerRule.assertRequestParam(expectedParam = "musicFolderId=$musicFolderId") {
client.api.getSongsByGenre("Trance", musicFolderId = musicFolderId).execute()
}
}
}

View File

@ -0,0 +1,51 @@
{
"subsonic-response" : {
"status" : "ok",
"version" : "1.15.0",
"songsByGenre" : {
"song" : [ {
"id" : "575",
"parent" : "576",
"isDir" : false,
"title" : "Time Machine (Vadim Zhukov Remix)",
"album" : "668",
"artist" : "Tasadi",
"year" : 2008,
"genre" : "Trance",
"size" : 22467672,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 561,
"bitRate" : 320,
"path" : "Tasadi/668/00 Time Machine (Vadim Zhukov Remix).mp3",
"isVideo" : false,
"playCount" : 0,
"created" : "2016-10-23T21:58:29.000Z",
"albumId" : "0",
"artistId" : "0",
"type" : "music"
}, {
"id" : "621",
"parent" : "622",
"isDir" : false,
"title" : "My Heart (Vadim Zhukov Remix)",
"album" : "668",
"artist" : "DJ Polyakov PPK Feat Kate Cameron",
"year" : 2009,
"genre" : "Trance",
"size" : 26805932,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 670,
"bitRate" : 320,
"path" : "DJ Polyakov PPK Feat Kate Cameron/668/00 My Heart (Vadim Zhukov Remix).mp3",
"isVideo" : false,
"playCount" : 2,
"created" : "2016-10-23T21:58:29.000Z",
"albumId" : "5",
"artistId" : "4",
"type" : "music"
} ]
}
}
}

View File

@ -16,6 +16,7 @@ import org.moire.ultrasonic.api.subsonic.response.GetPlaylistResponse
import org.moire.ultrasonic.api.subsonic.response.GetPlaylistsResponse
import org.moire.ultrasonic.api.subsonic.response.GetPodcastsResponse
import org.moire.ultrasonic.api.subsonic.response.GetRandomSongsResponse
import org.moire.ultrasonic.api.subsonic.response.GetSongsByGenreResponse
import org.moire.ultrasonic.api.subsonic.response.GetStarredResponse
import org.moire.ultrasonic.api.subsonic.response.GetStarredTwoResponse
import org.moire.ultrasonic.api.subsonic.response.JukeboxResponse
@ -201,4 +202,11 @@ interface SubsonicAPIDefinition {
@GET("getGenres.view")
fun getGenres(): Call<GenresResponse>
@GET("getSongsByGenre.view")
fun getSongsByGenre(
@Query("genre") genre: String,
@Query("count") count: Int = 10,
@Query("offset") offset: Int = 0,
@Query("musicFolderId") musicFolderId: Long? = null): Call<GetSongsByGenreResponse>
}

View File

@ -0,0 +1,18 @@
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.MusicDirectoryChild
class GetSongsByGenreResponse(
status: Status,
version: SubsonicAPIVersions,
error: SubsonicError?) : SubsonicResponse(status, version, error) {
@JsonProperty("songsByGenre") private val songsByGenreList = SongsByGenreWrapper()
val songsList get() = songsByGenreList.songsList
}
internal class SongsByGenreWrapper(
@JsonProperty("song") val songsList: List<MusicDirectoryChild> = emptyList())