Add getLyrics call.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2017-09-03 22:03:24 +02:00
parent 59ed898b23
commit 9844fb1282
5 changed files with 88 additions and 2 deletions

View File

@ -0,0 +1,51 @@
package org.moire.ultrasonic.api.subsonic
import org.amshove.kluent.`should equal to`
import org.junit.Test
/**
* Integration test for [SubsonicAPIClient] for getLyrics() call.
*/
class SubsonicApiGetLyricsTest : SubsonicAPIClientTest() {
@Test
fun `Should handle error response`() {
checkErrorCallParsed(mockWebServerRule) {
client.api.getLyrics().execute()
}
}
@Test
fun `Should handle ok response`() {
mockWebServerRule.enqueueResponse("get_lyrics_ok.json")
val response = client.api.getLyrics().execute()
assertResponseSuccessful(response)
with(response.body().lyrics) {
artist `should equal to` "Amorphis"
title `should equal to` "Alone"
text `should equal to` "Tear dimmed rememberance\nIn a womb of time\nBreath upon " +
"me\nPossessed by the"
}
}
@Test
fun `Should pass artist param in request`() {
val artist = "some-artist"
mockWebServerRule.assertRequestParam(responseResourceName = "get_lyrics_ok.json",
expectedParam = "artist=$artist") {
client.api.getLyrics(artist = artist).execute()
}
}
@Test
fun `Should pass title param in request`() {
val title = "some-title"
mockWebServerRule.assertRequestParam(responseResourceName = "get_lyrics_ok.json",
expectedParam = "title=$title") {
client.api.getLyrics(title = title).execute()
}
}
}

View File

@ -0,0 +1,11 @@
{
"subsonic-response" : {
"status" : "ok",
"version" : "1.15.0",
"lyrics" : {
"artist" : "Amorphis",
"title" : "Alone",
"value" : "Tear dimmed rememberance\nIn a womb of time\nBreath upon me\nPossessed by the"
}
}
}

View File

@ -4,6 +4,7 @@ import org.moire.ultrasonic.api.subsonic.response.GetAlbumResponse
import org.moire.ultrasonic.api.subsonic.response.GetArtistResponse
import org.moire.ultrasonic.api.subsonic.response.GetArtistsResponse
import org.moire.ultrasonic.api.subsonic.response.GetIndexesResponse
import org.moire.ultrasonic.api.subsonic.response.GetLyricsResponse
import org.moire.ultrasonic.api.subsonic.response.GetMusicDirectoryResponse
import org.moire.ultrasonic.api.subsonic.response.GetPlaylistResponse
import org.moire.ultrasonic.api.subsonic.response.GetPlaylistsResponse
@ -108,9 +109,13 @@ interface SubsonicAPIDefinition {
@Query("comment") comment: String? = null,
@Query("public") public: Boolean? = null,
@Query("songIdToAdd") songIdsToAdd: List<Long>? = null,
@Query("songIndexToRemove") songIndexesToRemove: List<Int>? = null) : Call<SubsonicResponse>
@Query("songIndexToRemove") songIndexesToRemove: List<Int>? = null): Call<SubsonicResponse>
@GET("getPodcasts.view")
fun getPodcasts(@Query("includeEpisodes") includeEpisodes: Boolean? = null,
@Query("id") id: Long? = null) : Call<GetPodcastsResponse>
@Query("id") id: Long? = null): Call<GetPodcastsResponse>
@GET("getLyrics.view")
fun getLyrics(@Query("artist") artist: String? = null,
@Query("title") title: String? = null): Call<GetLyricsResponse>
}

View File

@ -0,0 +1,8 @@
package org.moire.ultrasonic.api.subsonic.models
import com.fasterxml.jackson.annotation.JsonProperty
data class Lyrics(
val artist: String = "",
val title: String = "",
@JsonProperty("value") val text: String = "")

View File

@ -0,0 +1,11 @@
package org.moire.ultrasonic.api.subsonic.response
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions
import org.moire.ultrasonic.api.subsonic.SubsonicError
import org.moire.ultrasonic.api.subsonic.models.Lyrics
class GetLyricsResponse(status: Status,
version: SubsonicAPIVersions,
error: SubsonicError?,
val lyrics: Lyrics = Lyrics())
: SubsonicResponse(status, version, error)