From 9844fb128230d6d6ff9ec7aa0fd0c0da5002cfc1 Mon Sep 17 00:00:00 2001 From: Yahor Berdnikau Date: Sun, 3 Sep 2017 22:03:24 +0200 Subject: [PATCH] Add getLyrics call. Signed-off-by: Yahor Berdnikau --- .../api/subsonic/SubsonicApiGetLyricsTest.kt | 51 +++++++++++++++++++ .../resources/get_lyrics_ok.json | 11 ++++ .../api/subsonic/SubsonicAPIDefinition.kt | 9 +++- .../ultrasonic/api/subsonic/models/Lyrics.kt | 8 +++ .../subsonic/response/GetLyricsResponse.kt | 11 ++++ 5 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiGetLyricsTest.kt create mode 100644 subsonic-api/src/integrationTest/resources/get_lyrics_ok.json create mode 100644 subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/Lyrics.kt create mode 100644 subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetLyricsResponse.kt diff --git a/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiGetLyricsTest.kt b/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiGetLyricsTest.kt new file mode 100644 index 00000000..a5d29b57 --- /dev/null +++ b/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiGetLyricsTest.kt @@ -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() + } + } +} diff --git a/subsonic-api/src/integrationTest/resources/get_lyrics_ok.json b/subsonic-api/src/integrationTest/resources/get_lyrics_ok.json new file mode 100644 index 00000000..c3a0864c --- /dev/null +++ b/subsonic-api/src/integrationTest/resources/get_lyrics_ok.json @@ -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" + } + } +} diff --git a/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIDefinition.kt b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIDefinition.kt index bf683a6b..6bc5fdf8 100644 --- a/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIDefinition.kt +++ b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIDefinition.kt @@ -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? = null, - @Query("songIndexToRemove") songIndexesToRemove: List? = null) : Call + @Query("songIndexToRemove") songIndexesToRemove: List? = null): Call @GET("getPodcasts.view") fun getPodcasts(@Query("includeEpisodes") includeEpisodes: Boolean? = null, - @Query("id") id: Long? = null) : Call + @Query("id") id: Long? = null): Call + + @GET("getLyrics.view") + fun getLyrics(@Query("artist") artist: String? = null, + @Query("title") title: String? = null): Call } diff --git a/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/Lyrics.kt b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/Lyrics.kt new file mode 100644 index 00000000..830104b0 --- /dev/null +++ b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/Lyrics.kt @@ -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 = "") diff --git a/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetLyricsResponse.kt b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetLyricsResponse.kt new file mode 100644 index 00000000..a2fe0a0a --- /dev/null +++ b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetLyricsResponse.kt @@ -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)