Add getArtists call.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2017-08-15 21:51:55 +02:00
parent b9f885b521
commit 84198d38c8
6 changed files with 119 additions and 8 deletions

View File

@ -164,17 +164,18 @@ class SubsonicAPIClientTest {
lastModified `should equal` 1491069027523
ignoredArticles `should equal` "The El La Los Las Le Les"
shortcutList `should equal` listOf(
Artist(889L, "podcasts", null),
Artist(890L, "audiobooks", null)
Artist(id = 889L, name = "podcasts"),
Artist(id = 890L, name = "audiobooks")
)
indexList `should equal` mutableListOf(
Index("A", listOf(
Artist(50L, "Ace Of Base", parseDate("2017-04-02T20:16:29.815Z")),
Artist(379L, "A Perfect Circle", null)
Artist(id = 50L, name = "Ace Of Base",
starred = parseDate("2017-04-02T20:16:29.815Z")),
Artist(id = 379L, name = "A Perfect Circle")
)),
Index("H", listOf(
Artist(299, "Haddaway", null),
Artist(297, "Halestorm", null)
Artist(id = 299, name = "Haddaway"),
Artist(id = 297, name = "Halestorm")
))
)
}
@ -271,6 +272,55 @@ class SubsonicAPIClientTest {
}
}
@Test
fun `Should parse get artists error response`() {
val response = checkErrorCallParsed { client.api.getArtists(null).execute() }
response.indexes `should not be` null
with(response.indexes) {
lastModified `should equal to` 0
ignoredArticles `should equal to` ""
indexList.size `should equal to` 0
shortcutList.size `should equal to` 0
}
}
@Test
fun `Should parse get artists ok reponse`() {
enqueueResponse("get_artists_ok.json")
val response = client.api.getArtists(null).execute()
assertResponseSuccessful(response)
with(response.body().indexes) {
lastModified `should equal to` 0L
ignoredArticles `should equal to` "The El La Los Las Le Les"
shortcutList `should equal` emptyList()
indexList.size `should equal to` 2
indexList `should equal` listOf(
Index(name = "A", artists = listOf(
Artist(id = 362L, name = "AC/DC", coverArt = "ar-362", albumCount = 2),
Artist(id = 254L, name = "Acceptance", coverArt = "ar-254", albumCount = 1)
)),
Index(name = "T", artists = listOf(
Artist(id = 516L, name = "Tangerine Dream", coverArt = "ar-516", albumCount = 1),
Artist(id = 242L, name = "Taproot", coverArt = "ar-242", albumCount = 2)
))
)
}
}
@Test
fun `Should pass param on query for get artists call`() {
enqueueResponse("get_artists_ok.json")
val musicFolderId = 101L
client.api.getArtists(musicFolderId).execute()
val request = mockWebServerRule.mockWebServer.takeRequest()
request.requestLine `should contain` "musicFolderId=$musicFolderId"
}
private fun enqueueResponse(resourceName: String) {
mockWebServerRule.mockWebServer.enqueue(MockResponse()
.setBody(loadJsonResponse(resourceName)))

View File

@ -0,0 +1,43 @@
{
"subsonic-response": {
"status": "ok",
"version": "1.15.0",
"artists": {
"ignoredArticles": "The El La Los Las Le Les",
"index": [
{
"name": "A",
"artist": [
{
"id": "362",
"name": "AC/DC",
"coverArt": "ar-362",
"albumCount": 2
},
{
"id": "254",
"name": "Acceptance",
"coverArt": "ar-254",
"albumCount": 1
}
]
}, {
"name": "T",
"artist": [
{
"id": "516",
"name": "Tangerine Dream",
"coverArt": "ar-516",
"albumCount": 1
},
{
"id": "242",
"name": "Taproot",
"coverArt": "ar-242",
"albumCount": 2
}
]
} ]
}
}
}

View File

@ -1,5 +1,6 @@
package org.moire.ultrasonic.api.subsonic
import org.moire.ultrasonic.api.subsonic.response.GetArtistsResponse
import org.moire.ultrasonic.api.subsonic.response.GetIndexesResponse
import org.moire.ultrasonic.api.subsonic.response.GetMusicDirectoryResponse
import org.moire.ultrasonic.api.subsonic.response.LicenseResponse
@ -30,4 +31,7 @@ interface SubsonicAPIDefinition {
@GET("getMusicDirectory.view")
fun getMusicDirectory(@Query("id") id: Long): Call<GetMusicDirectoryResponse>
@GET("getArtists.view")
fun getArtists(@Query("musicFolderId") musicFolderId: Long?): Call<GetArtistsResponse>
}

View File

@ -4,4 +4,6 @@ import java.util.Calendar
data class Artist(val id: Long = -1,
val name: String = "",
val starred: Calendar?)
val coverArt: String = "",
val albumCount: Int = 0,
val starred: Calendar? = null)

View File

@ -0,0 +1,12 @@
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.Indexes
class GetArtistsResponse(status: Status,
version: SubsonicAPIVersions,
error: SubsonicError?,
@JsonProperty("artists") val indexes: Indexes = Indexes()) :
SubsonicResponse(status, version, error)

View File

@ -82,7 +82,7 @@ class APIConverterTest {
MusicFolder(id, name)
private fun createArtist(id: Long = -1, name: String = "", starred: Calendar? = null): Artist
= Artist(id, name, starred)
= Artist(id = id, name = name, starred = starred)
private fun createIndex(name: String = "", artistList: List<Artist> = emptyList()): Index
= Index(name, artistList)