Add jukebox control call.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2017-11-07 21:19:33 +01:00
parent 84e59a3581
commit 947a1ce3b5
8 changed files with 247 additions and 1 deletions

View File

@ -66,7 +66,7 @@ fun SubsonicResponse.assertBaseResponseOk() {
error `should be` null
}
fun MockWebServerRule.assertRequestParam(responseResourceName: String,
fun MockWebServerRule.assertRequestParam(responseResourceName: String = "ping_ok.json",
expectedParam: String,
apiRequest: () -> Response<out Any>) {
this.enqueueResponse(responseResourceName)

View File

@ -0,0 +1,110 @@
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.JukeboxAction
import org.moire.ultrasonic.api.subsonic.models.JukeboxAction.GET
import org.moire.ultrasonic.api.subsonic.models.JukeboxAction.STATUS
import org.moire.ultrasonic.api.subsonic.models.JukeboxStatus
import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild
/**
* Integration test for [SubsonicAPIDefinition.jukeboxControl] call.
*/
class SubsonicApiJukeboxControlTest : SubsonicAPIClientTest() {
@Test
fun `Should handle error response`() {
val response = checkErrorCallParsed(mockWebServerRule) {
client.api.jukeboxControl(GET).execute()
}
response.jukebox `should equal` JukeboxStatus()
}
@Test
fun `Should handle ok response with jukebox status`() {
mockWebServerRule.enqueueResponse("jukebox_control_status_ok.json")
val response = client.api.jukeboxControl(STATUS).execute()
assertResponseSuccessful(response)
with(response.body().jukebox) {
currentIndex `should equal to` 94
playing `should equal to` true
gain `should equal to` 0.32f
position `should equal to` 3
playlistEntries `should equal` emptyList()
}
}
@Test
fun `Should handle ok response with jukebox playlist`() {
mockWebServerRule.enqueueResponse("jukebox_control_playlist_ok.json")
val response = client.api.jukeboxControl(GET).execute()
assertResponseSuccessful(response)
with(response.body().jukebox) {
currentIndex `should equal to` 887
playing `should equal to` false
gain `should equal to` 0.88f
position `should equal to` 2
playlistEntries.size `should equal to` 2
playlistEntries[1] `should equal` MusicDirectoryChild(id = 4215L, parent = 4186L,
isDir = false, title = "Going to Hell", album = "Going to Hell",
artist = "The Pretty Reckless", track = 2, year = 2014, genre = "Hard Rock",
coverArt = "4186", size = 11089627, contentType = "audio/mpeg",
suffix = "mp3", duration = 277, bitRate = 320,
path = "The Pretty Reckless/Going to Hell/02 Going to Hell.mp3", isVideo = false,
playCount = 0, discNumber = 1,
created = parseDate("2016-10-23T21:30:41.000Z"), albumId = 388,
artistId = 238, type = "music")
}
}
@Test
fun `Should pass action in request params`() {
val action = JukeboxAction.SET_GAIN
mockWebServerRule.assertRequestParam(expectedParam = "action=$action") {
client.api.jukeboxControl(action).execute()
}
}
@Test
fun `Should pass index in request params`() {
val index = 440
mockWebServerRule.assertRequestParam(expectedParam = "index=$index") {
client.api.jukeboxControl(GET, index = index).execute()
}
}
@Test
fun `Should pass offset in request params`() {
val offset = 58223
mockWebServerRule.assertRequestParam(expectedParam = "offset=$offset") {
client.api.jukeboxControl(GET, offset = offset).execute()
}
}
@Test
fun `Should pass ids in request params`() {
val id = listOf("some-id1", "some-id2")
mockWebServerRule.assertRequestParam(expectedParam = "id=${id[0]}&id=${id[1]}") {
client.api.jukeboxControl(GET, ids = id).execute()
}
}
@Test
fun `Should pass gain in request params`() {
val gain = 0.73f
mockWebServerRule.assertRequestParam(expectedParam = "gain=$gain") {
client.api.jukeboxControl(GET, gain = gain).execute()
}
}
}

View File

@ -0,0 +1,61 @@
{
"subsonic-response" : {
"status" : "ok",
"version" : "1.15.0",
"jukeboxPlaylist" : {
"currentIndex" : 887,
"playing" : false,
"gain" : 0.88,
"position" : 2,
"entry" : [ {
"id" : "4209",
"parent" : "4186",
"isDir" : false,
"title" : "Follow Me Down",
"album" : "Going to Hell",
"artist" : "The Pretty Reckless",
"track" : 1,
"year" : 2014,
"genre" : "Hard Rock",
"coverArt" : "4186",
"size" : 11229681,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 280,
"bitRate" : 320,
"path" : "The Pretty Reckless/Going to Hell/01 Follow Me Down.mp3",
"isVideo" : false,
"playCount" : 1,
"discNumber" : 1,
"created" : "2016-10-23T21:30:43.000Z",
"albumId" : "388",
"artistId" : "238",
"type" : "music"
}, {
"id" : "4215",
"parent" : "4186",
"isDir" : false,
"title" : "Going to Hell",
"album" : "Going to Hell",
"artist" : "The Pretty Reckless",
"track" : 2,
"year" : 2014,
"genre" : "Hard Rock",
"coverArt" : "4186",
"size" : 11089627,
"contentType" : "audio/mpeg",
"suffix" : "mp3",
"duration" : 277,
"bitRate" : 320,
"path" : "The Pretty Reckless/Going to Hell/02 Going to Hell.mp3",
"isVideo" : false,
"playCount" : 0,
"discNumber" : 1,
"created" : "2016-10-23T21:30:41.000Z",
"albumId" : "388",
"artistId" : "238",
"type" : "music"
} ]
}
}
}

View File

@ -0,0 +1,12 @@
{
"subsonic-response" : {
"status" : "ok",
"version" : "1.15.0",
"jukeboxStatus" : {
"currentIndex" : 94,
"playing" : true,
"gain" : 0.32,
"position" : 3
}
}
}

View File

@ -2,6 +2,7 @@ package org.moire.ultrasonic.api.subsonic
import okhttp3.ResponseBody
import org.moire.ultrasonic.api.subsonic.models.AlbumListType
import org.moire.ultrasonic.api.subsonic.models.JukeboxAction
import org.moire.ultrasonic.api.subsonic.response.GetAlbumList2Response
import org.moire.ultrasonic.api.subsonic.response.GetAlbumListResponse
import org.moire.ultrasonic.api.subsonic.response.GetAlbumResponse
@ -16,6 +17,7 @@ import org.moire.ultrasonic.api.subsonic.response.GetPodcastsResponse
import org.moire.ultrasonic.api.subsonic.response.GetRandomSongsResponse
import org.moire.ultrasonic.api.subsonic.response.GetStarredResponse
import org.moire.ultrasonic.api.subsonic.response.GetStarredTwoResponse
import org.moire.ultrasonic.api.subsonic.response.JukeboxResponse
import org.moire.ultrasonic.api.subsonic.response.LicenseResponse
import org.moire.ultrasonic.api.subsonic.response.MusicFoldersResponse
import org.moire.ultrasonic.api.subsonic.response.SearchResponse
@ -179,4 +181,11 @@ interface SubsonicAPIDefinition {
@Query("estimateContentLength") estimateContentLength: Boolean? = null,
@Query("converted") converted: Boolean? = null,
@Header("Range") offset: Long? = null): Call<ResponseBody>
@GET("jukeboxControl.view")
fun jukeboxControl(@Query("action") action: JukeboxAction,
@Query("index") index: Int? = null,
@Query("offset") offset: Int? = null,
@Query("id") ids: List<String>? = null,
@Query("gain") gain: Float? = null): Call<JukeboxResponse>
}

View File

@ -0,0 +1,24 @@
package org.moire.ultrasonic.api.subsonic.models
/**
* Supported jukebox commands.
*
* It is used in [org.moire.ultrasonic.api.subsonic.SubsonicAPIDefinition.jukeboxControl] call.
*/
enum class JukeboxAction(val action: String) {
GET("get"),
STATUS("status"),
SET("set"),
START("start"),
STOP("stop"),
SKIP("skip"),
ADD("add"),
CLEAR("clear"),
REMOVE("remove"),
SHUFFLE("shuffle"),
SET_GAIN("setGain");
override fun toString(): String {
return action
}
}

View File

@ -0,0 +1,10 @@
package org.moire.ultrasonic.api.subsonic.models
import com.fasterxml.jackson.annotation.JsonProperty
data class JukeboxStatus(
val currentIndex: Int = -1,
val playing: Boolean = false,
val gain: Float = 0.0f,
val position: Int = 0,
@JsonProperty("entry") val playlistEntries: List<MusicDirectoryChild> = emptyList())

View File

@ -0,0 +1,20 @@
package org.moire.ultrasonic.api.subsonic.response
import com.fasterxml.jackson.annotation.JsonSetter
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions
import org.moire.ultrasonic.api.subsonic.SubsonicError
import org.moire.ultrasonic.api.subsonic.models.JukeboxStatus
class JukeboxResponse(status: Status,
version: SubsonicAPIVersions,
error: SubsonicError?,
var jukebox: JukeboxStatus = JukeboxStatus())
: SubsonicResponse(status, version, error) {
@JsonSetter("jukeboxStatus") fun setJukeboxStatus(jukebox: JukeboxStatus) {
this.jukebox = jukebox
}
@JsonSetter("jukeboxPlaylist") fun setJukeboxPlaylist(jukebox: JukeboxStatus) {
this.jukebox = jukebox
}
}